xScatta Posted September 1, 2013 Share Posted September 1, 2013 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. Link to comment
TAPL Posted September 1, 2013 Share Posted September 1, 2013 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) Link to comment
xScatta Posted September 1, 2013 Author Share Posted September 1, 2013 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... Link to comment
isa_Khamdan Posted September 2, 2013 Share Posted September 2, 2013 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. Link to comment
denny199 Posted September 3, 2013 Share Posted September 3, 2013 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! 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