GetPlayerArmour
#1

Hey....

i made a function which checks through all players if the player armour is >= 100, then do stuff...

PHP код:
public CheckPlayerArmour()
{
    foreach(
Playeri)
    {
        new 
Float:parmour[MAX_PLAYERS];
        
GetPlayerArmour(iparmour);
        if(
parmour(i) >= 100)
        {
                    
// stuff here
            
adminchat(COLOR_REDstring);
        
        }
            
    }

Has errors (ye ye).
Reply
#2

What are the errors?
Reply
#3

Код:
C:\Users\Simone\Desktop\samp1\pawno\include\cnr/cnr_functions.inc(4075) : error 035: argument type mismatch (argument 2)
C:\Users\Simone\Desktop\samp1\pawno\include\cnr/cnr_functions.inc(4076) : error 012: invalid function call, not a valid address
C:\Users\Simone\Desktop\samp1\pawno\include\cnr/cnr_functions.inc(4076) : warning 215: expression has no effect
C:\Users\Simone\Desktop\samp1\pawno\include\cnr/cnr_functions.inc(4076) : error 001: expected token: ";", but found ")"
C:\Users\Simone\Desktop\samp1\pawno\include\cnr/cnr_functions.inc(4076) : error 029: invalid expression, assumed zero
C:\Users\Simone\Desktop\samp1\pawno\include\cnr/cnr_functions.inc(4076) : fatal error 107: too many error messages on one linee
PHP код:
line 75:        GetPlayerArmour(iparmour);
    
line 76:            if(parmour(i) >= 100
Reply
#4

PHP код:
public CheckPlayerArmour()
{

    foreach(
Playeri)
    {
        new 
Float:parmour;
        
GetPlayerArmour(iparmour);
        if(
parmour >= 100)
        {
                    
// stuff here
            
adminchat(COLOR_REDstring);
        
        }
            
    }

Reply
#5

you don't need MAX_PLAYERS in parmour var, also you have to use [i] instead of (i) so your code should be:
PHP код:
public CheckPlayerArmour() 


    foreach(
Playeri
    { 
        new 
Float:parmour[MAX_PLAYERS]; 
        
GetPlayerArmour(iparmour[i]); 
        if(
parmour[i] >= 100
        { 
                    
// stuff here 
            
adminchat(COLOR_REDstring); 
         
        } 
             
    } 

better optimazed way:
PHP код:
public CheckPlayerArmour() 


    foreach(
Playeri
    { 
        new 
Float:parmour
        
GetPlayerArmour(iparmour); 
        if(
parmour >= 100
        { 
                    
// stuff here 
            
adminchat(COLOR_REDstring); 
         
        } 
             
    } 

Reply
#6

Thanks buddy, works like a charm +rep
Reply
#7

Код:
public CheckPlayerArmour() 
{ 

    foreach(Player, i) 
    { 
        new Float:parmour[MAX_PLAYERS]; 
        GetPlayerArmour(i, parmour); 
        if(parmour[i] >= 100) 
        { 
                    // stuff here 
            adminchat(COLOR_RED, string); 
         
        } 
             
    } 
}
You forgot to use [i] indeed.
Reply
#8

Quote:
Originally Posted by kanerandyfirst
Посмотреть сообщение
Код:
public CheckPlayerArmour() 
{ 

    foreach(Player, i) 
    { 
        new Float:parmour[MAX_PLAYERS]; 
        GetPlayerArmour(i, parmour); 
        if(parmour[i] >= 100) 
        { 
                    // stuff here 
            adminchat(COLOR_RED, string); 
         
        } 
             
    } 
}
You forgot to use [i] indeed.
That code would still give him errors!
Besides, what's the point of creating a new variable with MAX_PLAYERS when it's a loop?
Reply
#9

Even if is in a loop, GetPlayerArmour(i,parmour) will be different from GetPlayerArmour(i,parmour[i]).

E.g.
Код:
#define MAX_ZONES 5

new capturing[MAX_PLAYERS][MAX_ZONES];

public funcion()
{
foreach(Player,i)
{
if(capturing[i][zone] > 0)
//Stuff related to a player capturing a zone
}
return 1;
}
well it is really different from:
Код:
#define MAX_ZONES 5

new capturing[MAX_ZONES];

public funcion()
{
foreach(Player,i)
{
if(capturing[zone] > 0)
//Stuff related to a zone being capped totally ignoring the player.
}
return 1;
}
in this thread's case, you may save player's armour float linked to his id, and if the float is globally defined, you can load player's float in other functions aswell.
Reply
#10

Quote:
Originally Posted by jlalt
Посмотреть сообщение
you don't need MAX_PLAYERS in parmour var, also you have to use [i] instead of (i) so your code should be:
PHP код:
public CheckPlayerArmour() 

    foreach(
Playeri
    { 
        new 
Float:parmour[MAX_PLAYERS]; 
        
GetPlayerArmour(iparmour[i]); 
        if(
parmour[i] >= 100
        { 
                    
// stuff here 
            
adminchat(COLOR_REDstring); 
         
        } 
             
    } 

better optimazed way:
PHP код:
public CheckPlayerArmour() 

    foreach(
Playeri
    { 
        new 
Float:parmour
        
GetPlayerArmour(iparmour); 
        if(
parmour >= 100
        { 
                    
// stuff here 
            
adminchat(COLOR_REDstring); 
         
        } 
             
    } 

Even better version:

PHP код:
public CheckPlayerArmour() 

    new 
Float:parmour
    foreach(
Playeri
    { 
        
GetPlayerArmour(iparmour); 
        if(
parmour >= 100
        { 
                    
// stuff here 
            
adminchat(COLOR_REDstring); 
         
        } 
             
    } 

In this way you create just once the float.

With your script you create the same float every time the loop continues. It's useless. Just create it once before the loop starts.

kanerandyfirst's version it's even worse because he creates a float with max_players as array everytime the loop continues. Why creating the same thing for about 1 thousand times when you can create in just once?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)