maximumdrive Posted September 15, 2018 Share Posted September 15, 2018 Hi all, my question is so close to be "stupid/funny", but I wasted several hours to fight those lines. Here is a clientside function handling an event. Element's model is viewed to *debug* if the vehicle comes from server. The problem is that the vehicle exists, model also does, but the length of *sincerely beloved* getVehicleComponents(veh) is always "0"! It only can type component's list when the function is "bouned" on a key which has to be pushed for tens of times to meet a success! The "central surprise" is that the usage example of getVehicleComponents is taken from MTA Wiki and it fails! I've found some reports, so the components are in some way cached by MTA/GTA-single, so it could influence this simple code, but I can't even imagine what is the problem. I'm totally discouraged by such a mysticism and have no ideas about causes. Please, help. function tunBaseComp(veh) outputChatBox(tostring(getElementModel(veh))) local getComponent = getVehicleComponents(veh) if veh then for k in pairs(getComponent) do outputChatBox(k) end end end Link to comment
MIKI785 Posted September 16, 2018 Share Posted September 16, 2018 So this function is triggered by an event? Because that works fine for me... Code i've used: Server: addCommandHandler("gvc", function (player) triggerClientEvent(player, "onClientGetVehicleComp", player, getPedOccupiedVehicle(player)) end) Client: addEvent("onClientGetVehicleComp", true) addEventHandler("onClientGetVehicleComp", localPlayer, function (veh) outputChatBox(tostring(getElementModel(veh))) local getComponent = getVehicleComponents(veh) if veh then for k in pairs(getComponent) do outputChatBox(k) end end end) Link to comment
maximumdrive Posted September 17, 2018 Author Share Posted September 17, 2018 (edited) On 16/09/2018 at 18:26, MIKI785 said: Server: addCommandHandler("gvc", function (player) triggerClientEvent(player, "onClientGetVehicleComp", player, getPedOccupiedVehicle(player)) end) Oh, now it's clear: the problem is, that the getPedOccupiedVehicle() works really fine, but when I try to create another vehicle it doesn't work for a newly-created serverside vehicle. But it creates, it's model successfully outputs to chatbox, but getVehicleComponents()'s length is "0"... The clientside code is the same as yours now. E.g. (Server): addCommandHandler("gvc", function (player) local pVeh = getPedOccupiedVehicle(player) local seat = getPedOccupiedVehicleSeat(player) if pVeh and seat == 0 then local px, py, pz = getElementPosition(pVeh) local px, py, pz = getElementRotation(pVeh) local v = createVehicle(405, px, py, pz-20, rx, ry, rz) setElementFrozen(v, true) setElementCollisionsEnabled(v, false) setVehicleLocked(v, true) attachElements(v, pVeh, 0, 0, -6, 0, 0, 0) triggerClientEvent(player, "onClientGetVehicleComp", player, v) end end) Edited September 17, 2018 by maximumdrive Link to comment
MIKI785 Posted September 18, 2018 Share Posted September 18, 2018 I don't know, maybe it has something to do with sync? Try putting it in a timer to have it execute with a bit of a delay after creating the vehicle. Link to comment
maximumdrive Posted September 18, 2018 Author Share Posted September 18, 2018 I've already tried that on client, but perhaps it could be successful somewhere on server, thanks for idea. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now