[ROCMOD CODING] - Weapon Weighting / Player Speed
Select messages from # through # Forum FAQ
[/[Print]\]

Soldier Of Fortune 2 -> SOF2 Tutorials

#1: No icon [ROCMOD CODING] - Weapon Weighting / Player Speed Author: BuLLy PostPosted: Mon Aug 21, 2017 2:15 am
    —
Hi all,

I have recently got back into coding for RoCmod and have decided to release parts of my new code.

Those that have played Counter Strike will remember when you are carrying a small / light weapon you can run faster than someone carrying a larger heavier weapon.

It got me thinking it would be great to be able to do that with SoF2 so I coded it.

Every weapon now has its own speed CVAR for example "g_ak74speed" where a value can be defined to make the player run faster or slower while carrying the chosen weapon.

Default speed is "1" so a setting of "1.5" would see a 50% increase in running speed and a value of 0.5 a 50% decrease.

I have set the default values to what I think works well, but they are all adjustable by their respective CVARS.

--------------------------------------------------

Open g_main.c <<<<<<<<<<<<<<<<<<

Search for:
Code:
{ &g_motd7, "g_motd7", "", 0, 0.0f, 0.0f, 0, qfalse },
   { &g_motd8, "g_motd8", "", 0, 0.0f, 0.0f, 0, qfalse },
   { &g_motd9, "g_motd9", "", 0, 0.0f, 0.0f, 0, qfalse },
   { &g_motd10, "g_motd10", "", 0, 0.0f, 0.0f, 0, qfalse },


Add the following below the motd (or near) :
Code:
//WEAPON WEIGHTING - BuLLy
   { &g_playerspeed, "g_playerspeed", "1", 0, 0, qfalse },
   { &g_knifespeed, "g_knifespeed", "1.5", 0, 0, qfalse },
   { &g_pistolspeed, "g_pistolspeed", "1.4", 0, 0, qfalse },
   { &g_socomspeed, "g_socomspeed", "1.4", 0, 0, qfalse },
   { &g_talonspeed, "g_talonspeed", "1.4", 0, 0, qfalse },
   { &g_shotgunspeed, "g_shotgunspeed", "0.9", 0, 0, qfalse },
   { &g_uzispeed, "g_uzispeed", "1.3", 0, 0, qfalse },
   { &g_greasespeed, "g_greasespeed", "1.2", 0, 0, qfalse },
   { &g_mp5speed, "g_mp5speed", "1.3", 0, 0, qfalse },
   { &g_usasspeed, "g_usasspeed", "0.9", 0, 0, qfalse },
   { &g_m4speed, "g_m4speed", "1.2", 0, 0, qfalse },
   { &g_ak74speed, "g_ak74speed", "1.2", 0, 0, qfalse },
   { &g_sigspeed, "g_sigspeed", "1.1", 0, 0, qfalse },
   { &g_sniperspeed, "g_sniperspeed", "0.8", 0, 0, qfalse },
   { &g_m60speed, "g_m60speed", "0.7", 0, 0, qfalse },
   { &g_mm1speed, "g_mm1speed", "0.8", 0, 0, qfalse },
   { &g_rpgspeed, "g_rpgspeed", "0.8", 0, 0, qfalse },
   { &g_flashspeed, "g_flashspeed", "1.5", 0, 0, qfalse },
   { &g_fragspeed, "g_fragspeed", "1.5", 0, 0, qfalse },
   { &g_flamespeed, "g_flamespeed", "1.5", 0, 0, qfalse },
   { &g_smokespeed, "g_smokespeed", "1.5", 0, 0, qfalse },
//END WEAPON WEIGHTING


Search for :
Code:

vmCvar_t   g_timeRemaining;
vmCvar_t   g_suspendedAdmin;
vmCvar_t   g_inactivitySpectator;
vmCvar_t   g_explosionGore;


Add the following below the explosion gore cvar (or near)
Code:
//WEAPON WEIGHTING - BuLLy
vmCvar_t   g_playerspeed;
vmCvar_t   g_knifespeed;
vmCvar_t   g_pistolspeed;
vmCvar_t   g_socomspeed;
vmCvar_t   g_talonspeed;
vmCvar_t   g_shotgunspeed;
vmCvar_t   g_uzispeed;
vmCvar_t   g_greasespeed;
vmCvar_t   g_mp5speed;
vmCvar_t   g_usasspeed;
vmCvar_t   g_m4speed;
vmCvar_t   g_ak74speed;
vmCvar_t   g_sigspeed;
vmCvar_t   g_sniperspeed;
vmCvar_t   g_m60speed;
vmCvar_t   g_mm1speed;
vmCvar_t   g_rpgspeed;
vmCvar_t   g_flashspeed;
vmCvar_t   g_fragspeed;
vmCvar_t   g_flamespeed;
vmCvar_t   g_smokespeed;
//END WEAPON WEIGHTING


------------------------------------------------


Open g_local.h <<<<<<<<<<<<<<

Search For:
Code:

extern   vmCvar_t   g_restarted;
extern   vmCvar_t   g_logHits;


