View Issue Details

IDProjectCategoryView StatusLast Update
0009754New Feature RequestsGeneralpublic2018-09-22 18:59
Reporterxnikoxd Assigned To 
Status newResolutionopen 
Summary0009754: getElementsWithinColShape() doesn't always get the right position

Hi, I was making an edition to a system I make some time back, this system created colSpheres arround the vehicle so you can open and close your trunk. It worked fine, no problems at all, I created the ColSphere on 0 0 0 then attach it to the vehicle and everything worked fine.

The edition I make was creating the colSphere only when you are close and you use an /cmd, and the problems being, for some reason the function getElementsWithinColShape() thinked that all the time the colSphere was under x=0 y=0 and z=0 position, when it wasnt. I tried using timers but it didnt work, the only solution i had was that when the colSphere was on the right position, delete it and create it again, then for some reason it worked.

It seems like getElementsWithinColShape() saves the original position and after X time it updates, for some reason. I will get the code below.

Steps To Reproduce

--- CODE ---

colMaletero = {}
colEsferaMaletero = {}
function maletero(thePlayer)
local x, y, z = getElementPosition(thePlayer)
local dim = getElementDimension(thePlayer)
local int = getElementInterior(thePlayer)

colMaletero[thePlayer] = createColSphere(x, y, z, 5)
setElementInterior(colMaletero[thePlayer], int)
setElementDimension(colMaletero[thePlayer], dim)

local vehiculos = getElementsWithinColShape(colMaletero[thePlayer], "vehicle")
for k,veh in ipairs(vehiculos) do -- This checks every vehicle that is close to the player
    if veh and (veh ~= nil) and (getElementType(veh) == "vehicle") then -- This checks if its really an vehicle
        if (colEsferaMaletero[veh]) then
            colEsferaMaletero[veh] = nil
        local x, y, z = getElementPosition(veh)
        local pos = getVehicleHandlingProperty(veh, "centerOfMass")
        colEsferaMaletero[veh] = createColSphere(0, 0, 0, 2.5)
        attachElements(colEsferaMaletero[veh], veh, pos[1], pos[2]-2.5, pos[3])

        outputChatBox("x = "..x.." | y = "..y.." | z = "..z.." (veh)", thePlayer)

        --[[local x, y, z = getElementPosition(colEsferaMaletero[veh]) -- If you delete this comment, the script would work
        colEsferaMaletero[veh] = createColSphere(x, y, z, 2.5)]]

        if colEsferaMaletero[veh] then -- If there is an sphere created then
            setTimer(function() -- This timer was created to check if it was a delay problem, it wasnt
                players = getElementsWithinColShape(colEsferaMaletero[veh], "player") -- Gets all the players inside the sphere

                if players and #players > 0 then -- If there are players then do fancy stuff
                    for k,plr in ipairs(players) do
                        x, y, z = getElementPosition(colEsferaMaletero[veh])
                        outputChatBox("x = "..x.." | y = "..y.." | z = "..z.." (2)", thePlayer)
                        if (plr ~= nil) and (plr == thePlayer) then
                            if (getElementData(veh, "maletero")) then
                                setVehicleDoorOpenRatio(veh, 1, 0)
                                setElementData(veh, "maletero", false)
                                triggerClientEvent(root, "sonidoMaletero2", veh)
                                if (getElementData(veh, "dueno") == plr) then
                                    setVehicleDoorOpenRatio(veh, 1, 1)
                                    setElementData(veh, "maletero", true)
                                    triggerClientEvent(root, "sonidoMaletero", veh)
                                    if not (getElementData(thePlayer, "msg-mal")) then
                                        --outputChatBox("#FF3232[MALETERO] #FFFFFFDebes ser el dueño del vehículo para abrir el maletero.", thePlayer, 0,0,0,true)
                            if isElement(plr) then
                                outputChatBox("#FF3232Error: register "..getPlayerName(plr), thePlayer, 0,0,0,true) -- This thing started triggering when someone logged and i ussed the command, then i checked the other player position and it was 0, 0, 0, but the Sphere position was like 1000 units more south.
                                outputChatBox("#FF3232Error: "..#players.." jugadores", thePlayer, 0,0,0,true)

                colEsferaMaletero[veh] = nil -- This deletes it
            end, 250, 1)

addCommandHandler("maletero", maletero)

Additional Information
  • It only happend to me when I used it on a for loop and i created the colSphere inside the for loop, not when the colSphere was created first then on other function I tried to check if it is on the right position.

  • The for loop was created using a table from another getElementsWithinColShape()

TagsNo tags attached.



2017-11-03 22:04

viewer   ~~0026260

For some reason the code doesn't appear right, i just pastebinned it

Issue History

Date Modified Username Field Change