*** the following is a ripped trigger in jass form from the map :: RIVAL NATIONS :: by MicrosoftXP ***
function Trig_Give_Resources_Conditions takes nothing returns boolean
if ( not ( SubStringBJ(GetEventPlayerChatString(), 1, 1) == "-" ) ) then
return false
endif
return true
endfunction
function Trig_Give_Resources_Actions takes nothing returns nothing
local player playerGive = GetTriggerPlayer()
local player playerGet
local integer playerGiveIndex = GetConvertedPlayerId(playerGive)
local integer playerGetIndex
local integer i
local integer stringPointer = 0
local string chatString = GetEventPlayerChatString()
local integer resourceAmt = 0
local boolean resourceType
local string resourceString
set i = 10
loop
exitwhen i > 17
if( SubStringBJ(chatString, i, i) == " " ) then
set stringPointer = i
set i = 18
else
set i = i + 1
endif
endloop
if( stringPointer == 0 ) then
return
endif
set playerGetIndex = GetPlayerIndexFromColorString(SubStringBJ(chatString, 7, stringPointer - 1))
if ( playerGetIndex == 0 ) then
return
else
set playerGet = ConvertedPlayer(playerGetIndex)
endif
set resourceAmt = S2I(SubStringBJ(chatString, stringPointer + 1,17))
if ( SubStringBJ(chatString,1,5) == "-gold" ) then
set resourceType = true
else
set resourceType = false
endif
if ( not(resourceAmt > 0) ) then
return
endif
if ( (playerGive == playerGet) or (IsPlayerEnemy(playerGive, playerGet)) ) then
return
endif
if ( (resourceType and GetPlayerState(playerGive, PLAYER_STATE_RESOURCE_GOLD) < resourceAmt) or (not(resourceType) and GetPlayerState(playerGive, PLAYER_STATE_RESOURCE_LUMBER) < resourceAmt) ) then
return
endif
if ( resourceType ) then
call AdjustPlayerStateBJ( ( -1 * resourceAmt ), playerGive, PLAYER_STATE_RESOURCE_GOLD )
call AdjustPlayerStateBJ( resourceAmt, playerGet, PLAYER_STATE_RESOURCE_GOLD )
set resourceString = "gold"
else
call AdjustPlayerStateBJ( ( -1 * resourceAmt ), playerGive, PLAYER_STATE_RESOURCE_LUMBER )
call AdjustPlayerStateBJ( resourceAmt, playerGet, PLAYER_STATE_RESOURCE_LUMBER )
set resourceString = "lumber"
endif
call DisplayTimedTextToPlayer( playerGive, 0, 0, 10, "|cffffcc00Gave " + I2S(resourceAmt) + " " + resourceString + " to " + GetPlayerName(playerGet) + ".|r" )
call DisplayTimedTextToPlayer( playerGet, 0, 0, 10, "|cffffcc00Received " + I2S(resourceAmt) + " " + resourceString + " from " + GetPlayerName(playerGive) + ".|r" )
endfunction
function InitTrig_Give_Resources takes nothing returns nothing
set gg_trg_Give_Resources = CreateTrigger( )
call TriggerRegisterPlayerChatEvent( gg_trg_Give_Resources, Player(0), "-wood", false )
call TriggerRegisterPlayerChatEvent( gg_trg_Give_Resources, Player(0), "-gold", false )
call TriggerRegisterPlayerChatEvent( gg_trg_Give_Resources, Player(1), "-wood", false )
call TriggerRegisterPlayerChatEvent( gg_trg_Give_Resources, Player(1), "-gold", false )
call TriggerRegisterPlayerChatEvent( gg_trg_Give_Resources, Player(2), "-wood", false )
call TriggerRegisterPlayerChatEvent( gg_trg_Give_Resources, Player(2), "-gold", false )
call TriggerRegisterPlayerChatEvent( gg_trg_Give_Resources, Player(3), "-wood", false )
call TriggerRegisterPlayerChatEvent( gg_trg_Give_Resources, Player(3), "-gold", false )
call TriggerRegisterPlayerChatEvent( gg_trg_Give_Resources, Player(4), "-wood", false )
call TriggerRegisterPlayerChatEvent( gg_trg_Give_Resources, Player(4), "-gold", false )
call TriggerRegisterPlayerChatEvent( gg_trg_Give_Resources, Player(5), "-wood", false )
call TriggerRegisterPlayerChatEvent( gg_trg_Give_Resources, Player(5), "-gold", false )
call TriggerRegisterPlayerChatEvent( gg_trg_Give_Resources, Player(6), "-wood", false )
call TriggerRegisterPlayerChatEvent( gg_trg_Give_Resources, Player(6), "-gold", false )
call TriggerRegisterPlayerChatEvent( gg_trg_Give_Resources, Player(7), "-wood", false )
call TriggerRegisterPlayerChatEvent( gg_trg_Give_Resources, Player(7), "-gold", false )
call TriggerRegisterPlayerChatEvent( gg_trg_Give_Resources, Player(8), "-wood", false )
call TriggerRegisterPlayerChatEvent( gg_trg_Give_Resources, Player(8), "-gold", false )
call TriggerAddCondition( gg_trg_Give_Resources, Condition( function Trig_Give_Resources_Conditions ) )
call TriggerAddAction( gg_trg_Give_Resources, function Trig_Give_Resources_Actions )
endfunction