Add for following below the g_loghits cvar or near
Code:

//WEAPON WEIGHTING - BuLLy
extern    vmCvar_t   g_playerspeed;
extern    vmCvar_t   g_knifespeed;
extern    vmCvar_t   g_pistolspeed;
extern    vmCvar_t   g_socomspeed;
extern    vmCvar_t   g_talonspeed;
extern    vmCvar_t   g_shotgunspeed;
extern    vmCvar_t   g_uzispeed;
extern    vmCvar_t   g_greasespeed;
extern    vmCvar_t   g_mp5speed;
extern    vmCvar_t   g_usasspeed;
extern    vmCvar_t   g_m4speed;
extern    vmCvar_t   g_ak74speed;
extern    vmCvar_t   g_sigspeed;
extern    vmCvar_t   g_sniperspeed;
extern    vmCvar_t   g_m60speed;
extern    vmCvar_t   g_mm1speed;
extern    vmCvar_t   g_rpgspeed;
extern    vmCvar_t   g_flashspeed;
extern    vmCvar_t   g_fragspeed;
extern    vmCvar_t   g_flamespeed;
extern    vmCvar_t   g_smokespeed;
//END WEAPON WEIGHTING


------------------------

Open g_active.c <<<<<<<<<<<<<

Search for :
Code:

   // set speed
   client->ps.speed = g_speed.value;


Add for following below the search result.
Code:

   //BuLLy - Alter the player speed depending on current weapon selection.
   //Normal speed modifier (easier than relying on g_speed)
   client->ps.speed *= g_playerspeed.value;
   //Now check which weapon is in use, and perform the speed adjustment
   
      switch(client->ps.weapon) {
      case WP_KNIFE:
         client->ps.speed *= g_knifespeed.value;
         break;
      case WP_M1911A1_PISTOL:
         client->ps.speed *= g_pistolspeed.value;
         break;
      case WP_USSOCOM_PISTOL:
         client->ps.speed *= g_socomspeed.value;
         break;
      case WP_SILVER_TALON:
         client->ps.speed *= g_talonspeed.value;
         break;
      case WP_M590_SHOTGUN:
         client->ps.speed *= g_shotgunspeed.value;
         break;
      case WP_MICRO_UZI_SUBMACHINEGUN:
         client->ps.speed *= g_uzispeed.value;
         break;
      case WP_M3A1_SUBMACHINEGUN:
         client->ps.speed *= g_greasespeed.value;
         break;
      case WP_MP5:
         client->ps.speed *= g_mp5speed.value;
         break;
      case WP_USAS_12_SHOTGUN:
         client->ps.speed *= g_usasspeed.value;
         break;
      case WP_M4_ASSAULT_RIFLE:
         client->ps.speed *= g_m4speed.value;
         break;
      case WP_AK74_ASSAULT_RIFLE:
         client->ps.speed *= g_ak74speed.value;
         break;
      case WP_SIG551:
         client->ps.speed *= g_sigspeed.value;
         break;
      case WP_MSG90A1:
         client->ps.speed *= g_sniperspeed.value;
         break;
      case WP_M60_MACHINEGUN:
         client->ps.speed *= g_m60speed.value;
         break;
      case WP_MM1_GRENADE_LAUNCHER:
         client->ps.speed *= g_mm1speed.value;
         break;
      case WP_RPG7_LAUNCHER:
         client->ps.speed *= g_rpgspeed.value;
         break;
      case WP_M84_GRENADE:
         client->ps.speed *= g_flashspeed.value;
         break;
      case WP_SMOHG92_GRENADE:
         client->ps.speed *= g_fragspeed.value;
         break;
      case WP_ANM14_GRENADE:
         client->ps.speed *= g_flamespeed.value;
         break;
      case WP_M15_GRENADE:
         client->ps.speed *= g_smokespeed.value;
         break;
      default:
         break;
   };
   
   //End Alter Speed - BuLLy


----------------------------------

Usage :

As mentioned above, each weapon now has its own CVAR setting which you can control via RCON.

/rcon g_knifespeed 2 would see the player running 100% faster than normal, whereas a setting of 0.5 would see the player run 50% slower than normal.

By default I have set the setting to what I think is best, however it will likely need some tweaking as the initial g_speed cvar setting plays a part in how fast you run.

I recommend a g_speed setting of 300 and then let the weapon speed adjustments handle the rest.

Available Commands :

g_playerspeed //Set to a default of 1 (Globally adjusts all speed)

g_knifespeed
g_pistolspeed
g_socomspeed
g_talonspeed
g_shotgunspeed
g_uzispeed
g_greasespeed
g_mp5speed
g_usasspeed
g_m4speed
g_ak74speed
g_sigspeed
g_sniperspeed
g_m60speed
g_mm1speed
g_rpgspeed
g_flashspeed
g_fragspeed
g_flamespeed
g_smokespeed

---------------------------------------

Hope you guys enjoy, any questions let me know.

BuLLy



Soldier Of Fortune 2 -> SOF2 Tutorials


output generated using printer-friendly topic mod. All times are GMT + 2 Hours

Page 1 of 1