Jump to content

OnClientRender, getTickCount, getElementModel..


Recommended Posts

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?

getElementModel

getTickCount

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
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

 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
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

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
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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...