• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Need help with alliance script

Status
Not open for further replies.
Level 5
Joined
Jul 25, 2008
Messages
126
JASS:
scope TeamSetup initializer onInit
    private function Select_Team_One takes nothing returns nothing
        local integer i = 0
        call BJDebugMsg("This is how we do it!")
    
        loop
            if IsPlayerAlly(Player(i), Player(0)) then
                call SetPlayerAlliance(Player(i), Player(13), ALLIANCE_SHARED_VISION, true)
                call BJDebugMsg("Player " + I2S(i) + " allied!")
            endif
            set i = i + 1
            exitwhen i == bj_MAX_PLAYER_SLOTS
        endloop
    endfunction
    
    private function onInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerAddAction(t, function Select_Team_One)
    endfunction
endscope

my debug messages dsiplay but i am still not allied to nuetral victim (player 13)
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,255
Yes exactly how your trigger should work. You do not ally him, only set shared vision.

There are all these allience states to manage as well remember...
JASS:
ALLIANCE_HELP_REQUEST
ALLIANCE_HELP_RESPONSE
ALLIANCE_PASSIVE
ALLIANCE_RESCUABLE
ALLIANCE_SHARED_ADVANCED_CONTROL
ALLIANCE_SHARED_CONTROL
ALLIANCE_SHARED_SPELLS
ALLIANCE_SHARED_VISION
ALLIANCE_SHARED_VISION_FORCED
ALLIANCE_SHARED_XP

ALLIANCE_PASSIVE
Prevents enemies flagging as hostile.

ALLIANCE_SHARED_XP
Enables hero EXP to be shared.

ALLIANCE_SHARED_SPELLS
Enables the targeting behaviour of spells to be friendly towards them.

ALLIANCE_HELP_REQUEST
ALLIANCE_HELP_RESPONSE
Enables the allied attack notifications.

Be aware that allience changes are mono directional as well. He can appear friendly to you while you appear hostile to him. If you want both parties to partake the same in an allience you will have to repeat the call with the players swaped.
 
Level 5
Joined
Jul 25, 2008
Messages
126
aHH I see thankyou very much

how would I condense this code?


JASS:
scope TeamSetup initializer onInit
    private function onInit takes nothing returns nothing
        local integer i = 0
        call BJDebugMsg("This is how we do it!")
    
        loop
            if IsPlayerAlly(Player(i), Player(0)) then
                call SetPlayerAlliance(Player(i),Player(13), ALLIANCE_SHARED_VISION, true )
                call SetPlayerAlliance(Player(i),Player(13), ALLIANCE_PASSIVE, true )
                call SetPlayerAlliance(Player(i),Player(13), ALLIANCE_HELP_RESPONSE, true )
                call SetPlayerAlliance(Player(i),Player(13), ALLIANCE_HELP_REQUEST, true )
                call SetPlayerAlliance(Player(i),Player(13), ALLIANCE_PASSIVE, true )
                call SetPlayerAlliance(Player(i),Player(13), ALLIANCE_SHARED_XP, true )
                call SetPlayerAlliance(Player(i),Player(13), ALLIANCE_SHARED_SPELLS, true )
                call SetPlayerAlliance(Player(13),Player(i), ALLIANCE_SHARED_VISION, true )
                call SetPlayerAlliance(Player(13),Player(i), ALLIANCE_PASSIVE, true )
                call SetPlayerAlliance(Player(13),Player(i), ALLIANCE_HELP_RESPONSE, true )
                call SetPlayerAlliance(Player(13),Player(i), ALLIANCE_HELP_REQUEST, true )
                call SetPlayerAlliance(Player(13),Player(i), ALLIANCE_PASSIVE, true )
                call SetPlayerAlliance(Player(13),Player(i), ALLIANCE_SHARED_XP, true )
                call SetPlayerAlliance(Player(13),Player(i), ALLIANCE_SHARED_SPELLS, true )
                call BJDebugMsg("Player " + I2S(i) + " allied!")
            endif
            if IsPlayerAlly(Player(i), Player(1)) then
                call SetPlayerAlliance(Player(i),Player(14), ALLIANCE_SHARED_VISION, true )
                call SetPlayerAlliance(Player(i),Player(14), ALLIANCE_PASSIVE, true )
                call SetPlayerAlliance(Player(i),Player(14), ALLIANCE_HELP_RESPONSE, true )
                call SetPlayerAlliance(Player(i),Player(14), ALLIANCE_HELP_REQUEST, true )
                call SetPlayerAlliance(Player(i),Player(14), ALLIANCE_PASSIVE, true )
                call SetPlayerAlliance(Player(i),Player(14), ALLIANCE_SHARED_XP, true )
                call SetPlayerAlliance(Player(i),Player(14), ALLIANCE_SHARED_SPELLS, true )
                call SetPlayerAlliance(Player(14),Player(i), ALLIANCE_SHARED_VISION, true )
                call SetPlayerAlliance(Player(14),Player(i), ALLIANCE_PASSIVE, true )
                call SetPlayerAlliance(Player(14),Player(i), ALLIANCE_HELP_RESPONSE, true )
                call SetPlayerAlliance(Player(14),Player(i), ALLIANCE_HELP_REQUEST, true )
                call SetPlayerAlliance(Player(14),Player(i), ALLIANCE_PASSIVE, true )
                call SetPlayerAlliance(Player(14),Player(i), ALLIANCE_SHARED_XP, true )
                call SetPlayerAlliance(Player(14),Player(i), ALLIANCE_SHARED_SPELLS, true )
                call BJDebugMsg("Player " + I2S(i) + " allied!")
            endif
            set i = i + 1
            exitwhen i == bj_MAX_PLAYER_SLOTS
        endloop
    endfunction
    

endscope
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,255
Well you use the principles of breaking down procedural coupling on it...

JASS:
scope TeamSetup initializer onInit
    private function AllySingle takes player p1, player p2 returns nothing
        call SetPlayerAlliance(p1,p2, ALLIANCE_SHARED_VISION, true )
        call SetPlayerAlliance(p1,p2, ALLIANCE_PASSIVE, true )
        call SetPlayerAlliance(p1,p2, ALLIANCE_HELP_RESPONSE, true )
        call SetPlayerAlliance(p1,p2, ALLIANCE_HELP_REQUEST, true )
        call SetPlayerAlliance(p1,p2, ALLIANCE_SHARED_XP, true )
        call SetPlayerAlliance(p1,p2, ALLIANCE_SHARED_SPELLS, true )
    endfunction

    private function AllyMutural takes player p1, player p2 returns nothing
        call AllySingle(p1,p2)
        call AllySingle(p2,p1)
    endfunction

    private function AllyInCommon takes player p1, player p2, player who returns nothing
        if IsPlayerAlly(p1, who) then
            call AllyMutural(p1,p2)
        endif
    endfunction

    private function onInit takes nothing returns nothing
        local integer i = 0
        loop
            call AllyInCommon(Player(i),Player(13),Player(0))
            call AllyInCommon(Player(i),Player(14),Player(1))
            set i = i + 1
            exitwhen i == bj_MAX_PLAYER_SLOTS
        endloop
    endfunction
endscope

This is somewhat the result. Not the fastest to execute but most procedural coupling has been removed.
 
Status
Not open for further replies.
Top