Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Trigger : 3 kind of units giving me gold per minut.

Discussion in 'World Editor Help Zone' started by Daliox1, Sep 30, 2020.

  1. Daliox1

    Daliox1

    Joined:
    Sep 3, 2020
    Messages:
    103
    Resources:
    0
    Resources:
    0
    Hey there.

    First of all, I'm sorry if a thread was already open about this. I do also apologize for my english :peasant-confused:
    Then, I'm kinda reaaaaaally new with triggers, just learnt them a week ago :peasant-work-work: and I was wondering if someone could help me to fix something I cannot reach.

    I would like that 3 of my custom units give me 1 gold every 120 seconds while they're alive (let's say, a Peasant, a Footman and a Rifleman). Can someone explain me how I could reach this with triggers ? :)

    Thank youuuuuuuuuuu :peasant-grin:
     
  2. [db]east

    [db]east

    Joined:
    Feb 27, 2019
    Messages:
    144
    Resources:
    0
    Resources:
    0
    This will give players gold for the units every 120 seconds. Will give 1 gold for a unit that has been alive for the entire 120 seconds aswell as for the unit that has only been alive for 1 second.

    Variables
    TempGroup = Unit Group that is used temporarily to not create leaks. Can be used by any other trigger as long as it is set, used and destroyed immediatly without any waits.
    Gold = Integer with an array equal to the number of players playing.

    Every 120 seconds of game-time
    Set TempGroup = Units in Playable match area matching matching unit is alive equal to true and matching unit-type of matching unit equal to Peasant or matching unit-type of matching unit equal to Footman or matching unit-type of matching unit equal to Rifleman
    Pick every unit in TempGroup
    Set Gold(Player number of (Owner of (Picked unit) = Gold(Player number of (Owner of (Picked unit) + 1
    call DestroyGroup(udg_TempGroup)
    Pick every player in (All Players)
    Set property (Picked Player) current gold to (Picked Player) current gold + Gold(Player number of (Picked Player)
    Set Gold(Player number of (Picked Player) = 0




    The next one will add 1 gold when the count of all affected units reaches 120.

    Variables
    CashMoneeeeyGroup = Unit Group. Does not create a leak because we will always use it.
    Int = Integer to keep track of player number easily and to make the trigger more effective. Integers do not leak.
    GoldCount = Integer array with size of amount of players to keep track of when 1 gold should be added to the player.

    Add to Group
    -A unit enters Playable map area
    -A unit is revived <- (May not be needed)
    --Or any conditions are true
    ---Unit-type of triggering unit equal to Peasant
    ---Unit-type of triggering unit equal to Footman
    ---Unit-type of triggering unit equal to Rifleman
    ----Add triggering unit to CashMoneeeeyGroup
    ----If
    ----Trigger Periodic Gold is off
    ----Then
    ----Trigger turn on Periodic Gold
    ----Else

    Remove from Group
    -A unit dies
    --Triggering unit is in CashMoneeeeyGroup
    ---Remove (Triggering unit) from CashMoneeeeyGroup
    ---If
    ---Number of units in CashMoneeeeyGroup = 0
    ---Then
    ---Trigger turn off Periodic Gold
    ---Else
    (Does not work if the unit is Removed with Remove unit action)

    Periodic Gold
    -Every 1 seconds of game-time
    --Pick every unit in CashMoneeeeyGroup
    ---Set Int = (Player number of (Owner of (Picked unit)
    ---Set GoldCount(Int) = GoldCount(Int) + 1
    ----If
    ----GoldCount(Int) greater than 119
    ----Then
    ----Set Set Player(Int) current gold to Player(Int) current gold + 1
    ----Set GoldCount(Int) = GoldCount(Int) - 120
    ----Else
    (Can only give a maximum of 1 gold per second)



    Probably a more effective way of doing it.

    Variables
    GoldUnits = Integer array with size equal to amount of players to keep track of the amount of units adding to the GoldCount
    GoldCount
    GoldForce = Player Group. Players who have a unit that gives gold

    Increase GoldUnits
    -A unit enters Playable map area
    -A unit is revived
    --Or any conditions are true
    ---Unit-type of triggering unit equal to Peasant
    ---Unit-type of triggering unit equal to Footman
    ---Unit-type of triggering unit equal to Rifleman
    ----Set GoldUnits(Player number of (Triggering player) = GoldUnits(Player number of (Triggering player) + 1
    ----If
    ----(Triggering Player) is in GoldForce equal to False
    ----Then
    -------Add (Triggering Player) to GoldForce
    -------If
    -------Number of Players in (GoldForce) equal to 1
    -------Then
    -------Turn on Periodic Gold
    -------Else
    ----Else

    Decrease GoldUnits
    -A unit dies
    --Or any conditions are true
    ---Unit-type of triggering unit equal to Peasant
    ---Unit-type of triggering unit equal to Footman
    ---Unit-type of triggering unit equal to Rifleman
    ----Set GoldUnits(Player number of (Triggering player) = GoldUnits(Player number of (Triggering player) - 1
    ----If
    ----GoldUnits(Player number of (Triggering player) = 0
    ----Then
    -------Remove (Triggering Player) from GoldForce
    -------If
    -------Number of Players in (GoldForce) equal to 0
    -------Then
    -------Turn off Periodic Gold
    -------Else
    ----Else

    Periodic Gold
    -Every 1 seconds of game-time
    --Pick every player in (GoldForce)
    ---Set Int = (Player number of (Picked Player)
    ---Set GoldCount(Int) = GoldCount(Int) + GoldUnits(Int)
    ----If
    ----GoldCount(Int) greater than 119
    ----Then
    ----Set Set Player(Int) current gold to Player(Int) current gold + 1
    ----Set GoldCount(Int) = GoldCount(Int) - 120
    ----Else



    Yet another option would be to count all units GoldCount seperately and requires (I believe) a unit indexer. Or hashtable. This would be the most exact method of all I have listed.
     
    Last edited: Sep 30, 2020
  3. Chaosy

    Chaosy

    Tutorial Reviewer

    Joined:
    Jun 9, 2011
    Messages:
    11,063
    Resources:
    18
    Icons:
    1
    Maps:
    1
    Spells:
    10
    Tutorials:
    6
    Resources:
    18
  4. Daliox1

    Daliox1

    Joined:
    Sep 3, 2020
    Messages:
    103
    Resources:
    0
    Resources:
    0
    Thanks a lot for all the time you took writing me this man, I do appreciate a lot. I'll read all of this to understand all you've done and remade it by myself :)

    Thank you, I'll read this carefully :)
     
    Last edited: Oct 1, 2020