How to Challenge NPC's to a Card Game

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
In this tutorial, I will discuss how to allow players to interact with NPC's using different approaches and how to customize how the NPC responds depending on what approach was used. I will use a "card game challenge" where the NPC will mention that she's a pretty strong card player and has been looking for a suitable opponent and then offer to play a game with you.

Background

The story takes place in a world where a card game is extremely popular. In addition to the usual adventures that you go on, you also have the opportunity to participate in card battles and competitions that are held throughout the world as you progress through the game. You may be able to challenge NPC's that you meet to a game, and the winner gets to take one of the loser's cards as a reward.

In a particular city, you find yourself doing some work with the leader of the local guild. She offers guidance and sends you on important quests, such as the one shown below


 
However, she's also an avid card player and is always looking for a challenge. Having won a number of tournaments in the past, she has collected a large number of rare cards that would be a great asset to your own card deck if you manage to defeat her.

When you approach her about the card game, she talks about her own skills


 
And then proceeds to offer you a match



Implementing the Event

If you choose to offer this type of mini-game where the player can challenge different NPC's, as a game developer, you have to make a lot of decisions how to implement this for players.
You have several different ways to approach this depending on how you want to do it.

Using an Item

Suppose you wanted to trigger a card challenge by using an item. Maybe the item is a deck of cards.

One way to do this is assign a common event to the item that will

  • Turn on a switch
  • Check for any events in front of you that can be triggered
In order to perform an action trigger check using a common event, several approaches are available there as well. I will use the  Scripted Action Trigger script to accomplish this. You might choose to just use an autorun event and check the player's position.

 

With the script applied, the common event itself is straightforward: turn on the appropriate switch, then check for events. We assign the common event to the item we want to use.



The event will be set up so that if the switch is ON, it will run the card challenge commands. Otherwise, it will run the normal commands. We can use a two-page event for this: one of the pages is conditioned to activate only when the switch is ON. Because the purpose of the switch is simply to force the event to run a different page, the page should also remember to turn it off after it's done with it.


 
Now you will be able to interact with the event normally using a button press, as well as an item.

You can see a demonstration of the results in this video:





Want to see other solutions? Read the rest at HimeWorks!
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
So this is basically what would happen if you had set that event page to autorun or parallel process, with the additional check that the event is in a position where pressing the action button would normally trigger it (so, if you had 3 NPCs who you could challenge and all had the same switch, only the one in front of the player - if there IS one in front of the player - would trigger)?


Would be very useful for something like digging a hole by choosing the shovel item from your inventory.
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
Now that you mention the auto-run, it's possible to accomplish it without the script to perform action triggers as well: you just need to perform the same conditional checks as the action trigger and then turn off the switch before the other events run.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Yes, I did think of that, but it won't work that easily. Let's say you have 3 NPCs that are conditioned by the same switch. They would ALL be set to autorun or parallel process, perform the "where am I in relation to the player?" test, to decide whether they should run or not. This is all well and good, but what happens to the two (or three) events if they are not in a position where the player could activate them? You wouldn't want to turn the switch off, because it could affect the other events and maybe you want one to keep the switch on. You also don't want them to continually loop, checking, if they are not the event that's "activated".
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
Yes, I did think of that, but it won't work that easily. Let's say you have 3 NPCs that are conditioned by the same switch. They would ALL be set to autorun or parallel process, perform the "where am I in relation to the player?" test, to decide whether they should run or not. This is all well and good, but what happens to the two (or three) events if they are not in a position where the player could activate them? You wouldn't want to turn the switch off, because it could affect the other events and maybe you want one to keep the switch on. You also don't want them to continually loop, checking, if they are not the event that's "activated".
Hmm, that's a pretty tricky problem. Nice one!


I hadn't considered the possibility that no events would be activated. In that case, we wouldn't know when to turn off the switch...
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
oh ... what about this ...


All 3 NPC events have a page conditioned by the switch, set to Action Button. No test to see where they are in relation to the player.


Your common event turns on the switch, either does a Wait to allow Game_Map to update, or does a direct call to $game_map.update_events (to activate the switch-conditioned page of all 3 events), then calls $game_player.check_event_trigger_here and $game_player.check_event_trigger_there to activate them.


Still issues with that though ... what if there's no event on the tile the player is facing? What turns the switch off again? You don't want to turn it off immediately after the $game_player calls. What if there IS an action event on the facing tile, but it's not one conditioned by the switch? It would be triggered by the player using something in inventory.


I'm sure you probably COULD get around it by using events, but any that would work for all situations would probably do a lot of what your script does anyway, and not as neatly or efficiently.
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
I tried something like this

Parallel process

Code:
If (condition)  Turn Switch OFFEndwait 1 frameTurn Switch OFF
Hoping I could take advantage of the way parallel processes are done somehow, but it didn't seem to make a difference. However it doesn't work because they do not block the map from updating events. Therefore, all parallel process will have already started once the switch was turned on, and even if the switch was turned off in the middle of execution, they'll keep going because that's how events work.
 

GrandmaDeb

Modern Exteriors Posted!
Veteran
Joined
Apr 25, 2012
Messages
4,467
Reaction score
2,942
Primarily Uses
You also don't want them to continually loop, checking, if they are not the event that's "activated".
So many event systems rely entirely on constantly checking conditions. Is it really a bad thing for an event page to constantly ask "is the player looking at me?" in one way or another? (I was thinking of a separate parallel process checking on each NPC and setting an NPC specific switch for when they were the "active" NPC.)


Just so I understand the script here - It is making the event begin using an item or by usual event triggers (button press), right?


(thanks!)
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
Just so I understand the script here - It is making the event begin using an item or by usual event triggers (button press), right?


(thanks!)
Yes.


Well, that is how I have used the script.


The script itself is just making this script call

Code:
reserve_action_trigger
And once it occurs, the game will behave as if you pressed the action trigger button.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,865
Messages
1,017,059
Members
137,575
Latest member
akekaphol101
Top