From 3c5aeae341f013d2d0740f1821fa6a7398ee5665 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Mon, 27 Aug 2012 03:53:59 +0000 Subject: [PATCH] Modify EVENT_CHANGEWEAPON so that it actually serves a purpose. Instead of being triggered before curr_weapon is changed, with nothing used for input or output with RETURN (meaning you could not cancel), now RETURN is set to the prospective new weapon ID and you can change it or cancel it in the event. Note that since setting RETURN did nothing before, there is no backwards compatibility to uphold. Therefore, setting RETURN to 1 will cause the pistol to be selected, not disable the event. Set RETURN to -1 to cancel switching. git-svn-id: https://svn.eduke32.com/eduke32@2976 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/player.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/polymer/eduke32/source/player.c b/polymer/eduke32/source/player.c index 7063aaa52..34824387e 100644 --- a/polymer/eduke32/source/player.c +++ b/polymer/eduke32/source/player.c @@ -3491,6 +3491,11 @@ void P_AddWeapon(DukePlayer_t *p,int32_t weapon) if (p->reloading) return; + if (p->curr_weapon != weapon && apScriptGameEvent[EVENT_CHANGEWEAPON]) + weapon = VM_OnEvent(EVENT_CHANGEWEAPON,p->i, snum, -1, weapon); + if (weapon < 0) + return; + p->random_club_frame = 0; if (p->weapon_pos == 0) @@ -3508,9 +3513,6 @@ void P_AddWeapon(DukePlayer_t *p,int32_t weapon) p->kickback_pic = 0; - if (p->curr_weapon != weapon && apScriptGameEvent[EVENT_CHANGEWEAPON]) - VM_OnEvent(EVENT_CHANGEWEAPON,p->i, snum, -1, 0); - p->curr_weapon = weapon; Gv_SetVar(g_iWeaponVarID,p->curr_weapon, p->i, snum); @@ -3580,14 +3582,17 @@ void P_CheckWeapon(DukePlayer_t *p) // Found the weapon + if (apScriptGameEvent[EVENT_CHANGEWEAPON]) + weap = VM_OnEvent(EVENT_CHANGEWEAPON,p->i, snum, -1, weap); + if (weap < 0) + return; + p->last_weapon = p->curr_weapon; p->random_club_frame = 0; p->curr_weapon = weap; Gv_SetVar(g_iWeaponVarID,p->curr_weapon, p->i, snum); Gv_SetVar(g_iWorksLikeVarID, (unsigned)p->curr_weapon < MAX_WEAPONS ? aplWeaponWorksLike[p->curr_weapon][snum] : -1, p->i, snum); - if (apScriptGameEvent[EVENT_CHANGEWEAPON]) - VM_OnEvent(EVENT_CHANGEWEAPON,p->i, snum, -1, 0); p->kickback_pic = 0; if (p->holster_weapon == 1) {