Bleidex Posted June 9, 2011 Posted June 9, 2011 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
karlis Posted June 9, 2011 Posted June 9, 2011 its getPedOccupiedVehicle() not GetPlayerOccupiedVehicle() as you see, 2 errors, ped, not player, and caps at 1st letter also use tags, if you would use them, you would find the error yourself.
Bleidex Posted June 9, 2011 Author Posted June 9, 2011 Doesnt output any errors now, but it still doesnt set vehicle color. Tested on Infernus and Sandking. Maybe I use that funcion not how it should be?
Aibo Posted June 9, 2011 Posted June 9, 2011 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.
karlis Posted June 9, 2011 Posted June 9, 2011 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?
Aibo Posted June 9, 2011 Posted June 9, 2011 i was aware of setPlayerTeam only.is the a report in forum maintance section? somewhat: viewtopic.php?p=332456#p332456
Bleidex Posted June 11, 2011 Author Posted June 11, 2011 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 )
Aibo Posted June 11, 2011 Posted June 11, 2011 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 )
Bleidex Posted June 11, 2011 Author Posted June 11, 2011 Doesnt output any errors now, but it still doesnt work - sets random vehicle color (tested on vehicles that can have custom colors)
hobo Posted June 11, 2011 Posted June 11, 2011 All players aren't in vehicles on map start. Just use onPlayerVehicleEnter function. And isGuestAccount() check wouldn't hurt either.
FFS-Racing Posted June 11, 2011 Posted June 11, 2011 I hope you were smart enough to remove the looping.
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