SA-MP Forums Archive
Criminal Chat Problem [DCMD] - 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: Criminal Chat Problem [DCMD] (/showthread.php?tid=436002)



Criminal Chat Problem [DCMD] - CNRLIFE - 09.05.2013

pawn Код:
dcmd_cchat(playerid,params[])
{
    new string[128];
    if(!strlen(params))
    {
        SendClientMessage(playerid,COLOR_ERROR,"USAGE: /cchat (Message)");
        return 1;
    }
    if(GetPlayerWantedLevel(playerid) < 20)
    {
    return SendClientMessage(playerid, -1, "You are not a hardend criminal");
    }
    if(IsSpawned[playerid] == 0)
    {
        SendClientMessage(playerid,COLOR_ERROR,"You must be alive and spawned in order to be able to use this command.");
        return 1;
    }
    if(GetPlayerWantedLevel(playerid) >= 20)
   {
    format(string,sizeof(string),"4[CRIM CHAT] %s(%d): %s",PlayerName(playerid),playerid,params);
    IRC_GroupSay(gGroupAdminID,IRC_ADMINCHANNEL,string);
    for(new i=0; i<MAX_PLAYERS; i++)
    {
     if(GetPlayerWantedLevel(playerid) >= 20)
        {
            format(string,sizeof(string),"[CRIM CHAT] %s(%d): %s",PlayerName(playerid),playerid,params);
            SendClientMessage(i,COLOR_RED,string);
        }
        }
        }
    return 1;
}
Whats wrong with it?

Basically what its supposed to be is a chat for criminals with over 20 + wanted level. But yet, the criminals cant see the text, and the innocents can. Iv tried a while it wont work, i get no errors.

Please help ASAP,
-Jamie


Re: Criminal Chat Problem [DCMD] - Kwarde - 09.05.2013

Check your GetPlayerWantedLevel after the loop through all players; you used 'playerid' instead of 'i' so it only checks the wanted level of the player using the command.
Also, you are unneeded checking twice for wanted level 20 (first you block access then the level is beneath 20, a while later you check it again..)


Re: Criminal Chat Problem [DCMD] - CNRLIFE - 09.05.2013

Quote:
Originally Posted by Kwarde
Посмотреть сообщение
Check your GetPlayerWantedLevel after the loop through all players; you used 'playerid' instead of 'i' so it only checks the wanted level of the player using the command.
Also, you are unneeded checking twice for wanted level 20 (first you block access then the level is beneath 20, a while later you check it again..)
so
pawn Код:
if(GetPlayerWantedLevel(playerid) >= 20)
should be

pawn Код:
if(GetPlayerWantedLevel(i) >= 20)
right?


Re: Criminal Chat Problem [DCMD] - Kwarde - 09.05.2013

That is correct.
Also, here is your command again, fixed (atleast it should be :P) and a little speed improvement:
pawn Код:
dcmd_cchat(playerid, params[])
{
    if (!strlen(params)) return SendClientMessage(playerid, COLOR_ERROR, "USAGE: /cchat (Message)");
    if (GetPlayerWantedLevel(playerid) < 20) return SendClientMessage(playerid, -1, "You are not a hardened criminal");
    if (IsSpawned[playerid] == 0) return SendClientMessage(playerid, COLOR_ERROR, "You must be alive and spawned in order to be able to use this command.");
    new string[128];
    format(string, 128, "4[CRIM CHAT] %s(%d): %s", PlayerName(playerid), playerid, params);
    IRC_GroupSay(gGroupAdminID, IRC_ADMINCHANNEL, string);
    format(string, 128, "[CRIM CHAT] %s(%d): %s", PlayerNAme(playerid), playerid, params);
    for (new i = 0; i < MAX_PLAYERS; i++)
    {
        if (!IsPlayerConnected(i) || GetPlayerWantedLevel(i) < 20) continue;
        SendClientMessage(i, COLOR_RED, string);
    }
    return 1;
}



Re: Criminal Chat Problem [DCMD] - CNRLIFE - 09.05.2013

Quote:
Originally Posted by Kwarde
Посмотреть сообщение
That is correct.
Also, here is your command again, fixed (atleast it should be :P) and a little speed improvement:
pawn Код:
dcmd_cchat(playerid, params[])
{
    if (!strlen(params)) return SendClientMessage(playerid, COLOR_ERROR, "USAGE: /cchat (Message)");
    if (GetPlayerWantedLevel(playerid) < 20) return SendClientMessage(playerid, -1, "You are not a hardened criminal");
    if (IsSpawned[playerid] == 0) return SendClientMessage(playerid, COLOR_ERROR, "You must be alive and spawned in order to be able to use this command.");
    new string[128];
    format(string, 128, "4[CRIM CHAT] %s(%d): %s", PlayerName(playerid), playerid, params);
    IRC_GroupSay(gGroupAdminID, IRC_ADMINCHANNEL, string);
    format(string, 128, "[CRIM CHAT] %s(%d): %s", PlayerNAme(playerid), playerid, params);
    for (new i = 0; i < MAX_PLAYERS; i++)
    {
        if (!IsPlayerConnected(i) || GetPlayerWantedLevel(i) < 20) continue;
        SendClientMessage(i, COLOR_RED, string);
    }
    return 1;
}
Thank you very much