[vJASS] Alliance System v1.0.0.1

This bundle is marked as approved. It works and satisfies the submission rules.
ALLIANCE SYSTEM v1.0.0.1

Features
  • Simulate how real life alliances work. The establishment has to be mutually agreed upon but termination can be executed one-sidedly.
  • Sufficiently GUI-friendly.
  • => A simple alliance system, could be useful for melee maps and the like.



JASS:
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
  • Step 1: Copy the Required Libraries folder to your map.
  • Step 2: Copy the system code to your map.
  • Step 3: ???
  • Step 4: Profit!!1



+ v1.0.0.0: Initial release.
+ v1.0.0.1: Enable allying by player number. Now you cannot send an alliance request to players that have left or AI players.


CREDIT
  • Nestharus for PlayerAlliance.
  • Lohengrin for the system idea, originating from this thread.

FINAL WORDS
+All feedback, testing, criticism, suggestions, etc. are welcome. Thanks in advance.
+If you need help with this system, contact me or post in this thread.

Keywords:
alliance, ally, melee, swag, yolo, magtheridon96, jass
Contents

Alliance System (Map)

Reviews
11:36, 27th Jul 2013 PurgeandFire: Reviewed this via VM. It has been updated, so approved! I recommend this system for anyone who wants a solid -ally/-war system!

Moderator

M

Moderator

11:36, 27th Jul 2013
PurgeandFire: Reviewed this via VM. It has been updated, so approved! I recommend this system for anyone who wants a solid -ally/-war system!
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
you have double set IsAllyBoolean[j*12 + i] = false in ally method

also providing a way to ally by color would be great, because if I join game with some Chinesse or whoever, I will for sure wont be able to type his name in
 
Level 16
Joined
Dec 15, 2011
Messages
1,423
you have double set IsAllyBoolean[j*12 + i] = false in ally method

also providing a way to ally by color would be great, because if I join game with some Chinesse or whoever, I will for sure wont be able to type his name in

Whoops lol it seems I missed that. Thanks.

Yeh okay. Updating now :)

edit

System updated :)

edit

Of course this doesn't account for players naming themselves with an integer number between 1 and 12. But yeah, that is pretty stupid so I decided to overlook it ^^
 
Last edited:
Level 16
Joined
Dec 15, 2011
Messages
1,423
Not bad mate, this is very useful, worth a 5/5.

JASS:
                            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)
I presume it's possible to optimize it?

Thanks.

Hmm? That is for displaying the message to both players. Not sure what you mean mate :p
 
Level 8
Joined
Oct 1, 2010
Messages
412
Any way to limit the alliances? IE Players can only have 1 or 2 allies. And would it be possible to make alliances permanent? IE when you ally someone you cannot war them, and add a time limit so if after 10 minutes of game time you haven't allied someone you are randomly paired up with another player.
 
Level 16
Joined
Dec 15, 2011
Messages
1,423
Any way to limit the alliances? IE Players can only have 1 or 2 allies. And would it be possible to make alliances permanent? IE when you ally someone you cannot war them, and add a time limit so if after 10 minutes of game time you haven't allied someone you are randomly paired up with another player.

Sorry for the late reply, I have been extra busy recently.

Anyhow, there is an option to set the maximum number of alliances allowed. Just check the manual again.

About the new features, if I can manage somehow, I will add them. This is not a promise though since there are still real life and other things :p
 
Top