joriss11 Posted October 7, 2013 Share Posted October 7, 2013 Hey Guys, im not an scripter and i wanted to know if you guys maybe could explain/give me a good script to lock cars to classes. because me and a Friend making an Server and it would be nice to have some cars that we can lock to gangs. ( no teams ) I hope you guys could help me. PS. it would be nice if we could add the vehicles simply with a command or GUI but we don't mind to use the Ingame editor to place some. Thx, anyways guys Link to comment
Castillo Posted October 7, 2013 Share Posted October 7, 2013 This isn't a request forum, if you want this, you must either learn to make it by yourself, or pay someone to do it for you. Link to comment
qaisjp Posted October 8, 2013 Share Posted October 8, 2013 You need: onClientVehicleEnter to detect when someone enters the car, you then want to cancelEvent to prevent them from entering. Since car locks are synced (iirc) you can't use locking mechanisms to prevent certain players from entering. You might want to use outputChatBox to say why they can't enter. Create a function that detects if a player is in a gang. Something like "getPlayerGang". When creating vehicles set an element data saying which gang owns it. Then when entering compare getPlayerGang with that element data and only cancel if they aren't the same. Good luck. This isn't a request forum, if you want this, you must either learn to make it by yourself, or pay someone to do it for you. Well then you could've just explained it to him, like he said. He asked for "someone to explain how to create it for him, but to give him the script if possible". Link to comment
joriss11 Posted October 8, 2013 Author Share Posted October 8, 2013 okey, thx Citizen. I know im not an scripter and i wanted to use this for an Server. I still don't really get it. Could you maybe help me with 1 car? or help me on the way so i can try/learn it myself? Link to comment
qaisjp Posted October 8, 2013 Share Posted October 8, 2013 Okay. So first I'll explain the event. function limitVehiclesToGang(player) local userGang = getElementData(player, "gang") -- This needs to be set local vehicleOwner = getElementData(source, "gang") -- This needs to be set if vehicleOwner and (userGang ~= vehicleOwner) then outputChatBox("You don't own this vehicle.", player) cancelEvent() end end addEventHandler("onClientVehicleEnter", root, limitVehiclesToGang) You want to modify the message, and make sure that the element data is set. The GUI seems really simple. Link to comment
joriss11 Posted October 8, 2013 Author Share Posted October 8, 2013 i'll try it right now, thx Link to comment
joriss11 Posted October 8, 2013 Author Share Posted October 8, 2013 something like this? : Vehicle = (506, 2100.2697, 1397.4947, 10.3, 0, 0, 0) addEventHandler("onVehicleStartEnter", root, function ( thePlayer ) local vehicleOwner = getElementData ( class, "Chief" ); local gangGroup = getElementData ( thePlayer, "Chief" ); if not ( vehicleOwner == gangGroup ) then outputChatBox ("This car is Locked and belongs to the Following Class : Chief", thePlayer); cancelEvent(); end end Link to comment
glowdemon1 Posted October 8, 2013 Share Posted October 8, 2013 If you want to create the vehicle by code, yo'ull have to use createVehicle instead of vehicle. Link to comment
joriss11 Posted October 9, 2013 Author Share Posted October 9, 2013 if i try this : createVehicle = (506, 2100.2697, 1397.4947, 10.3, 0, 0, 0) addEventHandler("onVehicleStartEnter", root) function ( thePlayer ) local vehicleOwner = getElementData ( class, "Chief" ) local gangGroup = getElementData ( thePlayer, "Chief" ) if not ( vehicleOwner == gangGroup ) then outputChatBox ("This car is Locked and belongs to the Following Class : Chief", thePlayer) cancelEvent() end end then it won't work. Link to comment
myonlake Posted October 9, 2013 Share Posted October 9, 2013 if i try this : createVehicle = (506, 2100.2697, 1397.4947, 10.3, 0, 0, 0) addEventHandler("onVehicleStartEnter", root) function ( thePlayer ) local vehicleOwner = getElementData ( class, "Chief" ) local gangGroup = getElementData ( thePlayer, "Chief" ) if not ( vehicleOwner == gangGroup ) then outputChatBox ("This car is Locked and belongs to the Following Class : Chief", thePlayer) cancelEvent() end end then it won't work. You made createVehicle a variable index. You're supposed to make variable for the createVehicle function instead. You also never defined the function within the event handler. Also, there is no "class" vehicle defined in the function. The vehicle is defined "source" by the Wiki. --setElementData(getPlayerFromName("yournickhere"), "Chief", true, false) -- Uncomment this in order to make yourself a chief local vehicle = createVehicle(506, 2100.2697, 1397.4947, 10.3, 0, 0, 0) -- Create the vehicle setElementData(vehicle, "Chief", true, false) -- Give it element data in 'Chief' and make its value a boolean 'true' addEventHandler("onVehicleStartEnter", root, function(thePlayer, seat, jacked, door) local vehicleOwner = getElementData(source, "Chief") -- Get the vehicle's element data on 'Chief' local gangGroup = getElementData(thePlayer, "Chief") -- Get the entering player's element data on 'Chief' if (not vehicleOwner) then return end -- If the vehicle doesn't have such data, then cancel if (gangGroup ~= vehicleOwner) then -- If the entering player's data doesn't match the vehicle data, continue outputChatBox("This car is locked and belongs to the following class: Chief", thePlayer, 245, 20, 20, false) -- Display a warning cancelEvent() -- Prevent the player from entering the vehicle end end ) Link to comment
joriss11 Posted October 9, 2013 Author Share Posted October 9, 2013 I actually used this code as server.lua . I changed my Coördinates to the location i anted, and the Vehicle is placed there now. I didn't change anything except the Coördinates like i said and it almost works. its lcoked to Chief but when i spawn as the Class : Chief then it is still locked to Chief and i can't enter Link to comment
myonlake Posted October 9, 2013 Share Posted October 9, 2013 Then your element data is wrong. Make sure the two element datas (vehicle and you) are identical. The script I posted sets the element data value to a boolean value 'true'. Link to comment
joriss11 Posted October 9, 2013 Author Share Posted October 9, 2013 But you did that in the Script already right? becuase you setted the Car + the Class Element's date, but when i spawn as the Class it still won't work. and Ye, im just a noob in such a things and I hope that i will Learn it by this way. Link to comment
myonlake Posted October 9, 2013 Share Posted October 9, 2013 In order to debug it, uncomment the first line of code. It will set your element data to the same as the vehicle's data. Also, where does your spawner set the element data? Client-side or server-side? Link to comment
joriss11 Posted October 9, 2013 Author Share Posted October 9, 2013 The spawner is Server-Side , bu how will i uncomment that? ( Srry for being such a noob in Scripting ) Link to comment
myonlake Posted October 9, 2013 Share Posted October 9, 2013 http://en.wikibooks.org/wiki/Lua_Progra ... ua/comment Link to comment
joriss11 Posted October 9, 2013 Author Share Posted October 9, 2013 Like this then? server.lua : setElementData(getPlayerFromName("Joris" or "joriss11"), "Chief", true, false) -- Uncomment this in order to make yourself a chief local vehicle = createVehicle(506, 2100.2697, 1397.4947, 10.3, 0, 0, 0) -- Create the vehicle setElementData(vehicle, "Chief", true, false) -- Give it element data in 'Chief' and make its value a boolean 'true' addEventHandler("onVehicleStartEnter", root, function(thePlayer, seat, jacked, door) local vehicleOwner = getElementData(source, "Chief") -- Get the vehicle's element data on 'Chief' local gangGroup = getElementData(thePlayer, "Chief") -- Get the entering player's element data on 'Chief' if (not vehicleOwner) then return end -- If the vehicle doesn't have such data, then cancel if (gangGroup ~= vehicleOwner) then -- If the entering player's data doesn't match the vehicle data, continue outputChatBox("This car is locked and belongs to the following Class: Chief", thePlayer, 245, 20, 20, false) -- Display a warning cancelEvent() -- Prevent the player from entering the vehicle end end ) its still locked and its still not working when im spawned as Chief Link to comment
myonlake Posted October 9, 2013 Share Posted October 9, 2013 setElementData((getPlayerFromName("Joris") and getPlayerFromName("Joris") or (getPlayerFromName("joriss11") and getPlayerFromName("joriss11") or nil)), "Chief", true, false) -- Uncomment this in order to make yourself a chief Link to comment
joriss11 Posted October 9, 2013 Author Share Posted October 9, 2013 Okey, but if someone new joins Chief class. i will need to add him there or can i Use something with getPlayerFromName(ThePlayer) ? Link to comment
myonlake Posted October 9, 2013 Share Posted October 9, 2013 I don't know how your class system works, so I can't tell what the element data index is. Apparently it's not "Chief", so you've got to fix it in the class system, or just replace "Chief" in the above code with the one that the class system uses. Link to comment
qaisjp Posted October 9, 2013 Share Posted October 9, 2013 My code applies to all vehicles as long as it has a gang set. My code should be independent to vehicle creation. But ignore this advice for now and follow it later. 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