• 🏆 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!

[Spell Request] Periodic Gold Gain

Status
Not open for further replies.
Level 8
Joined
Dec 16, 2007
Messages
252
I've tried a few times but just couldn't succed with a MPI/MUI one of this spell.

Spell Description:
It's a passive spell that will give you 40/100/160/220 gold every 60 seconds and a floating golden text will also appear at the unit's position with the gained amount of gold. But it will give you gold 60 seconds FROM the time you added the spell. So a Every 60 seconds wouldn't work. Tried with timer but couldn't keep it MUI/MPI.
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
Thank you. Nah vJass is fine with me, I use NewGen anyway (I guess I can manage to modify it).

_____________

@XiligerNah I don't want to create 8 triggers just for a spell like this.

I will do as much as possible to make it most modifiable! ^^
Time interval, Gold amount, and you will need the Rawcode of the ability!
It is currently under construction (omg like that one ^^)
Since it is my very first vJass function, it might be really unfunctional =P
Lets hope for the best! ^^
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
ok, i think this should work:
JASS:
library GoldGain initializer Init uses TimerUtils
   globals
      private constant real TimeInterval = 60
      private integer array GoldPerInterval
      private constant integer AbID = 'A000' //Change this to rawcode of your Ability!
   endglobals
   struct GG
      unit u
      timer t
 
      static method Loop takes nothing returns nothing
         local timer t = GetExpiredTimer()
         local GG g = GetTimerData(t)
         if GetUnitAbilityLevel(g.u, AbID) != 0 then
            call SetPlayerState(GetOwningPlayer(g.u), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(GetOwningPlayer(g.u), PLAYER_STATE_RESOURCE_GOLD) + GoldPerInterval[GetUnitAbilityLevel(g.u, AbID)])
         else
            call PauseTimer(g.t)
            call ReleaseTimer(g.t)
            call g.destroy()
         endif
         set t = null
      endmethod
      static method Start takes nothing returns nothing
         local GG g = g.allocate()
         set g.u = GetTriggerUnit()
         set g.t = NewTimer()
         call SetTimerData(g.t, g)
         call TimerStart(g.t, TimeInterval, true, function GG.Loop)
      endmethod
      method onDestroy takes nothing returns nothing
         set .u = null
         set .t = null
      endmethod
   endstruct 
   private function Condition takes nothing returns boolean
      return GetSpellAbilityId() == AbID
   endfunction 
 
   private function Init takes nothing returns nothing
      local trigger t = CreateTrigger()
      local player p
      local integer i = 0
      loop
         exitwhen i == bj_MAX_PLAYER_SLOTS
         set p = Player(i)
         call TriggerRegisterPlayerUnitEvent(t, p, EVENT_PLAYER_HERO_SKILL, null)
         set p = null
         set i = i + 1
      endloop
      call TriggerAddCondition(t, function Condition)
      call TriggerAddAction(t, function GG.Start)
      set GoldPerInterval[1] = 40
      set GoldPerInterval[2] = 100
      set GoldPerInterval[3] = 160
      set GoldPerInterval[4] = 220
      set t = null
   endfunction
endlibrary
Contact me when it doesnt work (i cant test myself =S )

(Dont check the name! xD,, but it really is my very first! =P )
 

Attachments

  • My first Library.j
    2.1 KB · Views: 69
Status
Not open for further replies.
Top