Jump to content

What is wrong with getPedOccupiedVehicle?


Recommended Posts

  
function onPlayerLogout ( ) 
    local vehicle = getPedOccupiedVehicle ( source ) 
    local playeraccount = getPlayerAccount ( source ) 
    if ( playeraccount ) then 
        setAccountData ( playeraccount, "s.handCar", getElementModel ( vehicle ) ) 
            setAccountData ( playeraccount, "s.skin", tostring (getPedSkin (source))) 
        setAccountData ( playeraccount, "s.HandMoney", getPlayerMoney ( source ) ) 
            setAccountData (playeraccount, "s.upgradeWheel", getVehicleUpgradeOnSlot ( vehicle, 12 )) 
    end 
end 
addEventHandler ( "onPlayerLogout", getRootElement ( ), onPlayerLogout ) 
  

The problem is the getPedOccupiedVehicle, debugscript says bad argument getElementModel.

getAccountData gets correctly the handmoney and skin, but doesn't get the upgradewheel and handcar, because can't read getPedOccupiedVehicle, why not?

Edited by Guest
Link to comment

Try adding a check. For example:

  
function onPlayerLogout ( ) 
 local vehicle = getPedOccupiedVehicle ( source ) 
 if vehicle then 
  --code 
 end 
end 
addEventHandler ( "onPlayerLogout", getRootElement ( ), onPlayerLogout ) 
  

OR

  
function onPlayerLogout ( ) 
 if isPedInVehicle(source) then 
  local vehicle = getPedOccupiedVehicle ( source ) 
  --code 
 end 
end 
addEventHandler ( "onPlayerLogout", getRootElement ( ), onPlayerLogout ) 
  

Link to comment

try this

  
function onPlayerLogout ( ) 
local isVeh = isPedInVehicle(source) 
if isVeh then 
    local vehicle = getPedOccupiedVehicle ( source ) 
    local playeraccount = getPlayerAccount ( source ) 
    if ( vehicle ) and ( playeraccount ) then 
        local model = getElementModel ( vehicle ) 
        local skin = getPedSkin (source) 
        local money = getPlayerMoney ( source ) 
        local vehUpgrade =  getVehicleUpgradeOnSlot ( vehicle, 12 ) 
        setAccountData ( playeraccount, "s.handCar", model ) 
        setAccountData ( playeraccount, "s.skin", skin ) 
        setAccountData ( playeraccount, "s.HandMoney", money ) 
        setAccountData (playeraccount, "s.upgradeWheel", vehUpgrade )     
        end 
    end 
end 
addEventHandler ( "onPlayerLogout", getRootElement ( ), onPlayerLogout ) 
  

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...