Sparrow Posted December 31, 2011 Share Posted December 31, 2011 I'm thinking to do a script that allow players enter the vehicles that is belong to them. (admin set the vehicle owner by the account name), and all what I need to know is the functions needed, I saw the wiki and I didn't find what is needed (didn't know what is needed for this script). thank you. Link to comment
Castillo Posted December 31, 2011 Share Posted December 31, 2011 setElementData -- To set the vehicle owner. getElementData -- To get the vehicle owner. getPlayerAccount -- To get the player who tries to enter account. getAccountName -- To get the account name. onVehicleStartEnter -- The event. I may have missed something. Link to comment
Sparrow Posted December 31, 2011 Author Share Posted December 31, 2011 thank you, I'll start working Link to comment
BinSlayer1 Posted December 31, 2011 Share Posted December 31, 2011 Since you say you don't know what is needed, I'll explain so u understand (having the function names isn't everything so this might help u) so let's start off by using command handler: addCommandHandler in the cmd handler, check that the player is in a vehicle with isPedInVehicle Check that the vehicle has no existent element data about owner, because if it does then you shouldn't override it Attach the player element to the vehicle as element data afterwards, onVehicleStartEnter. Check to see if the vehicle has an owner. If it does, you will cancel this event IF the player stored as element data in the vehicle that is about to be entered is different than the player attempting to enter it Note: everything gets lost in case of vehicle being destroyed somehow. It's gonna be harder to avoid this, but not impossible I believe. Link to comment
Sparrow Posted December 31, 2011 Author Share Posted December 31, 2011 thank you slayer for this information Link to comment
Sparrow Posted January 1, 2012 Author Share Posted January 1, 2012 sorry for this double posting. I do this, I know I'm failer function vehOwner (thePlayer) local acc = getPlayerAccount (thePlayer) if not acc or isGuestAccount(acc) then return end local accName = getAccountName(acc) if ( hasObjectPermissionTo ( thePlayer , "function.banPlayer", true ) ) then if getElementData (thePlayer, "veh.owner") then setElementData (thePlayer, "veh.owner", true) outputChatBox ("You successfully seted owner of this vehicle.", thePlayer, 0, 255, 0) else setElementData (thePlayer, "veh.owner", false) outputChatBox ("Fail to set owner of this vehicle.", thePlayer, 0, 255, 0) end end end addCommandHandler ("setowner", vehOwner) function vehEnter (thePlayer) if (acc) then outputChatBox ("Welcome to your vehicle.", thePlayer, 0, 255, 0) else outputChatBox ("This vehicle is owned by "getAccountName..".", thePlayer, 255, 0, 0) end end addEventHandler ("onVehicleStartEnter", vehEnter) Link to comment
Castillo Posted January 1, 2012 Share Posted January 1, 2012 function vehOwner (thePlayer, cmd, owner) local acc = getPlayerAccount (thePlayer) if (not acc or isGuestAccount(acc)) then return end local accName = getAccountName(acc) if ( hasObjectPermissionTo ( thePlayer , "function.banPlayer", true ) ) then local vehicle = getPedOccupiedVehicle(thePlayer) if (not vehicle) then outputChatBox("You must be in a vehicle to set it's owner.", thePlayer, 255, 0, 0) return end if setElementData (vehicle, "veh.owner", owner) then outputChatBox ("You successfully set the owner of this vehicle to ".. tostring(owner) ..".", thePlayer, 0, 255, 0) else outputChatBox ("Fail to set owner of this vehicle.", thePlayer, 255, 0, 0) end end end addCommandHandler ("setowner", vehOwner) function vehEnter (thePlayer) local acc = getPlayerAccount (thePlayer) if (not acc or isGuestAccount(acc)) then return end local accName = getAccountName(acc) local owner = getElementData(source, "veh.owner") if (not owner) then return end if (owner == accName) then outputChatBox ("Welcome to your vehicle.", thePlayer, 0, 255, 0) else outputChatBox ("This vehicle is owned by ".. tostring(owner) ..".", thePlayer, 255, 0, 0) cancelEvent() end end addEventHandler ("onVehicleStartEnter", root, vehEnter) This will set the owner of the vehicle you're driving. /setowner Link to comment
Sparrow Posted January 1, 2012 Author Share Posted January 1, 2012 Thanks EDIT: I can't also get in as passenger, how to fix that? 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