• 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.

Multi Player instance

Status
Not open for further replies.
Level 15
Joined
Aug 7, 2013
Messages
1,338
In some cases it might not be as straightforward as having a variable/array position for each player, e.g. there are some events which have to be binded to a single player (player unit events), and so you would need to loop over your total players and create a trigger for each one (but the condition/action could be the same).

Here's an example
JASS:
    loop
        exitwhen i == TOTAL_PLAYERS
        set t = CreateTrigger()
        call TriggerRegisterPlayerChatEvent(t, Player(i), "-", false)
        call TriggerAddCondition(t, Condition(function main))
        set playerDatum[i].npcTrig = t
        call DisplayTimedTextToPlayer(Player(i), 0, 0, 15, "Are you a guy or a girl?  Type '-male' or '-female' to choose your gender!")
        set i = i + 1
    endloop
 
Level 7
Joined
Mar 6, 2014
Messages
203
In some cases it might not be as straightforward as having a variable/array position for each player, e.g. there are some events which have to be binded to a single player (player unit events), and so you would need to loop over your total players and create a trigger for each one (but the condition/action could be the same).

Here's an example
JASS:
    loop
        exitwhen i == TOTAL_PLAYERS
        set t = CreateTrigger()
        call TriggerRegisterPlayerChatEvent(t, Player(i), "-", false)
        call TriggerAddCondition(t, Condition(function main))
        set playerDatum[i].npcTrig = t
        call DisplayTimedTextToPlayer(Player(i), 0, 0, 15, "Are you a guy or a girl?  Type '-male' or '-female' to choose your gender!")
        set i = i + 1
    endloop

Can you convert it in GUI? im not good in jass
 
Level 11
Joined
Aug 6, 2009
Messages
697
  • Heal
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • Set TempInt = (Player number of (Owner of (Triggering unit)))
      • Set H_Target[TempInt] = (Target unit of ability being cast)
      • Set H_Time[TempInt] = 3.00
I used TempInt to make the trigger more readable. TempInt uses the player number of the triggering unit which is a number between 1-12.

  • Heal Loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • For each (Integer H_Loop) from 1 to 12, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • H_Time[H_Loop] Greater than 0.00
            • Then - Actions
              • Set H_Time[H_Loop] = (H_Time[H_Loop] - 0.03)
              • Unit - Set life of H_Target[H_Loop] to ((Life of H_Target[H_Loop]) + 1.00)
            • Else - Actions
The 1 to 12 in the loop represents the amount of players in the game so I made this spell for 12 players.
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
Actually Chaosy gave the answer.

I don't think that's true.

AFAIK the OP's question was

Hello can anyone show me an example of MPI?? THX!:)

Chaosy described the general approach to making something MPI, but didn't give an actual example, which is what my post did (a string event that works for all players). The only problem with my answer is that the OP does GUI and not (v)JASS, which was not mentioned in the OP.
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
IcemanBo said:
But your example had not much to do with MPI. Your code is an example for usage of loops

Whatever is needed to make something MPI. And it is an example of MPI. I use a global array for each player in the body of the loop, with i as the player id index.

JASS:
set playerDatum[i].npcTrig = t
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
I don't think that's true.

AFAIK the OP's question was



Chaosy described the general approach to making something MPI, but didn't give an actual example, which is what my post did (a string event that works for all players). The only problem with my answer is that the OP does GUI and not (v)JASS, which was not mentioned in the OP.

