PDA

View Full Version : Why I can't compile it and how to fix this "String"?


sereky
01-11-2012, 13:54
I have another problem.
This plugin would remove player's primary weapon when he shoot with his pistol, and would give it back after 5 sec. (This is another example for my another problem.)

#include <sourcemod>
#include <sdktools>

new String:weaponprimary[MAXPLAYERS + 1][32];

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, 1);
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, 0);

if (victim != -1)
{
GetEdictClassname(GetPlayerWeaponSlot(client, 0), weaponprimary[client], 32);
remove(client, 0);
CreateTimer(5.0, giveprimary, client);
return;
}
return;
}
}

public Action:giveprimary(Handle:timer, any:client)
{
giveweapon(client, weaponprimary[client]);
}

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 would remove the primary weapon, it would save player's actual primary weapon by GetEdictClassname(GetPlayerWeaponSlot(client, 0), weaponprimary[client], 32);. Then when it would give back the primary weapon, it should give back the saved/original weapon but it doesn't work.

Players can hold many types of primary weapons in game (like shotguns, rifles, ...), and when this plugin would remove the weapon, it should give back the original weapon that the players had before.

But unfortunately it doesn't work. Moreover I can't compile it. :(

The weapon type saved in new String:weaponprimary[MAXPLAYERS + 1][32]; but it doesn't work. How to fix it?

Farzad
01-12-2012, 10:58
The size of your weaponprimary array (its 32) is different from the function giveweapon's class varible (its 40).

To fix it:
Change
giveweapon(client, String:class[40])
to
giveweapon(client, String:class[])

sereky
01-15-2012, 04:46
The size of your weaponprimary array (its 32) is different from the function giveweapon's class varible (its 40).

To fix it:
Change
giveweapon(client, String:class[40])to
giveweapon(client, String:class[])

Thanks. It works. :)