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

static method acces to this. methods

Status
Not open for further replies.
Level 2
Joined
Aug 4, 2011
Messages
12
I need to make it worK:
JASS:
///////GREAT QUEST SYSTEM/////////////////////////////////

interface Quest
   trigger eventTrigger = null
   unit unitGiver = null
   integer rewardXp = 0
   integer rewardGold = 0
   string beginString = ""
   string finishString = ""
   string toFinishString = ""
   trigger eventGive = null
   effect effectGiver = null
   
   method Reward takes nothing returns nothing
   
   method Init takes nothing returns nothing
endinterface

struct KillQuest extends Quest
   integer unitToKill = 0
   integer unitCount = 0
   integer unitTotal = 0
   string killString = ""
   
   method Reward takes nothing returns nothing
      local integer i = 0
      local player pl = GetOwningPlayer(Heroes[i])
      loop
         call AddHeroXP(Heroes[i], this.rewardXp, true)
         call SetPlayerState(pl, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(pl, PLAYER_STATE_RESOURCE_GOLD))
         set i = i + 1
         exitwhen(i == HeroesCount)
      endloop   
      set pl = null
   endmethod
   
   method Init takes nothing returns nothing
      set this.eventGive = CreateTrigger()
      set this.unitTotal = this.unitCount
      set this.effectGiver = AddSpecialEffectTarget("Abilities\\Spells\\Other\\TalkToMe\\TalkToMe.mdl",this.unitGiver,"overhead")
      call TriggerRegisterUnitEvent(this.eventGive, this.unitGiver, EVENT_UNIT_ATTACKED)
      call TriggerAddAction(this.eventGive, function thistype.onBegin)
   endmethod
   
   method Death takes nothing returns nothing
      set this.unitCount = this.unitCount - 1
      if(this.unitCount == 0) then
         call this.ToFinish()
      else
         call BJDebugMsg(I2S(this.unitCount) + this.killString + I2S(this.unitTotal))
      endif   
   endmethod
   
   static method onDeath takes nothing returns nothing
      call ExecuteFunc("Death")
   endmethod
   
   static method onBegin takes nothing returns nothing
      call ExecuteFunc("Begin")
   endmethod
   
   method ToFinish takes nothing returns nothing
      call BJDebugMsg(this.toFinishString)
      set this.eventGive = CreateTrigger()
      set this.effectGiver = AddSpecialEffectTarget("Abilities\\Spells\\Other\\TalkToMe\\TalkToMe.mdl",this.unitGiver,"overhead")
      call TriggerRegisterUnitEvent(this.eventGive, this.unitGiver, EVENT_UNIT_ATTACKED)
      call TriggerAddAction(this.eventGive, function thistype.onFinish)
   endmethod
   
   static method onFinish takes nothing returns nothing
      ExecuteFunc("Finish")
   endmethod
   
   method Begin takes nothing returns nothing
      call BJDebugMsg(this.beginString)
      call DestroyTrigger(this.eventGive)
      set this.eventGive = null
      call DestroyEffect(this.effectGiver)
      call AddSpecialEffectTarget("Objects\\RandomObject\\RandomObject.mdl",this.unitGiver,"overhead")
      set this.eventTrigger = CreateTrigger()
      call TriggerRegisterPlayerUnitEvent(this.eventTrigger, Player(12), EVENT_PLAYER_UNIT_DEATH, null)
      call TriggerAddAction(this.eventTrigger, function thistype.onDeath)
   endmethod
   
   method Destroy takes nothing returns nothing
      call DestroyEffect(this.effectGiver)
      set this.effectGiver = null
      set this.unitGiver = null
      set this.beginString = null
      set this.finishString = null
      call DestroyTrigger(this.eventTrigger)
      set this.eventTrigger = null
   endmethod
   
   method Finish takes nothing returns nothing
      call DestroyTrigger(this.eventGive)
      set this.eventGive = null
      call BJDebugMsg(this.finishString)
      call this.Reward()
      call this.Destroy()
   endmethod
endstruct


//////END QUEST SYSTEM/////////////////////////////////////////
So ExecuteFunc("") doesn't work... How can i do that?
 
