SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 07/11/2011, 03:03 PM   #1
Knappen
Huge Clucker
 
Knappen's Avatar
 
Join Date: Apr 2007
Location: Norway
Posts: 251
Reputation: 12
Default What's wrong with this loop?

I haven't made that many loops before, and the loops I've made has been pretty simple.

pawn Code:
for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(strfind(result, NameTagInfo[playerid][nFirstName], true) != -1 || strfind(result, NameTagInfo[playerid][nLastName], true) != -1)
        {
            while(GetDistanceBetweenPlayers(playerid, i) < 10)
            {
                if(NameTagInfo[i][nFriend1] == 0)
                {
                    NameTagInfo[i][nFriend1] = PlayerInfo[playerid][pSQLID];
                    SaveFriends(i);
                }
                else if(NameTagInfo[i][nFriend2] == 0)
                {
                    SendClientMessage(i, COLOR_YELLOW, "It didn't work");
                    SendClientMessage(playerid, COLOR_YELLOW, "It didn't work");
                }
            }
            SendClientMessage(playerid, COLOR_YELLOW, "It worked!");
            return 1;
        }
    }
    return true;

I does work, but it also affects the players that types the command, and I want it to only affect the players around the player who types in the command.

It's just something I made for fun I guess, a piece where a player have to type in their name, and then the other players in range, can see his name.
Knappen is offline   Reply With Quote
Old 07/11/2011, 03:08 PM   #2
Scarred
Big Clucker
 
Scarred's Avatar
 
Join Date: Aug 2011
Posts: 138
Reputation: 12
Default Re: What's wrong with this loop?

Quote:
Originally Posted by Knappen View Post
I haven't made that many loops before, and the loops I've made has been pretty simple.

pawn Code:
for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(strfind(result, NameTagInfo[playerid][nFirstName], true) != -1 || strfind(result, NameTagInfo[playerid][nLastName], true) != -1)
        {
            while(GetDistanceBetweenPlayers(playerid, i) < 10)
            {
                if(NameTagInfo[i][nFriend1] == 0)
                {
                    NameTagInfo[i][nFriend1] = PlayerInfo[playerid][pSQLID];
                    SaveFriends(i);
                }
                else if(NameTagInfo[i][nFriend2] == 0)
                {
                    SendClientMessage(i, COLOR_YELLOW, "It didn't work");
                    SendClientMessage(playerid, COLOR_YELLOW, "It didn't work");
                }
            }
            SendClientMessage(playerid, COLOR_YELLOW, "It worked!");
            return 1;
        }
    }
    return true;

I does work, but it also affects the players that types the command, and I want it to only affect the players around the player who types in the command.

It's just something I made for fun I guess, a piece where a player have to type in their name, and then the other players in range, can see his name.
Add another check like

pawn Code:
if(i != playerid) {
//rest of your code
}

This will skip the player that typed the command.
__________________
Current Project: New Equinox Roleplay! (Don't be afraid to click it! )

Quote:
Originally Posted by 2KY
We are a community defined by nothing except for the script we play on (which is edited frequently, may I add!) and the ground we walk on (and even that isn't final ) Everything in our community is dynamic, and easily editable meaning YOU, the character, define who you are. The script doesn't ask you questions such as how old you are, what gender, what race, et cetera. YOU define yourself, not a variable in your file sitting on a database along with 500,000 other "users".

You are your own character, and I will leave you with one question;

Who will you be?
Scarred is offline   Reply With Quote
Old 07/11/2011, 03:51 PM   #3
Knappen
Huge Clucker
 
Knappen's Avatar
 
Join Date: Apr 2007
Location: Norway
Posts: 251
Reputation: 12
Default Re: What's wrong with this loop?

It worked! Thank you!
Knappen is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
showing wrong/wrong string TextDraws Voldemort Help Archive 5 22/02/2011 05:50 PM
[Map] [MAP]Big Loop Patch-PT Maps 22 12/08/2010 11:17 PM


All times are GMT. The time now is 04:43 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.