A Problem with a command
#1

Hello ,i've a problem with this /am command
pawn Код:
CMD:am(playerid, params[])
{
    new string[256];
    if(gPlayerLogged{playerid} == 0)
    {
        SendClientMessageEx(playerid, COLOR_GREY, "You're not logged in.");
        return 1;
    }
    if(PlayerInfo[playerid][pTut] == 0)
    {
        SendClientMessageEx(playerid, COLOR_GREY, "You can't do that at this time.");
        return 1;
    }
    if(PlayerInfo[playerid][pAmute] == 1) {
        SendClientMessageEx(playerid, COLOR_RED, "You are muted from using /am!");
        return 1;
    }
    if(noam == 1 && PlayerInfo[playerid][pAdmin] < 1)
    {
        SendClientMessageEx(playerid, COLOR_GRAD2, "  The Admin Message System has been disabled by an adminstrator, try again later.");
        return 1;
    }
    if(PlayerInfo[playerid][pHelper]< 1 && PlayerInfo[playerid][pAdmin] < 1)
    {
        NewbieTimer[playerid] = 15;
    }
    if(PlayerInfo[playerid][pHelper] >= 1 && PlayerInfo[playerid][pAdmin] < 1)
    {
        NewbieTimer[playerid] = 5;
    }
    if(IsAdmin(playerid))
    {
        NewbieTimer[playerid] = 0;
    }
    if(NewbieTimer[playerid] > 0)
    {
        format(string, sizeof(string), "You must wait %d seconds before using this channel again.", NewbieTimer[playerid]);
        SendClientMessageEx(playerid, COLOR_GREY, string);
        return 1;
    }
    if(IsAdmin(playerid))
    {
        new toid, message[128];
        if(sscanf(params, "is[128]", toid, message)) return Syntax(playerid, "[a]dmin[m]essage", "[playerid] [message]");
        if(strlen(message) > 128) return Error(playerid, "Your message cannot be longer than 128 characters.");
        if(!IsPlayerConnected(toid)) return Error(playerid, "That player is not connected!");
        //new string[128];
        format(STRING, "Admin message from %s: %s", GetPlayerNameEx(playerid), message);
        SendClientMessageEx(toid, COLOR_GREEN, string);
        format(STRING, "Admin %s [%d] > %s [%d]: %s", GetPlayerNameEx(playerid), playerid, GetPlayerNameEx(toid), toid, message);
        SendAdminMessage(COLOR_GREEN,string);
        Log("logs/adminmessage.log", string);
        PlayerInfo[playerid][pAMSSent] ++;
    }
    else
    {
        new message[80];
        if(sscanf(params, "s[80]", message)) return Syntax(playerid, "[a]dmin[m]essage", "[message]");
        if(strlen(message) > 80) return Error(playerid, "Your message cannot be longer than 80 characters.");
        //if(strfind(message, "Falling", true) != -1) return Error(playerid, "Type (/falling) and a administrative person will be there to assist you right away!");
        //new string[128];
        format(STRING, "Admin message from %s [%d]: %s", GetPlayerNameEx(playerid), playerid, message);
        SendAdminMessage(COLOR_GREEN,string);
        format(STRING, "Your message, %s, has been sent.", message);
        SendClientMessageEx(playerid, COLOR_GREEN, string);
        format(STRING, "Player %s [%d] > Admins: %s", GetPlayerNameEx(playerid), playerid, message);
        Log("logs/adminmessage.log", string);
    }
    return 1;
}
it keeps repeating the "You must wait %d seconds before using this channel again." message when i'm a regular player even if i didn't use the /am ,Can someone help me with it ?
++ REP
Reply
#2

Quote:

if(NewbieTimer[playerid] >= 1)
{
format(string, sizeof(string), "You must wait %d seconds before using this channel again.", NewbieTimer[playerid]);
SendClientMessageEx(playerid, COLOR_GREY, string);
return 1;
}

