Errors
#1

pawn Код:
CMD:newb(playerid, params[])
{
    new id;
    if(sscanf(params, "u", id)) return SendClientMessage(playerid, red, "USAGE: (/newb)ie [text]");
    if(!strlen(params)) return SendClientMessage(playerid, red, "USAGE: (/newb)ie [text]");
    {
    new name[24], string[128];
    GetPlayerName(playerid, name, 24);
    format(string, sizeof string, "** Newbie %s: %s",name,params);
    SendClientMessageToAll(-1, string);
    else
    {
    SetTimer("NoMsg", 50000, false);
    SendClientMessage(playerid, red, "You need to wait 50 seconds to re-post!");
    }
  }
    return 1;
}
pawn Код:
C:\Users\Alex\Desktop\NPCTest\filterscripts\SCRIPT.pwn(24) : error 029: invalid expression, assumed zero
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


1 Error.
Thanks.
Reply
#2

You have an else statement that is not part of an if statement, so how do you think the code is going to know what you're trying to check "else" of? What are you trying to do exactly?
Reply
#3

Missing bracket. Next time indent your code.
pawn Код:
CMD:newb(playerid, params[])
{
    new id;
    if(sscanf(params, "u", id)) return SendClientMessage(playerid, red, "USAGE: (/newb)ie [text]");
    if(!strlen(params)) return SendClientMessage(playerid, red, "USAGE: (/newb)ie [text]");
    {
        new name[24], string[128];
        GetPlayerName(playerid, name, 24);
        format(string, sizeof string, "** Newbie %s: %s",name,params);
        SendClientMessageToAll(-1, string);
    }
    else
    {
        SetTimer("NoMsg", 50000, false);
        SendClientMessage(playerid, red, "You need to wait 50 seconds to re-post!");
    }
    return 1;
}
Reply
#4

Looks like it should be something like:

pawn Код:
CMD:newb(playerid, params[])
{
    new id;
    if(sscanf(params, "u", id)) return SendClientMessage(playerid, red, "USAGE: (/newb)ie [text]");
    if(!strlen(params)) return SendClientMessage(playerid, red, "USAGE: (/newb)ie [text]");
    if(NoMsg[playerid] == 0)
    {
        new name[24], string[128];
        GetPlayerName(playerid, name, 24);
        format(string, sizeof string, "** Newbie %s: %s",name,params);
        SendClientMessageToAll(-1, string);
    }
    else
    {
    SetTimer("NoMsg", 50000, false);
    SendClientMessage(playerid, red, "You need to wait 50 seconds to re-post!");
    }
    return 1;
}
Reply
#5

pawn Код:
CMD:newb(playerid, params[])
{
    new id;
    if(sscanf(params, "u", id)) return SendClientMessage(playerid, red, "USAGE: (/newb)ie [text]");
    if(!strlen(params)) return SendClientMessage(playerid, red, "USAGE: (/newb)ie [text]");
    {
        new name[24], string[128];
        GetPlayerName(playerid, name, 24);
        format(string, sizeof string, "** Newbie %s: %s",name,params);
        SendClientMessageToAll(-1, string);
    }
    else
    {
        SetTimer("NoMsg", 50000, false);
        SendClientMessage(playerid, red, "You need to wait 50 seconds to re-post!");
    }
    return 1;
}
[pawn]//Im getting the same problem (Asumed to cero)
Reply
#6

Quote:
Originally Posted by Alex_Obando
Посмотреть сообщение
pawn Код:
CMD:newb(playerid, params[])
{
    new id;
    if(sscanf(params, "u", id)) return SendClientMessage(playerid, red, "USAGE: (/newb)ie [text]");
    if(!strlen(params)) return SendClientMessage(playerid, red, "USAGE: (/newb)ie [text]");
    {
        new name[24], string[128];
        GetPlayerName(playerid, name, 24);
        format(string, sizeof string, "** Newbie %s: %s",name,params);
        SendClientMessageToAll(-1, string);
    }
    else
    {
        SetTimer("NoMsg", 50000, false);
        SendClientMessage(playerid, red, "You need to wait 50 seconds to re-post!");
    }
    return 1;
}
[pawn]//Im getting the same problem (Asumed to cero)
Again like I said, that's because your else statement is not following an if statement, therefore there is no way for the computer to know what you want it to be an else of. So the compiler is giving you an error! You need a preceeding if statement before having an else statement.
Reply
#7

