Author Topic: Adding a 'duel' option to NPC conversation menu  (Read 1426 times)

0 Members and 1 Guest are viewing this topic.

Phosphoer

  • Recruit
  • *
    • View Profile
  • Faction: Rhodok
Adding a 'duel' option to NPC conversation menu
« on: February 07, 2009, 11:41:11 PM »
Hi, I was thinking how it would be cool to duel any of the heroes in your party, and started looking into ways to accomplish this. I'm still really new to the module system and such, so I was wondering if I could get some tips and advice on the subject?

So far I've added a new bit of code in the module_dialogs file like this, but am not sure what to do from here.
Code: [Select]
  [anyone|plyr,"member_talk", [], "Let's have a practice duel.", "view_member_char_requested",[]],
  [anyone,"view_member_char_requested", [], "Oh it's on!", "do_member_view_char",[(change_screen_view_character)]],

I'd like it to transport you to a random battlefield like it does for regular battles or possibly the arena map, but somehow spawn just you and the chosen npc, fighting for the opposing side obviously.

Thanks much :)

Galtran

  • Knight
  • *
    • View Profile
  • Faction: Sarranid
  • MP nick: Galtran
  • WB
Re: Adding a 'duel' option to NPC conversation menu
« Reply #1 on: February 08, 2009, 06:52:52 AM »
Since native already has duels(in behalf of a wronged lady) you can simply find it at mission_templates and adapt it to your needs

Phosphoer

  • Recruit
  • *
    • View Profile
  • Faction: Rhodok
Re: Adding a 'duel' option to NPC conversation menu
« Reply #2 on: February 09, 2009, 12:01:42 AM »
Good point, I'll check that out :)

Thanks!

Phosphoer

  • Recruit
  • *
    • View Profile
  • Faction: Rhodok
Re: Adding a 'duel' option to NPC conversation menu
« Reply #3 on: February 12, 2009, 03:52:47 AM »
Alright, I've got the thing mostly done, but there is a bug :(

At the moment you can request a duel with any lord who isn't out for your blood, and you can fight him with no relationship loss in a nice friendly duel. You also don't come out of the battle all beaten up the way you do in a quest duel.

You can also duel party members, both heroes and troops, but that is where the bug shows up. The first duel with a party member works fine, but after the second duel, you can't get back to the main map ><  I have a screen that says the duel is over when it is so, but after the second duel, the continue button just doesn't work, even though it works the first time! Any ideas?

Dialogue code:

(click to show/hide)

Mission Templates Code:

(click to show/hide)

Game Menu's Code:

(click to show/hide)



MartinF

  • Squire
  • *
  • Down Under
    • View Profile
  • Faction: Neutral
Re: Adding a 'duel' option to NPC conversation menu
« Reply #4 on: February 12, 2009, 06:24:40 AM »
Not sure if I understand where the bug is coming from but there's something I did notice. In the heroes duel dialogue option you've got a different bit at the end than at the lords and troops. The first one ends:

Code: [Select]
    (try_begin),     (neq, "$talk_context", tc_court_talk),     (jump_to_menu, "mnu_duel_begin"),    (try_end),
While the second one ends:

Code: [Select]
   (try_begin),      (neq, "$talk_context", tc_court_talk),      (jump_to_menu, "mnu_arena_duel_fight"),    (try_end),
I don't see the mnu_arena_duel_fight here but that may just be a piece of native code. Either way I don't know what that bit is supposed to do exactly, since it comes after the call to the scene and I don't know if the game would come back to this line after the scene is finished, cause in that case it may have something to do with it?

The only other thing I can see is this variable (assign, "$g_leave_encounter", 1), but in this code I don't see how it could affect anything really...

Phosphoer

  • Recruit
  • *
    • View Profile
  • Faction: Rhodok
Re: Adding a 'duel' option to NPC conversation menu
« Reply #5 on: February 12, 2009, 07:09:54 AM »
Aye I was messing about with sending the player to different menus to see if that fixed the bug. Needless to say it didn't, but the bug still occurs even if both of those lines are the same.


Thanks for trying :)

Jinnai

  • Sergeant at Arms
  • *
    • View Profile
  • Faction: Khergit
