Jump to content

Car Ownership Script Problem.


xScatta

Recommended Posts

Posted

Hey guys my code here.

names = {} 
vehicles ={} 
function carown(playerSource,vehicle) 
    playerName = getPlayerName(playerSource) 
    names[playerSource] = getPlayerName(playerSource) 
    x, y, z = getElementPosition(playerSource) 
    vehicles[vehicle] = createVehicle(411,x,y+2,z) 
    setElementID(vehicles[vehicle],"abc") 
end 
  
function save(playerSource,vehicle) 
    if getElementModel(source)==411 
        then if seat==0  
        then if getElementID(source)=="abc" then if getPlayerName(playerSource)==names[playerSource] then 
        setVehicleEngineState(vehicles[vehicle],true) else outputChatBox("Only "..names[playerSource].." can drive this vehicle.",playerSource) 
        setVehicleEngineState(vehicles[vehicle],false) 
        end 
    end 
end 
end 
end 
  
addCommandHandler("vehicle",carown) 
addEventHandler("onVehicleEnter",getRootElement(),save) 

Error is here because if i have nick other than allowed i still can drive the car.

It's fine to celebrate success but it is more important to heed the lessons of failure.

Posted

I'm not sure how you want it to look so i tried to make it similar to your code.

vehicle ={} 
names = {} 
  
addCommandHandler("vehicle", 
function(player) 
    local x, y, z = getElementPosition(player) 
    vehicle[player] = createVehicle(411, x, y+2, z) 
    names[vehicle[player]] = getPlayerName(player) 
    setElementID(vehicle[player], "abc") 
end) 
  
addEventHandler("onVehicleEnter", root, 
function(player, seat) 
    if getElementID(source)== "abc" and getElementModel(source) == 411 and seat == 0 then 
        if vehicle[player] == source then 
            setVehicleEngineState(source, true) 
        else  
            outputChatBox("Only "..names[source].." can drive this vehicle.", player) 
            setVehicleEngineState(source, false) 
        end 
    end 
end) 

CiTLh.png
Posted

Some error there because when i have nick xScatta then use /vehicle is it working but when i change name to xScattax and /vehicle its working too but when i rename my nick to xScatta again then i cannot drive xScatta car...

It's fine to celebrate success but it is more important to heed the lessons of failure.

Posted
Some error there because when i have nick xScatta then use /vehicle is it working but when i change name to xScattax and /vehicle its working too but when i rename my nick to xScatta again then i cannot drive xScatta car...

Use player serial instead of player name.

350x20_FFFFFF_FFFFFF_000000_000000.png
Posted

You can always use elementdata storing on the vehicle, like this:

setElementData ( vehicleElement, "car:owner1", getPlayerSerial ( playerElement ) ) 
setElementData ( vehicleElement, "car:owner2", getPlayerSerial ( playerElement ) ) 
setElementData ( vehicleElement, "car:owner3", getPlayerSerial ( playerElement ) ) 
  
--etc. 

For chekking:

local serial = getPlayerSerial(playerElement) 
if not (serial == getElementData(vehicleElement, "car:owner1") or not (serial == vehicleElement, "car:owner2") or  not (serial == vehicleElement, "car:owner3") then 
--excecute 
end 
  

Or if you prefer tables:

local owner1 = {} 
local owner2 = {} 
local owner3 = {} 
--etc. 
  
owner1[vehicleElement] = getPlayerSerial(playerElement) 
owner2[vehicleElement] = getPlayerSerial(playerElement) 
owner3[vehicleElement] = getPlayerSerial(playerElement) 
--etc. 
  

and then for chekking:

local serial = getPlayerSerial(playerElement) 
if not (serial == owner1[vehicleElement]) or not (serial == owner2[vehicleElement]) or  not (serial == owner3[vehicleElement]) then 
--excecute 
end 
  

Good luck!

Sometimes I dream about cheese

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