Jump to content

Element Data


myonlake

Recommended Posts

Hello again,

I have a problem with issuing someone a car key. It seems to work just fine. I can give him a key, it saves the key, everything is normal. Now, when he goes inside the car, which has the same key than the player, he still can't drive the car.

Don't take notice about the findPlayer() thing, I've got a seperate script for it and it works.

I gave the player a key: "five", the vehicle has "five" too...

function issueKey(player, cmd, name, key) 
    local target = findPlayer(name, player) 
     
    if hasObjectPermissionTo(player, "command.ban") then 
        if target then 
            if key then 
                setElementData(target, "sfserver.carkey", key) 
                outputChatBox("* " .. getPlayerName(player) .. " issued you a car key (ID: " .. key .. ")", target, 0, 255, 0, false) 
                outputChatBox("* You have issued " .. getPlayerName(target) .. " a car key (ID: " .. key .. ")", player, 0, 255, 0, false) 
            else 
                outputChatBox("* Syntax: /issuekey ", player, 220, 220, 0, false) 
            end 
        else 
            outputChatBox("* No player found.", player, 255, 0, 0, false) 
        end 
    else 
        outputChatBox("* You must be an administrator to use this command.", player, 255, 0, 0, false) 
    end 
end 
addCommandHandler("issuekey", issueKey) 
  
function cars() 
    local car_1 = createVehicle(587, -2270, 2392, 5) 
    setElementData(car_1, "sfserver.carkey", five) 
end 
addEventHandler("onResourceStart", root, cars) 
  
function vehicleEnterKey(thePlayer) 
    local theVehicle = getPedOccupiedVehicle(thePlayer) 
    local boom1 = getElementData(thePlayer, "sfserver.carkey") 
    local boom2 = getElementData(theVehicle, "sfserver.carkey") 
     
    if boom1 == boom2 then 
    else 
        outputChatBox("* You don't own this vehicle!", thePlayer, 255, 0, 0, false) 
        removePedFromVehicle(thePlayer) 
    end 
end 
addEventHandler("onVehicleEnter", rElement, vehicleEnterKey) 
 
Edited by myonlake
Link to comment

attach onVehicleEnter to rElement? you sure that's defined?

setElementData(car_1, "sfserver.carkey", five)

in this line, five is probably a nil variable, maybe you mean "five" as a string

and btw, only ONE car will have this carkey assigned, and that is the car that is created onResourceStart (Hope you knew this)

Link to comment
Yes, it affects every car..

Because it will always go on the ELSE removePed blah blah

because boom1 is never equal to boom2

because like I said, boom2 is NIL and boom1 is "five"

the fix:

setElementData(car_1, "sfserver.carkey", "five")

Aaaaah... :lol:

heh, thank you ;)

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