Problem With loop!
#1

i've this loop

for (i = 0; i < MAX_PLAYERS; i++)

how can i skip myslef from all players?
like i added birthday

Then Server Should Send Message To Other players playername (playerid)' Birthday.
and Server Should Sebd Messae To me Today is Your Birthday.

How can i skip mysleft from MAX_PLAYERS?
when i use this loop with /freezeall command and but im also getting freezed with others.
i want that all players get freeze without me
Reply
#2

pawn Код:
for(new i=0; i < MAX_PLAYERS; i++) //Start the loop looping through all players
{
    if(i != playerid) //Make sure the 'i' variable is NOT your playerid
    {
        //Do stuff here, your playerid will NOT be used between these brackets
   
   
    }
}
This should do the trick I guess, you can also use BroZeus' code. The code I wrote is not 'the' way to do it, it's just another way of doing it.
Reply
#3

use "continue;" keyword for it
like this
pawn Код:
for(new i=0; i<MAX_PLAYERS ;i++)
{
if(i == your_playerid)continue;
//rest of codes
}
continue keyword basically skips a step of loop
Reply
#4

aight, Thank You!
but what is this //rest of codes?

PHP код:
for(new i=0i<MAX_PLAYERS ;i++){if(== your_playerid)continue;//rest of codes} 
Reply
#5

i used this but! read //comments on lines!

PHP код:
for(new i=0i<MAX_PLAYERS ;i++)
{
if(
== playerid)continue;
SCM(playerid,COLOR_CYAN,"its Your Birthday!");//this shit spam's 100's of times!
SCM(i,COLOR_CYAN,"its X_MAN's Birthday!");

Reply
#6

look, what i want

i just want that if a recieve my birthday in server

then server should send me message its ur birthday and to others its X_MAN's or anyname birthday!

when i use ur code it keep spam!
Reply
#7

Yo X_man
Reply
#8

Quote:
Originally Posted by AroseKhanNaizi
Посмотреть сообщение
Yo X_man
Yo! Arose Would You like to help me!
Reply
#9

i know how to fix this its easy but never do i look like fool destroying my own commuinty
Reply
#10

Quote:
Originally Posted by danish007
Посмотреть сообщение
look, what i want

i just want that if a recieve my birthday in server

then server should send me message its ur birthday and to others its X_MAN's or anyname birthday!

when i use ur code it keep spam!
Код:
new szString[22+MAX_PLAYER_NAME], szPlayername[MAX_PLAYER_NAME+1]; //creates 2 new strings, one for the text and one for the name
GetPlayerName(playerid, szPlayername, sizeof(szPlayername)); //gets the players name
format(szString, sizeof(szString), "* It is %s's birthday!", szPlayername); //formats the text that everyone else will see
for(new i =0; i < MAX_PLAYERS; i++)
{
	if(IsPlayerConnected(i)) //checks that the player is connected
	{
		if(playerid == i) //if the player specified is you, send you a unique message
			SendClientMessage(i, -1, "It is your birthday today!");
		else //if it is any other player, send them the message formatted earlier
			SendClientMessage(i, -1, szString);
	}
}
You can add braces to the if/else statements if you want to but it isnt needed
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)