• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Creating Forces?

Status
Not open for further replies.
Level 6
Joined
Jun 30, 2006
Messages
230
Creating Forces and assigning an upgrade?

I've taken a 2 year break from Warcraft III, and now I'm getting back into it. Horay for me. However, it means I've lost almost everything I learned.

Problem:
In Scenario > Force Properties I've created two forces, Alliance and Horde. Now... how do I use those forces in a trigger? Do they have a global variable or something?

I'd also like to know how to create a force in JASS, I can't seem to remember all the aspects of doing this. I mean, selecting a player in a slot and then adding them to a force depending on the slot they are in. Then depending on which force they are in, research an upgrade.

Obviously, I've rusted :)

JASS:
scope InitForces

private function Alliance takes nothing returns nothing
    call SetPlayerState( GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD, 900 )
    call SetPlayerTechResearched( GetEnumPlayer(), 1, udg_ResearchId[0] )
endfunction

private function Horde takes nothing returns nothing
    call SetPlayerState( GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD, 900 )
    call SetPlayerTechResearched( GetEnumPlayer(), 1, udg_ResearchId[25] )
endfunction

private function Actions takes nothing returns nothing
    local integer i = 0
    call CreepSpawnPreload()
    set udg_Alliance = CreateForce()
    set udg_Horde = CreateForce()
    loop
        exitwhen i==6 
        call ForceAddPlayer(udg_Alliance,Player(i))
        call ForceAddPlayer(udg_Horde,Player(i+6))
        set i = i+1
    endloop
    call ForForce(udg_Alliance, function Alliance )
    call ForForce(udg_Horde, function Horde )
endfunction

//===========================================================================
public function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    call TriggerAddAction( trig, function Actions )
endfunction

endscope
JASS:
scope Init

private function Alliance takes nothing returns nothing
    call SetPlayerTechResearched( GetEnumPlayer(), 1, udg_ResearchId[0] )
endfunction

private function Horde takes nothing returns nothing
    call SetPlayerTechResearched( GetEnumPlayer(), 1, udg_ResearchId[25] )
endfunction

private function Actions takes nothing returns nothing
    local integer i = GetPlayerId(GetTriggerPlayer())
    call CreepSpawnPreload()
    if i < 10  then
        if i < 5 then
            call ForceAddPlayer( udg_Alliance, GetTriggerPlayer() )
        else
            call ForceAddPlayer( udg_Horde, GetTriggerPlayer() )
        endif
    endif
   call ForForce( udg_Alliance, function Alliance )
   call ForForce( udg_Horde, function Horde )
endfunction

//===========================================================================
public function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    call TriggerAddAction( trig, function Actions )
endfunction

endscope
JASS:
scope InitialResearch

private function Research takes nothing returns nothing
    local integer i = GetPlayerId(GetTriggerPlayer())
    if i < 10  then
        if i < 5 then
            call SetPlayerTechResearched( GetEnumPlayer(), 1, udg_ResearchId[0] )
        else
            call SetPlayerTechResearched( GetEnumPlayer(), 1, udg_ResearchId[25] )
        endif
    endif
endfunction
private function Actions takes nothing returns nothing
    local integer i = GetPlayerId(GetTriggerPlayer())
    local force f = CreateForce()
    if i < 10  then
        if i < 5 then
            set f = udg_Alliance
        else
            set f = udg_Horde
        endif
    endif
   call ForForce( f, function Research )
    set f = null
endfunction

//===========================================================================
public function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    call TriggerAddAction( trig, function Actions )
endfunction

endscope
 

Attachments

  • Blue_Jeans_test.w3x
    102.4 KB · Views: 91
Last edited:
I don't think the Force Properties affect the triggers. (basically, I don't think it creates a global) Thus, you will have to manually group them as a force. In GUI, it is a player group. In JASS:
JASS:
local force Alliance = CreateForce()
call ForceAddPlayer(Alliance,Player(0))

Or however you'd like to do it. :)

JASS:
//============================================================================
// Force API
//
native CreateForce              takes nothing returns force
native DestroyForce             takes force whichForce returns nothing
native ForceAddPlayer           takes force whichForce, player whichPlayer returns nothing
native ForceRemovePlayer        takes force whichForce, player whichPlayer returns nothing
native ForceClear               takes force whichForce returns nothing
native ForceEnumPlayers         takes force whichForce, boolexpr filter returns nothing
native ForceEnumPlayersCounted  takes force whichForce, boolexpr filter, integer countLimit returns nothing
native ForceEnumAllies          takes force whichForce, player whichPlayer, boolexpr filter returns nothing
native ForceEnumEnemies         takes force whichForce, player whichPlayer, boolexpr filter returns nothing
native ForForce                 takes force whichForce, code callback returns nothing

Welcome back. :)
 
Level 6
Joined
Jun 30, 2006
Messages
230
I added some code to my first post. I just need to figure out how to add each player to his corresponding force and it SHOULD work. Think so? I also realized that I don't need to create a local force, simple set up the global forces (because they will be used elsewhere) and then run an upgrade for each force. I realized the code is overcomplicated, I'll fix it in a moment.

And yes, those udg_'s are defined. And I keep udg_ there to remind me that they are globals, in case you are wondering.

Edit: Updated code. Think it will work?
 
Yep. You can just look in the force properties and copy whatever forces each player is in; and then on map initialization, you would do something like this:
JASS:
function InitializeForces takes nothing returns nothing
    local integer i = 0
    set udg_Alliance = CreateForce()
    set udg_Horde = CreateForce()
    loop
        exitwhen i==6 
        call ForceAddPlayer(udg_Alliance,Player(i))
        call ForceAddPlayer(udg_Horde,Player(i+6))
        set i = i+1
    endloop
