Veteran Member
Join Date: Jan 2010
Location: mom's basement
|
05-16-2012
, 13:38
Re: Acessing structs inside arrays
|
#3
|
I'll be crazy...
Is this right way add another "tag" inside other enum ??
Don't know of these.
Code:
enum PlayerStat
{
Kills,
Deaths,
PlayerWeapon:lastwpn // Store last weapon ID
}
PHP Code:
// weapon names
new String:weapons[][] =
{
"none", "knife", "flashbang", "smokegrenade", "hegrenade", "galil", "ak47", "scout", "sg552", "awp", "g3sg1", "famas", "m4a1",
"aug", "sg550", "glock", "usp", "p228", "deagle", "elite", "fiveseven", "m3", "xm1014", "mac10", "tmp",
"mp5navy", "ump45", "p90", "m249"
}
// weapon ID's
enum PlayerWeapon
{
none, knife, flashbang, smokegrenade, hegrenade, galil, ak47, scout, sg552, awp, g3sg1, famas, m4a1, aug, sg550, glock, usp,
p228, deagle, elite, fiveseven, m3, xm1014, mac10, tmp, mp5navy, ump45, p90, m249
}
enum PlayerStat
{
Kills,
Deaths,
PlayerWeapon:lastwpn // Store last weapon ID
}
new g_stats[MAXPLAYERS+1][PlayerStat];
new g_statsweapon[MAXPLAYERS+1][PlayerWeapon];
public OnPluginStart()
{
HookEventEx("player_death", player_death);
}
public OnClientConnected(client)
{
// Clear stats
new a;
for(a = 0; a < sizeof(g_stats[]); a++)
{
g_stats[client][a] = 0;
}
for(a = 0; a < sizeof(g_statsweapon[]); a++)
{
g_statsweapon[client][a] = 0;
}
}
public player_death(Handle:event, const String:name[], bool:dontBroadcast)
{
// There always victim
new victim = GetClientOfUserId(GetEventInt(event, "userid"));
g_stats[victim][Deaths] += 1;
PrintToChat(victim, "Kills %i, Deaths %i", g_stats[victim][Kills], g_stats[victim][Deaths]);
// Attacker could be world or victim itself
new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
if(attacker != 0 && attacker != victim)
{
g_stats[attacker][Kills] += 1;
g_stats[attacker][lastwpn] = PlayerWeapon:0; // Set weapon "none" just in case when weapon not found.
new String:weapon[30];
GetEventString(event, "weapon", weapon, sizeof(weapon));
for(new a = 0; a < sizeof(weapons); a++)
{
if(StrContains(weapon, weapons[a], false) != -1)
{
g_stats[attacker][lastwpn] = PlayerWeapon:a;
break;
}
}
// new variable b with right tag PlayerWeapon:
new PlayerWeapon:b = g_stats[attacker][lastwpn];
g_statsweapon[attacker][b] += 1;
PrintToChat(attacker, "Kills %i, Deaths %i, this weapon %s = kills %i",
g_stats[attacker][Kills],
g_stats[attacker][Deaths],
weapons[b],
g_statsweapon[attacker][b]
);
}
}
|
|