Try this code, hopefully it works
Reply
#3

Quote:
Originally Posted by Ciandlah
Посмотреть сообщение
Try this code, hopefully it works
You know that > 0 is the exact same as >= 1 right?


EDIT:

It's this:
pawn Код:
if(PlayerInfo[playerid][pHelper]< 1 && PlayerInfo[playerid][pAdmin] < 1)
    {
        NewbieTimer[playerid] = 15;
    }
    if(PlayerInfo[playerid][pHelper] >= 1 && PlayerInfo[playerid][pAdmin] < 1)
    {
        NewbieTimer[playerid] = 5;
    }
    if(IsAdmin(playerid))
    {
        NewbieTimer[playerid] = 0;
    }
    if(NewbieTimer[playerid] > 0)
    {
        format(string, sizeof(string), "You must wait %d seconds before using this channel again.", NewbieTimer[playerid]);
        SendClientMessageEx(playerid, COLOR_GREY, string);
        return 1;
    }
- You're setting the newbie timer before it even checks if the newbie timer is above what it should be.

::
pawn Код:
if(NewbieTimer[playerid] > 0)
    {
        format(string, sizeof(string), "You must wait %d seconds before using this channel again.", NewbieTimer[playerid]);
        SendClientMessageEx(playerid, COLOR_GREY, string);
        return 1;
    }
    if(PlayerInfo[playerid][pHelper]< 1 && PlayerInfo[playerid][pAdmin] < 1)
    {
        NewbieTimer[playerid] = 15;
    }
    if(PlayerInfo[playerid][pHelper] >= 1 && PlayerInfo[playerid][pAdmin] < 1)
    {
        NewbieTimer[playerid] = 5;
    }
    if(IsAdmin(playerid))
    {
        NewbieTimer[playerid] = 0;
    }
Reply
#4

pawn Код:
if(NewbieTimer[playerid])
    {
        new numstring[60];
        format(numstring, sizeof(numstring), "You must wait %d seconds before using this channel again.", NewbieTimer[playerid]);
        return SendClientMessageEx(playerid, COLOR_GREY, numstring);
    }
    NewbieTimer[playerid] = (PlayerInfo[playerid][pAdmin]) ? (0) : ((PlayerInfo[playerid][pHelper]) ? (5) : (15));
You were setting the NewbieTimer[playerid] to 5 or 15, before you were checking if it was above 0. So it would have been above 0 every time.