endfunction

For this example, it will create the forces, and then add Player 1, 2, 3, 4, 5, and 6 to Alliance, and 7, 8, 9, 10, 11, and 12 to the Horde. :)

@Your code: Well, since it isn't responding to a player event, GetTriggerPlayer() would return as null. You might be looking for GetLocalPlayer() instead, which refers to the player currently running the code.
 
Level 6
Joined
Jun 30, 2006
Messages
230
@Your code: Well, since it isn't responding to a player event, GetTriggerPlayer() would return as null. You might be looking for GetLocalPlayer() instead, which refers to the player currently running the code.
Noted.

Okay, I have the following code. I added a piece so that each player in the force gets their starting gold set. It helps me debug whether it works, plus it needs done anyway. I also added the CreepSpawnPreload() function so that creeps will spawn based on the upgrade. I know the system works, no trouble there. However, in game this doesn't work:
JASS:
scope InitForces

private function Alliance takes nothing returns nothing
    call SetPlayerState( GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD, 900 )
    call SetPlayerTechResearched( GetEnumPlayer(), 1, udg_ResearchId[0] )
endfunction

private function Horde takes nothing returns nothing
    call SetPlayerState( GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD, 900 )
    call SetPlayerTechResearched( GetEnumPlayer(), 1, udg_ResearchId[25] )
endfunction

private function Actions takes nothing returns nothing
    local integer i = 0
    call CreepSpawnPreload()
    set udg_Alliance = CreateForce()
    set udg_Horde = CreateForce()
    loop
        exitwhen i==6 
        call ForceAddPlayer(udg_Alliance,Player(i))
        call ForceAddPlayer(udg_Horde,Player(i+6))
        set i = i+1
    endloop
    call ForForce(udg_Alliance, function Alliance )
    call ForForce(udg_Horde, function Horde )
endfunction

//===========================================================================
public function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    call TriggerAddAction( trig, function Actions )
endfunction

endscope

No gold is set, and my footmen don't spawn as if the research isn't done.
 
I forget whether or not you need to add initializer or not. (I think you could just use "InitTrig" before, but I am not sure. You can try adding an initializer anyway)
JASS:
scope InitForces initializer Init

private function Alliance takes nothing returns nothing
    call SetPlayerState( GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD, 900 )
    call SetPlayerTechResearched( GetEnumPlayer(), 1, udg_ResearchId[0] )
endfunction

private function Horde takes nothing returns nothing
    call SetPlayerState( GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD, 900 )
    call SetPlayerTechResearched( GetEnumPlayer(), 1, udg_ResearchId[25] )
endfunction

private function Actions takes nothing returns nothing
    local integer i = 0
    call CreepSpawnPreload()
    set udg_Alliance = CreateForce()
    set udg_Horde = CreateForce()
    loop
        exitwhen i==6 
        call ForceAddPlayer(udg_Alliance,Player(i))
        call ForceAddPlayer(udg_Horde,Player(i+6))
        set i = i+1
    endloop
    call ForForce(udg_Alliance, function Alliance )
    call ForForce(udg_Horde, function Horde )
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    call TriggerRegisterTimerEvent(trig,0,false)
//you can either: 
//   - checkmark "run at initialization"
//   - use this timer event
//   - or just directly replace all this functions' contents with "call Actions()"
    call TriggerAddAction( trig, function Actions )
endfunction

endscope
 
Level 6
Joined
Jun 30, 2006
Messages
230
I've tried all three methods you mentioned (who knows if I did them correctly), but I couldn't get them to work. I uploaded the map to my first post. Help if you can! I can't see why it doesn't work. If you cheat and give yourself gold, research the call rifleman upgrade and he should appear every 30 seconds...
 
Works for me (at least the gold part, didn't check the other one) when I add this initializer:
JASS:
scope InitForces initializer InitForces

private function Alliance takes nothing returns nothing
    call SetPlayerState( GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD, 900 )
    call SetPlayerTechResearched( GetEnumPlayer(), 1, udg_ResearchId[0] )
endfunction

private function Horde takes nothing returns nothing
    call SetPlayerState( GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD, 900 )
    call SetPlayerTechResearched( GetEnumPlayer(), 1, udg_ResearchId[25] )
endfunction

private function Actions takes nothing returns nothing
    local integer i = 0
    set udg_Alliance = CreateForce()
    set udg_Horde = CreateForce()
    loop
        exitwhen i==6 
        call ForceAddPlayer(udg_Alliance,Player(i))
        call ForceAddPlayer(udg_Horde,Player(i+6))
        set i = i+1
    endloop
    call ForForce(udg_Alliance, function Alliance )
    call ForForce(udg_Horde, function Horde )
endfunction

//===========================================================================
public function InitForces takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    call TriggerRegisterTimerEvent(trig,3,false)
    call TriggerAddAction( trig, function Actions )
endfunction

endscope

Good luck. :)
 
Yeah, it used to require you to use:
public function InitTrig takes nothing returns nothing

I'm not sure if that works still, it might.

But basically, initializers just allow you to declare any function you want to be called upon map initialization. It works on any kind of trigger/scope.

EDIT: Yeah, using public function InitTrig takes nothing returns nothing still works. It is just a choice of preference. Most people ditched using that, I guess they like typing "Init" more than InitTrig. :p Anyway, it is the same thing for the scope. It just helps to have initializers if you want more than one scope (with initializers) in a trigger. It is the same efficiency-wise though.
 
Level 6
Joined
Jun 30, 2006
Messages
230
When I would use the timer, the map freezes. My final solution was to add the initializer and directly call Actions inside of the InitTrig.

I'm done with this thread, but could you send me a link for Zinc?
 
Status
Not open for further replies.
Top