Jump to content

OnClientRender, getTickCount, getElementModel..


Recommended Posts

Posted

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)

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

jIcd9sc.png

Not worry about the future. Very soon it will come.

Posted

 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) 

A unique GangWar gamemode waiting for you!
Click here for more information.

560x95_FFFFFF_FF9900_000000_000000.png

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

And now Aurora is back again, pm for more info.

Ex. Lead dev & L6 Staff at AUR, NGC, MTA RP & SAA.

Ex. Developer at Community of Social Gamers - CSG

Ex Founder of International Gaming Community - IGC and Union of Individual Players- UIP

9o6E8.png Ab-47

Posted

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

A unique GangWar gamemode waiting for you!
Click here for more information.

560x95_FFFFFF_FF9900_000000_000000.png

Posted

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

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

A unique GangWar gamemode waiting for you!
Click here for more information.

560x95_FFFFFF_FF9900_000000_000000.png

Posted

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.

And now Aurora is back again, pm for more info.

Ex. Lead dev & L6 Staff at AUR, NGC, MTA RP & SAA.

Ex. Developer at Community of Social Gamers - CSG

Ex Founder of International Gaming Community - IGC and Union of Individual Players- UIP

9o6E8.png Ab-47

Posted

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.

A unique GangWar gamemode waiting for you!
Click here for more information.

560x95_FFFFFF_FF9900_000000_000000.png

Posted

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.

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