ertlflorian1 Posted March 12, 2013 Share 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? Link to comment
denny199 Posted March 12, 2013 Share Posted March 12, 2013 cars = 0 addEventHandler ("onVehicleEnter",root, function ( thePlayer, seat, jacked ) cars = cars + 1 outputChatBox (tonumber(cars)) end) Link to comment
Moderators IIYAMA Posted March 12, 2013 Moderators Share 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. Link to comment
ertlflorian1 Posted March 12, 2013 Author Share 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? Link to comment
Moderators IIYAMA Posted March 12, 2013 Moderators Share 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 Link to comment
ertlflorian1 Posted March 12, 2013 Author Share Posted March 12, 2013 Else it will shown ass an bad word ^^ Link to comment
denny199 Posted March 12, 2013 Share 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 ( ... ) Link to comment
Anderl Posted March 12, 2013 Share 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. Link to comment
ertlflorian1 Posted March 12, 2013 Author Share Posted March 12, 2013 Thank you so much 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