You would need to do:
JASS:
call ExecuteFunc("s__Quest_Death")

Add the same prefix "s__Quest_" to the other function names, and then it should execute. However, you cannot execute normal methods. They have to be static for it to work properly. (However, that means that you need to access this through other means [the instance])

Which means that you have to attach data to the trigger somehow. I recommend that you use hashtables. Here is an example of attaching data to the trigger:
JASS:
struct Example
    // just an example, this doesn't really do anything special
    private static hashtable Hash = InitHashtable() // you can use any hashtable
    unit ex
    real speed
    
    static method onDeath takes nothing returns nothing
        local trigger  t        = GetTriggeringTrigger()
        local thistype this     = LoadInteger( Hash, GetHandleId(t), 0 ) // load it in the "actions"
        call SetUnitMoveSpeed( this.ex, this.speed ) // now you can use "this" as if in a normal method
        set t = null
    endmethod

    static method create takes unit u, real vel returns thistype
        local thistype this   = thistype.allocate()
        local trigger  test   = CreateTrigger()
        set this.ex    = u
        set this.vel   = speed
        call SaveInteger( Hash, GetHandleId(test), 0, this )  // save your instance to the handle id of your trigger
        call TriggerRegisterUnitEvent( test, u, EVENT_UNIT_DEATH )
        call TriggerAddAction( test, function thistype.onDeath )
        set test = null
    endmethod
endstruct
 
Level 2
Joined
Aug 4, 2011
Messages
12
Thank you, i'll try this!


---

JASS:
static method create takes unit questGiver, integer rewardXp, integer rewardGold returns thistype
      local thistype this   = thistype.allocate()
      local trigger  eventTrigger   = CreateTrigger()
      set this.rewardXp    =rewardXp
      set this.rewardGold   = rewardGold
      set this.questGiver   = questGiver
      call SaveInteger( Hash, GetHandleId(eventTrigger), 0, this )  // save your instance to the handle id of your trigger
      call TriggerRegisterUnitEvent( eventTrigger, questGiver, EVENT_UNIT_ATTACKED )
      call TriggerAddAction( eventTrigger, function thistype.onTalk )
      set eventTrigger = null
   endmethod

Throws an error: "Missing return" :goblin_jawdrop:

---

return this -> everything okey.
Thanks, it works!!!

---
How to "clear" hash value? I want to recreate trigger "t" and save it to the hash.
 
Last edited:
Level 2
Joined
Aug 4, 2011
Messages
12
JASS:
struct SpeakQuest
   integer rewardXp = 0
   integer rewardGold = 0
   unit questGiver = null
   unit questFinisher = null
   string stringBegin = ""
   string stringFinish = ""
   
   static method onTalk takes nothing returns nothing
      local trigger  t        = GetTriggeringTrigger()
      local thistype this     = LoadInteger( Hash, GetHandleId(t), 0 ) // load it in the "actions"
      call DestroyTrigger(t)
      set t = CreateTrigger()
      call CreateFloatText(this.stringBegin, 100, 100, 100, GetUnitX(this.questGiver), GetUnitY(this.questGiver))
      call SaveInteger( Hash, GetHandleId(t), 0, this )  // save your instance to the handle id of your trigger
      call TriggerRegisterUnitEvent( t, this.questFinisher, EVENT_UNIT_ATTACKED )
      call TriggerAddAction( t, function thistype.onFinish )
      set this.questGiver = null
      set t = null
    endmethod
    
   
    static method onFinish takes nothing returns nothing
      local trigger  t        = GetTriggeringTrigger()
      local thistype this     = LoadInteger( Hash, GetHandleId(t), 0 ) // load it in the "actions"
      call Reward(this.rewardXp,this.rewardGold) /*doesn't work (Reward function is ok) */
      call CreateFloatText(this.stringFinish, 100, 150, 100, GetUnitX(this.questFinisher), GetUnitY(this.questGiver)) //doesn't work
      call DestroyTrigger(t)
      set this.questFinisher = null
      set t = null
    endmethod
   
   static method create takes unit questGiver, unit questFinisher, string stringBegin, string stringFinish ,integer rewardXp, integer rewardGold returns thistype
      local thistype this   = thistype.allocate()
      local trigger  eventTrigger   = CreateTrigger()
      set this.rewardXp    =rewardXp
      set this.rewardGold   = rewardGold
      set this.questGiver   = questGiver
      set this.questFinisher   = questFinisher
      set this.stringBegin   = stringBegin
      set this.stringFinish   = stringFinish
      call SaveInteger( Hash, GetHandleId(eventTrigger), 0, this )  // save your instance to the handle id of your trigger
      call TriggerRegisterUnitEvent( eventTrigger, questGiver, EVENT_UNIT_ATTACKED )
      call TriggerAddAction( eventTrigger, function thistype.onTalk )
      set eventTrigger = null
      return this
   endmethod
   
