Vercetti1010 Posted March 21, 2008 Share Posted March 21, 2008 (edited) Hey guys. this script is perfect except for that it wont remember the players name. Essentially what i want it to do is when the player sends the command it parks the car and remembers who parks it. if the person who parked it gets back in then it should start automatically and if it isnt then it expels the player from the car. the problem is that I park the car and when i get back in it expels me. how can i get it to remember me? function publicPark ( thePlayer ) playervehicle = getPlayerOccupiedVehicle ( thePlayer ) playername = getVehicleOccupant ( playervehicle, 0 ) id = getVehicleID ( playervehicle ) if ( playervehicle ) then if id == 444 or id == 556 or id == 557 or id == 406 then setVehicleFrozen ( playervehicle, true ) setVehicleDamageProof ( playervehicle, true ) setVehicleOverrideLights ( playervehicle, 1 ) setVehicleEngineState ( playervehicle, false ) authorized = getClientName ( playername ) outputChatBox ( "Vehicle Parked", thePlayer, 255, 0, 0 ) else if ( playervehicle ) then if isVehicleOnGround ( playervehicle ) then setVehicleFrozen ( playervehicle, true ) setVehicleDamageProof ( playervehicle, true ) setVehicleOverrideLights ( playervehicle, 1 ) setVehicleEngineState ( playervehicle, false ) outputChatBox ( "Vehicle Parked", thePlayer, 255, 0, 0 ) end end end end end function playerExpel ( thePlayer ) if ( authorized ) then setVehicleFrozen ( playervehicle, false ) setVehicleDamageProof ( playervehicle, false ) setVehicleOverrideLights ( playervehicle, 0 ) setVehicleEngineState ( playervehicle, true ) outputChatBox ( "Vehicle Started", thePlayer, 255, 0, 0 ) else removePlayerFromVehicle ( thePlayer ) outputChatBox ( "This is not your vehicle!", thePlayer, 255, 0, 0 ) end end addCommandHandler ( "parkcar", publicPark ) addEventHandler ( "onVehicleEnter", getRootElement(), playerExpel ) Edited January 4, 2011 by Guest Link to comment
Morelli Posted March 21, 2008 Share Posted March 21, 2008 You're setting it as a global variable, so if multiple people try to park, then you're going to get mixed results about who is the variable 'authorised'. Try pulling the data and having it save to an external file, and then when you need it, pull it from the file again and run a check on it. Link to comment
Vercetti1010 Posted March 21, 2008 Author Share Posted March 21, 2008 i suck at xml stuff. i have no idea how to do that Link to comment
eAi Posted March 21, 2008 Share Posted March 21, 2008 Try setElementData - setElementData(vehicle, "parkedby", player ) Then getElementData - if ( getElementData ( vehicle, "parkedby" ) == player ) then ... Link to comment
Vercetti1010 Posted March 21, 2008 Author Share Posted March 21, 2008 (edited) that kind of works. if i enter any car it expels me, if i give myself a car with admin CP and get out and get back it it expels me. however if i give myself a car with CP and park it, get out then back in it starts for me. any soltions? function publicPark ( thePlayer ) playervehicle = getPlayerOccupiedVehicle ( thePlayer ) playername = getVehicleOccupant ( playervehicle, 0 ) id = getVehicleID ( playervehicle ) if ( playervehicle ) then if id == 444 or id == 556 or id == 557 or id == 406 then setVehicleFrozen ( playervehicle, true ) setVehicleDamageProof ( playervehicle, true ) setVehicleOverrideLights ( playervehicle, 1 ) setVehicleEngineState ( playervehicle, false ) authorized = getClientName ( playername ) setElementData ( playervehicle, "parkedby", playername ) outputChatBox ( "Vehicle Parked", thePlayer, 255, 0, 0 ) else if ( playervehicle ) then if isVehicleOnGround ( playervehicle ) then setVehicleFrozen ( playervehicle, true ) setVehicleDamageProof ( playervehicle, true ) setVehicleOverrideLights ( playervehicle, 1 ) setVehicleEngineState ( playervehicle, false ) setElementData ( playervehicle, "parkedby", playername ) outputChatBox ( "Vehicle Parked", thePlayer, 255, 0, 0 ) end end end end end function playerExpel ( thePlayer ) if ( getElementData ( playervehicle, "parkedby" ) == playername ) then setVehicleFrozen ( playervehicle, false ) setVehicleDamageProof ( playervehicle, false ) setVehicleOverrideLights ( playervehicle, 0 ) setVehicleEngineState ( playervehicle, true ) outputChatBox ( "Vehicle Started", thePlayer, 255, 0, 0 ) else removePlayerFromVehicle ( thePlayer ) outputChatBox ( "This is not your vehicle!", thePlayer, 255, 0, 0 ) end end addCommandHandler ( "parkcar", publicPark ) addEventHandler ( "onVehicleEnter", getRootElement(), playerExpel ) I get errors for the elementData stuff. i dont have much faith for this script anymore if i cant figure something out soon Edited January 4, 2011 by Guest Link to comment
eAi Posted March 21, 2008 Share Posted March 21, 2008 If you get errors, you need to tell us what they are. Link to comment
Vercetti1010 Posted March 21, 2008 Author Share Posted March 21, 2008 if i can remember it was something about them being null or bad arguements or something Link to comment
tma Posted March 21, 2008 Share Posted March 21, 2008 function playerExpel ( thePlayer ) if ( getElementData ( playervehicle, "parkedby" ) == playername ) then setVehicleFrozen ( playervehicle, false ) setVehicleDamageProof ( playervehicle, false ) setVehicleOverrideLights ( playervehicle, 0 ) setVehicleEngineState ( playervehicle, true ) outputChatBox ( "Vehicle Started", thePlayer, 255, 0, 0 ) else removePlayerFromVehicle ( thePlayer ) outputChatBox ( "This is not your vehicle!", thePlayer, 255, 0, 0 ) end end In this function playervehicle and playername are undefined - you determine them in the other function but not in this one. You're also saving the owner of a vehicle as a player element type but call the variable "playername" which is confusing. And what is the "authorized" variable ? That's the name of the player but you don't use it. In fact, I wouldn't use the name (you're not) as it could change. Edit: I notice that you've made the variables global - that's never going to work in the long run when you've multiple people on the server. function playerExpel ( thePlayer ) playervehicle = getPlayerOccupiedVehicle ( thePlayer ) if ( getElementData ( playervehicle, "parkedby" ) == thePlayer ) then setVehicleFrozen ( playervehicle, false ) setVehicleDamageProof ( playervehicle, false ) setVehicleOverrideLights ( playervehicle, 0 ) setVehicleEngineState ( playervehicle, true ) outputChatBox ( "Vehicle Started", thePlayer, 255, 0, 0 ) else removePlayerFromVehicle ( thePlayer ) outputChatBox ( "This is not your vehicle!", thePlayer, 255, 0, 0 ) end end Link to comment
Vercetti1010 Posted March 21, 2008 Author Share Posted March 21, 2008 so is there any way that I could accomplish this task? Link to comment
[Ska]Vladmo Posted March 21, 2008 Share Posted March 21, 2008 function playerExpel ( thePlayer ) if ( getElementData ( playervehicle, "parkedby" ) == playername ) then setVehicleFrozen ( playervehicle, false ) setVehicleDamageProof ( playervehicle, false ) setVehicleOverrideLights ( playervehicle, 0 ) setVehicleEngineState ( playervehicle, true ) outputChatBox ( "Vehicle Started", thePlayer, 255, 0, 0 ) else removePlayerFromVehicle ( thePlayer ) outputChatBox ( "This is not your vehicle!", thePlayer, 255, 0, 0 ) end end In this function playervehicle and playername are undefined - you determine them in the other function but not in this one. You're also saving the owner of a vehicle as a player element type but call the variable "playername" which is confusing. And what is the "authorized" variable ? That's the name of the player but you don't use it. In fact, I wouldn't use the name (you're not) as it could change. Edit: I notice that you've made the variables global - that's never going to work in the long run when you've multiple people on the server. function playerExpel ( thePlayer ) playervehicle = getPlayerOccupiedVehicle ( thePlayer ) if ( getElementData ( playervehicle, "parkedby" ) == thePlayer ) then setVehicleFrozen ( playervehicle, false ) setVehicleDamageProof ( playervehicle, false ) setVehicleOverrideLights ( playervehicle, 0 ) setVehicleEngineState ( playervehicle, true ) outputChatBox ( "Vehicle Started", thePlayer, 255, 0, 0 ) else removePlayerFromVehicle ( thePlayer ) outputChatBox ( "This is not your vehicle!", thePlayer, 255, 0, 0 ) end end Tested your code and when I spawn a vehicle it says it isn't myne when it was nobodys... Link to comment
Vercetti1010 Posted March 21, 2008 Author Share Posted March 21, 2008 (edited) ugh, a different error now. it ways INFO: loading script failed park.lua:11: ")" expected near "," function publicPark ( thePlayer ) playervehicle = getPlayerOccupiedVehicle ( thePlayer ) playername = getVehicleOccupant ( playervehicle, 0 ) id = getVehicleID ( playervehicle ) if ( playervehicle ) then if id == 444 or id == 556 or id == 557 or id == 406 or id == 472 or id == 473 or id == 493 or id == 595 or id == 484 or id == 430 or id == 453 or id == 452 or id == 446 or id == 454 then setVehicleFrozen ( playervehicle, true ) setVehicleDamageProof ( playervehicle, true ) setVehicleOverrideLights ( playervehicle, 1 ) setVehicleEngineState ( playervehicle, false ) local setElementData ( playervehicle, "parkedby", playername ) outputChatBox ( "Vehicle Parked", thePlayer, 255, 0, 0 ) else if ( playervehicle ) then if isVehicleOnGround ( playervehicle ) then setVehicleFrozen ( playervehicle, true ) setVehicleDamageProof ( playervehicle, true ) setVehicleOverrideLights ( playervehicle, 1 ) setVehicleEngineState ( playervehicle, false ) local setElementData ( playervehicle, "parkedby", playername ) outputChatBox ( "Vehicle Parked", thePlayer, 255, 0, 0 ) end end end end end function playerExpel ( thePlayer ) playervehicle = getPlayerOccupiedVehicle ( thePlayer ) playername = getVehicleOccupant ( playervehicle, 0 ) if isVehicleFrozen ( playervehicle ) then if ( local getElementData ( playervehicle, "parkedby" ) == playername ) then setVehicleFrozen ( playervehicle, false ) setVehicleDamageProof ( playervehicle, false ) setVehicleOverrideLights ( playervehicle, 0 ) setVehicleEngineState ( playervehicle, true ) outputChatBox ( "Vehicle Started", thePlayer, 255, 0, 0 ) else removePlayerFromVehicle ( thePlayer ) outputChatBox ( "This is not your vehicle!", thePlayer, 255, 0, 0 ) end end end addCommandHandler ( "parkcar", publicPark ) addEventHandler ( "onVehicleEnter", getRootElement(), playerExpel ) Edited January 4, 2011 by Guest Link to comment
50p Posted March 21, 2008 Share Posted March 21, 2008 ugh, a different error now. it ways INFO: loading script failed park.lua:11: ")" expected near "," function publicPark ( thePlayer ) playervehicle = getPlayerOccupiedVehicle ( thePlayer ) playername = getVehicleOccupant ( playervehicle, 0 ) id = getVehicleID ( playervehicle ) if ( playervehicle ) then if id == 444 or id == 556 or id == 557 or id == 406 or id == 472 or id == 473 or id == 493 or id == 595 or id == 484 or id == 430 or id == 453 or id == 452 or id == 446 or id == 454 then setVehicleFrozen ( playervehicle, true ) setVehicleDamageProof ( playervehicle, true ) setVehicleOverrideLights ( playervehicle, 1 ) setVehicleEngineState ( playervehicle, false ) local setElementData ( playervehicle, "parkedby", playername ) outputChatBox ( "Vehicle Parked", thePlayer, 255, 0, 0 ) else if ( playervehicle ) then if isVehicleOnGround ( playervehicle ) then setVehicleFrozen ( playervehicle, true ) setVehicleDamageProof ( playervehicle, true ) setVehicleOverrideLights ( playervehicle, 1 ) setVehicleEngineState ( playervehicle, false ) local setElementData ( playervehicle, "parkedby", playername ) outputChatBox ( "Vehicle Parked", thePlayer, 255, 0, 0 ) end end end end end function playerExpel ( thePlayer ) playervehicle = getPlayerOccupiedVehicle ( thePlayer ) playername = getVehicleOccupant ( playervehicle, 0 ) if isVehicleFrozen ( playervehicle ) then if ( local getElementData ( playervehicle, "parkedby" ) == playername ) then setVehicleFrozen ( playervehicle, false ) setVehicleDamageProof ( playervehicle, false ) setVehicleOverrideLights ( playervehicle, 0 ) setVehicleEngineState ( playervehicle, true ) outputChatBox ( "Vehicle Started", thePlayer, 255, 0, 0 ) else removePlayerFromVehicle ( thePlayer ) outputChatBox ( "This is not your vehicle!", thePlayer, 255, 0, 0 ) end end end addCommandHandler ( "parkcar", publicPark ) addEventHandler ( "onVehicleEnter", getRootElement(), playerExpel ) Line 11, remove local and just leave setElementData Link to comment
Vercetti1010 Posted March 21, 2008 Author Share Posted March 21, 2008 i give up on it, i get a bunch of other errors when i fix one thing and its just giving me a headache Link to comment
50p Posted March 21, 2008 Share Posted March 21, 2008 i give up on it, i get a bunch of other errors when i fix one thing and its just giving me a headache What are the errors? Link to comment
Vercetti1010 Posted March 22, 2008 Author Share Posted March 22, 2008 at first it says it needs a parenthese around setelementdata. i got rid of local then it said that if was not supposed to be there. i got rid of if and it said == was not supposed to be there. by then i got pissed and gave up. its like when i try to define a colSphere in another script. i do it like the wiki says and it doesnt work Link to comment
50p Posted March 22, 2008 Share Posted March 22, 2008 Look here: ugh, a different error now. it ways INFO: loading script failed park.lua:11: ")" expected near "," function publicPark ( thePlayer ) playervehicle = getPlayerOccupiedVehicle ( thePlayer ) playername = getVehicleOccupant ( playervehicle, 0 ) end You want to get "player" element and assign it to the playername variable. What do you need player element for if thePlayer is already what you need? Anyways, I'll have a deeper look into it if you'll want to give up an I'll have some time. Link to comment
Vercetti1010 Posted March 24, 2008 Author Share Posted March 24, 2008 well, it seems that it would make sense to do that, but it was giving me errors with basic things like "id == 123" which works on other stuff i make. this is no issue however, i already made a vehicle parking script in the past but i was just trying to make it more user friendly and let everyone use it. the current version doesnt work on boats and vehicles with big wheels like the monster ( game doesnt see them as on the ground ) and all the functions are command based therefore it is for admins only ( for things like parking a dangerous vehicle in area 69 ). you can look into it if you feel like it. im just saying dont feel obligated to fix my problems if you dont have to. Link to comment
[Ska]Vladmo Posted March 29, 2008 Share Posted March 29, 2008 I'm not saying this will work but try this..... Replace addEventHandler ( "onVehicleEnter", getRootElement(), playerExpel ) with this: addCommandHandler ( "unpark", playerExpel ) And something to add so no one can destroy it when its parked add this with your vehicle park functions: setVehicleDamageProof ( theVehicle, true ) Then add this one on your vehicle started function: setVehicleDamageProof ( theVehicle, false ) Link to comment
Douks08fr Posted January 2, 2011 Share Posted January 2, 2011 Hey, I know last post was very old but, does anybody know if this script is working ? For now, theres nothing like this... Link to comment
Fabio(GNR) Posted January 2, 2011 Share Posted January 2, 2011 Hey, I know last post was very old but, does anybody know if this script is working ?For now, theres nothing like this... lol bumping a 3 year old script, anyway i dont think the script works Link to comment
Scooby Posted January 4, 2011 Share Posted January 4, 2011 (edited) Hey, I know last post was very old but, does anybody know if this script is working ?For now, theres nothing like this... not sure if he ever got it to work, so heres a basic one for you. it will allow players to /lock cars... local vehicleOwner = {} function lockCar( thePlayer ) local vehicle = getPlayerOccupiedVehicle( thePlayer ) local vehicleID = getVehicleID( vehicle ) if vehicle then if getVehicleOccupant( vehicle,0 ) == thePlayer then vehicleOwner[vehicle] = getPlayerName(thePlayer) setVehicleEngineState ( vehicle, false ) outputChatBox( "Vehicle Parked And Locked", thePlayer, 255, 0, 0 ) else outputChatBox("You need to be the driver!",thePlayer,255,0,0) end else outputChatBox("You need to be in a vehicle!",thePlayer,255,0,0) end end addCommandHandler ( "lock", lockCar ) function ownerCheck( thePlayer ) local playerName = getPlayerName(thePlayer) local owner = vehicleOwner[source] if owner == playerName then setVehicleEngineState ( source, true ) outputChatBox( "Vehicle Unlocked And Started", thePlayer, 0, 255, 0 ) vehicleOwner[source] = nil -- < remove the current owner end end addEventHandler( "onVehicleEnter", getRootElement(), ownerCheck ) function expelCheck( thePlayer ) local playerName = getPlayerName(thePlayer) local owner = vehicleOwner[source] if owner then if owner ~= playerName then removePlayerFromVehicle( thePlayer ) outputChatBox( "Vehicle Locked, Current Owner: " .. tostring(vehicleOwner[source]), thePlayer, 255, 0, 0 ) end end end addEventHandler( "onVehicleStartEnter", getRootElement(), expelCheck ) restarting the script will unlock all the cars and remove current owners. Edited January 4, 2011 by Guest 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