Jump to content

Somekinda error...


Bleidex

Recommended Posts

function MapStarting(mapInfo, mapOptions, gameOptions) 
    for id, player in ipairs(getElementsByType("player")) do 
        local playerAccount = getPlayerAccount ( player ) 
        local playerPlayedMaps = getAccountData ( playerAccount, "MapsPlayed" ) or 0 
        local playerTeam = getPlayerTeam ( player ) 
        local playerVehicle = GetPlayerOccupiedVehicle ( player ) 
        setAccountData ( playerAccount, "MapsPlayed", tonumber(playerPlayedMaps) + 1 ) 
        if playerTeam == "Red" then 
            setVehicleColor ( playerVehicle, 3, 3, 3, 3 ) 
        elseif playerTeam == "Blue" then 
            setVehicleColor ( playerVehicle, 7, 7, 7, 7 ) 
        end 
    end 
end 
addEventHandler ( "onMapStarting", getRootElement(), MapStarting ) 

script fails getting player vehicle, but i dont know how to make it that it would get player vehicle and would set its color on map start

Link to comment
also use
 tags, if you would use them, you would find the error yourself.

Lua highlighter breaks the code on certain functions (get/setPlayerTeam for example), dunno if it will ever be fixed.

i was aware of setPlayerTeam only.

is the a report in forum maintance section?

Link to comment

Everything is ok now, but it gets stuck on setVehicleColor - bad argument... I don't know how i shoudl change it

function MapStarting(mapInfo, mapOptions, gameOptions) 
    for id, player in ipairs(getElementsByType("player")) do 
        local playerAccount = getPlayerAccount ( player ) 
        local playerPlayedMaps = getAccountData ( playerAccount, "MapsPlayed" ) or 0 
        local playerTeam = getTeamName ( getPlayerTeam ( player ) ) 
        local playerVehicle = getPedOccupiedVehicle ( player ) 
        setAccountData ( playerAccount, "MapsPlayed", tonumber(playerPlayedMaps) + 1 ) 
        if playerTeam == "Red" then 
            setVehicleColor ( playerVehicle, 3, 3, 3, 3 ) 
        elseif playerTeam == "Blue" then 
            setVehicleColor ( playerVehicle, 7, 7, 7, 7 ) 
        end 
    end 
end 
addEventHandler ( "onMapStarting", getRootElement(), MapStarting ) 

Link to comment

you should always check if player is in a vehicle, before doing anything with the (supposedly) vehicle element.

even in race mode player can be not in a vehicle at all.

function MapStarting(mapInfo, mapOptions, gameOptions) 
    for id, player in ipairs(getElementsByType("player")) do 
        local playerAccount = getPlayerAccount ( player ) 
        local playerPlayedMaps = getAccountData ( playerAccount, "MapsPlayed" ) or 0 
        local playerTeam = getTeamName ( getPlayerTeam ( player ) ) 
        local playerVehicle = getPedOccupiedVehicle ( player ) 
        setAccountData ( playerAccount, "MapsPlayed", tonumber(playerPlayedMaps) + 1 ) 
        if playerVehicle and playerTeam == "Red" then 
            setVehicleColor ( playerVehicle, 3, 3, 3, 3 ) 
        elseif playerVehicle and playerTeam == "Blue" then 
            setVehicleColor ( playerVehicle, 7, 7, 7, 7 ) 
        end 
    end 
end 
addEventHandler ( "onMapStarting", getRootElement(), MapStarting ) 

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...