Gabriel1375 Posted March 17, 2017 Share Posted March 17, 2017 (edited) Hello, i need a help... I have an base system on my MTA DayZ Server, that works like that: it creates an col zone, then when a player that is not from the group hit the col zone it gets teleported... It's working fine but i need to add a function that i think its really simple but idk how... This is what i need: A function that when a member of the group enter the base it says how much vehicle it's on the base... A function that when a player try to enter with a vehicle, if the base have more than 15 vehicles on the zone, it teleport the player out of the base... Basically is this: A function that checks how much vehicle has in the base, and a function that teleport the player if he tries to get more than 15 vehicles in the base zone... Here is what i think it will look like: function checkVehicles(theElement) --local veh = getPedOccupiedVehicle(theElement) -- random variable from the ready resource that identify the veh player is using --local accName = getAccountName(getPlayerAccount(theElement)) -- idk why i put that in but... if ( getElementData ( theElement , "Group" ) == GroupName ) and functionThatChecksVehiclesOnTheBase < 15 then sendMsg(theElement, "Welcome Player") end elseif functionThatChecksVehiclesOnTheBase > 15 then setElementPosition( theElement, TeleportLocation[1], TeleportLocation[2], TeleportLocation[3]) end end addEventHandler("onColShapeHit", getRootElement(), checkVehicles) Thanks !!! Edited March 17, 2017 by Gabriel1375 Link to comment
Mr.Loki Posted March 17, 2017 Share Posted March 17, 2017 At line 2 make a check (getElementType) for "vehicle" so that it only works when vehicles hit it. remove line 2 and 3 that's commented. Use (getElementsWithinColShape) with "vehicle" as the second arg to return a table of all the vehicles in the colshape. So functionThatChecksVehiclesOnTheBase should look like: #getElementsWithinColShape(colShape,"vehicle") adding a # to a table counts it. Link to comment
NeXuS™ Posted March 17, 2017 Share Posted March 17, 2017 function checkVehicles(theElement) if ( getElementData ( theElement , "Group" ) == GroupName ) and #getElementsWithinColShape(source, "vehicle") < 15 then sendMsg(theElement, "Welcome Player") elseif #getElementsWithinColShape(source, "vehicle") > 15 then setElementPosition(theElement, TeleportLocation[1], TeleportLocation[2], TeleportLocation[3]) end end addEventHandler("onColShapeHit", getRootElement(), checkVehicles) Here is the code if you would not understand it. Link to comment
Gordon_G Posted March 17, 2017 Share Posted March 17, 2017 He'll never understand if you make everything for him just explain next time NeXus... 2 Link to comment
NeXuS™ Posted March 17, 2017 Share Posted March 17, 2017 Its our job to help on this forum, try not to be a moderator if you are not one. Thank you @Gordon_G. 1 Link to comment
Anubhav Posted March 17, 2017 Share Posted March 17, 2017 Job to help him, not to copy paste and write everything for him. The way you have to do this by making a colshape and using getElementsWithinColShape "vehicle" and then it s hould be done it is our duty to help him as long as he learns not blindly give codes all time 2 Link to comment
NeXuS™ Posted March 17, 2017 Share Posted March 17, 2017 I wont start a fight here, because this is a public-forum. But if he wanted to learn programming, he could do it already. You can easily learn programming by just looking at codes, and we can help the way we want. If I have time to just make a code for a guy who needs help, I'll do it. Thank ya @Anubhav. Link to comment
Mr.Loki Posted March 18, 2017 Share Posted March 18, 2017 @NeXuS™ Well probably he's new to scripting hence his post count is only 7. so I gave him some instructions to see what he could have done on his own and if not after a few tries, then I'd try to line by line explain it to him. Teach him to fish don't give him 1. Link to comment
NeXuS™ Posted March 18, 2017 Share Posted March 18, 2017 @Mr.Loki as I said, if he wanted to learn programming, he could have done it already. You can learn it by just looking at someone else's script, and I had time to just write a code for someone who is in need to help. ( And again, I won't start a fight here. ) Link to comment
pa3ck Posted March 18, 2017 Share Posted March 18, 2017 At least try to comment your code next time. Dont tell me your maths teacher solved all the equations for you without explaining. Link to comment
NeXuS™ Posted March 18, 2017 Share Posted March 18, 2017 @pa3ck If you want to learn sth. you'll read after it. Add a bit of challange, so he'll learn about the functions. Link to comment
Gabriel1375 Posted March 19, 2017 Author Share Posted March 19, 2017 12 hours ago, pa3ck said: At least try to comment your code next time. Dont tell me your maths teacher solved all the equations for you without explaining. I'm not really a newbie at scripting, just at LUA scripting, i dont know about the functions and things like this... But i understand scripts, my problem is at writing it... Like the code: function checkVehicles(theElement) if ( getElementData ( theElement , "Group" ) == GroupName ) and #getElementsWithinColShape(source, "vehicle") < 15 then sendMsg(theElement, "Welcome Player") elseif #getElementsWithinColShape(source, "vehicle") > 15 then setElementPosition(theElement, TeleportLocation[1], TeleportLocation[2], TeleportLocation[3]) end end addEventHandler("onColShapeHit", getRootElement(), checkVehicles) Means: Declare function named checkVehicles(hereistheplayer) if the group of the element its equal to groupname and the vehicles its minor of 15 then send message only to the player saying Welcome Player but if the vehicles is more than 15 then set element position, teleport locations array and end the code after this and end the function after set the event to happens only when hit the collision shape, element, and the function that will happens My biggest problems is at writing it, to memorize the function names you know... Link to comment
Mr.Loki Posted March 19, 2017 Share Posted March 19, 2017 11 hours ago, Gabriel1375 said: My biggest problems is at writing it, to memorize the function names you know... 1 Just use N++ or sublime autocomplete/syntax highlighter for the function names it helps a lot. function checkVehicles(theElement) -- Check if theElement is a vehicle. if getElementType(theElement) == "vehicle" then -- Get the driver of said vehicle. local driver = getVehicleController( theElement ) -- Check if he belongs to the group and get the count of current vehicles in colshape. if ( getElementData ( driver , "Group" ) == GroupName ) and #getElementsWithinColShape(source, "vehicle") > 15 then -- Sets the position of the player's vehicle. setElementPosition(veh, TeleportLocation[1], TeleportLocation[2], TeleportLocation[3]) else -- For each player in the vehicle... for _,plr in pairs (getVehicleOccupants( theElement )) do -- execute the sendMsg function. sendMsg(theElement, "Welcome Player") end end end end addEventHandler("onColShapeHit", root, checkVehicles) 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