From 0e3a08206f7d37b0ae1dd095c1f13b2c7829b86c Mon Sep 17 00:00:00 2001 From: Steam Deck User Date: Wed, 22 Mar 2023 11:31:11 -0400 Subject: [PATCH] SERVER: Add new utility for streamlined Viewmodel animations, start integrating; add support for 'first raise' --- source/server/entities/machines.qc | 42 ++++------- source/server/utilities/command_parser.qc | 16 ++--- source/server/utilities/weapon_utilities.qc | 62 +++++++++++++++- source/server/weapons/weapon_core.qc | 80 ++++----------------- 4 files changed, 91 insertions(+), 109 deletions(-) diff --git a/source/server/entities/machines.qc b/source/server/entities/machines.qc index 09402fe..2f09075 100644 --- a/source/server/entities/machines.qc +++ b/source/server/entities/machines.qc @@ -112,15 +112,12 @@ void GivePerk(optional float p) { GiveAchievement(6, self); sound_perk_delay = time + 4.5; + self.isBuying = false; - string modelname = GetWeaponModel(self.weapon, 0); - - local float startframe = GetFrame(self.weapon,TAKE_OUT_START); - local float endframe = GetFrame(self.weapon,TAKE_OUT_END); - self.weaponskin = backupWepSkin; self.perk_delay = self.fire_delay; - Set_W_Frame (startframe, endframe, 0, 0, 0, SUB_Null, modelname, false, S_BOTH); + + Weapon_PlayViewModelAnimation(ANIM_TAKE_OUT, SUB_Null, 0); SetPerk(self, self.perks); } @@ -1464,8 +1461,6 @@ void() mystery_box_tp_spot = void() mystery_touch = { entity tempe; - float startframe, endframe; - string modelname; if (other.classname != "player" || other.downed) return; @@ -1581,10 +1576,12 @@ void() mystery_touch = sound(self, 0,"sounds/misc/ching.wav", 1, 1); tempe = self; self = other; - startframe = GetFrame(self.weapon,TAKE_OUT_START); - endframe = GetFrame(self.weapon,TAKE_OUT_END); - modelname = GetWeaponModel(self.weapon, 0); - Set_W_Frame (startframe, endframe, 0, 0, 0, SUB_Null, modelname, false, S_BOTH);//FIXME + + if (GetFrame(self.weapon, FIRST_TAKE_START) != 0) + Weapon_PlayViewModelAnimation(ANIM_FIRST_TAKE, SUB_Null, 0); + else + Weapon_PlayViewModelAnimation(ANIM_TAKE_OUT, SUB_Null, 0); + SwitchWeapon(self.weapon); self = tempe; remove (self.boxweapon); @@ -1842,10 +1839,6 @@ void touch_pap() { centerprint (other, STR_NOTENOUGHPOINTS); } } else if (self.papState == 2) { - float startframe; - float endframe; - string modelname; - useprint (other, 7, 0, 0); if (other.button7) { @@ -1866,19 +1859,14 @@ void touch_pap() { } entity tempe = self; - startframe = GetFrame(other.weapon,TAKE_OUT_START); - endframe = GetFrame(other.weapon,TAKE_OUT_END); - modelname = GetWeaponModel(other.weapon, 0); - other.weaponmodel = GetWeaponModel(other.weapon, 0);// Give weapon model - - // Kar Scope - if (other.weapon == W_HEADCRACKER) - other.weapon2model = "models/weapons/kar/v_karscope.mdl"; - self = other; + SwitchWeapon(self.weapon); - UpdateV2model(other.weapon2model, 0); - Set_W_Frame (startframe, endframe, 0, 0, 0, SUB_Null, modelname, true, S_BOTH);//FIXME + + if (GetFrame(self.weapon, FIRST_TAKE_START) != 0) + Weapon_PlayViewModelAnimation(ANIM_FIRST_TAKE, SUB_Null, 0); + else + Weapon_PlayViewModelAnimation(ANIM_TAKE_OUT, SUB_Null, 0); #ifndef FTE diff --git a/source/server/utilities/command_parser.qc b/source/server/utilities/command_parser.qc index 9788bc1..b71b842 100644 --- a/source/server/utilities/command_parser.qc +++ b/source/server/utilities/command_parser.qc @@ -53,9 +53,6 @@ float(string params) Command_give = WeaponSwitch(self); } - float startframe, endframe; - string modelname; - self.weapon = wep; self.currentammo = getWeaponAmmo(wep); self.currentmag = getWeaponMag(wep); @@ -63,15 +60,10 @@ float(string params) Command_give = self.currentmag2 = self.currentmag; } - self.weaponskin = GetWepSkin(self.weapon); - - startframe = GetFrame(self.weapon,TAKE_OUT_START); - endframe = GetFrame(self.weapon,TAKE_OUT_END); - modelname = GetWeaponModel(wep, 0); - - SwitchWeapon(wep); - - Set_W_Frame (startframe, endframe, 0, 0, 0, SUB_Null, modelname, false, S_BOTH); + if (GetFrame(self.weapon, FIRST_TAKE_START) != 0) + Weapon_PlayViewModelAnimation(ANIM_FIRST_TAKE, SUB_Null, 0); + else + Weapon_PlayViewModelAnimation(ANIM_TAKE_OUT, SUB_Null, 0); self.reload_delay2 = self.fire_delay2 = self.reload_delay = self.fire_delay = 0; diff --git a/source/server/utilities/weapon_utilities.qc b/source/server/utilities/weapon_utilities.qc index b9a3690..ffe43c1 100644 --- a/source/server/utilities/weapon_utilities.qc +++ b/source/server/utilities/weapon_utilities.qc @@ -26,6 +26,18 @@ */ +// TODO: Actually implement some of these.. +// Frame types, generalized. +#define ANIM_FIRE 0 +#define ANIM_RELOAD 1 +#define ANIM_SPRINT_START 2 +#define ANIM_SPRINT 3 +#define ANIM_SPRINT_STOP 4 +#define ANIM_FIRST_TAKE 5 +#define ANIM_TAKE_OUT 6 +#define ANIM_PUT_AWAY 7 +#define ANIM_AIM 8 + // // Weapon_GetPlayerAmmoInSlot(person, slot) // Returns the reserve ammo the player has in a weapon slot. @@ -38,7 +50,7 @@ float(entity person, float slot) Weapon_GetPlayerAmmoInSlot = case 3: return person.thirdammo; break; default: return 0; break; } -} +}; // // Weapon_SetPlayerAmmoInSlot(person, slot, ammo) @@ -104,7 +116,7 @@ float(float weapon) Weapon_IsSemiAutomatic = return true; return false; -} +}; // // Weapon_FiresTraceshot(weapon) @@ -120,4 +132,48 @@ float(float weapon) Weapon_FiresTraceshot = return true; return false; -} +}; + +// +// Weapon_PlayViewModelAnimation(animation_type, end_function, playback_duration) +// Sets up and plays the weapon sequence for you. +// +void (float animation_type, void(optional float t) end_function, float playback_duration) Weapon_PlayViewModelAnimation = +{ + float start_frame = 0; + float end_frame = 0; + + switch(animation_type) { + case ANIM_SPRINT_START: + start_frame = GetFrame(self.weapon, SPRINT_IN_START); + end_frame = GetFrame(self.weapon, SPRINT_IN_END); + break; + case ANIM_SPRINT: + start_frame = GetFrame(self.weapon, SPRINT_START); + end_frame = GetFrame(self.weapon, SPRINT_END); + break; + case ANIM_SPRINT_STOP: + start_frame = GetFrame(self.weapon, SPRINT_OUT_START); + end_frame = GetFrame(self.weapon, SPRINT_OUT_END); + break; + case ANIM_TAKE_OUT: + start_frame = GetFrame(self.weapon, TAKE_OUT_START); + end_frame = GetFrame(self.weapon, TAKE_OUT_END); + break; + case ANIM_PUT_AWAY: + start_frame = GetFrame(self.weapon, PUT_OUT_START); + end_frame = GetFrame(self.weapon, PUT_OUT_END); + break; + case ANIM_FIRST_TAKE: + start_frame = GetFrame(self.weapon, FIRST_TAKE_START); + end_frame = GetFrame(self.weapon, FIRST_TAKE_END); + break; + default: + break; + } + + UpdateVmodel(self.weaponmodel, GetWepSkin(self.weapon)); + UpdateV2model(self.weapon2model, GetWepSkin(self.weapon)); + + Set_W_Frame(start_frame, end_frame, playback_duration, 0, 0, end_function, GetWeaponModel(self.weapon, 0), false, S_BOTH); +}; \ No newline at end of file diff --git a/source/server/weapons/weapon_core.qc b/source/server/weapons/weapon_core.qc index f6ab579..57e97e8 100644 --- a/source/server/weapons/weapon_core.qc +++ b/source/server/weapons/weapon_core.qc @@ -51,13 +51,7 @@ void() ReturnWeaponModel = void() W_PlayTakeOut = { - float startframe, endframe; - string modelname; - - startframe = GetFrame(self.weapon,TAKE_OUT_START); - endframe = GetFrame(self.weapon,TAKE_OUT_END); - modelname = GetWeaponModel(self.weapon, 0); - Set_W_Frame (startframe, endframe, 0, 0, 0, ReturnWeaponModel, modelname, false, S_BOTH); + Weapon_PlayViewModelAnimation(ANIM_TAKE_OUT, ReturnWeaponModel, 0); } .float scopetime; @@ -133,18 +127,13 @@ void() W_SprintStop = self.sprint_stop_time = time; self.sprint_duration = self.sprint_timer; } - - float startframe = GetFrame(self.weapon,SPRINT_OUT_START); - float endframe = GetFrame(self.weapon,SPRINT_OUT_END); - string modelname = GetWeaponModel(self.weapon, 0); - + if (self.isBuying || !self.sprinting) return; - - self.zoom = 0; - Set_W_Frame (startframe, endframe, 0, 0, SPRINT, SUB_Null, modelname, false, S_BOTH); // BUG IS HERE - + Weapon_PlayViewModelAnimation(ANIM_SPRINT_STOP, SUB_Null, 0); + + self.zoom = 0; self.sprinting = 0; self.into_sprint = 0; self.reload_delay2 = self.fire_delay2 = self.reload_delay = self.fire_delay = 0; @@ -179,17 +168,10 @@ void W_SprintStart () { self.sprint_delay > time) { return; } - - float startframe = GetFrame(self.weapon,SPRINT_IN_START); - float endframe = GetFrame(self.weapon,SPRINT_IN_END); - string modelname = GetWeaponModel(self.weapon, 0); + + Weapon_PlayViewModelAnimation(ANIM_SPRINT_START, ContinueRun, 0); self.zoom = 3; - - if (startframe || endframe) { - Set_W_Frame (startframe, endframe, 0, 0, SPRINT, ContinueRun, modelname, false, S_BOTH); - } - self.sprint_delay = time + 1; self.sprinting = true; self.reload_delay2 = self.fire_delay2 = self.reload_delay = self.fire_delay = 0; @@ -200,9 +182,6 @@ void() W_Switch = if (self.secondaryweapon && self.secondaryweapon != 0 && !self.new_anim_stop && !other.button7) { float tempf,tempf1,tempf2,tempf3,tempf4; - float startframe; - float endframe; - string modelname; // un-zoom camera self.zoom = false; @@ -261,27 +240,8 @@ void() W_Switch = self.secondaryweaponskin = tempf4; } - startframe = GetFrame(self.weapon,TAKE_OUT_START); - endframe = GetFrame(self.weapon,TAKE_OUT_END); - modelname = GetWeaponModel(self.weapon, 0); - SwitchWeapon(self.weapon); - - if (IsDualWeapon(self.weapon)) { - self.weapon2model = GetLeftWeaponModel(self.weapon); - } else if (self.weapon == W_KAR_SCOPE || self.weapon == W_HEADCRACKER) - self.weapon2model = "models/weapons/kar/v_karscope.mdl"; - else - self.weapon2model = ""; - - UpdateV2model(self.weapon2model, 0); - - // TEMP - if (self.weapon == W_M2 || self.weapon == W_FIW) - UpdateVmodel(modelname, GetWepSkin(self.weapon)); - - - Set_W_Frame (startframe, endframe, 0, 0, 0, ReturnWeaponModel, modelname, false, S_BOTH);//FIXME + Weapon_PlayViewModelAnimation(ANIM_TAKE_OUT, ReturnWeaponModel, 0); self.reload_delay2 = self.fire_delay2 = self.reload_delay = self.fire_delay = 0; @@ -308,32 +268,18 @@ void() W_PutOut = if (self.secondaryweapon && !self.new_anim_stop) { - float startframe; - float endframe; - string modelname; - startframe = GetFrame(self.weapon,PUT_OUT_START); - endframe = GetFrame(self.weapon,PUT_OUT_END); - modelname = GetWeaponModel(self.weapon, 0); - - Set_W_Frame (startframe, endframe, (endframe - startframe)/10, 0, SWITCHWEP, W_Switch, modelname, false, S_BOTH);//FIXME + Weapon_PlayViewModelAnimation(ANIM_PUT_AWAY, W_Switch, 0); self.reload_delay2 = self.fire_delay2 = self.reload_delay = self.fire_delay = 0; } } void() W_TakeOut = { - W_AimOut(); - - float startframe; - float endframe; - string modelname; - startframe = GetFrame(self.weapon,TAKE_OUT_START); - endframe = GetFrame(self.weapon,TAKE_OUT_END); - modelname = GetWeaponModel(self.weapon, 0); + self.isBuying = false; + + W_AimOut(); + Weapon_PlayViewModelAnimation(ANIM_TAKE_OUT, SUB_Null, 0); - self.isBuying = false; - - Set_W_Frame (startframe, endframe, (endframe - startframe)/10, 0, SWITCHWEP, SUB_Null, modelname, false, S_BOTH);//FIXME self.reload_delay2 = self.fire_delay2 = self.reload_delay = self.fire_delay = 0; }