Description | 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
destroyElement(colEsferaMaletero[veh])
colEsferaMaletero[veh] = nil
end
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
destroyElement(colEsferaMaletero[veh])
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)
else
if (getElementData(veh, "dueno") == plr) then
setVehicleDoorOpenRatio(veh, 1, 1)
setElementData(veh, "maletero", true)
triggerClientEvent(root, "sonidoMaletero", veh)
else
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)
end
end
end
else
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.
else
outputChatBox("#FF3232Error: "..#players.." jugadores", thePlayer, 0,0,0,true)
end
end
end
end
destroyElement(colEsferaMaletero[veh])
colEsferaMaletero[veh] = nil -- This deletes it
end, 250, 1)
end
end
end
end
addCommandHandler("maletero", maletero) |
---|