Stock help
#1

I made a stock to check if player is near a cop:

pawn Код:
stock IsPlayerNearALawEnforcement(playerid)
{
    new team = GetPlayerTeam(playerid);

    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);

    foreach (new i : Player)
    {
        if (i != playerid)
        {
            if (team != gTeam(i) == TEAM_COP)
            {
                if (IsPlayerInRangeOfPoint(i, 20.0, x, y, z))
                {
                    return true;
                }
            }
        }
    }

    return false;
}
But i want to add radius to this stock, so i can use it like:

IsPlayerNearALawEnforcement(playerid, 20)

How?
Reply
#2

Try.
PHP код:
stock IsPlayerNearALawEnforcement(playeridFloatRadius)
{
    new 
team GetPlayerTeam(playerid);

    new 
Float:xFloat:yFloat:z;
    
GetPlayerPos(playeridxyz);

    new 
Float:range GetPlayerDistanceFromPoint(playeridxyz);
    
    if(
range <= Radius) return 1;

    foreach (new 
Player)
    {
        if (
!= playerid)
        {
            if (
team != gTeam(i) == TEAM_COP)
            {
                if (
IsPlayerInRangeOfPoint(i20.0xyz))
                {
                    return 
true;
                }
            }
        }
    }

    return 
false;

or
PHP код:
stock IsPlayerNearALawEnforcement(playeridFloatRadius)
{
    new 
team GetPlayerTeam(playerid);

    new 
Float:xFloat:yFloat:z;
    
GetPlayerPos(playeridxyz);

    foreach (new 
Player)
    {
        if (
!= playerid)
        {
            if (
team != gTeam(i) == TEAM_COP)
            {
                if (
IsPlayerInRangeOfPoint(i20.0xyz))
                {
                    return 
true;
                }
            }
        }
    }

    return 
Radius >= GetPlayerDistanceFromPoint(playeridxyz);

Reply
#3

PHP код:
stock IsPlayerNearALawEnforcement(playeridFloat:radius)
{
    new 
team GetPlayerTeam(playerid);
    new 
Float:xFloat:yFloat:z;
    
GetPlayerPos(playeridxyz);
    foreach (new 
Player)
    {
        if (
== playerid) continue;
         if (
team != gTeam(i) == TEAM_COP)
          {
               if (
IsPlayerInRangeOfPoint(iradiusxyz))
               {
                   return 
true;
               }
           }
    }
    return 
false;

Reply
#4

Thank you both. I'm trying Lokii's example and i get this errors:

Quote:

error 012: invalid function call, not a valid address
warning 215: expression has no effect
error 001: expected token: ";", but found ")"
error 029: invalid expression, assumed zero
fatal error 107: too many error messages on one line

Referred to this line:

pawn Код:
if (team != gTeam(i) == TEAM_COP)
Reply
#5

sorry it should be like this:

PHP код:
if (team != gTeam(i) && gTean(i) == TEAM_COP
and about these errors

Код:
error 012: invalid function call, not a valid address
warning 215: expression has no effect
error 001: expected token: ";", but found ")"
error 029: invalid expression, assumed zero
fatal error 107: too many error messages on one line
its not coming from that

PHP код:
if (team != gTeam(i) == TEAM_COP
Reply
#6

Still getting that error.

Another question, i made a timer to reduce player's wanted level every 60 seconds if there isn't a cop in a range of 70 meters, so i did in this way:

pawn Код:
task WantedLevelReduce[60000]()
{
    foreach (new i : Player)
    {
    if(gTeam[i] == TEAM_CIV)
    {
    if(GetPlayerWantedLevel(i) >= 1 && IsPlayerNearALawEnforcement(i, 70))
    {
        SetPlayerWantedLevelEx(i, GetPlayerWantedLevel(i)-1);
    }
    }
    }
}
The IsPlayerNearLawEnforcement check is correct?

Basically: No cop in a range of 70 meters = reduce 1 wanted level.

Is it correct?
Reply
#7

Quote:
Originally Posted by KinderClans
Посмотреть сообщение
Still getting that error.

Another question, i made a timer to reduce player's wanted level every 60 seconds if there isn't a cop in a range of 70 meters, so i did in this way:

pawn Код:
task WantedLevelReduce[60000]()
{
    foreach (new i : Player)
    {
    if(gTeam[i] == TEAM_CIV)
    {
    if(GetPlayerWantedLevel(i) >= 1 && IsPlayerNearALawEnforcement(i, 70))
    {
        SetPlayerWantedLevelEx(i, GetPlayerWantedLevel(i)-1);
    }
    }
    }
}
The IsPlayerNearLawEnforcement check is correct?

Basically: No cop in a range of 70 meters = reduce 1 wanted level.

Is it correct?
NO you'r checking if he is in range of 70 meters it should be like this

PHP код:
if(GetPlayerWantedLevel(i) >= && !IsPlayerNearALawEnforcement(i70)) 
Reply
#8

Ok and what about your stock?

This errors:

Quote:

error 012: invalid function call, not a valid address
warning 215: expression has no effect
error 001: expected token: ";", but found ")"
error 029: invalid expression, assumed zero
fatal error 107: too many error messages on one line

are gone if i remove the stock. So problem should be there...mh
Reply
#9

the stock works fine for me show me the lines where you use the function
Reply
#10

In that timer.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)