Near Cops
#1

PHP Code:
if(IsPlayerNearLawEnforcement(playerid) && GetPlayerWantedLevel(playerid) < 6)
    {
         
shotsfired[playerid] ++;
         if(
shotsfired[playerid] >= 2)
         {
            new 
string[256], copmsg[256], ID;
            
SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 1);
            
format(string, sizeof(string), "Comitted A Crime: Shooting in public - Wanted Level %d", GetPlayerWantedLevel(playerid));
            
SendClientMessage(playerid, COLOR_WANTED, string);
            
pInfo[playerid][pCrimes] ++;
            
pInfo[playerid][pWantedLevel] = pInfo[playerid][pWantedLevel] + 1;
            
format(copmsg, sizeof(copmsg), "Suspect %s (%d) has shooting in public near %s", GetName(playerid), playerid, ReturnPlayerZone(ID));
            
SendRadioMessageToCops(copmsg);
            
shotsfired[playerid] = 0;
         }
    } 
PHP Code:
stock IsPlayerNearLawEnforcement(playerid)
{
    new 
Float:cPos[3], Float:range = 100.0;
    foreach(
Player, i)
    {
        if(
GetTeam{i} == CLASS_CIV || GetTeam{i} == CLASS_MEDIC) continue;
        
GetPlayerPos(i, cPos[0], cPos[1], cPos[2]);
        if(
IsPlayerInRangeOfPoint(playerid, range, cPos[0], cPos[1], cPos[2]))
        {
            return 
1;
        }
    }
    return 
0;
} 
Problem: I am trying to do if a player shoots in public like if there's a cop in range then player should gain a wanted level

but i dont know why its not working there are 2 problems

1- If a cop shoots cop gets wanted level too
2- if a civlian shoots he gets wanted level too even if there's no cop
Reply
#2

This might be caused by a too high range: 2- if a civlian shoots he gets wanted level too even if there's no cop

KK, changed some stuff, but overall it looka like it should work:

PHP Code:
if(GetTeam(playerid) == CLASS_CIV || GetTeam(playerid) == CLASS_MEDIC)
{
    if(
IsPlayerNearLawEnforcement(playerid) && GetPlayerWantedLevel(playerid) < 6) 
    { 
        
shotsfired[playerid] ++; 
        if(
shotsfired[playerid] >= 2) 
        { 
            new 
msg[128], ID; 
            
SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 1); 
            
format(msg, sizeof(msg), "Comitted A Crime: Shooting in public - Wanted Level %d", GetPlayerWantedLevel(playerid)); 
            
SendClientMessage(playerid, COLOR_WANTED, msg); 
            
//Decide for one way, either use var++, var = var + 1 or var += 1;
            
pInfo[playerid][pCrimes] ++; 
            
pInfo[playerid][pWantedLevel] ++; 
            
format(msg, sizeof(msg), "Suspect %s (%d) has shooting in public near %s", GetName(playerid), playerid, ReturnPlayerZone(ID)); 
            
SendRadioMessageToCops(msg); 
            
shotsfired[playerid] = 0; 
        } 
    }  
}
IsPlayerNearLawEnforcement(playerid) 
{ 
    static 
Float:range = 100.0;
    new 
Float:x, Float:y, Float:z;
    foreach(
Player, i) 
    { 
        if(
GetTeam(i) == CLASS_CIV || GetTeam(i) == CLASS_MEDIC)
        {
            continue;
        } 
        
GetPlayerPos(i, x, y, z); 
        if(
IsPlayerInRangeOfPoint(playerid, range, x, y, z)) 
        { 
            return 
1; 
        } 
    } 
    return 
0; 
} 
As you can see, i changed a couple of things, first of all, i changed the coding style a little, sorry, personal preference :P.

Also, i removed an unnecessary variable, shortend the msg variable, replaced ranged with a static, the position array with single variables (faster) and added an additional teamcheck to the first piece of code.

also i replaced the "{" and "}" behind GetTeam with "(" and ")".
Reply
#3

Thank you. The problem was I didn't add in the first code.
PHP Code:
if(GetTeam(playerid) == CLASS_CIV || GetTeam(playerid) == CLASS_MEDIC) 
Now its working and just added this line ^^^
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)