LabiVila Posted September 5, 2016 Share Posted September 5, 2016 (edited) Hello, can you help me fix this part? It's the 'warpPedIntoVehicle', every time I use this I get 'Network Trouble' and I don't know why, for a, b in ipairs (getElementsByType ("player")) do local mySpawn = math.random (1, #mapSpawns) for c, d in ipairs (mapSpawns) do if (c == mySpawn) then local veh = createVehicle (d.id, d.x, d.y, d.z) if veh then outputDebugString ("created veh") end warpPedIntoVehicle (b, veh) setCameraTarget (b, b) fadeCamera (b, true) end end end mapSpawns is fine, I can output any value of it. And I as well get the 'created veh' from outputDebugString. Dunno what's wrong... Edited September 5, 2016 by LabiVila Link to comment
qaisjp Posted September 5, 2016 Share Posted September 5, 2016 How about this code? Instead of looping through the "mapSpawns" table to find the spawn that has the correct key, you can directly access the table. See line 3 below. for _, player in ipairs (getElementsByType ("player")) do local spawnIndex = math.random (1, #mapSpawns) local spawn = mapSpawns[spawnIndex] local veh = createVehicle (spawn.id, spawn.x, spawn.y, spawn.z) if veh then outputDebugString ("created veh") end warpPedIntoVehicle (player, veh) setCameraTarget (player, player) fadeCamera (player, true) end It's also a good idea to name variables something more informative, so I have made this change for you too. Depending on how many items you have in `mapSpawns`, and how many players you have, this could have been the source of your issue. It's unlikely this was the actual cause of the network trouble, but nevertheless, give it a go and get back to us. 1 Link to comment
LabiVila Posted September 5, 2016 Author Share Posted September 5, 2016 I just solved that by setting a timer to warpPedIntoVehicle (100 ms). I don't know why but somehow it's solved. Does it matter that I call the functions with: function () without event handlers? Maybe that messed me up earlier. I'll definitely change it to the style your style tho Link to comment
qaisjp Posted September 5, 2016 Share Posted September 5, 2016 3 minutes ago, LabiVila said: Does it matter that I call the functions with: function () without event handlers? It is only necessary to use event handlers with function variables if you plan to use removeEventHandler on that event later on. This will not actually remove the event: -- Add an event addEventHandler("onPlayerJoin", root, function() outputChatBox("Player joined!") end ) -- Now to remove the event (WILL NOT ACTUALLY REMOVE THE EVENT) removeEventHandler("onPlayerJoin", root, function() outputChatBox("Player joined!") end ) It does not work because even though both functions contain the same code, they are technically different functions. This will remove the event, however: function announceJoin() outputChatBox("Player joined!") end -- Add an event addEventHandler("onPlayerJoin", root, announceJoin) -- Now to remove the event removeEventHandler("onPlayerJoin", root, announceJoin) 1 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