shooting problem -
1fret - 22.12.2014
pawn Code:
forward OnPlayerShootPlayer(Shooter,Target,Float:HealthLost,Float:ArmourLost);
public OnPlayerShootPlayer(Shooter,Target,Float:HealthLost,Float:ArmourLost)
{
new issuerid ;
new targetid ;
if(issuerid != INVALID_PLAYER_ID && targetid != INVALID_PLAYER_ID)
{
if(GetPlayerTeam(targetid) == GetPlayerTeam(issuerid))
{
new Float:AttackerHP;
GetPlayerHealth(issuerid, AttackerHP);
SetPlayerHealth(issuerid, AttackerHP-5.0);
GameTextForPlayer(issuerid, "~r~Thats your team mate, stop shooting ", 5000, 5);
}
}
new srtin[128];
if(gTeam[issuerid] != TEAM_POLICE)
{
if(GetPlayerTeam(targetid) == TEAM_POLICE)
{
IncreaseWantedLevel(issuerid,2);
format(srtin,sizeof(srtin),"[POLICE RADIO] Suspect %s is wanted for shooting/murdering officer %s and is Harmed and Dangerours proceed with caution.",issuerid,targetid);
SendClientMessageToAllCops(srtin);
}
}
new rstring2 [128],rstring [128];
if(gTeam[issuerid] == TEAM_POLICE)
{
if(GetPlayerWantedLevel(targetid) == 0)
{
format(rstring,sizeof(rstring),"%s is not a wanted player.",targetid);
SendClientMessage(issuerid,red,rstring);
format(rstring2,sizeof(rstring2),"Officer %s is shooting a player thats not wanted",issuerid);
SendClientMessageToAllAdmins(rstring2);
}
}
return 1;
}
can someone tell me why doesnt this command work it only crash the game and i have the #include <OPSP>. And i get no errors so what could be the problem
Re: shooting problem -
Threshold - 22.12.2014
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.
pawn Code:
new gTeam[MAXIMUM_ELEMENTS];
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:
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;
}