Re: Adding a 'duel' option to NPC conversation menu
« Reply #6 on: February 12, 2009, 02:34:33 PM »
Never ever ever ever call a jump_to_menu from inside mission_templates.  It doesn't clean up the engine and can lead to crashes and lockups.  You need to ALWAYS finish a mission with (finish_mission).  Afterward it'll call the same menu that called the mission in the first place.  So you can use global variables to check if you're about to duel, finished dueling and won, or finished dueling and lost.  In module_mission_templates take a look at the common_battle_check_victory_condition trigger to see a partial example.  The other half of that is buried in module_game_menus.  Search for "encounter_attack" to see the other side of things.
Native Expansion - A mod for M&B version 1.010/11

HokieBT

  • Grandmaster Knight
  • *
  • may the force be with you
    • View Profile
  • Faction: Neutral
Re: Adding a 'duel' option to NPC conversation menu
« Reply #7 on: February 12, 2009, 02:50:22 PM »

this is a very cool idea, I'd love to add a lightsaber duel option to my mod.  ;)   I don't think I can help with the code, but please post an updated version if you get it working!   
 

jik

  • Knight
  • *
    • View Profile
  • Faction: Neutral
Re: Adding a 'duel' option to NPC conversation menu
« Reply #8 on: February 12, 2009, 03:07:27 PM »
Phosphoer,

The tutorial I am updating has a quest that should actually be a duel that starts from dialog.  Do you mind if I borrow from you to adjust the tutorial?

Phosphoer

  • Recruit
  • *
    • View Profile
  • Faction: Rhodok
Re: Adding a 'duel' option to NPC conversation menu
« Reply #9 on: February 12, 2009, 10:34:01 PM »
Feel free to use my code ^^, if you get something working with it then I'd appreciate it if you posted it here for me to see :p

This is how it is now:
Everything should work with the lord, the other two still crash on the second duel.

@Jinnai: Thanks, being really new to the module system, I don't really have any idea how to do that ><
How exactly would I use the victory condition thingy?


Dialogues: This goes right above Generic Member Chat
(click to show/hide)

Mission Templates: Right after the arena_challenge_fight mission
(click to show/hide)

Game Menus: Right before simple_encounter
(click to show/hide)

MartinF

  • Squire
  • *
  • Down Under
    • View Profile
  • Faction: Neutral
Re: Adding a 'duel' option to NPC conversation menu
« Reply #10 on: February 13, 2009, 07:45:35 AM »
ZOMG.. five hours on I figured it out, haha.. I was just about to place a post cause I was completely stumped. It wouldn't compile and I couldn't figure out why. Went over everything, commenting out one line at a time but still couldn't find it, then finally I saw that I had placed one thing outside a bracket, ffs! Anywho, here's what I did.


If added this to the mission_template so we've got a global variable to work with.

(click to show/hide)

I tried looking at how the game does the transition from dialogue to game menu but couldn't figure it out. I looked at the one where you tell a lord 'I'm listing my demands' since that's the way you engage a neutral lord in a fight and I figure the game has to redirect from the dialog to the game menu there, but it just says
Code: [Select]
  [anyone,"lord_attack_verify_commit", [], "{s43}", "close_window",
   [
    (call_script, "script_lord_comment_to_s43", "$g_talk_troop", "str_lord_challenged_default"),
    (call_script, "script_make_kingdom_hostile_to_player", "$g_encountered_party_faction", -3),
    (call_script, "script_change_player_relation_with_troop", "$g_talk_troop", -30),
    ]],

And I don't really get where reg(43) gets set in this case so how does the game know which menu to go to and to start the encounter?

Anyway I've been fiddling around the dueling code and changed the dialogue and mission template to:
(click to show/hide)

Basically the idea is to give two menu options, one if you're just duelling for the first time (Start) and one in if you've just fought a duel (Fight again). This was just to test the victory variable idea and to see if I understood the concept of a menu that shows different options based on the value of a variable and also to see if the game does indeed come back to this menu after the mission.

And it does, so that's cool. Plus, if you win the fight (or lose I guess, haven't tried that) it comes up the second time with 'fight again'. Now this is a very basic usage of the variable. What you'd probably want is the 'you won the duel' or 'you lost the duel'  thingie at the top which isn't too hard to implement using this example.

