• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[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,223
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,223
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