Code:
register_event("CurWeapon", "Change_Wpn", "be")//Weapon changed
......
// Called on player switches his weapon
public Change_Wpn(id)
{
if (!get_pcvar_num(g_speed_enabled)) return PLUGIN_HANDLED
new WeaponNum = read_data(2) // read and store the weaponID
new WeaponActive = read_data(1) // read the flag if weapon is active (user holds in his hand)
if (WeaponNum != WeaponUsed[id] && WeaponActive) // if weapon has changed and its the active weapon continue
{
WeaponUsed[id] = WeaponNum
calculate_speed(id, WeaponNum)
give_speed(id)
}
return PLUGIN_HANDLED
}
......
// Calculate the percentual running- and walking-speed for current Weapon (e.g. awp gives a slower speed than knife)
stock calculate_speed(id, WeaponNum)
{
new speed_value = get_pcvar_num(g_speed_value)
switch (WeaponNum)
{
case 3:{
// CSW_SCOUT
g_data[id][0] = (speed_value * 104)/100; // Calculate the speed for current Weapon
g_data[id][1] = (g_data[id][0]*55)/100; // Calculate the walking speed for current Weapon(plus a little buffer)
}
case 30:{
// CSW_P90
g_data[id][0] = (speed_value * 98)/100;
g_data[id][1] = (g_data[id][0]*55)/100;
}
case 5, 8, 14, 15:{
// CSW_XM1014, CSW_AUG, CSW_GALI, CSW_FAMAS
g_data[id][0] = (speed_value * 96)/100;
g_data[id][1] = (g_data[id][0]*55)/100;
}
case 27:{
// CSW_SG552
g_data[id][0] = (speed_value * 94)/100;
g_data[id][1] = (g_data[id][0]*55)/100;
}
case 21, 22:{
// CSW_M3, CSW_M4A1
g_data[id][0] = (speed_value * 92)/100;
g_data[id][1] = (g_data[id][0]*55)/100;
}
case 28:{
// CSW_AK47
g_data[id][0] = (speed_value * 884)/1000;
g_data[id][1] = (g_data[id][0]*55)/100;
}
case 20:{
// CSW_M249
g_data[id][0] = (speed_value * 88)/100;
g_data[id][1] = (g_data[id][0]*55)/100;
}
case 13, 18, 24:{
// CSW_SG550, CSW_AWP, CSW_G3SG1
g_data[id][0] = (speed_value * 84)/100;
g_data[id][1] = (g_data[id][0]*55)/100;
}
default:{
// All other weapons and nades
g_data[id][0] = speed_value;
g_data[id][1] = (g_data[id][0]*55)/100;
}
}
return PLUGIN_CONTINUE
}