myonlake Posted October 9, 2011 Share Posted October 9, 2011 (edited) 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 May 30, 2019 by myonlake Link to comment
BinSlayer1 Posted October 9, 2011 Share Posted October 9, 2011 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
myonlake Posted October 9, 2011 Author Share Posted October 9, 2011 (edited) I have rElement defined like this earlier in the script: local rElement = getRootElement() Aww, :O, I just saw that this script effects on EVERY car. "five" is the thing I will put here: /issuekey playername five Edited May 30, 2019 by myonlake Link to comment
BinSlayer1 Posted October 9, 2011 Share Posted October 9, 2011 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") Link to comment
myonlake Posted October 9, 2011 Author Share Posted October 9, 2011 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... heh, thank you Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now