System Alliance System

Doug

New Member
Reaction score
1
Dougleton Alliance System
version 1.5
by Doug


This is a vJASS player alliance system easy to implement as long as you have JASS New Gen Pack. Even if you're only experienced with GUI, you can easily implement this system into your map. The system allows players to ally or unally each other in game via -ally color and -unally color (-ally/unally player name or -ally number/-unally number even) chat messages.

Features

+ You can type out the full color name or abreviations when using -ally or -unally. Some examples: -ally lightblue -ally lb -unally orange -ally oj. Player numbers can also be use to ally. For example: -ally 4 You can now even use -ally player name!
+ You can toggle the Alliance system on or off for certain players.
+ A message displays saying who allied who or vise versa. You can toggle this message on or off and easily edit the string "has allied" or "has unallied."
+ Extremely easy to implement.

The Code

JASS:

//            
//           .^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^.
//          /| Dougleton Alliance System v1.5 |\
//  /^^^^^^/ |   Made by Dougleton@Azeroth    | \^^^^^^^^\
// /       \_.________________________________._/         \
// |                                                      | 
// |Simple system that allows players to ally or unally   | 
// |one another using -ally/unally color, number,         |
// |or player name.                                       |
// |You can toggle ally message display on or off in      |
// |the globals. To toggle the system on or off for       |
// |certain players edit struct DAS in the function       |
// |LoadDougletonAllianceSystem()                         |
// |                                                      |
// |Go to map.ruthlessreign.com for help with this system |
// <______________________________________________________>
// |                   Change log                         |
// <______________________________________________________>
// |v1.5  *Rewrote entire code.                           |  
// <______________________________________________________>

library DougletonAllianceSystem initializer InitDougletonAlly

globals
    //Set this to false if you do not want
    //the system displaying a message who
    //allied who, etc.
    private constant boolean Dougleton_Alliance_Messages_On = true 
       
    //Change the Ally or Unally message
    // ex. "Player 1 has unallied Player 2"
    private constant string AllyMessage = "has allied"             
    private constant string UnallyMessage = "has unallied"         
endglobals

struct DAS extends array
    string col   //Player's color code example "|cffFF8000"
    string sub1  //Substring1 example "orange"
    string sub2  //Substring2 example "oj"
    string num1  //Player Number example "5"
    string name  //Player Name 
    boolean on   //Player able to ally and be allied with?
endstruct
    
private function LoadDougletonAllianceSystem takes nothing returns nothing
    local integer i = 0
    set DAS[0].col = "|cffFF0000"
    set DAS[0].sub1 = "red"
    set DAS[0].sub2 = ""
    set DAS[1].col = "|cff0000FF"
    set DAS[1].sub1 = "blue"
    set DAS[1].sub2 = ""
    set DAS[2].col = "|cff00FFFF"
    set DAS[2].sub1 = "teal"
    set DAS[2].sub2 = ""
    set DAS[3].col = "|cff800080"
    set DAS[3].sub1 = "purple"
    set DAS[3].sub2 = "purp"
    set DAS[4].col = "|cffFFFF00"
    set DAS[4].sub1 = "yellow"
    set DAS[4].sub2 = "yel"
    set DAS[5].col = "|cffFF8000"
    set DAS[5].sub1 = "orange"
    set DAS[5].sub2 = "oj"
    set DAS[6].col = "|cff00FF00"
    set DAS[6].sub1 = "green"
    set DAS[6].sub2 = ""
    set DAS[7].col = "|cffFF00FF"
    set DAS[7].sub1 = "pink"
    set DAS[7].sub2 = ""
    set DAS[8].col = "|cff808080"
    set DAS[8].sub1 = "gray"
    set DAS[8].sub2 = "grey"
    set DAS[9].col = "|cff80FFFF"
    set DAS[9].sub1 = "lightblue"
    set DAS[9].sub2 = "lb"
    set DAS[10].col = "|cff008040"
    set DAS[10].sub1 = "darkgreen"
    set DAS[10].sub2 = "dg"
    set DAS[11].col = "|cff804000"
    set DAS[11].sub1 = "brown"
    set DAS[11].sub2 = ""
    loop
    exitwhen i > 11
        set DAS<i>.on = true
        set DAS<i>.num1 = I2S(GetPlayerId(Player(i))+1)
        set DAS<i>.name = GetPlayerName(Player(i))
        set i = i+1
    endloop
    // If you want to turn the alliance system off for specific players
    // below this comment is a good place to do it. ex set DAS[1].on=false
    // Turns it off for Player 2 Blue
    
endfunction

