Jump to content

need help on police only


arris

Recommended Posts

Hi i have this code but it doesn't work and it doesn't even come up with errors can someone help me

local policevehicles = { [407]=true, [416]=true, [425]=true, [427]=true, [428]=true, [432]=true, [433]=true, [470]=true, [490]=true, [523]=true, [528]=true, [544]=true, [596]=true, [597]=true, [598]=true, [599]=true, [601]=true } 
local policeskins = { [280]=true, [281]=true, [282]=true, [283]=true, [284]=true, [285]=true, [286]=true, [287]=true, [288]=true }  
function enterVehicle ( theVehicle, seat, jacked )  
    local skinID = getPlayerSkin ( source ) 
    local vehID = getVehicleID ( theVehicle )       
    if policevehicles[vehID] and not policeskins[skinID] then  
        removePlayerFromVehicle ( source ) 
        outputChatBox ( "Only someones name can enter police car!", source ) 
    end 
end 
addEventHandler ( "onPlayerEnterVehicle", getRootElement(), enterVehicle  

)

Edited by Guest
Link to comment

im pretty new to scripting myself but i can see a few errors

local polecvehicles = { [407]=true, [416]=true, [425]=true, [427]=true, [428]=true, [432]=true, [433]=true, [470]=true, [490]=true, [523]=true, [528]=true, [544]=true, [596]=true, [597]=true, [598]=true, [599]=true, [601]=true }

i think this should just be the number and no local so like this --->

polecvehicles = { 407, 416, 425, etc. } 

and same for policeskins ---->

policeskins = { 280, 281, 282, etc. } 

if your using the nightly 1.0 version of MTA i dont think getVehicleID works anymore ( pretty sure its getElementID )

you would need to use getPedOccupiedVehicle first though ( once again only if using nightly 1.0 MTA. If its DP2.3 getVehicleID is fine )

if policevehicles[vehID] and not policeskins[skinID] then

i think this should be

if vehID == "policevehicles" and skinID ~= "policeskins" then 

do the remove player from vehicle ( i havent used this command before so id have to check wiki for exact syntax )

u will also need to put in what to do if the player is a police

obviously this is not a complete function but if u can tell me what version u are using i may be able to help a bit more

But please remember im pretty new to scripting myself so my answers may not be perfect :D

Link to comment

thank you for the info im using mta dp 2.3 deathmatch. The thing im trying to do is when a police man with the skin police enters the car he stay in it but if the person doesn't have the police skin he gets kick out of the car

Link to comment

unfortunately like i said im pretty new to scripting but i will try and write you a working function for this but it may take a while :)

the people on this forum are very helpful though so im sure somebody will give u a hand

if u have a look at the scripts in the BROPH and FR and FREEROAM resources every thing u need is there if the examples on the wiki dont help

thats how i picked up most of what i know just by comparing those scripts and the wiki examples ( and a lot of trial and error and a lot more help from the forums )

i wish u luck and will post whatever i can come up with :wink:

Link to comment

Heavyair, no you were wrong.

randomtable = {["key"] = "value"} means that

randomtable["key"] == "value"

Which means that if he defines randomtable[111] = true somewhere, then all he has to do is try if randomtable[vehicleID] is true. Eg he is doing it right there

Only mistake I could find at the moment is that he's got the event name wrong

It's "onPlayerVehicleEnter" not "onPlayerEnterVehicle"

Link to comment

You need to debug the script. Go step by step where the code goes and try to find out why it doesn't work. The previous code looked ok and your current code probably too. The thing is that when code looks fine and you get no error messages you need to trace what cause the problem by printing some text to chatbox, console or debug window. For instance, AFTER you getPlayerSkin, use outputChatBox( tostring( skinID ) ) to find out if the skinID returned a value (as you expected), then AFTER getVehicleID output some text what vehID is (the same way with outputChatBox or any other output functions).

Hope you will try to debug it yourself.

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