22.12.2014, 09:06
I suspect that you were crashing due to an 'out of bounds' error, where 'issuerid' was an invalid player and you were trying to use it in an array.
If you try to access the array 'gTeam' with an element that is equal or larger to the MAXIMUM_ELEMENT given in the 'new' line, then you will get an out of bounds error.
For example, if I have:
I will NOT crash if I try to access:
I WILL crash if I try to access:
I WILL crash if I try to access:
if issuerid is GREATER than 100. INVALID_PLAYER_ID = 65535, so if issuerid is not a valid player, I will be accessing:
and I will therefore crash...
---
Here is the correct code:
pawn Code:
new gTeam[MAXIMUM_ELEMENTS];
For example, if I have:
pawn Code:
new gTeam[100];
pawn Code:
gTeam[99];
pawn Code:
gTeam[100];
pawn Code:
gTeam[issuerid];
pawn Code:
gTeam[65535];
---
Here is the correct code:
pawn Code:
forward OnPlayerShootPlayer(Shooter, Target, Float:HealthLost, Float:ArmourLost);
public OnPlayerShootPlayer(Shooter, Target, Float:HealthLost, Float:ArmourLost)
{
if(Shooter != INVALID_PLAYER_ID && Target != INVALID_PLAYER_ID)
{
if(GetPlayerTeam(Target) == GetPlayerTeam(Shooter))
{
new Float:AttackerHP;
GetPlayerHealth(Shooter, AttackerHP);
SetPlayerHealth(Shooter, AttackerHP - 5.0);
GameTextForPlayer(Shooter, "~r~That's your team mate~n~stop shooting!", 5000, 5);
}
if(gTeam[Shooter] != TEAM_POLICE)
{
if(GetPlayerTeam(Target) == TEAM_POLICE)
{
new srtin[128], playersname[MAX_PLAYER_NAME], othername[MAX_PLAYER_NAME];
GetPlayerName(Shooter, playersname, sizeof(playersname));
GetPlayerName(Target, othername, sizeof(othername));
IncreaseWantedLevel(Shooter, 2);
format(srtin, sizeof(srtin), "[POLICE RADIO] Suspect %s is wanted for shooting/murdering officer %s, proceed with caution.", playersname, othername);
SendClientMessageToAllCops(srtin);
}
}
else
{
if(!GetPlayerWantedLevel(Target))
{
new rstring[75], playersname[MAX_PLAYER_NAME];
GetPlayerName(Target, playersname, sizeof(playersname));
format(rstring, sizeof(rstring), "%s is not a wanted player.", playersname);
SendClientMessage(Shooter, red, rstring);
GetPlayerName(Shooter, playersname, sizeof(playersname));
format(rstring, sizeof(rstring), "Officer %s is shooting a player that's not wanted.", playersname);
SendClientMessageToAllAdmins(rstring);
}
}
}
return 1;
}