endstruct
method onFinish can't use this.* somewhy... everything becomes null.

i think i did something wrong here:
JASS:
static method onTalk takes nothing returns nothing
      local trigger  t        = GetTriggeringTrigger()
      local thistype this     = LoadInteger( Hash, GetHandleId(t), 0 ) // load it in the "actions"
      call DestroyTrigger(t)
      set t = CreateTrigger()
      call CreateFloatText(this.stringBegin, 100, 100, 100, GetUnitX(this.questGiver), GetUnitY(this.questGiver)) // works!
      call SaveInteger( Hash, GetHandleId(t), 0, this )  // save your instance to the handle id of your trigger
      call TriggerRegisterUnitEvent( t, this.questFinisher, EVENT_UNIT_ATTACKED )
      call TriggerAddAction( t, function thistype.onFinish )
      set this.questGiver = null 
      set t = null
    endmethod

method onFinish is calling okay, but loading "this" doesn't works there... Help pls!
 
Level 2
Joined
Aug 4, 2011
Messages
12
JASS:
static method onFinish takes nothing returns nothing
      local trigger  t        = GetTriggeringTrigger()
      call BJDebugMsg(I2S(LoadInteger( Hash, GetHandleId(t), 0 )))
      local thistype this     = LoadInteger( Hash, GetHandleId(t), 0 ) // load it in the "actions"
      call Reward(this.rewardXp,this.rewardGold)
      call CreateFloatText(this.stringFinish, 100, 150, 100, GetUnitX(this.questFinisher), GetUnitY(this.questGiver))
      call DestroyTrigger(t)
      set this.questFinisher = null
      set t = null
    endmethod

BJ debug returns 0 (null)... Look like saveinteger saves null trigger... but:
JASS:
local thistype this     = LoadInteger( Hash, GetHandleId(t), 0 ) // load it in the "actions"
      call DestroyTrigger(t)
      set t = null
      set t = CreateTrigger()
      call CreateFloatText(this.stringBegin, 100, 100, 100, GetUnitX(this.questGiver), GetUnitY(this.questGiver))
      call BJDebugMsg(I2S(GetHandleId(t)))
      call SaveInteger( Hash, GetHandleId(t), 0, this )  // save your instance to the handle id of your trigger
Looks okay :goblin_jawdrop:
 
Level 2
Joined
Aug 4, 2011
Messages
12
Or just use the name field

JASS:
call ExecuteFunc(thistype.Death.name)

Then again, why would you prefer ExecuteFunc over TriggerExecute/Evaluate or the vJass abbreviations call thistype.Death.execute()/evaluate()?

Okay, i'll try this...

evaluate() - > don't know what is it)))

TriggerExecute - > i don't use conditions

Evaluate - > don't know what is it

call thistype.Death.execute() -> is it possible? looks strange!

i'll try everything) thank you
 