EDIT: Full command:
pawn Код:
CMD:am(playerid, params[])
{
    if(!gPlayerLogged{playerid}) return SendClientMessageEx(playerid, COLOR_GREY, "You're not logged in.");
    if(!PlayerInfo[playerid][pTut]) return SendClientMessageEx(playerid, COLOR_GREY, "You can't do that at this time.");
    if(PlayerInfo[playerid][pAmute]) return SendClientMessageEx(playerid, COLOR_RED, "You are muted from using /am!");
    if(noam == 1 && !PlayerInfo[playerid][pAdmin]) return SendClientMessageEx(playerid, COLOR_GRAD2, "  The Admin Message System has been disabled by an adminstrator, try again later.");
    if(NewbieTimer[playerid])
    {
        new numstring[60];
        format(numstring, sizeof(numstring), "You must wait %d seconds before using this channel again.", NewbieTimer[playerid]);
        return SendClientMessageEx(playerid, COLOR_GREY, numstring);
    }
    NewbieTimer[playerid] = (PlayerInfo[playerid][pAdmin]) ? (0) : ((PlayerInfo[playerid][pHelper]) ? (5) : (15));
    if(IsAdmin(playerid))
    {
        new toid, message[128];
        if(sscanf(params, "is[128]", toid, message)) return Syntax(playerid, "[a]dmin[m]essage", "[playerid] [message]");
        if(strlen(message) > 128) return Error(playerid, "Your message cannot be longer than 128 characters.");
        if(!IsPlayerConnected(toid)) return Error(playerid, "That player is not connected!");
        //new string[128];
        format(STRING, "Admin message from %s: %s", GetPlayerNameEx(playerid), message);
        SendClientMessageEx(toid, COLOR_GREEN, string);
        format(STRING, "Admin %s [%d] > %s [%d]: %s", GetPlayerNameEx(playerid), playerid, GetPlayerNameEx(toid), toid, message);
        SendAdminMessage(COLOR_GREEN,string);
        Log("logs/adminmessage.log", string);
        PlayerInfo[playerid][pAMSSent] ++;
    }
    else
    {
        new message[80];
        if(sscanf(params, "s[80]", message)) return Syntax(playerid, "[a]dmin[m]essage", "[message]");
        if(strlen(message) > 80) return Error(playerid, "Your message cannot be longer than 80 characters.");
        //if(strfind(message, "Falling", true) != -1) return Error(playerid, "Type (/falling) and a administrative person will be there to assist you right away!");
        //new string[128];
        format(STRING, "Admin message from %s [%d]: %s", GetPlayerNameEx(playerid), playerid, message);
        SendAdminMessage(COLOR_GREEN,string);
        format(STRING, "Your message, %s, has been sent.", message);
        SendClientMessageEx(playerid, COLOR_GREEN, string);
        format(STRING, "Player %s [%d] > Admins: %s", GetPlayerNameEx(playerid), playerid, message);
        Log("logs/adminmessage.log", string);
    }
    return 1;
}
I was going to tidy up the bottom half a bit, but I just don't have much time at the moment.
Reply
#5

I know the issue was probably resolved, but can someone explain this to me:
pawn Код:
if(gPlayerLogged{playerid} == 0)
A little red flag tells me those are the wrong brackets.
Reply
#6

why do you even you sendclientmessageex? use sendclientmessage instead....
pawn Код:
if(NewbieTimer[playerid] > 0)
    {
        format(string, sizeof(string), "You must wait %d seconds before using this channel again.", NewbieTimer[playerid]);
        SendClientMessage(playerid, COLOR_GREY, string);
        return 1;
    }
Reply
#7

ok it works but for Helpers and Regular Players the timer starts even if the player didn't even use it
Reply
#8

Quote:
Originally Posted by Aerotactics
Посмотреть сообщение
I know the issue was probably resolved, but can someone explain this to me:
pawn Код:
if(gPlayerLogged{playerid} == 0)
A little red flag tells me those are the wrong brackets.
Quote:
Originally Posted by Slice
Посмотреть сообщение
"Char-arrays"
PAWN has a feature for accessing single bytes in arrays, intended for use with packed strings. Most SA-MP natives doesn't cover packed strings, though.
You can, however, utilize these arrays a lot for memory optimization. A normal array can store values between -2,147,483,648 and 2,147,483,647; you don't always need that capacity, do you?
With packed strings you can store values between 0-255 (yes, no negative values; -1 will wrap to 255). When you know you don't need negative values and won't ever exceed 255, why not save some memory?

pawn Код:
new bool:g_IsPlayerSomething[ MAX_PLAYERS ]; // 500 cells * 4 bytes per cell = 2000 bytes!
new bool:g_IsPlayerSomething[ MAX_PLAYERS char ]; // 500 bytes = .. 500 bytes!
If you use "char arrays" instead of normal ones where needed 50 times you'll save 75,000 bytes (~73 kb).

Note!
When accessing these arrays, you need to use curly brackets (aka braces) as opposed to the normal square brackets.
Example:
pawn Код:
public OnPlayerConnect( playerid )
{
    g_IsPlayerSomething{ playerid } = false;
//                     ^          ^
}

public OnPlayerSpawn( playerid )
{
//                          v          v
    if ( g_IsPlayerSomething{ playerid } )
    {
        // ..
    }
}
Not always.
Reply
#9

Anyone knows how to fix it ?
Reply
#10

Bump..
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)