/(adv)ertisement Error. :/
#1

i made a advertisement command but everytime it keeps on showing the usage no matter if the person is using it in a right way.
pawn Код:
COMMAND:advertisement(playerid, params[])
{
    new msg[64], fstr[150];
    if(sscanf(params, "s[64]", msg)) return SendClientMessage(playerid, COLOR_ERROR, "[USAGE]: /advertisement [msg]");
    if(strlen(msg) < 1 || strlen(msg) > 64) return SendClientMessage(playerid, COLOR_ERROR, "Your ad can only contain 1-64 characters.");
    {
        format(fstr, sizeof(fstr), "[ADVERT]: %s - [CONTACT]: %s [%d]", msg, PlayerInfo[playerid][pName], playerid);
        SendClientMessageToAll(LIGHTGREEN, fstr);
    }
    return 1;
}
COMMAND:adv(playerid, params[])
{
    return cmd_advertisement(playerid, params);
}
Reply
#2

PHP код:
COMMAND:advertisement(playeridparams[])
{
    new 
msg[64], fstr[150];
    if(
sscanf(params"s[64]"msg))
    return 
SendClientMessage(playeridCOLOR_ERROR"[USAGE]: /advertisement [msg]");
    if(
strlen(msg) < || strlen(msg) > 64)
        return 
SendClientMessage(playeridCOLOR_ERROR"Your ad can only contain 1-64 characters.");
    
format(fstrsizeof(fstr), "[ADVERT]: %s - [CONTACT]: %s [%d]"msgPlayerInfo[playerid][pName], playerid);
    
SendClientMessageToAll(LIGHTGREENfstr);
    return 
true;

Reply
#3

thanks solved +rape :P
Reply
#4

BUMP! (i know i can only bump per 24 hrs but it isnt working)
pawn Код:
COMMAND:advertisement(playerid, params[])
{
    new msg[64], fstr[150];
    if(sscanf(params, "s[64]", msg)) return SendClientMessage(playerid, COLOR_ERROR, "[USAGE]: /advertisement [msg]");
    if(strlen(msg) < 1 || strlen(msg) > 64) return SendClientMessage(playerid, COLOR_ERROR, "Your ad can only contain 1-64 characters.");
    format(fstr, sizeof(fstr), "[ADVERT]: %s - [CONTACT]: %s [%d]", msg, PlayerInfo[playerid][pName], playerid);
    SendClientMessageToAll(LIGHTGREEN, fstr);
    return 1;
}
COMMAND:adv(playerid, params[])
{
    return cmd_advertisement(playerid, params);
}
its stil just showing the usage message
Reply
#5

Why don't you just use params?
pawn Код:
#define isnull(%1) \
    ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))

COMMAND:advertisement(playerid, params[])
{
    new fstr[150];
    if(isnull(params)) return SendClientMessage(playerid, COLOR_ERROR, "[USAGE]: /advertisement [msg]");
    // If the player didn't write anything as the params, return that message

    if(strlen(params) > 64) return SendClientMessage(playerid, COLOR_ERROR, "Your ad can only contain max 64 characters.");
    // Why check if it's below 1, if you're already using sscanf / isnull to check if it's not filled in?

    format(fstr, sizeof(fstr), "[ADVERT]: %s - [CONTACT]: %s [%d]", params, PlayerInfo[playerid][pName], playerid);
    SendClientMessageToAll(LIGHTGREEN, fstr);
    return 1;
}
Reply
#6

pawn Код:
COMMAND:advertisement(playerid, params[])
{
    new fstr[150];
    if(sscanf(params, "s[64]", params)) return SendClientMessage(playerid, COLOR_ERROR, "[USAGE]: /advertisement [msg]");
    if(strlen(params) < 1 || strlen(params) > 64) return SendClientMessage(plyerid, COLOR_ERROR, "Your ad can only contain 1 - 64 characters.");

    format(str, sizeof(fstr), "[ADVERT]: %s - [CONTACT]: %s [%d]", params, PlayerInfo[playerid][pName], playerid);
    SendClientMessageToAll(LIGHTGREEN, fstr);
    return true;
}
Use params. It's easier.

EDIT: Calvin ;c
Reply
#7

The above command should work, but won't work with the other command to return, this should work using the two commands.

PHP код:
COMMAND:advertisement(playeridparams[])
{
    new 
fstr[150];
    if(
sscanf(params"s[65]"params))
        return 
SendClientMessage(playeridCOLOR_ERROR"[USAGE]: /advertisement [msg]");

    if(((
params[0] == 0) || (params[0] == && params[1] == 0)) && strlen(params) > 64)
        return 
SendClientMessage(playerid, -1"Your ad can only contain 1-64 characters.");

    
format(fstrsizeof(fstr), "[ADVERT]: %s - [CONTACT]: %s [%d]"paramsPlayerInfo[playerid][pName], playerid);
    
SendClientMessageToAll(LIGHTGREENfstr);
    return 
true;

Reply
#8

none working at last i also made this...this isnt even working.. and calvinc i didnt tried the is null...sscanf is easier and according to me it should work
pawn Код:
COMMAND:advertisement(playerid, params[])
{
    new msg[64], fstr[200];
    if(sscanf(params, "s[64]", msg)) return SendClientMessage(playerid, COLOR_ERROR, "[USAGE]: /ad [msg]");
    if(strlen(msg) < 1 || strlen(msg) > 64) return SendClientMessage(playerid, COLOR_ERROR, "Your ad can only contain 1-64 characters.");
    {
        format(fstr, sizeof(fstr), "[ADVERT]: %s - [CONTACT]: %s [%d]", msg, PlayerInfo[playerid][pName], playerid);
        SendClientMessageToAll(LIGHTGREEN, fstr);
    }
    return true;
}
can someone help .-.
Reply
#9

I don't see what's wrong in using isnull?
It's designed to check if params isn't filled in, instead of running sscanf on creating a new variable.
But try this then:
pawn Код:
COMMAND:advertisement(playerid, params[])
{
    // Removed msg, no need to waste memory on it when you can use params
    if(sscanf(params, "s[64]", params)) return SendClientMessage(playerid, COLOR_ERROR, "[USAGE]: /ad [msg]");
    if(strlen(msg) > 64) return SendClientMessage(playerid, COLOR_ERROR, "Your ad can only contain 1-64 characters.");
    new fstr[128]; // Moved it down, no need to waste memory if the above stops the cmd anyways
    format(fstr, sizeof(fstr), "[ADVERT]: %s - [CONTACT]: %s [%d]", params, PlayerInfo[playerid][pName], playerid);
    SendClientMessageToAll(LIGHTGREEN, fstr);
    return true;
}
It should work with the above examples as well though.
Reply
#10

But if u removed 'msg' then it ll show a error at If(strlen(msg) wouldnt it?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)