sereky
01-09-2012, 07:27
This plugin removes player's pistol when he shoot with his primary weapon, and gives it back after 5 sec. (This is an example for my problem.)
#include <sourcemod>
#include <sdktools>
new clip;
public OnPluginStart()
{
HookEvent("weapon_fire", OnWeaponFire);
}
public Action:OnWeaponFire(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
new victim;
new slot = GetPlayerWeaponSlot(client, 0);
decl String:weaponname[32];
decl String:gun[64];
GetClientWeapon(client, weaponname, sizeof weaponname);
GetEdictClassname(slot, gun, sizeof(gun));
if (StrEqual(gun, weaponname, false))
{
victim = GetPlayerWeaponSlot(client, 1);
if (victim != -1)
{
clip = GetEntProp(GetPlayerWeaponSlot(client, 1), Prop_Send, "m_iClip1")
remove(client, 1);
CreateTimer(5.0, givepistol, client);
return;
}
return;
}
}
public Action:givepistol(Handle:timer, any:client)
{
giveweapon(client, "weapon_pistol");
SetEntProp(GetPlayerWeaponSlot(client, 1), Prop_Send, "m_iClip1", clip);
}
giveweapon(client, String:class[40])
{
new ent = CreateEntityByName(class);
if (ent != -1)
{
DispatchSpawn(ent);
EquipPlayerWeapon(client, ent);
}
}
remove(client, slot)
{
new ent = GetPlayerWeaponSlot(client, slot);
if (ent != -1)
{
RemovePlayerItem(client, ent);
RemoveEdict(ent);
}
}
Before it removes the pistol, it saves player's pistol's clip size by clip = GetEntProp(GetPlayerWeaponSlot(client, 1), Prop_Send, "m_iClip1"). Then when it gives back the pistol, it set the pistol's clip size with SetEntProp(GetPlayerWeaponSlot(client, 1), Prop_Send, "m_iClip1", clip); to the saved/original value.
The problem is that it saves only the last player's value. :(
Here is an example:
There are A player and B player.
A player has 28 ammo in his pistol clip. B player has 11 ammo in his pistol clip.
A player shoot with his primary weapon. His pistol removed, and 5 sec timer started (for A player). Before the timer ends, B player shoot with his primary weapon (timer started for B player). After both timer ends, you can see that the both player's pistol clip ammo is 11.
The value saved in new clip; but it saves only the last value. How to fix it? How to save each player's value separately?
#include <sourcemod>
#include <sdktools>
new clip;
public OnPluginStart()
{
HookEvent("weapon_fire", OnWeaponFire);
}
public Action:OnWeaponFire(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
new victim;
new slot = GetPlayerWeaponSlot(client, 0);
decl String:weaponname[32];
decl String:gun[64];
GetClientWeapon(client, weaponname, sizeof weaponname);
GetEdictClassname(slot, gun, sizeof(gun));
if (StrEqual(gun, weaponname, false))
{
victim = GetPlayerWeaponSlot(client, 1);
if (victim != -1)
{
clip = GetEntProp(GetPlayerWeaponSlot(client, 1), Prop_Send, "m_iClip1")
remove(client, 1);
CreateTimer(5.0, givepistol, client);
return;
}
return;
}
}
public Action:givepistol(Handle:timer, any:client)
{
giveweapon(client, "weapon_pistol");
SetEntProp(GetPlayerWeaponSlot(client, 1), Prop_Send, "m_iClip1", clip);
}
giveweapon(client, String:class[40])
{
new ent = CreateEntityByName(class);
if (ent != -1)
{
DispatchSpawn(ent);
EquipPlayerWeapon(client, ent);
}
}
remove(client, slot)
{
new ent = GetPlayerWeaponSlot(client, slot);
if (ent != -1)
{
RemovePlayerItem(client, ent);
RemoveEdict(ent);
}
}
Before it removes the pistol, it saves player's pistol's clip size by clip = GetEntProp(GetPlayerWeaponSlot(client, 1), Prop_Send, "m_iClip1"). Then when it gives back the pistol, it set the pistol's clip size with SetEntProp(GetPlayerWeaponSlot(client, 1), Prop_Send, "m_iClip1", clip); to the saved/original value.
The problem is that it saves only the last player's value. :(
Here is an example:
There are A player and B player.
A player has 28 ammo in his pistol clip. B player has 11 ammo in his pistol clip.
A player shoot with his primary weapon. His pistol removed, and 5 sec timer started (for A player). Before the timer ends, B player shoot with his primary weapon (timer started for B player). After both timer ends, you can see that the both player's pistol clip ammo is 11.
The value saved in new clip; but it saves only the last value. How to fix it? How to save each player's value separately?