adithegman Posted November 25, 2016 Share Posted November 25, 2016 (edited) Hey! I just started scripting in LUA and I need some help... I have a very good knowledge of the C languages (mainly C++) but I'm having trouble understanding a few things. What I want to do is create a timer (x = setTimer(...) ) for every vehicle on the server... and I have no idea how to do it. I know it must be tied to tables, I tried using tables but I failed... I only just started on LUA today so I'm a pretty big noob NOTE: This account is not MINE so disregard my other posts Edited November 25, 2016 by adithegman Link to comment
iPrestege Posted November 25, 2016 Share Posted November 25, 2016 You can get all the vehicles in the server using getElementsByType make a loop and get all the vehicles in a table. @adithegman Link to comment
LoPollo Posted November 25, 2016 Share Posted November 25, 2016 Is really needed binding every vehicle to a timer? Did you check the events? Most things can be achieved with events, and most people (me at least) don't like timers A note on what @iPrestege said: also store the created timers on a table so you can manage them. Don't store only vehicles. The best way would be creating a table for every pair of vehicle-timer, so for every vehicle you can easily acces its timer. Or use the vehicle as key/index Spoiler example of that table: local thingsTable1 = {} local thingsTable2 = {} function callMeOnStart() for _,theVehicle in pairs(getElementsByType( "vehicle" )) do --pair of vehicle+timer thingsTable1[#thingsTable1+1] = {theVehicle, setTimer(function(theVeh) end, 60000, 0, theVehicle)} --or even better, use the veh as index thingsTable2.theVehicle = setTimer(function(theVeh) end, 60000, 0, theVehicle) -- equivalent: thingsTable2[theVehicle] = setTimer(function(theVeh) end, 60000, 0, theVehicle) end end Link to comment
adithegman Posted November 25, 2016 Author Share Posted November 25, 2016 9 minutes ago, LoPollo said: Is really needed binding every vehicle to a timer? Did you check the events? Most things can be achieved with events, and most people (me at least) don't like timers A note on what @iPrestege said: also store the created timers on a table so you can manage them. Don't store only vehicles. The best way would be creating a table for every pair of vehicle-timer, so for every vehicle you can easily acces its timer. Or use the vehicle as key/index Reveal hidden contents example of that table: local thingsTable1 = {} local thingsTable2 = {} function callMeOnStart() for _,theVehicle in pairs(getElementsByType( "vehicle" )) do --pair of vehicle+timer thingsTable1[#thingsTable1+1] = {theVehicle, setTimer(function(theVeh) end, 60000, 0, theVehicle)} --or even better, use the veh as index thingsTable2.theVehicle = setTimer(function(theVeh) end, 60000, 0, theVehicle) -- equivalent: thingsTable2[theVehicle] = setTimer(function(theVeh) end, 60000, 0, theVehicle) end end Thanks for the example man! I think I got the idea... And BTW, I don't really need a timer for every vehicle, It is something close to that but a bit more complicated to explain so I just asked that question hoping that it will implicitly answer my ohter unknowings and fortunately it did. Thanks for the help! Link to comment
LoPollo Posted November 25, 2016 Share Posted November 25, 2016 Good! Then good luck with scripting! 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