HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

JASS - player set/add property causing crash

06-07-2003, 08:55 AM#1
MicrosoftXP
I get a Fatal Error and crash when i use set or add properties functions with ConvertedPlayer() but when i use GUI Player (1) Red it works fine... very odd behavior, I think my indecies must have been getting messed up but I checked them...
06-07-2003, 09:58 AM#2
PitzerMike
Don't know, I never use ConvertedPlayer()
06-07-2003, 11:38 AM#3
AIAndy
Well, ConvertedPlayer(x) calls Player(x-1). So valid arguments for ConvertedPlayer is 1-16 . If used with 0 it might well cause a Fatal Error.
06-07-2003, 06:34 PM#4
MicrosoftXP
but there are no issues with changing resources for players who have left the game or were never there (unused)?

[edit] below is the trouble maker if your interested. It doesn't blow up the first time its run, but on the second.

Note that GetPlayerColorString() is there but i didnt paste it. Returns ff0000 for red, 0000ff for blue, etc.

Code:
function Share_gold takes integer playerIndex returns nothing
    // find teammate player #s
    local integer teammate1 = ( playerIndex + ( ModuloInteger(playerIndex, 3) - ModuloInteger(( playerIndex - 1 ), 3) ) )
    local integer teammate2 = ( playerIndex + ( ModuloInteger(( playerIndex + 1 ), 3) - ModuloInteger(( playerIndex - 1 ), 3) ) )
    local integer townplayer = ( 10 + ( ( ( playerIndex - 1 ) - ModuloInteger(( playerIndex - 1 ), 3) ) / 3 ) ) 
    local string playerindexcolor = GetPlayerColorString(playerIndex)
    // share units
    call SetPlayerAllianceBJ( ConvertedPlayer(playerIndex), ALLIANCE_SHARED_CONTROL, true, ConvertedPlayer(teammate1) )
    call SetPlayerAllianceBJ( ConvertedPlayer(playerIndex), ALLIANCE_SHARED_CONTROL, true, ConvertedPlayer(teammate2) )
    // share gold and wood
    if ( GetPlayerSlotState(ConvertedPlayer(teammate1)) == PLAYER_SLOT_STATE_PLAYING ) then
        call AdjustPlayerStateBJ( GetPlayerState(ConvertedPlayer(playerIndex), PLAYER_STATE_RESOURCE_GOLD) / 2 , ConvertedPlayer(teammate1), PLAYER_STATE_RESOURCE_GOLD )
        call AdjustPlayerStateBJ( GetPlayerState(ConvertedPlayer(playerIndex), PLAYER_STATE_RESOURCE_LUMBER) / 2 , ConvertedPlayer(teammate1), PLAYER_STATE_RESOURCE_LUMBER )
    else
        call AdjustPlayerStateBJ( GetPlayerState(ConvertedPlayer(playerIndex), PLAYER_STATE_RESOURCE_GOLD) / 2 , ConvertedPlayer(teammate2), PLAYER_STATE_RESOURCE_GOLD )
        call AdjustPlayerStateBJ( GetPlayerState(ConvertedPlayer(playerIndex), PLAYER_STATE_RESOURCE_LUMBER) / 2 , ConvertedPlayer(teammate2), PLAYER_STATE_RESOURCE_LUMBER )
    endif
    if ( GetPlayerSlotState(ConvertedPlayer(teammate2)) == PLAYER_SLOT_STATE_PLAYING ) then
        call AdjustPlayerStateBJ( GetPlayerState(ConvertedPlayer(playerIndex), PLAYER_STATE_RESOURCE_GOLD) / 2 , ConvertedPlayer(teammate2), PLAYER_STATE_RESOURCE_GOLD )
        call AdjustPlayerStateBJ( GetPlayerState(ConvertedPlayer(playerIndex), PLAYER_STATE_RESOURCE_LUMBER) / 2 , ConvertedPlayer(teammate2), PLAYER_STATE_RESOURCE_LUMBER )
    else
        call AdjustPlayerStateBJ( GetPlayerState(ConvertedPlayer(playerIndex), PLAYER_STATE_RESOURCE_GOLD) / 2 , ConvertedPlayer(teammate1), PLAYER_STATE_RESOURCE_GOLD )
        call AdjustPlayerStateBJ( GetPlayerState(ConvertedPlayer(playerIndex), PLAYER_STATE_RESOURCE_LUMBER) / 2 , ConvertedPlayer(teammate1), PLAYER_STATE_RESOURCE_LUMBER )
    endif

    call DisplayTimedTextToForce( GetPlayersAllies(ConvertedPlayer(townplayer)), 30, "|cff" + playerindexcolor + GetPlayerName(ConvertedPlayer(playerIndex)) + "|r |cffffcc00has left the game.
His resources have been divided between his remaining teammates.
Type|r |cff00ff00-take|r |cffffcc00to gain ownership of his units.|r" )
    call DisplayTextToForce( GetPlayersEnemies(ConvertedPlayer(townplayer)),"|cff" + playerindexcolor + GetPlayerName(ConvertedPlayer(playerIndex)) + "|r |cffffcc00HAS BEEN DEFEATED!|r" )
    call SetPlayerStateBJ( ConvertedPlayer(playerIndex), PLAYER_STATE_RESOURCE_GOLD, 0 )
    call SetPlayerStateBJ( ConvertedPlayer(playerIndex), PLAYER_STATE_RESOURCE_LUMBER, 0 )
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 9
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        if ( udg_infoBoardOn[GetForLoopIndexA()] == false ) then
            if (  playerIndex != GetForLoopIndexA() ) then
                call LeaderboardSetPlayerItemLabelBJ( ConvertedPlayer(playerIndex), PlayerGetLeaderboardBJ(ConvertedPlayer(GetForLoopIndexA())), ( "(X) " + SubStringBJ(GetPlayerName(ConvertedPlayer(playerIndex)), 1, 12) ) )
            endif
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
endfunction

function Trig_Kick_x_Actions takes nothing returns nothing
    local integer playerIndex = 0
    if ( SubStringBJ(GetEventPlayerChatString(), 7, 12) == "red" ) then
        set playerIndex = 1
    elseif (SubStringBJ(GetEventPlayerChatString(), 7, 12) == "blue" ) then
        set playerIndex = 2
    elseif ( SubStringBJ(GetEventPlayerChatString(), 7, 12) == "teal" ) then
        set playerIndex = 3
    elseif ( SubStringBJ(GetEventPlayerChatString(), 7, 12) == "purple" ) then
        set playerIndex = 4
    elseif ( SubStringBJ(GetEventPlayerChatString(), 7, 12) == "yellow" ) then
        set playerIndex = 5
    elseif ( SubStringBJ(GetEventPlayerChatString(), 7, 12) == "orange" ) then
        set playerIndex = 6
    elseif ( SubStringBJ(GetEventPlayerChatString(), 7, 12) == "green" ) then
        set playerIndex = 7
    elseif ( SubStringBJ(GetEventPlayerChatString(), 7, 12) == "pink" ) then
        set playerIndex = 8
    elseif ( SubStringBJ(GetEventPlayerChatString(), 7, 12) == "grey" ) then
        set playerIndex = 9
    endif

    if ( playerIndex == 0 ) then
      return
      endif
    call CustomVictoryBJ( ConvertedPlayer(playerIndex), false, false )
    call ClearTextMessagesBJ( GetPlayersAll() )
    call Share_gold( playerIndex )
endfunction

//===========================================================================
function InitTrig_Kick_x_old takes nothing returns nothing
    set gg_trg_Kick_x_old = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Kick_x_old, Player(0), "-kick", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Kick_x_old, Player(1), "-kick", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Kick_x_old, Player(2), "-kick", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Kick_x_old, Player(3), "-kick", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Kick_x_old, Player(4), "-kick", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Kick_x_old, Player(5), "-kick", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Kick_x_old, Player(6), "-kick", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Kick_x_old, Player(7), "-kick", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Kick_x_old, Player(8), "-kick", false )
    call TriggerAddCondition( gg_trg_Kick_x_old, Condition( function Trig_Kick_x_Conditions ) )
    call TriggerAddAction( gg_trg_Kick_x_old, function Trig_Kick_x_Actions )
endfunction