SA-MP Forums Archive
Simple question, - Need for multiple strings? - 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: Simple question, - Need for multiple strings? (/showthread.php?tid=416982)



Simple question, - Need for multiple strings? - denNorske - 19.02.2013

pawn Код:
CMD:cops(playerid, params[])
{
    new string[200];
    SendClientMessage(playerid, pink, " - - - - - <<<<<< Cop's Online on --- >>>>>>  - - - - - ");
    for(new i; i<MAX_PLAYERS; i++)
    {
        if(GetPVarInt(i, "cophidden") == 0)
        {
            if(cop[i][level] == 8)
            {
                format(string, sizeof(string), "%s %s [ID: %d] Rank: %d", CopRank(i), PlayerName(i), GetPlayerID(PlayerName(i)), cop[i][level]);
                SendClientMessage(playerid, blue, string);
            }
            if(cop[i][level] == 7)
            {
                format(string, sizeof(string), "%s %s [ID: %d] Rank: %d", CopRank(i), PlayerName(i), GetPlayerID(PlayerName(i)), cop[i][level]);
                SendClientMessage(playerid, blue, string);
            }
            if(cop[i][level] == 6)
            {
                format(string, sizeof(string), "%s %s [ID: %d] Rank: %d", CopRank(i), PlayerName(i), GetPlayerID(PlayerName(i)), cop[i][level]);
                SendClientMessage(playerid, blue, string);
            }
            if(cop[i][level] == 5)
            {
                format(string, sizeof(string), "%s %s [ID: %d] Rank: %d", CopRank(i), PlayerName(i), GetPlayerID(PlayerName(i)), cop[i][level]);
                SendClientMessage(playerid, blue, string);
            }
            if(cop[i][level] == 4)
            {
                format(string, sizeof(string), "%s %s [ID: %d] Rank: %d", CopRank(i), PlayerName(i), GetPlayerID(PlayerName(i)), cop[i][level]);
                SendClientMessage(playerid, blue, string);
            }
            if(cop[i][level] == 3)
            {
                format(string, sizeof(string), "%s %s [ID: %d] Rank: %d", CopRank(i), PlayerName(i), GetPlayerID(PlayerName(i)), cop[i][level]);
                SendClientMessage(playerid, blue, string);
            }
            if(cop[i][level] == 2)
            {
                format(string, sizeof(string), "%s %s [ID: %d] Rank: %d", CopRank(i), PlayerName(i), GetPlayerID(PlayerName(i)), cop[i][level]);
                SendClientMessage(playerid, blue, string);
            }
            if(cop[i][level] == 1)
            {
                format(string, sizeof(string), "%s %s [ID: %d] Rank: %d", CopRank(i), PlayerName(i), GetPlayerID(PlayerName(i)), cop[i][level]);
                SendClientMessage(playerid, blue, string);
            }
            else if(cop[i][level] == 0 || GetPVarInt(i, "cophidden") == 1)
                return SendClientMessage(playerid, pink, ">>>>> No Cops Found Online! <<<<<");
        }
    }
    return 1;
}
Okay, look at the code, i have defined the "string[200]" on the top, but i am not sure how it will act when i use this command, and there is multiple cops online.. Is there need for different strings all over the code here, or is it enough with one, simple string for it all ?

Please explain
Thanks alot!


Re: Simple question, - Need for multiple strings? - Nuke547 - 19.02.2013

1 string for it all is fine.


Re: Simple question, - Need for multiple strings? - denNorske - 19.02.2013

Quote:
Originally Posted by Nuke547
Посмотреть сообщение
1 string for it all is fine.
Thanks for reply, i thought so too. But is this because the string is used once per player ?


Re: Simple question, - Need for multiple strings? - FUNExtreme - 19.02.2013

Quote:
Originally Posted by airplanesimen
Посмотреть сообщение
Thanks for reply, i thought so too. But is this because the string is used once per player ?
This works fine because samp is single threaded. Nothing else than what is currently running can change the string.


Re: Simple question, - Need for multiple strings? - Vince - 19.02.2013

Question for you: why do you have 9 if-statements, while the output will always be the same, regardless of the player's level? Also this is retarded:

pawn Код:
GetPlayerID(PlayerName(i))
Get the name of a playerid you know, then use that name to determine the playerid that you knew in the first place.


Re: Simple question, - Need for multiple strings? - denNorske - 19.02.2013

Quote:
Originally Posted by Vince
Посмотреть сообщение
Question for you: why do you have 9 if-statements, while the output will always be the same, regardless of the player's level? Also this is retarded:

pawn Код:
GetPlayerID(PlayerName(i))
Get the name of a playerid you know, then use that name to determine the playerid that you knew in the first place.
Oh, yea, that was kind of stupid of me, i could have used only "i" there xD


And about this: Question for you: why do you have 9 if-statements, while the output will always be the same, regardless of the player's level?

That is because the "CopRank" wont be the same in all the statements, and i want the ranks Sorted ^^


Thanks FunExtreme
Quote:

This works fine because samp is single threaded. Nothing else than what is currently running can change the string.




Re: Simple question, - Need for multiple strings? - Vince - 19.02.2013

In that case you still need 8 separate loops, because this won't work as you'd expect.


Re: Simple question, - Need for multiple strings? - denNorske - 19.02.2013

Quote:
Originally Posted by Vince
Посмотреть сообщение
In that case you still need 8 separate loops, because this won't work as you'd expect.
Okay, thanks, then i will attempt to make it work :P