Atleast I tried it
#1

Well, I tried to make it, as I have a few errors.
Finally I know how to work with sscanf now.

Quote:

C:\Users\selma\Desktop\Samp\gamemodes\Lerenscripte n.pwn(576) : error 003: declaration of a local variable must appear in a compound block
C:\Users\selma\Desktop\Samp\gamemodes\Lerenscripte n.pwn(576) : error 017: undefined symbol "target"
C:\Users\selma\Desktop\Samp\gamemodes\Lerenscripte n.pwn(576) : warning 215: expression has no effect
C:\Users\selma\Desktop\Samp\gamemodes\Lerenscripte n.pwn(577) : error 017: undefined symbol "target"
C:\Users\selma\Desktop\Samp\gamemodes\Lerenscripte n.pwn(579) : error 017: undefined symbol "target"
C:\Users\selma\Desktop\Samp\gamemodes\Lerenscripte n.pwn(581) : error 017: undefined symbol "target"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


5 Errors.


PHP код:
CMD:resetweapon(playeridparams[])
{
    if (!
IsPlayerAdmin(playerid))
    {
    
SendClientMessage(playerid, -1"SERVER: Unknown command.");
    }
    else if (
IsPlayerAdmin(playerid))
    new 
target;
    if(
sscanf(params"i"target))
    
SendClientMessage(playeridCOLOR_WARN"USAGE: /resetweapon [playerid]");
    
ResetPlayerWeapons(target);
    
SendClientMessage(playeridCOLOR_WARN"You removed the player's weapon.");
    
SendClientMessage(targetCOLOR_RED"You have been disarmed!");
    return 
1;

Reply
#2

Remove the "else if" line and you should be good. Also sscanf parameter for other players is "u"
You should use { } after every if / else / else if statement
Reply
#3

An example of a method I recommend you to use:

pawn Код:
CMD:resetweapon(playerid, params[])
{
    // You don't always need to use callbacks, you can simply do this:
    if (!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "SERVER: Unknown command.");

    // Doing this will also prevent you from requiring an "else if" function.
   
    new target;

    // Instead of "i" (which is integer), we use "u" (user) so we can use player's names aswell and then return the message aswell.
    if(sscanf(params, "u", target)) return SendClientMessage(playerid, COLOR_WARN, "USAGE: /resetweapon [playerid]");

    ResetPlayerWeapons(target);

    SendClientMessage(playerid, COLOR_WARN, "You removed the player's weapon.");
    SendClientMessage(target, COLOR_RED, "You have been disarmed!");

    return 1;
}
Alternative method, using callbacks (the correct way of how to use callbacks):

pawn Код:
CMD:resetweapon(playerid, params[])
{
    new target;

    if(sscanf(params, "u", target))
    {
        SendClientMessage(playerid, COLOR_WARN, "USAGE: /resetweapon [playerid]");
    }

    if (!IsPlayerAdmin(playerid))
    {
        SendClientMessage(playerid, -1, "SERVER: Unknown command.");
    }
   
    else if(IsPlayerAdmin(playerid))
    {
        ResetPlayerWeapons(target);

        SendClientMessage(playerid, COLOR_WARN, "You removed the player's weapon.");
        SendClientMessage(target, COLOR_RED, "You have been disarmed!");
    }

    return 1;
}
Reply
#4

pawn Код:
CMD:resetweapon(playerid, params[])
{
    if (!IsPlayerAdmin(playerid))
    {
    SendClientMessage(playerid, -1, "SERVER: Unknown command.");
    return 1;
    }
    new target;
    if(sscanf(params, "i", target))
    SendClientMessage(playerid, COLOR_WARN, "USAGE: /resetweapon [playerid]");
    ResetPlayerWeapons(target);
    SendClientMessage(playerid, COLOR_WARN, "You removed the player's weapon.");
    SendClientMessage(target, COLOR_RED, "You have been disarmed!");
    return 1;
}
Reply
#5

Yep thanks, fixed now, And I know how to make it next time in a correct way. Thank you for teaching it.

Just 1 simple question :::: whe the data is playerid, Isn't it "i" ?? why is it "u"? I thought it is "i"
Reply
#6

Here.
Quote:
Originally Posted by SAMP Wiki
players are special so we can use 'u' so people can enter their name OR ID.
Reply
#7

"i" is for integers, while "u" is for users, it allows you to use parts of a player's name AND the ID.

https://github.com/Y-Less/sscanf/wiki

Quote:

Specifiers

"s" - Strings
"q", "r", "u" - Users
"f" - Float
"h" - Hex
"i" - Integer

It will work regardless though, but it's recommended to use "u" for players.
Reply
#8

Ok, thanks broo's.
1 very little little thing, When I do /resetweapon and enter. it says I removed the player's his weapon, while I did not even type a ID. why? @Mionee, I used you're code.
everything works fine except the ID,
Reply
#9

Which code? The first one or the second? The second one is dodgy and isn't recommended, it was only an example.

The first one should work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)