Level 2
Joined
Aug 4, 2011
Messages
12
JASS:
struct SpeakQuest
   integer rewardXp = 0
   integer rewardGold = 0
   unit questGiver = null
   unit questFinisher = null
   string stringBegin = ""
   string stringFinish = ""
   
   method onTalk takes nothing returns nothing
      local trigger t = CreateTrigger()
      call CreateFloatText(this.stringBegin, 100, 100, 100, GetUnitX(this.questGiver), GetUnitY(this.questGiver))
      call TriggerRegisterUnitEvent( t, this.questFinisher, EVENT_UNIT_ATTACKED )
      call TriggerAddAction( t, function thistype.FonFinish )
      set this.questGiver = null
      set t = null
   endmethod
   
   static method FonTalk takes nothing returns nothing
      local trigger  t        = GetTriggeringTrigger()
      call DestroyTrigger(t)
      call ExecuteFunc(thistype.onTalk.name)
      set t = null
   endmethod
   
   static method FonFinish takes nothing returns nothing
      local trigger  t        = GetTriggeringTrigger()
      call DestroyTrigger(t)
      call ExecuteFunc(thistype.onFinish.name)
      set t = null
   endmethod
   
   method onFinish takes nothing returns nothing
      call Reward(this.rewardXp,this.rewardGold)
      call CreateFloatText(this.stringFinish, 100, 150, 100, GetUnitX(this.questFinisher), GetUnitY(this.questGiver))
      set this.questFinisher = null
   endmethod
   
   static method create takes unit questGiver, unit questFinisher, string stringBegin, string stringFinish ,integer rewardXp, integer rewardGold returns thistype
      local thistype this = thistype.allocate()
      local trigger  eventTrigger   = CreateTrigger()
      set this.rewardXp    =rewardXp
      set this.rewardGold   = rewardGold
      set this.questGiver   = questGiver
      set this.questFinisher   = questFinisher
      set this.stringBegin   = stringBegin
      set this.stringFinish   = stringFinish
      call TriggerRegisterUnitEvent( eventTrigger, questGiver, EVENT_UNIT_ATTACKED )
      call TriggerAddAction( eventTrigger, function thistype.FonTalk )
      set eventTrigger = null
      return this
   endmethod
   
endstruct
Causes fatal error :goblin_cry:
I'm out of breath! Give me an example pls !!!



--------------
It works, i did it ! :D
JASS:
struct SpeakQuest
   integer rewardXp = 0
   integer rewardGold = 0
   unit questGiver = null
   unit questFinisher = null
   string stringBegin = ""
   string stringFinish = ""
   trigger eventTrigger = null
   static hashtable hash = InitHashtable()
   
   static method onFinish takes nothing returns nothing
      local trigger trig = GetTriggeringTrigger()
      local integer id = GetHandleId(trig)
      local thistype this = LoadInteger(thistype.hash, id, 0)
      call FlushChildHashtable(thistype.hash, id)
      call DestroyTrigger(trig)
      call Reward(this.rewardXp, this.rewardGold)
      set trig = null
   endmethod
   
   static method onTalk takes nothing returns nothing
      local trigger trig = GetTriggeringTrigger()
      local integer id = GetHandleId(trig)
      local thistype this = LoadInteger(thistype.hash, id, 0)
      call FlushChildHashtable(thistype.hash, id)
      call DestroyTrigger(trig)
      set trig = CreateTrigger()
      call SaveInteger(thistype.hash, GetHandleId(trig), 0, this)
      call TriggerRegisterUnitEvent( trig, this.questFinisher, EVENT_UNIT_ATTACKED )
      call TriggerAddAction( trig, function thistype.onFinish)
      set trig = null
   endmethod
   
   static method create takes unit questGiver, unit questFinisher, string stringBegin, string stringFinish ,integer rewardXp, integer rewardGold returns thistype
      local thistype this = thistype.allocate()
      set this.eventTrigger = CreateTrigger()
      set this.rewardXp    =rewardXp
      set this.rewardGold   = rewardGold
      set this.questGiver   = questGiver
      set this.questFinisher   = questFinisher
      set this.stringBegin   = stringBegin
      set this.stringFinish   = stringFinish
      call SaveInteger(thistype.hash, GetHandleId(this.eventTrigger), 0, this)
      call TriggerRegisterUnitEvent( this.eventTrigger, questGiver, EVENT_UNIT_ATTACKED )
      call TriggerAddAction( this.eventTrigger, function thistype.onTalk)
      set this.eventTrigger = null
      return this
   endmethod
endstruct
 
Last edited:
Status
Not open for further replies.
Top