Veteran Member
Join Date: May 2009
Location: Russia
|
10-06-2012
, 05:37
Re: How to switch to weapon without delays after GivePlayerItem command?
|
#5
|
I found sourcemod plugin [CSS] Weapon Mod
I can change many properties including quickswitch, fire rates, norecoil.
It can change it on the fly, for exampe if i want to quickly switch to AK47, i can use "weaponmod ak47 quickswitch 1" command.
It works for all the weapons, and when i added csgo weapons to it then it keeps working on csgo too.
So i checked the source code and i found quick switch implementation there
Code:
/* if quickswitch was used change from the deploy animation back to the idle one on the players viewmodel.
also remove the attack delay from switching weapons. */
if (ProcessArray[client][ProcessQuickSwitch] == 1)
{
ProcessArray[client][ProcessQuickSwitch] = 0;
/* "m_flNextAttack" is whent the player can next attack, set it to next game frame
instead of the deploy animation length */
SetEntPropFloat(client, Prop_Send, "m_flNextAttack", GetGameTime());
new ViewModel = GetEntPropEnt(client, Prop_Send, "m_hViewModel");
// make sure the correct animation is used if the silencer is on.
if (StrEqual("usp", WeaponName, false))
{
if (!GetEntProp(WeaponIndex, Prop_Send, "m_bSilencerOn"))
{
SetEntProp(ViewModel, Prop_Send, "m_nSequence", 8);
return;
}
}
else if (StrEqual("m4a1", WeaponName, false))
{
if (!GetEntProp(WeaponIndex, Prop_Send, "m_bSilencerOn"))
{
SetEntProp(ViewModel, Prop_Send, "m_nSequence", 7);
return;
}
}
SetEntProp(ViewModel, Prop_Send, "m_nSequence", 0);
}
- it even fixes the model animation
- correctly work with silencers and burstfire modes
- makes quick switch when use switches weapons by himmself without GivePlayerItem command
nice plugin
so i updated test plugin and now it works
Code:
#pragma semicolon 1
#include <sdktools>
#include <sdkhooks>
public Plugin:myinfo = {
name = "test",
author = "test",
description = "test",
version = "test",
url = "test"
};
new g_index = 0;
new g_index2 = 0;
new String:g_weapons[][] = {
"weapon_glock",
"weapon_p250",
"weapon_fiveseven",
"weapon_deagle",
"weapon_elite",
"weapon_hkp2000",
"weapon_tec9",
"weapon_nova",
"weapon_xm1014",
"weapon_sawedoff",
"weapon_m249",
"weapon_negev",
"weapon_mag7",
"weapon_mp7",
"weapon_ump45",
"weapon_p90",
"weapon_bizon",
"weapon_mp9",
"weapon_mac10",
"weapon_famas",
"weapon_m4a1",
"weapon_aug",
"weapon_galilar",
"weapon_ak47",
"weapon_sg556",
"weapon_ssg08",
"weapon_awp",
"weapon_scar20",
"weapon_g3sg1",
"weapon_taser",
"weapon_molotov",
"weapon_hegrenade"
};
SwitchWeapon(client) {
if (g_index+1>= sizeof(g_weapons)) {
g_index = 0;
} else {
g_index++;
}
for (new i = 0, ent; i < 2; i++) {
ent = GetPlayerWeaponSlot(client, i);
if (ent > 0) {
RemovePlayerItem(client, ent);
RemoveEdict(ent);
}
}
new weapon = GivePlayerItem(client, g_weapons[g_index]);
FakeClientCommand(client, "use %s", g_weapons[g_index]);
InstantSwitch(client, weapon);
}
public OnPluginStart() {
HookEvent("player_death", Event_PlayerDeath);
}
public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast) {
new client = GetClientOfUserId(GetEventInt(event, "attacker"));
if (!client) {
return;
}
SwitchWeaponDelayed(client);
}
SwitchWeaponDelayed(client) {
CreateTimer(0.1, Timer_SwitchWeapon, client);
}
public Action:Timer_SwitchWeapon(Handle:timer, any:client) {
if (client&&IsClientInGame(client)&&IsPlayerAlive(client)) {
SwitchWeapon(client);
}
}
public OnMapStart() {
for (new client = 1; client <= MaxClients; client++) {
if (IsClientInGame(client)) {
SDKHook(client, SDKHook_WeaponSwitch, OnWeaponSwitch);
}
}
}
public OnClientPutInServer(client) {
SDKHook(client, SDKHook_WeaponSwitch, OnWeaponSwitch);
}
public Action:OnWeaponSwitch(client, weapon) {
new Handle:data;
data = CreateDataPack();
WritePackCell(data, client);
WritePackCell(data, weapon);
CreateTimer(0.1, Timer_InstantSwitch, data);
return Plugin_Continue;
}
public Action:Timer_InstantSwitch(Handle:timer, any:data) {
ResetPack(data);
new client = ReadPackCell(data);
new weapon = ReadPackCell(data);
CloseHandle(data);
if (client&&IsClientInGame(client)&&IsPlayerAlive(client)) {
InstantSwitch(client, weapon, 1);
}
}
InstantSwitch(client, weapon, timer = 0) {
new Float:GameTime = GetGameTime();
if (!timer) {
SetEntPropEnt(client, Prop_Send, "m_hActiveWeapon", weapon);
SetEntPropFloat(weapon, Prop_Send, "m_flNextPrimaryAttack", GameTime);
}
SetEntPropFloat(client, Prop_Send, "m_flNextAttack", GameTime);
new ViewModel = GetEntPropEnt(client, Prop_Send, "m_hViewModel");
SetEntProp(ViewModel, Prop_Send, "m_nSequence", 0);
}
__________________
Last edited by altex; 10-06-2012 at 05:40.
|
|