myonlake Posted October 8, 2011 Share Posted October 8, 2011 (edited) Hello, I am just thinking that is it possible to make many cars via a command, then giving them all a different name. When I enter the car, I need to have the correct key for it. I have tried elementData, but it seems impossible, because... I have only one createVehicle. I dunno. function createVehicle(thePlayer, cmd, id) local x, y, z = getElementPosition(thePlayer) if id then createVehicle(id, x, y, z) setElementData(whathere, "server.key", math.random(0, 1000)) setElementData(thePlayer, "server.key", getElementData(whathere, "server.key")) outputChatBox(getElementData(whathere, "server.key") .. " is the ID of the vehicle.", thePlayer, 255, 255, 255, false) else outputChatBox("Syntax: /cv ", thePlayer, 220, 220, 0, false) end end addCommandHandler("cv", createVehicle) function enterVehicle(thePlayer) local theVehicle = getPedOccupiedVehicle(thePlayer) if not getElementData(whathere, "server.key") == getElementData(thePlayer, "server.key") then outputChatBox("Incorrect key", thePlayer, 255, 0, 0, false) end end addEventHandler("onVehicleEnter", getRootElement(), enterVehicle) Edited May 30, 2019 by myonlake Link to comment
JR10 Posted October 8, 2011 Share Posted October 8, 2011 What do you mean? Creating multiple vehicles is with multiple createVehicle, preferably a loop. Post your trial? Link to comment
myonlake Posted October 8, 2011 Author Share Posted October 8, 2011 (edited) What do you mean?Creating multiple vehicles is with multiple createVehicle, preferably a loop. Post your trial? I am trying to do a vehicle key script. You spawn a vehicle, it has a key that you have too, if you don't have the same key, you won't be able to enter the vehicle, there is an example below, I didn't do the lock thing yet.. function createVehicle(thePlayer, cmd, id) local x, y, z = getElementPosition(thePlayer) if id then createVehicle(id, x, y, z) setElementData(theVehicle, "server.key", math.random(0, 1000)) setElementData(thePlayer, "server.key", getElementData(whathere, "server.key")) outputChatBox(getElementData(whathere, "server.key") .. " is the ID of the vehicle.", thePlayer, 255, 255, 255, false) else outputChatBox("Syntax: /cv ", thePlayer, 220, 220, 0, false) end end addCommandHandler("cv", createVehicle) function enterVehicle(thePlayer) local theVehicle = getPedOccupiedVehicle(thePlayer) if not getElementData(theVehicle, "server.key") == getElementData(thePlayer, "server.key") then outputChatBox("Incorrect key", thePlayer, 255, 0, 0, false) end end addEventHandler("onVehicleEnter", getRootElement(), enterVehicle) Edited October 8, 2011 by Guest Link to comment
JR10 Posted October 8, 2011 Share Posted October 8, 2011 Your problem, is making a key for every vehicle? use setElementData ( vehicle, "key", math.random(0,1000)) Link to comment
myonlake Posted October 8, 2011 Author Share Posted October 8, 2011 Your problem, is making a key for every vehicle?use setElementData ( vehicle, "key", math.random(0,1000)) So, I don't need to care about the createVehicle function? Usually we do "local theVehicle = createVeh.." Link to comment
JR10 Posted October 8, 2011 Share Posted October 8, 2011 You do need to have a vehicle variable, to use it with setElementData. Link to comment
myonlake Posted October 8, 2011 Author Share Posted October 8, 2011 You do need to have a vehicle variable, to use it with setElementData. If I do: local vehicle = createVehicle(id, x, y, z) It changes all the "vehicle"s data's, right? Link to comment
JR10 Posted October 8, 2011 Share Posted October 8, 2011 What? vehicle is a variable, it's not related to any other element. Link to comment
myonlake Posted October 8, 2011 Author Share Posted October 8, 2011 Alright, I am doing this another way now. I have a command that spawns a car, the command gives me a data with math.random. It works normally. When I enter the car I spawned, it sets MY DATA into the car aswell, we both have identical DATA. When someone else does the command too, it works normally. When he enters my car, he SHOULD get ejected from the vehicle, but... unfortunatly he doesn't. What's wrong? function enterVehicle(thePlayer) local theVehicle = getPedOccupiedVehicle(thePlayer) local veh = getElementData(theVehicle, "sfserver.key") local pla = getElementData(thePlayer, "sfserver.key") if not getElementData(theVehicle, "sfserver.key") and getElementData(thePlayer, "sfserver.key") then setElementData(theVehicle, "sfserver.key", getElementData(thePlayer, "sfserver.key")) outputChatBox("Vehicle has now a key: " .. getElementData(thePlayer, "sfserver.key") .. ".", thePlayer, 0, 255, 0, false) elseif getElementData(theVehicle, "sfserver.key") and not veh == pla or not getElementData(thePlayer, "sfserver.key") then removePedFromVehicle(thePlayer) outputChatBox("You have an incorrect key, it means you don't own this vehicle.", thePlayer, 0, 255, 0, false) end end addEventHandler("onVehicleEnter", getRootElement(), enterVehicle) Link to comment
Castillo Posted October 8, 2011 Share Posted October 8, 2011 function enterVehicle(thePlayer) local theVehicle = source local veh = getElementData(theVehicle, "sfserver.key") local pla = getElementData(thePlayer, "sfserver.key") if not getElementData(theVehicle, "sfserver.key") and getElementData(thePlayer, "sfserver.key") then setElementData(theVehicle, "sfserver.key", getElementData(thePlayer, "sfserver.key")) outputChatBox("Vehicle has now a key: " .. getElementData(thePlayer, "sfserver.key") .. ".", thePlayer, 0, 255, 0, false) elseif getElementData(theVehicle, "sfserver.key") and not veh == pla or not getElementData(thePlayer, "sfserver.key") then removePedFromVehicle(thePlayer) outputChatBox("You have an incorrect key, it means you don't own this vehicle.", thePlayer, 0, 255, 0, false) end end addEventHandler("onVehicleEnter", getRootElement(), enterVehicle) Not sure if it'll work, as i couldn't test it. P.S: The 'source 'of onVehicleEnter is the VEHICLE the player just entered. 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