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

[vJASS] Setting up an OOP NPC interaction system

Status
Not open for further replies.
Level 15
Joined
Aug 7, 2013
Messages
1,338
Hi,

I'm having a bit of trouble setting up an object based interaction system for dealing with NPCs. What's impeding my progress the most is that apparently you can't use struct methods to create trigger conditions (I don't see why this should be a limitation) and also coming up with a way to dynamically create dialog-based triggers and then remove these. I wrote up an outline of how I wanted to design the NPC system--reading it will help explain what my JASS code attempts to do.

Ultimately I'd like to avoid hardcoding in dealing with each individual NPC and rather create different objects that represent each one (Merchant, Priest, Inn Keeper, etc.) and then when a player interacts with an NPC unit, I would just make a simple call like "NPC.interact(playerId)" and then the rest would be specific to that NPC.

if the player selects reviveBttn, it will create a new dialog that lists out the player's current party members (each as a dialog button), and then the player selects one. This one gets revived (assuming the player has adequate gold). I have already handled creating this second dialog in another object, but the problem is assigning each of those buttons a meaning, because sometimes they will be involved in other interactions which aren't reviving.

Please advise.
 
Last edited:
You can use struct methods as conditions.

Use like this if inside struct method.

JASS:
struct test extends array
    method two takes nothing returns boolean
        return false
    endmethod
    method one takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerAddCondition( t, thistype.two)
    endmethod
endstruct
outside of struct using same things as above. The function must be below the struct i believe.
JASS:
function one takes nothing returns nothing
    call TriggerAddCondition( t, test.two)
endfunction
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
That won't compile
it has to be static method two and ofc TriggerAddCondition(t, Condition(function thistype.two))

Towards your dialog problem: Dialog Wrapper
There is a sample sample code in the first post. Maybe it helps with your problem.

What do you mean by "static?" The method has to be static in order to be a trigger condition? Do I need to put the function keyword in, and also thistype.functionName ?
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
I'm having trouble, how do I make this into a static method that compiles? Do
I really need to search for the buttons instead of using them as fields?!

JASS:
static method main takes nothing returns boolean
    local button b = GetClickedButton()
    local player p = GetTriggerPlayer()
    if b == quitBttn then
        call DialogClear(intro)
    elseif b == reviveBttn then //we need to call the player's monsterGroup for now we'll cheat
    endif
    return false
endmethod

So static methods (except create?) cannot reference field members. Then how do I get handles on the quitBttn and reviveBttn inside the static method WITHOUT making them globals and WITHOUT having a data structure that I search for the appropriate button...
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
You can save them into a hashtable or simply use this resource Table

JASS:
static Table table

private static method onInit takes nothing returns nothing
    set table = Table.create()
endmethod

set table[GetHandleId(button)] = this
-------------------------------
set this = thistype(table[GetHandleId(button)])
call table.handle.remove(GetHandleId(button))// In wc3 you have to take care of handle leaks.
 
Last edited:
Status
Not open for further replies.
Top