SA-MP Forums Archive
Count - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Count (/showthread.php?tid=616256)



Count - ISmokezU - 02.09.2016

Hey i made a arena command and when someone joins it should send a message to everyone about how much players are in the arena but it doesnt work look

PHP код:
new Participants[MAX_PLAYERS];
new 
bool:InArena[MAX_PLAYERS char];
CMD:arena(playeridparams[])
{
        
InArena[playerid] = true;
        new 
string[90];
        
format(string,sizeof(string),"[ARENA]: %s(%d) has joined The Arena  [%i Participants]",GetName(playerid),Participants);
        
Participants[playerid] ++;
SendClientMessageToAll(-1,string); 



Re: Count - lackmail - 02.09.2016

you have to plus one participant then format the message also you have to put return 1; so it should look like:

PHP код:
new Participants;
CMD:arena(playeridparams[])
{
    new 
string[90];
    
InArena[playerid] = true;
    
Participants++;
    
format(string,sizeof(string),"[ARENA]: %s(%d) has joined The Arena  [%i Participants]",GetName(playerid), playeridParticipants);
    
SendClientMessageToAll(-1,string);
    return 
1;

edit: i dont think you should make arena Participants[MAX_PLAYERS] it should be a normal variable just new Participants because

Participants[MAX_PLAYERS] < one variable for each player so when they join each player variable will count the player itself not other players


Re: Count - Misiur - 02.09.2016

Also your InArena is a char array, you must use {} to access it:
pawn Код:
InArena{playerid} = true;



Re: Count - ISmokezU - 02.09.2016

Quote:
Originally Posted by lackmail
Посмотреть сообщение
you have to plus one participant then format the message also you have to put return 1; so it should look like:

PHP код:
new Participants;
CMD:arena(playeridparams[])
{
    new 
string[90];
    
InArena[playerid] = true;
    
Participants++;
    
format(string,sizeof(string),"[ARENA]: %s(%d) has joined The Arena  [%i Participants]",GetName(playerid), playeridParticipants);
    
SendClientMessageToAll(-1,string);
    return 
1;

edit: i dont think you should make arena Participants[MAX_PLAYERS] it should be a normal variable just new Participants because

Participants[MAX_PLAYERS] < one variable for each player so when they join each player variable will count the player itself not other players
Thanks.

Quote:
Originally Posted by Misiur
Посмотреть сообщение
Also your InArena is a char array, you must use {} to access it:
pawn Код:
InArena{playerid} = true;
I use that way alot in my script should i change it? also what would happen if i use it with [ instead of {


Re: Count - Vince - 02.09.2016

Quote:
Originally Posted by ISmokezU
Посмотреть сообщение
I use that way alot in my script should i change it? also what would happen if i use it with [ instead of {
Yes, you should change it. You will get out-of-bounds errors and other glitchy behavior if you don't because a char-array is only 1/4th the size of a regular array. A regular array stores one item in one cell, a char array stores four items per cell. Assuming a MAX_PLAYERS setting of 100, a char array of that size will only produce 25 cells. Attempting to use it with a playerid of 25 or higher will yield OOB errors.