[SSCANF] Help please.
#1

Hi,

Why this command doesn't give the weapon to the targetid?

PHP код:
CMD:giveweapon(playeridparams[])
{
    new 
weap,targetidstring[128];
    if(
sscanf(params,"uk<weapon>"targetidweap)) return SendClientMessage(playeridNO_PARAMS"USAGE: /giveweapon [ID or Name] [Weapon]");
    if(
targetid == INVALID_PLAYER_ID) return SendClientMessage(playeridERROR"Error: Player is not connected or is yourself");
    
GivePlayerWeapon(targetidweap99999);
    
format(stringsizeof(string), "You have given a weapon to %s"Name(targetid));
    
SendClientMessage(playeridSUCCESSstring);
    
format(stringsizeof(string), "You have received a weapon from %s"Name(playerid));
    
SendClientMessage(targetidSUCCESSstring);
    return 
1;

That's what I saw on sscanf2:

PHP код:
SSCANF:weapon(string[])
{
    
// This function is VERY basic, needs VASTLY improving to detect variations.
    
if ('0' <= string[0] <= '9')
    {
        new
            
ret strval(string);
        if (
<= ret <= 18 || 22 <= ret <= 46)
        {
            return 
ret;
        }
    }
    else if (!
strcmp(string"Unarmed")) return 0;
    else if (!
strcmp(string"Brass Knuckles")) return 1;
    else if (!
strcmp(string"Golf Club")) return 2;
    else if (!
strcmp(string"Night Stick")) return 3;
    else if (!
strcmp(string"Knife")) return 4;
    else if (!
strcmp(string"Baseball Bat")) return 5;
    else if (!
strcmp(string"Shovel")) return 6;
    else if (!
strcmp(string"Pool cue")) return 7;
    else if (!
strcmp(string"Katana")) return 8;
    else if (!
strcmp(string"Chainsaw")) return 9;
    else if (!
strcmp(string"Purple Dildo")) return 10;
    else if (!
strcmp(string"White Dildo")) return 11;
    else if (!
strcmp(string"Long White Dildo")) return 12;
    else if (!
strcmp(string"White Dildo 2")) return 13;
    else if (!
strcmp(string"Flowers")) return 14;
    else if (!
strcmp(string"Cane")) return 15;
    else if (!
strcmp(string"Grenades")) return 16;
    else if (!
strcmp(string"Tear Gas")) return 17;
    else if (!
strcmp(string"Molotovs")) return 18;
    else if (!
strcmp(string"Pistol")) return 22;
    else if (!
strcmp(string"Silenced Pistol")) return 23;
    else if (!
strcmp(string"Desert Eagle")) return 24;
    else if (!
strcmp(string"Shotgun")) return 25;
    else if (!
strcmp(string"Sawn Off Shotgun")) return 26;
    else if (!
strcmp(string"Combat Shotgun")) return 27;
    else if (!
strcmp(string"Micro Uzi")) return 28;
    else if (!
strcmp(string"Mac 10")) return 28;
    else if (!
strcmp(string"MP5")) return 29;
    else if (!
strcmp(string"AK47")) return 30;
    else if (!
strcmp(string"M4")) return 31;
    else if (!
strcmp(string"Tec9")) return 32;
    else if (!
strcmp(string"Rifle")) return 33;
    else if (!
strcmp(string"Sniper Rifle")) return 34;
    else if (!
strcmp(string"RPG")) return 35;
    else if (!
strcmp(string"Missile Launcher")) return 36;
    else if (!
strcmp(string"Flame Thrower")) return 37;
    else if (!
strcmp(string"Minigun")) return 38;
    else if (!
strcmp(string"Sachel Charges")) return 39;
    else if (!
strcmp(string"Detonator")) return 40;
    else if (!
strcmp(string"Spray Paint")) return 41;
    else if (!
strcmp(string"Fire Extinguisher")) return 42;
    else if (!
strcmp(string"Camera")) return 43;
    else if (!
strcmp(string"Nightvision Goggles")) return 44;
    else if (!
strcmp(string"Thermal Goggles")) return 45;
    else if (!
strcmp(string"Parachute")) return 46;
    return -
1;

That's why I did:
Код:
k<weapon>
Thanks
Reply
#2

Try this:

pawn Код:
CMD:giveweapon(playerid, params[])
{
    new weap,targetid, string[128];
    if(sscanf(params,"ui", targetid, weap)) return SendClientMessage(playerid, NO_PARAMS, "USAGE: /giveweapon [ID or Name] [Weapon]");
    if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, ERROR, "Error: Player is not connected or is yourself");
    if(weap < 1 || weap > 46) return SendClientMessage, ERROR, "Error: You have entered an invalid weapon ID.");
    GivePlayerWeapon(targetid, weap, 99999);
    format(string, sizeof(string), "You have given a weapon to %s", Name(targetid));
    SendClientMessage(playerid, SUCCESS, string);
    format(string, sizeof(string), "You have received a weapon from %s", Name(playerid));
    SendClientMessage(targetid, SUCCESS, string);
    return 1;
}
Reply
#3

You did not even have read the SSCANF2 Include explanation.
Reply
#4

Quote:
Originally Posted by Magic_Time
Посмотреть сообщение
You did not even have read the SSCANF2 Include explanation.
Btw he did it right! Man I think you need to apologize or nobody will help you next time! and you need to read...

This: https://sampforum.blast.hk/showthread.php?tid=300397
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)