The thing I find most annoying is that after you click on 'let's have a practise duel' and you go through the 'have at thee', it goes back to the party menu. I'll have a look and see if I can figure out why (probably replace "close_window" with something else", if not maybe one of the more talented coders can help out there ;-)

Oh and also, you'll prob want to put the combatants a bit further apart. If you start on horseback and your opponent doesn't, you can't even see him cause he's blocked by your horse. Which hits another point: horseback. Prob want to but a check in there that if the opponent isn't on horseback, your player doesn't get to use his horse.

Hope this helps you, certainly learnt a lot from working it out.

[edit] ok just found out that the duel again option doesn't work, it crashes the game. You probably have to set up the duel again, so have to rerun the code that's in the dialogue. Have to think of the best way to do that.
« Last Edit: February 13, 2009, 09:42:30 AM by MartinF »

MartinF

  • Squire
  • *
  • Down Under
    • View Profile
  • Faction: Neutral
Re: Adding a 'duel' option to NPC conversation menu
« Reply #11 on: February 13, 2009, 10:14:24 AM »
Ok I think I've made it more the way Jinnai suggested now:

(click to show/hide)

That's the code for the game_menu.
After the 'have at thee' it will show you 'You are preparing to duel [troop name]' and the option to start the duel or leave. Leave takes you back to the map screen, the change_screen_return option doesn't seem to work with this.

If you've won, it'll take you back and show 'You've won your duel against [troop name]' and if you've lost it'll show 'You've lost your duel against [troop name]" and in both cases will only offer you the option to leave, since I haven't figured out to reset the mission from here yet.

I guess one way to do it would be to write a script for the whole mission (instead of keeping it in the dialogue) but then that would be another file that needs to be editted. But that way you could just call the script from the game_menu and I guess that would work. I would like it to go back to the dialog menu and offer the option 'Let's duel again', based on the $g_duel_result setting. But then you'd also have to code in a check for previous duels otherwise everyone would come up with 'lets duel again' once you've dueled one guy once.. so in that case you'd probably want to use a slot for this.. which might be a better option anyway, instead of a global variable.

Heh.. making it more and more difficult for myself here ;) But it's fun to see that it works

[Edit]

I've tried to do the bit with horse/no horse. I made two mission templates, one which uses af_override_mount to strip the player of his mount in case his opponent doesn't have one and then I check for that in the dialog by using:

Code: [Select]
    (set_visitor, 0, "trp_player"),   
    (set_visitor, 1, "$g_talk_troop"),
         (try_begin),
             (this_or_next|troop_is_mounted, "$g_talk_troop"),
             (troop_is_guarantee_horse, "$g_talk_troop"),
             (set_jump_mission, "mt_arena_duel_thing_std"),
         (else_try),
             (set_jump_mission, "mt_arena_duel_thing_horse"),[/,

I tried it with one template and using the (try_begin) bit in the template but the compiler didn't like that so it'll have to be like this. I used both checks since I guess heroes don't have the guarantee_horse bit but will be mounted if you give them a horse, whereas normal mounted units would have the guarantee_horse flag.

Oh yeah, the mission_template looks like this now:

(click to show/hide)

I think it could use a tab_press thingie so you can leave the duel, but that's pretty easy to copy/paste from somewhere else.

[edit 2]

Sorry for spamming your thread full Phosphoer, but hopefully it'll lead to the result you're after.
« Last Edit: February 13, 2009, 02:05:31 PM by MartinF »

Jinnai

  • Sergeant at Arms
  • *
    • View Profile
  • Faction: Khergit
Re: Adding a 'duel' option to NPC conversation menu
« Reply #12 on: February 13, 2009, 02:25:01 PM »
Sorry I didn't answer sooner, I've been busy with work.

First off, reg43 isn't getting set, string 43 is.  And it's in the script you call, script_lord_comment_to_s43.

Since you're using the arena rather than open fields for the duel, try changing the 56 and 58 to 0 and 8, respectively, if you want them to start far enough apart.  It looks like you've pretty much got it sorted out the way you want it.

Using change_screen_map like you are is the correct way to do it. If you use _return there's a chance the game can lock up after a second duel if you started it on the map from the party screen.  Not sure why, but it seems pretty consistent, but you figured out the right way around that.  If you want to reset the duel to allow the fight again, put the setup code right in front of change_screen_mission.  Should work without requiring you write a new script_ entry.

As for going straight from dialog to a menu, if it's a potential hostile encounter it'll automatically take you to the attack menu on exit, it's hard coded like that.  If you want to automatically take the player to another menu, though, take a look at script_add_notification_menu.  It's what I've used for this type of thing in the past.  Unfortunately, if the dialog is started from the party menu, there's no way to go straight to the menu.  But if you add it with that add_notification_menu when the player exits the party screen back to the map screen it'll dump them automatically into the menu.
Native Expansion - A mod for M&B version 1.010/11

MartinF

  • Squire
  • *
  • Down Under
    • View Profile
  • Faction: Neutral
Re: Adding a 'duel' option to NPC conversation menu
« Reply #13 on: February 13, 2009, 03:04:59 PM »
Sorry I didn't answer sooner, I've been busy with work.


work.. for shame! :)

