library AllianceSystem /* v1.0.0.1 by Doomlord
*************************************************************************************
*
* Establish an alliance between two players with a single command.
* The alliance proposal must be agreed on mutually before it takes effect.
* However, a player can one-sidedly terminate the alliance.
* This is to simulate the way real life alliances work.
*
* Each player has a fixed number of alliance attempt. You can set it to unlimited though.
*
* I will consider adding features such as bribing, multi-partied alliance, etc. in the future.
*
*************************************************************************************
*
* Credits
*
* Nestharus
* -----------------------
*
* PlayerAlliance snippet
*
* Lohengrin
* -----------------------
*
* System Idea
*
*
*************************************************************************************
*
* How to use
*
* Type -ally <target_player_name> or -ally <player_number> (i.e -ally 1 will send an alliance request to player Red) to send an alliance request to the target player.
* Player that receives the ally request can type -ally <request_player_name> to confirm the alliance.
*
* A player within an alliance can type -war <target_player_name> or -war <player_number> to terminate the alliance.
*
*
*************************************************************************************
*
* */ uses /*
*
* */ BlizzardMessage /* hiveworkshop.com/forums/jass-resources-412/snippet-blizzardmessage-237845/
* */ PlayerAlliance /* hiveworkshop.com/forums/jass-resources-412/snippet-playeralliance-192941/
*
************************************************************************************
*
* SETTINGS
*
*/
globals
// CONFIGURABLES
// Maximum alliance attempt per player. Put in -1 to enable unlimited alliance attempt.
private constant integer MAX_ALLIANCE_ATTEMPT = -1
// Request-to-ally chat message prefix
private constant string ALLY_PREFIX = "-ally"
// Request-to-disally chat message prefix
private constant string DISALLY_PREFIX = "-war"
// END CONFIGURABLES
private integer array MaxAlliance
private boolean array IsAllyBoolean
endglobals
// Bleh
private module ASInit
private static method onInit takes nothing returns nothing
call init()
endmethod
endmodule
// You know what? Just skip this.
private struct AS extends array
private static method getPlayer takes string s returns player
local integer i = 0
loop
exitwhen i > 11
if GetPlayerName(Player(i)) == s or GetPlayerId(Player(i)) + 1 == S2I(s) then
return Player(i)
endif
set i = i + 1
endloop
return null
endmethod
private static method ally takes nothing returns boolean
local player p1 = GetTriggerPlayer()
local player p2 = thistype.getPlayer (SubString(GetEventPlayerChatString(), StringLength(ALLY_PREFIX) + 1, StringLength(GetEventPlayerChatString())))
local integer i = GetPlayerId(p1)
local integer j = GetPlayerId(p2)
local integer k = MaxAlliance[i]
local string s1 = GetPlayerName(p1)
local string s2 = GetPlayerName(p2)
if p2 != null and /*
*/ p1 != p2 and /*
*/ GetPlayerSlotState(p2) == PLAYER_SLOT_STATE_PLAYING and /*
*/ GetPlayerController(p2) == MAP_CONTROL_USER then
if IsAllyBoolean[j*12 + i] and IsAllyBoolean[i*12 + j] then
call BlizzardMessage("Alliance between " + s1 + " and " + s2 + " has already been established", "|cffffcc00", 55, p1)
else
if k > 0 or k == -1 then
if k != -1 then
set MaxAlliance[i] = MaxAlliance[i] - 1
endif
if IsAllyBoolean[j*12 + i] then
call Ally(p1, p2, 7)
call BlizzardMessage("Alliance between " + s1 + " and " + s2 + " is successfully established", "|cffffcc00", 71, p1)
call BlizzardMessage("Alliance between " + s1 + " and " + s2 + " is successfully established", "|cffffcc00", 71, p2)
set IsAllyBoolean[i*12 + j] = true
else
call BlizzardMessage("Alliance request sent to " + s2, "|cffffcc00", 45, p1)
call BlizzardMessage("Alliance request received from " + s1, "|cffffcc00", 45, p2)
set IsAllyBoolean[i*12 + j] = true
endif
else
call BlizzardMessage("Out of alliance attempt", "|cffffcc00", 55, p1)
endif
endif
else
call BlizzardMessage("[AllianceSystem] Invalid target player", "|cffffcc00", 55, p1)
endif
set p1 = null
set p2 = null
return false
endmethod
private static method disally takes nothing returns boolean
local player p1 = GetTriggerPlayer()
local player p2 = thistype.getPlayer (SubString(GetEventPlayerChatString(), StringLength(DISALLY_PREFIX) + 1, StringLength(GetEventPlayerChatString())))
local integer i = GetPlayerId(p1)
local integer j = GetPlayerId(p2)
local string s1 = GetPlayerName(p1)
local string s2 = GetPlayerName(p2)
if p2 != null and /*
*/ p1 != p2 and /*
*/ GetPlayerSlotState(p2) == PLAYER_SLOT_STATE_PLAYING and /*
*/ GetPlayerController(p2) == MAP_CONTROL_USER then
if IsAllyBoolean[i*12 + j] and IsAllyBoolean[j*12 + i] then
call Ally(p1, p2, 0)
call BlizzardMessage("Alliance between " + s1 + " and " + s2 + " has been terminated", "|cffffcc00", 131, p1)
call BlizzardMessage("Alliance between " + s1 + " and " + s2 + " has been terminated", "|cffffcc00", 131, p2)
set IsAllyBoolean[i*12 + j] = false
set IsAllyBoolean[j*12 + i] = false
else
call BlizzardMessage("No alliance established between " + s1 + " and " + s2, "|cffffcc00", 55, p1)
endif
else
call BlizzardMessage("[AllianceSystem] Invalid target player", "|cffffcc00", 55, p1)
endif
set p1 = null
set p2 = null
return false
endmethod
private static method init takes nothing returns nothing
local trigger ally = CreateTrigger()
local trigger disally = CreateTrigger()
local integer j = 0
loop
exitwhen j > 11
if GetPlayerSlotState(Player(j)) == PLAYER_SLOT_STATE_PLAYING and /*
*/ GetPlayerController(Player(j)) == MAP_CONTROL_USER then
call TriggerRegisterPlayerChatEvent(ally, Player(j), ALLY_PREFIX, false)
call TriggerRegisterPlayerChatEvent(disally, Player(j), DISALLY_PREFIX, false)
set MaxAlliance[j] = MAX_ALLIANCE_ATTEMPT
endif
set j = j + 1
endloop
call TriggerAddCondition(ally, Condition(function thistype.ally))
call TriggerAddCondition(disally, Condition(function thistype.disally))
set ally = null
set disally = null
endmethod
implement ASInit
endstruct
endlibrary