ertlflorian1 Posted March 12, 2013 Posted March 12, 2013 I have an little problem with this code! local cars = 0 function onenter (player) local cars = cars+1 outputChatBox (cars, root) end addEventHandler ("onVehicleEnter",root,onenter) I will when a player Enters a Vehicle that cars will be increase at +1?
denny199 Posted March 12, 2013 Posted March 12, 2013 cars = 0 addEventHandler ("onVehicleEnter",root, function ( thePlayer, seat, jacked ) cars = cars + 1 outputChatBox (tonumber(cars)) end) Sometimes I dream about cheese
Moderators IIYAMA Posted March 12, 2013 Moderators Posted March 12, 2013 The problem with your script was that local data won't exit the function. local cars = 0 function onenter (player) cars = cars+1 --local cars = cars+1[/color] outputChatBox (cars, root) end addEventHandler ("onVehicleEnter",root,onenter) local A = 0 if A then > local A = A +1 -- local will not exit > outputChatBox(A) -- in the chatbox you will see "1" because it is in the function.(local) end outputChatBox(A) -- in the chatbox you will see "0" Try the function/event of denny, it is the best/fastest sample. Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
ertlflorian1 Posted March 12, 2013 Author Posted March 12, 2013 Works thank now I have another querstion When somebody is sitting on a f.aggio from the table noobf.aggios respawnVehicle he will be warped to the spawnpoint how i can make that only the f.aggios which are empty will be respawned? Code: local noobf.aggios = { [f.aggio1]=true, [f.aggio2]=true, [f.aggio3]=true, ... } function respawnF.aggiosAdmin () for allf.aggios, index in pairs ( noobf.aggios ) do respawnVehicle (allf.aggios) end end addCommandHandler ("f.agg", respawnF.aggiosAdmin) Sorry for "." it will be identified as an cuss?
Moderators IIYAMA Posted March 12, 2013 Moderators Posted March 12, 2013 hhhhmmm first check your syntax. local noobf.aggios = { f.aggio1, f.aggio2, f.aggio3 --... } for index, allf.aggios in pairs (noobf.aggios)do -- index is left, not right. if isElement (allf.aggios) then -- some vehicles can be delete by adminpannel(or something else) you will get errors/warnings. Check with isElement(). respawnVehicle (allf.aggios) end end I will not recommend you to use "." between normal value's, but I leave the script for what it is. and no I don't know what you mean. Check if people are inside: https://wiki.multitheftauto.com/wiki/Ge ... eOccupants Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
ertlflorian1 Posted March 12, 2013 Author Posted March 12, 2013 Else it will shown ass an bad word ^^
denny199 Posted March 12, 2013 Posted March 12, 2013 Better, use getVehicleOccupant Then it will look something like this: local noobf.aggios = { [f.aggio1]=true, [f.aggio2]=true, [f.aggio3]=true, ... } function respawnF.aggiosAdmin () for allf.aggios, index in pairs ( noobf.aggios ) do driver = getVehicleOccupant ( allf.aggios ) if not ( driver ) then respawnVehicle (allf.aggios) end end end addCommandHandler ("f.agg", respawnF.aggiosAdmin) (BTW, why not store the vehicles which are created in a table, it's much easier.) for example: dannycar = {} dannycar[ playerelement ] = createVehicle ( ... ) Sometimes I dream about cheese
Anderl Posted March 12, 2013 Posted March 12, 2013 cars = 0 addEventHandler ("onVehicleEnter",root, function ( thePlayer, seat, jacked ) cars = cars + 1 outputChatBox (tonumber(cars)) end) Use local variables instead whenever possible. "[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007
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