I just noticed you missed some points.
pawn Код:
CMD:newb(playerid, params[])
{
    new id;
    if(sscanf(params, "us[129]", id,params)) return SendClientMessage(playerid, red, "USAGE: (/newb)ie [text]");
    if(isnull(params)) return SendClientMessage(playerid, red, "USAGE: (/newb)ie [text]");
    {
        new name[24], string[128];
        GetPlayerName(playerid, name, 24);
        format(string, sizeof string, "** Newbie %s: %s",name,params);
        SendClientMessageToAll(-1, string);
    }
    else
    {
        SetTimer("NoMsg", 50000, false);
        SendClientMessage(playerid, red, "You need to wait 50 seconds to re-post!");
    }
    return 1;
}
Where's the error line?

EDIT: Just read Jatoch post. Yeah that's your problem. My bad.
Reply
#8

pawn Код:
CMD:newb(playerid, params[])
{
    if(isnull(params)) return SendClientMessage(playerid, red, "USAGE: (/newb)ie [text]");
    new name[24], string[128];
    GetPlayerName(playerid, name, 24);
    format(string, sizeof string, "** Newbie %s: %s",name,params);
    SendClientMessageToAll(-1, string);
    SetTimer("NoMsg", 50000, false);
    SendClientMessage(playerid, red, "You need to wait 50 seconds to re-post!");
    return 1;
}
EDIT: too late -.-
Reply
#9

Quote:
Originally Posted by Jafet_Macario
Посмотреть сообщение
pawn Код:
CMD:newb(playerid, params[])
{
    if(isnull(params)) return SendClientMessage(playerid, red, "USAGE: (/newb)ie [text]");
    new name[24], string[128];
    GetPlayerName(playerid, name, 24);
    format(string, sizeof string, "** Newbie %s: %s",name,params);
    SendClientMessageToAll(-1, string);
    SetTimer("NoMsg", 50000, false);
    SendClientMessage(playerid, red, "You need to wait 50 seconds to re-post!");
    return 1;
}
EDIT: too late -.-
He need 2 params

pawn Код:
CMD:newb(playerid, params[])
{
    new id;
    if(!Message[playerid]) return SendClientMessage(playerid, red, "You need to wait 50 seconds to re-post!");//Change the variable to your own one.
    if(sscanf(params, "us[129]", id,params)) return SendClientMessage(playerid, red, "USAGE: (/newb)ie [text]");
    new name[24], string[128];
    GetPlayerName(playerid, name, 24);
    format(string, sizeof string, "** Newbie %s: %s",name,params);
    SendClientMessageToAll(-1, string);
    SetTimer("NoMsg", 50000, false);
    return 1;
}
Reply
#10

Okay since everyone is posting non-working solutions, apart from one guy who got fairly close. The best solution to limiting a command to be useable every 50 seconds is to simply use GetTickCount() and not timers, here is an example of using it in your command.

pawn Код:
new iLastStamp[MAX_PLAYERS];

CMD:newb(playerid, params[])
{
    if((GetTickCount() -  iLastStamp[playerid]) < 50000) return SendClientMessage(playerid, red, "You can only use this command every 50 seconds!");
    new id;
    if(sscanf(params, "us[129]", id,params)) return SendClientMessage(playerid, red, "USAGE: (/newb)ie [text]");
    new name[24], string[128];
    GetPlayerName(playerid, name, 24);
    format(string, sizeof string, "** Newbie %s: %s",name,params);
    SendClientMessageToAll(-1, string);
    iLastStamp[playerid] = GetTickCount();
    return 1;
}
So let me explain what's happening here, you're getting the current tick count from when the server started in miliseconds and then subtracting the last time someone executed the command, then checking if it's less than 50000. If it's less than 50,000, then 50000 miliseconds (50 seconds) have not passed and the player cannot use the command yet.

The upside is that you're not using timers and making loads of public functions just to reset a variable. Another upside is that you could easily tell the player exactly how long more they have to wait!

Isn't that much better and easier than using timers?

Note: The reason your command was not working is because your if statement is finishing with the return, if statements can only have one function executed after it, if you have a bracket after it, then it will run everything inside of the bracket, but you had a function after it, so those brackets meant nothing and the else statement wasn't actually part of that if statement.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)