LonelyRoad Posted April 26, 2014 Posted April 26, 2014 I have some scripts to apply protection to player's vehicles, but I only want it to 'recognize' vehicles created by the 'vehicle-system' resource... How, if at all - is this possible?
tosfera Posted April 26, 2014 Posted April 26, 2014 I would say, whenever a vehicle is created inside that 'vehicle-system'. Set a data value on the element ( the vehicle ). You can do this with the setElementData function. When you want to loop trough your vehicles, seek for that data and you're in. ^^ If you want to contact me directly concerning Advanced-Gaming, please contact me at [email protected]
LonelyRoad Posted April 26, 2014 Author Posted April 26, 2014 That seems like a long-winded way to do it, and its a lot of element data. Kinda surprised there's not a better way (as yet) to do this?
Castillo Posted April 26, 2014 Posted April 26, 2014 local vehicles = getElementsByType ( "vehicle", getResourceRootElement ( getResourceFromName ( "vehicle-system" ) ) ) for _, vehicle in ipairs ( vehicles ) do fixVehicle ( vehicle ) end That will fix all vehicles created by the "vehicle-system" resource. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
LonelyRoad Posted April 26, 2014 Author Posted April 26, 2014 That's kind of what I'm looking for, and has given me a good idea of another way in which that could be useful Snake. However the context I want to apply it to is as below: function EngineToggle(src, key, state) local occuVeh = getPedOccupiedVehicle(src) if (occuVeh ~= false) then local vehOwner = tonumber(getElementData(occuVeh, "veh:owner")) local charID = tonumber(getElementData(src, "character:id")) if (vehOwner == charID) then local vehState = getVehicleEngineState(occuVeh) setVehicleEngineState(occuVeh, not vehState) setVehicleLocked(occuVeh, not vehState) else if (getPedOccupiedVehicleSeat(src) == 0) then outputChatBox("This ain't your car!", src) if (isPedInVehicle(src)) then local x, y, z = getElementPosition(src) removePedFromVehicle(src) setElementPosition(src, x, y, z+5) local x, y, z = nil, nil, nil end end end end end Notice line 9 I check if the owner info matches, and then on lines 14-23 I eject the guy from the car if he doesn't own it. I want to only do that on vehicles created by the vehicle-system resource.
Castillo Posted April 26, 2014 Posted April 26, 2014 function isValidVehicle ( vehicle ) if isElement ( vehicle ) then local parent = getElementParent ( vehicle ) if ( parent ) then local parent = getElementParent ( parent ) if ( parent ) then return ( parent == getResourceRootElement ( getResourceFromName ( "vehicle-system" ) ) ) else return false end else return false end else return false end end function EngineToggle ( src, key, state ) local occuVeh = getPedOccupiedVehicle ( src ) if ( occuVeh ~= false ) then if ( not isValidVehicle ( occuVeh ) ) then return end local vehOwner = tonumber ( getElementData ( occuVeh, "veh:owner" ) ) local charID = tonumber ( getElementData ( src, "character:id" ) ) if ( vehOwner == charID ) then local vehState = getVehicleEngineState ( occuVeh ) setVehicleEngineState ( occuVeh, not vehState ) setVehicleLocked ( occuVeh, not vehState ) else if ( getPedOccupiedVehicleSeat ( src ) == 0 ) then outputChatBox ( "This ain't your car!", src ) if isPedInVehicle ( src ) then local x, y, z = getElementPosition ( src ) removePedFromVehicle ( src ) setElementPosition ( src, x, y, z + 5 ) end end end end end Try it. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
LonelyRoad Posted April 26, 2014 Author Posted April 26, 2014 That worked perfectly, I didn't think that getElementParent would behave like that, based on the example. If it intrigues you, I changed the behaviour of the EngineToggle function slightly: function EngineToggle(src, key, state) local occuVeh = getPedOccupiedVehicle(src) local vehState = getVehicleEngineState(occuVeh) if ( not isValidVehicle ( occuVeh ) ) then setVehicleEngineState(occuVeh, not vehState) return end if (occuVeh ~= false) then local vehOwner = tonumber(getElementData(occuVeh, "veh:owner")) local charID = tonumber(getElementData(src, "character:id")) if (vehOwner == charID) then setVehicleEngineState(occuVeh, not vehState) setVehicleLocked(occuVeh, not vehState) else if (getPedOccupiedVehicleSeat(src) == 0) then outputChatBox("This ain't your car!", src) if (isPedInVehicle(src)) then local x, y, z = getElementPosition(src) removePedFromVehicle(src) setElementPosition(src, x, y, z+5) local x, y, z = nil, nil, nil end end end end end Either way, thank you!
Castillo Posted April 26, 2014 Posted April 26, 2014 You're welcome. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
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