What's wrong with this code?
#1

Hey guys, as a new scripter to pawno I'm trying to understand dcmd commands, seems pretty easy to do so but here's one problem I have.

There's nothing wrong when i compile but when i type /pb ingame it says nothing, not even Unkown Command.

What did i miss? Please explain why and what I've done wrong here even if it is, to you, obvious, note that i'm very new to scripting overall.

pawn Код:
dcmd_pb(playerid, params[])
{
    #pragma unused params
    if(GetPlayerScore(playerid) >= 1000)
    {
        new Name[MAX_PLAYER_NAME]; GetPlayerName(playerid, Name, sizeof(Name));
        new string[128];
        format(string, sizeof(string), "{FF0000}===REQUESTING BACKUP=== {FFFFFF}%s {FF0000}is requesting for backup!", Name);
        printf("%s", string);
        for(new i = 0; i < MAX_PLAYERS; i++)
        SendClientMessage(playerid, RED,"You need to be Rank 4 to use this command!");
    }
    return 1;
}
Thnx!
Reply
#2

pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
SendClientMessage(playerid, RED,"You need to be Rank 4 to use this command!");
That really makes no sense. That's a loop statement but nothing follows it, so it's most likely that the command had failed there. Plus, there's no condition checking to send the "Rank 4" part so it will always send it.


As for the rest, check your server console,
pawn Код:
format(string, sizeof(string), "{FF0000}===REQUESTING BACKUP=== {FFFFFF}%s {FF0000}is requesting for backup!", Name);
printf("%s", string);
You're printing the formatted message into the console, not sending it out to any client.


Also make sure you've got more than or have 1000 points
Reply
#3

Then my next question is, when you're done laughing, how can i fix this, to make it work? To prevent this kind of faults in the future.

Much appreciation if anyone answer!
Reply
#4

Quote:
Originally Posted by Sergeant
Посмотреть сообщение
Then my next question is, when you're done laughing, how can i fix this, to make it work? To pevent this kind of faulty in the future.
I'm not laughing, I've seen way worse, and to answer your question I need more information. What do you want it exactly to do? Send the message to all players? Send the message to certain players? If so, which condition should those players meet to receive the message? Those are basic questions you should always ask yourself.

To begin with, remove the loop part and the last message -- They are not needed on that piece.
Reply
#5

Just send it to the player that types /pb

It's when they want to request backup, but they need to be Rank4 in the rank system to actually use it, If you need/want i can post full script here
Reply
#6

Check these out:

SendClientMessage
SendClientMessageToAll

In your case if you want it to send to the player that types the command then just use the first one.

As for the rank, replace
pawn Код:
if(GetPlayerScore(playerid) >= 1000)
With whatever you use to store the player's rank, for example:
pawn Код:
if(GetPVarInt(playerid,"Rank") >= 4)
or
pawn Код:
if(rank[playerid] >= 4)
or
pawn Код:
if(PlayerInfo[playerid][pRank] >= 4)

Read this quick guide
Reply
#7

Thank you so much, i listened to what you said and also i were thinking that an 'else' was missing somewhere, cuz it somehow didn't sound right so this is how it's now and it works perfectly !

I'd rep you 20 times if it was possible !

pawn Код:
dcmd_pb(playerid, params[])
{
    #pragma unused params
    if(GetPlayerScore(playerid) >= 1000)
        {
            new Name[MAX_PLAYER_NAME]; GetPlayerName(playerid, Name, sizeof(Name));
            new string[128];
            format(string, sizeof(string), "{FF0000}===REQUESTING BACKUP=== {FFFFFF}%s {FF0000}is requesting for backup!", Name);
            printf("%s", string);
        }
        else
        {
            SendClientMessage(playerid, RED,"You need to be Rank 4 to use this command!");
        }
    return 1;
}
Reply
#8

pawn Код:
dcmd_pb(playerid, params[])
{
    #pragma unused params
    if(GetPlayerScore(playerid) >= 1000)
    {
        new Name[MAX_PLAYER_NAME]; GetPlayerName(playerid, Name, sizeof(Name));
        new string[128];
        format(string, sizeof(string), "{FF0000}===REQUESTING BACKUP=== {FFFFFF}%s {FF0000}is requesting for backup!", Name);
        SendClientMessageToAll(COLOR_RED, string);
        printf("%s", string);
        for(new i = 0; i < MAX_PLAYERS; i++) // Why this? ._.
    }
    else
    {
        SendClientMessage(playerid, RED,"You need to be Rank 4 to use this command!");
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)