the problem with your example is that no GUI-er will ever need anything like that, because they dont have access to custom script within events block. So to this point, Chaosy's and Iceman's answers are valid and correct ones(Iceman's especially, he even showed what to use as index)
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
Can you convert it in GUI? im not good in jass

MUI/MPI is so much easier in jass though :(

JASS:
    struct FlameWave extends array
        implement Alloc
        implement StructAttach
        
        unit caster
        private integer lvl
        real dmgPerMainHit
        real dmgPerSideHit
        boolean continue
        boolean tick
        Missile dragon
        
        public method onTimerExpire takes nothing returns nothing
            set caster = null
            call detach(caster)
            call this.deallocate()
        endmethod
        
        public method onExpire takes nothing returns nothing
        
        endmethod
        
        public method onLoop takes nothing returns boolean
            local real x
            local real y
            local real angle = GetRandomAngle()
            local group g
            local unit u
            
            if not continue then
                //call DestroyGroup(g)
                return false
            endif
           
            set x = dragon.x + (GetRandomInt(1,200) * Cos(angle))
            set y = dragon.y + (GetRandomInt(1,200) * Sin(angle))
            
            call DestroyEffect(AddSpecialEffect(FW_BRANCH_FX, x, y))
            
            set g = CreateGroup()
            
            call GroupEnumUnitsInRange(g, x, y, FW_BRANCH_RADIUS, getTargetFilter(GetOwningPlayer(caster)))
            set u = FirstOfGroup(g)
            loop
                exitwhen u == null
                call spellDamage(caster,u,dmgPerSideHit)
                call GroupRemoveUnit(g,u)
                set u = FirstOfGroup(g)
            endloop
            call DestroyGroup(g)
            return true
        endmethod
        
        implement FAT
        implement T32Interface
        
        static method onFinish takes Missile this returns boolean
            set FlameWave(this.data).continue = false
            return true
        endmethod
        
        static method onCollide takes Missile this, unit justHit returns boolean
            if isViableTarget(this.source,justHit) then
                call spellDamage(this.source, justHit, FlameWave(this.data).dmgPerMainHit * BurningSoul.applyBurnPercentage(this.source,justHit))
            endif
            return false
        endmethod
            
            
        implement MissileStruct
        
        public static method shoot takes unit casterv, real x, real y, boolean isPhoenix returns nothing
            local thistype this = thistype.allocate()
            //local unit       cast = casterv
            local real       casx = GetUnitX(casterv)
            local real       casy = GetUnitY(casterv)
            local integer spellId = FW_ID
            local real        ang =  Atan2((y - casy),(x - casx))
            local real       dist = FW_DIST
            local Missile       m
            if not isPhoenix then
                set this.caster = casterv
            else
                set this.caster = GetPlayerHero(GetOwningPlayer(casterv))
            endif
            
            set lvl = GetUnitAbilityLevel(caster, spellId)
            call setu(caster, this)
            set dmgPerMainHit = (FW_CORE_INT + (FW_CORE_INT_FACTOR * lvl)) * GetHeroInt(caster,true)
            set dmgPerSideHit = (FW_BRANCH_INT + (FW_BRANCH_INT_FACTOR * lvl)) * GetHeroInt(caster,true)
            set continue = true
             
            //---------------------------------------------------------
            set m             = Missile.create(casx, casy, 100, ang, dist, 100)
            set m.model       = FW_FX
            set m.speed       = FW_SPEED
            set m.collision   = 150
            set m.data        = this
            set m.source      = caster 
            set dragon = m
            call thistype.launch(m)
            
            call runTime(20,this)
            call add()
        endmethod
    
    endstruct
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
the problem with your example is that no GUI-er will ever need anything like that.

The OP didn't state in what format he/she needed until after my answer, only asking for an example. This doesn't invalidate the information I provided.

answers are valid and correct ones

My solution is just as valid. Chaosy described the general technique, but did not supply an actual example. My answer was supplementing that post, showing that it also can require loops over the total players (for player events). AFAIK registering events which require a player as an argument require this kind of looping, otherwise they can't be MPI.

In any case, all my code is MPI, otherwise my project couldn't run (its a multiplayer RPG). And that's an example of how it's done, which is what the OP asked. Note he/she didn't say it had to be in GUI, vJASS, JASS, etc. until after I posted my answer. I'm no psychic.

Hello can anyone show me an example of MPI?? THX!:)
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
yes, your answer is valid and working, but if someone is asking for example on MPI, chances are, he has no ideea what Jass is, therefore will have no idea how events work internally, therefore making your example kind of pointless in this case, because I dont think op cares about this at this point of time. He maybe wants to make some good spell, which would work for all players, and last time I checked there is Generic Unit Event - Unit Starts Effect of ability.

My point is that yours(as well as Arhowk's) example is a bit higher level for the user
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
The OP hasn't clarified what he/she needs to make MPI--we don't know if its a custom spell yet or a string chat event. It is a rather vague question, and hopefully the OP clarifies on his/her specific needs.
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,219
If this was some kind of competition I would understand your argument. "Yeah you didn't specify so I want a point for that" however this is about being helpful you can't just say like "Deal with it, you didn't specify"

Also to be realistic my explanation work in 9/10 cases and that one time it's likely something very specific that I wont even come up with on the spot.

Here's an example btw. http://www.hiveworkshop.com/forums/...ed-213880/?prev=search=MPI&r=20&d=list&page=2
 
Status
Not open for further replies.
Top