RPG Style Event Triggers

Aerisetta

Active member
Hi

Recently i learned about setglobavariable and I started to think about how I can incorporate some RPG style quest and dialogue in the game, however I also learned that globalvariables is not that ideal because once triggered it seems to stay triggered even if I start a new game, unless I alt-f4 the game.

More specifically, I wanted to create scenarios like this:

player talks to NPC, NPC says "go kill 10 boars"
If player plays the game normally, after killing 10 boars over 3 stages, the player returns to the NPC
player talks to NPC, the NPC says "thanks for killing 10 boars". Player gains +1000 score (or exp)

1. How do I keep count of the boars being killed? or any objective being done?
2. How to get the NPC to check the number of boars killed
3. How do I keep this information stored, but not permanently stored globally like in setglobalvariable?
 
1. How do I keep count of the boars being killed? or any objective being done?
This is a job for Entity Variables. You could have the NPC set an entity var on the player's entity that indicates the quest is active, and then use the boar's ondeath event to increment another entity to count the bacon.

C:
void main()
{   
    void attacking_entity = getlocalvar("attacker");
    
    // Run quest counter. Pass attacking entity as the acting entity.
    dc_quest_counter(attacking_entity, "quest_boar");
}

/*
* Caskey, Damon V.
* 2023-05-10
*
* Simple quest counter. Accepts a quest name.
* Checks if quest is active, and if so increments
* the quest count.
*/
void dc_quest_counter(void acting_entity, char quest)
{   
    char active = quest + "_active";
    char count = quest + "_count";   
        
    // Check if quest active is set
    int quest_active = getentityvar(acting_entity, active);
    
    if (!quest_active) {
        return;
    }
        
    // Get the current quest count entity variable
    int quest_count = getentityvar(acting_entity, count);

    // If quest count is empty, set it to 0
    if (!quest_count) {           
        quest_count = 0;
    }

    // Increment the quest_count entity variable
    quest_count++;       
    setentityvar(acting_entity, quest, quest_count);   
}



Then when you talk to the NPC, it could tally the kills, reward EXP and reset your count. Note this also means the count resets if player dies unless you add extra script to transfer the count.

2. How to get the NPC to check the number of boars killed

Entity vars are global. The NPC would just read the player's entity var for active quest and kill count.

3. How do I keep this information stored, but not permanently stored globally like in setglobalvariable?

Same as above. Entity vars live as long as the entity does, no more or less.

From there it's a matter of setting it up to suit your exact goals. Do you want to keep Exp through game saves? If you do, would you also want to prevent the players from running the quest over and over again? That of course would be a job for global variables.

HTH,
DC
 
however I also learned that globalvariables is not that ideal because once triggered it seems to stay triggered even if I start a new game, unless I alt-f4 the game.

That's why in my metroidvanias and some games such as Robz Rush, certain global variables are resetted at start of new game with levelscript. It's simple cause you only need to declare one line to reset one variable. Though you need to take note of all global variables you are using in the game so you know which variables you need to reset at new game.
 
Back
Top Bottom