private function Dougleton_Ally_Or_Unally takes nothing returns nothing
    local string s = SubString(GetEventPlayerChatString(), 0, 50)
    local integer p = 11
    local boolean allying
    local integer state
    if DAS[GetPlayerId(GetTriggerPlayer())].on then
        if SubString(s, 0, 2) == &quot;-u&quot; then
            set s = SubString(s, 8, 50)
            set allying = false
            set state = bj_ALLIANCE_UNALLIED
        else
            set s = SubString(s, 6, 50)
            set allying = true
            set state = bj_ALLIANCE_ALLIED_VISION
        endif
        loop
        exitwhen p &lt; 0
            if s == DAS[p].sub1 or s == DAS[p].sub2 or s == DAS[p].num1 or s == DAS[p].name then
                if DAS[p].on then
                    call SetPlayerAllianceStateBJ( GetTriggerPlayer(), Player(p), state )
                    if Dougleton_Alliance_Messages_On then
                        if allying then
                            set s = AllyMessage
                        else
                            set s = UnallyMessage
                        endif
                    call BJDebugMsg( DAS[GetPlayerId(GetTriggerPlayer())].col + DAS[GetPlayerId(GetTriggerPlayer())].name + &quot;|r|cffFFFFFF &quot; + s + &quot; |r&quot; + DAS[p].col + DAS[p].name)
                    endif
                endif
                set p = -1
            else
                set p = p-1
            endif
        endloop
    endif
endfunction

private function InitDougletonAlly takes nothing returns nothing
    local integer i = 0
    local trigger t = CreateTrigger(  )
    call LoadDougletonAllianceSystem()
    loop
    exitwhen i &gt; 11
        call TriggerRegisterPlayerChatEvent( t, Player(i), &quot;-ally&quot;, false )
        call TriggerRegisterPlayerChatEvent( t, Player(i), &quot;-unally&quot;, false )
        set i = i+1
    endloop
    call TriggerAddAction( t, function Dougleton_Ally_Or_Unally)
endfunction
endlibrary



</i></i></i>


Quick Implement

If you're experienced with JASS all you need to do is copy this code into your map header or a trigger box and it is ready to use! If you're not very experienced with JASS, but know the basics of GUI here is a simple process to implement this system:
1. Download the system map file by clicking here.
2. Copy the trigger Dougleton Alliance System and then paste it into your map. Remember this is coded in vJASS so you will need Jass New Gen Pack for this to work.


 

Attachments

  • DougletonAllianceSystemv1_5.w3x
    19.4 KB · Views: 334

Azlier

Old World Ghost
Reaction score
461
You cannot simply copy this into your map header. Why use a library if all you are going to take advantage of are some global variables? The ally and unally triggers will simply not work. Inefficient, as well, with all the SubString hubbub.
 

Doug

New Member
Reaction score
1
You don't copy it into the header you copy each piece into a trigger. Why not use a library?
 

Azlier

Old World Ghost
Reaction score
461
You said:
If you're expereinced with Jass all you need to do is copy that library into your map along with the ally and unally triggers.

Looky there. A good, easy to import script only requires you to highlight all the text and paste it anywhere they like, whether it be the map header or even a normal trigger box.
 

Azlier

Old World Ghost
Reaction score
461
You neglected to mention that the trigger pages must have exact trigger names, otherwise you get syntax errors.
 

Azlier

Old World Ghost
Reaction score
461
And you didn't make it so that a simple copy and paste does the trick why...?
 

Doug

New Member
Reaction score
1
Hmm if its possible i would like to know how. Im guessing it wouldn't be too hard from what you're saying. Im kinda new to vJass so cut me some slack here.
 

Azlier

Old World Ghost
Reaction score
461
JASS:
function InitTrig_JASS_Ally takes nothing returns nothing
    local integer i =0
    set gg_trg_JASS_Ally = CreateTrigger(  )
    loop
    exitwhen i &gt; 11
        call TriggerRegisterPlayerChatEvent( gg_trg_JASS_Ally, Player(i), &quot;-ally&quot;, false )
        set i = i+1
    endloop
    call TriggerAddAction( gg_trg_JASS_Ally, function Dougleton_Ally)
endfunction


Should be

JASS:
function InitTrig_JASS_Ally takes nothing returns nothing
    local integer i =0
    local trigger t = CreateTrigger(  )
    loop
    exitwhen i &gt; 11
        call TriggerRegisterPlayerChatEvent( t, Player(i), &quot;-ally&quot;, false )
        set i = i+1
    endloop
    call TriggerAddAction( t, function Dougleton_Ally)
endfunction

You see what I did there? It can be safely ported into the map header now.
 

Doug

New Member
Reaction score
1
If you do it that way, can it be put in a regular trigger box as well?
 

Azlier

Old World Ghost
Reaction score
461
Bah, ignore my upper post. It wouldn't work.

Here is a good version.

JASS:
scope Ally initializer Init

private function Init takes nothing returns nothing
    local integer i =0
    local trigger t = CreateTrigger(  )
    loop
    exitwhen i &gt; 11
        call TriggerRegisterPlayerChatEvent( t, Player(i), &quot;-ally&quot;, false )
        set i = i+1
    endloop
    call TriggerAddAction( t, function Dougleton_Ally)
endfunction

endscope


I'd read up on the intricates of scopes and libraries. In modern JASS, all code should exist within one.
 

Doug

New Member
Reaction score
1
Sweet dude, i'm going to fix this up then. Thanks for teaching me this trick.

Edit: Ok fixed up!
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top