2kristof2 Posted March 1, 2015 Share Posted March 1, 2015 Hey, I want to make a script which checks every 5 seconds if the player is not cheating. Only 3 vehicles are avaliable 522,411 and 470. Unfair person can easily get a plane or better car by using his admin panel but the script gotta close the door on it. Should i use following functions/events? getElementModelgetTickCount OnClientRender I tried something like that but it doesn't work: (checking every render) function noCheat ()if isPedInVehicle(localPlayer) then if vehicle == getPedOccupiedVehicle(localPlayer) then if id == getElementModel(vehicle) then if not id == 411 or id==522 or id==470 then blowVehicle(vehicle) end end end end end addEventHandler("onClientRender", getRootElement(), noCheat) Link to comment
Banex Posted March 1, 2015 Share Posted March 1, 2015 local allowed = {[411] = true,[522] = true, [470] = true} function noCheat() local vehicle = getPedOccupiedVehicle(localPlayer) if vehicle and not allowed[getElementModel(vehicle)] then blowVehicle(vehicle) end end setTimer(noCheat,5000,0) Link to comment
xeon17 Posted March 1, 2015 Share Posted March 1, 2015 Well , in this case a timer isn't necessary. My code will give a better result than Banex's local allowed = {[411] = true,[522] = true, [470] = true} addEventHandler("onVehicleEnter", root, function(thePlayer) if not allowed[getElementModel(source)] then destroyElement(source) end end) Link to comment
2kristof2 Posted March 1, 2015 Author Share Posted March 1, 2015 Thank you! The script is simple and effective. @Xeon~ Unfortunately your script doesn't work :c Link to comment
Ab-47 Posted March 1, 2015 Share Posted March 1, 2015 Thank you! The script is simple and effective.@Xeon~ Unfortunately your script doesn't work :c local allowed = {[411] = true,[522] = true, [470] = true} addEventHandler("onVehicleEnter", root, function(thePlayer) local veh = getPedOccupiedVehicle(thePlayer) if not allowed[getElementModel(veh)] then destroyElement(veh) end end) Link to comment
xeon17 Posted March 1, 2015 Share Posted March 1, 2015 What do you mean my script doesn't work. I've tested and it works excelent. Are you sure the script is server side on meta.XML?' Link to comment
vx89 Posted March 1, 2015 Share Posted March 1, 2015 Xeon's solution is the correct one. However, before destroying the vehicle (if you even want to) call cancelEvent() so that the player just cant get inside it. I'm not 100% sure if onVehicleEnter is called when somehow switching vehicle (not actually entering it). Link to comment
WhoAmI Posted March 1, 2015 Share Posted March 1, 2015 Use onVehicleStartEnter instead. Link to comment
xeon17 Posted March 1, 2015 Share Posted March 1, 2015 Xeon's solution is the correct one. However, before destroying the vehicle (if you even want to) call cancelEvent() so that the player just cant get inside it.I'm not 100% sure if onVehicleEnter is called when somehow switching vehicle (not actually entering it). The event onVehicleEnter can't be canceled , my code works. I'm pretty sure he did something wrong in meta. Use onVehicleStartEnter instead. Well , this event will only trigger when the player try to enter in the vehicle , not when warped in the vehicle by the admin panel. Link to comment
Ab-47 Posted March 2, 2015 Share Posted March 2, 2015 Then Xeon's code is wrong if you want to prevent admins from spawning vehicles. When they're spawned directly into a vehicle the event "onVehicleEnter" will not be called. Banex's code looks great and more neater, instead of "blowVehicle" use "destroyElement" and there's the solution. Link to comment
xeon17 Posted March 2, 2015 Share Posted March 2, 2015 The event onVehicleEnter will be called when a player warped into a vehicle,how i know? I've tested my code and it works. If you still have doubts please test the code and i think using a timer in this case is stupid since the event onVehicleEnter exists. Link to comment
Anubhav Posted March 2, 2015 Share Posted March 2, 2015 XeoN code is the best. Why to check every 5 seconds? A admin can change his cars back and back by using binds. Someone use your brains, no offence. Xeon's will check whenever player enters a car. So please, think before posting. 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