Thanks for your input. It works great.

I added that and added a new menu item called "duel again" which does a neq on $g_duel_result, 0 and then does (assign, "$g_duel_result, 0) and (jump_to_menu, "duel_menu). In other words this should reset the whole thing back to zero and you should get your 'you're preparing to duel [troopname]' again.

I actually had it more or less like this originally this morning (I'm in Australia atm so there's a slight timedifference) but it wouldn't compile. However back then I had no clue about half this stuff so it was prob another problem :)

Here's the new game_menu code

(click to show/hide)

And just to be complete, the new dialogs code as well, since that is now much slimmer. I've also put the original stuff back in so you can duel heroes and lords. I've tested it all and it works. Have to say that duelling on horseback is pretty gay, the AI is so bad at it you actually have to be considerably stupid to die. Probably a good idea to make an option to duel on horseback or on foot, that's pretty easy to do now that the basic code is all done.

(click to show/hide)

Also regarding the jumping to menu, thanks for that. The problem here is that the dialog exits to the party menu. Once you exit that by pressing 'done', it takes you straight to the duel_menu, it's just a bit strange that you go back to the party menu first after agreeing to a duel. But I guess you're saying that's just tough cookies?


jik

  • Knight
  • *
    • View Profile
  • Faction: Neutral
Re: Adding a 'duel' option to NPC conversation menu
« Reply #14 on: February 13, 2009, 04:35:18 PM »
Sorry I didn't answer sooner, I've been busy with work.

First off, reg43 isn't getting set, string 43 is.  And it's in the script you call, script_lord_comment_to_s43.

Since you're using the arena rather than open fields for the duel, try changing the 56 and 58 to 0 and 8, respectively, if you want them to start far enough apart.  It looks like you've pretty much got it sorted out the way you want it.

Using change_screen_map like you are is the correct way to do it. If you use _return there's a chance the game can lock up after a second duel if you started it on the map from the party screen.  Not sure why, but it seems pretty consistent, but you figured out the right way around that.  If you want to reset the duel to allow the fight again, put the setup code right in front of change_screen_mission.  Should work without requiring you write a new script_ entry.

As for going straight from dialog to a menu, if it's a potential hostile encounter it'll automatically take you to the attack menu on exit, it's hard coded like that.  If you want to automatically take the player to another menu, though, take a look at script_add_notification_menu.  It's what I've used for this type of thing in the past.  Unfortunately, if the dialog is started from the party menu, there's no way to go straight to the menu.  But if you add it with that add_notification_menu when the player exits the party screen back to the map screen it'll dump them automatically into the menu.

I'm still a bit confused with the hostile encounter on the map.  So it's hardcoded that after the dialog it goes to the battle menu.  Does this mean that a duel cannot happen with a hostile encounter on the map?  I looked at the code for add_notification_menu, but I don't clearly understand what it is doing...

To diversify things, I am making it possible (for the tutorial quest dule) to have 3 paths to completing it:
1- if your STR score is 14 or higher, you can intimidate Geoffrey into leaving
2- instead of meeting him outside at noon, you can challenge him, 1 on 1 in the areana
3- go out side and wait for noon for him to spawn.  I was going to set up a dialog here to lead to the duel, but as it is the encounter is set to hostile...

The reason I am doing this is to show 3 different things.  Check on a stat, spawn a custom battle (duel), spawn a party on the field and battle (with tracked outcome)