sscanf parameter problem
#1

pawn Код:
CMD:duel(playerid, params[])
{
    if(!strval(params)) return SendClientMessage(playerid, -1, "USAGE: /duel <id> <bet> <weap1> <weap2> <weap3>");
   
    new third[60];
    sscanf(params[5], "s[60]", third);
    new Player, Bet, gWeap1[85], gWeap2[85], gWeap3[85], slot[3], Float:HealthP, Float:HealthG, string[128];
    sscanf(third, "uis[85]s[85]s[85]", Player, Bet, gWeap1, gWeap2, gWeap3);
               
    if(Player == playerid) return SendClientMessage(playerid, -1, "You cannot duel with yourself.");
    if(Player == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "Player not found.");

    GetPlayerHealth(playerid, HealthP);
    GetPlayerHealth(Player, HealthG);

    if(HealthP < 100) return SendClientMessage(playerid, -1, "You need full health to fight a duel.");
    if(HealthG < 100) return SendClientMessage(playerid, -1, "You can only duel players with full health.");
    if(IsPlayerInAnyInterior(playerid)) return SendClientMessage(playerid, -1, "You must leave this interior first.");
    if(IsPlayerInAnyInterior(Player)) return SendClientMessage(playerid, -1, "Player is inside an interior.");
    if(!pData[Player][P_SPAWNED]) return SendClientMessage(playerid, -1, "Player has not spawned yet.");
    if(pData[playerid][P_ONLINE] < 3600)return SendClientMessage(playerid, -1, "New users can't fight duels.");
    if(pData[Player][P_ONLINE] < 3600) return  SendClientMessage(playerid, -1, "New users can't fight duels.");
    if(pData[playerid][P_INVITED]) return SendClientMessage(playerid, -1, "You are already invited to a duel. Type /yes to accept the request.");
    if(pData[Player][P_INVITED]) return SendClientMessage(playerid, -1, "This player already received a duel request from another player.");
    if(pData[playerid][P_IN_DUEL]) return SendClientMessage(playerid, -1, "You are already in a duel.");
    if(pData[Player][P_IN_DUEL])   return SendClientMessage(playerid, -1,"This player is already fighting a duel.");
    if(Bet < 1 || Bet > 5000) return SendClientMessage(playerid, -1, "Invalid bet amount (min $1 / max $5000).");
    if(GetPlayerMoney(playerid) < Bet) return SendClientMessage(playerid, -1, "You don't have that amount of money to bet.");
    if(GetPlayerMoney(Player) < Bet) return SendClientMessage(playerid, -1, "This player has not enough money to bet.");
    return 1;
}
I got problem with parameters. Basically I need it to work like I can enter 1 weapon or 2 or 3 so it wont ask me to put 3 weapons.

It's messy and doesnt work, when I type /duel it sends me the right message, when I type /duel 1 it says invalid money amount etc. It should still give me the return or the usage but it doesnt work properly.
Reply
#2

You're using sscanf a bit wrong:

pawn Код:
CMD:duel(playerid, params[])
{
    new Player, Bet, gWeap1[32], gWeap2[32], gWeap3[32];
    if(sscanf(params, "uis[32]S( )[32]S( )[32]", Player, Bet, gWeap1, gWeap2, gWeap3)) return SendClientMessage(playerid, -1, "USAGE: /duel <id> <bet> <weap1> <weap2> <weap3>");
               
    if(Player == playerid) return SendClientMessage(playerid, -1, "You cannot duel with yourself.");
    if(Player == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "Player not found.");

    new Float:HealthP, Float:HealthG;
    GetPlayerHealth(playerid, HealthP);
    GetPlayerHealth(Player, HealthG);
    if(HealthP < 100) return SendClientMessage(playerid, -1, "You need full health to fight a duel.");
    if(HealthG < 100) return SendClientMessage(playerid, -1, "You can only duel players with full health.");

    if(IsPlayerInAnyInterior(playerid)) return SendClientMessage(playerid, -1, "You must leave this interior first.");
    if(IsPlayerInAnyInterior(Player)) return SendClientMessage(playerid, -1, "Player is inside an interior.");
    if(!pData[Player][P_SPAWNED]) return SendClientMessage(playerid, -1, "Player has not spawned yet.");

    if(pData[playerid][P_ONLINE] < 3600)return SendClientMessage(playerid, -1, "New users can't fight duels.");
    if(pData[Player][P_ONLINE] < 3600) return  SendClientMessage(playerid, -1, "New users can't fight duels.");

    if(pData[playerid][P_INVITED]) return SendClientMessage(playerid, -1, "You are already invited to a duel. Type /yes to accept the request.");
    if(pData[Player][P_INVITED]) return SendClientMessage(playerid, -1, "This player already received a duel request from another player.");
    if(pData[playerid][P_IN_DUEL]) return SendClientMessage(playerid, -1, "You are already in a duel.");
    if(pData[Player][P_IN_DUEL])   return SendClientMessage(playerid, -1,"This player is already fighting a duel.");

    if(Bet < 1 || Bet > 5000) return SendClientMessage(playerid, -1, "Invalid bet amount (min $1 / max $5000).");
    if(GetPlayerMoney(playerid) < Bet) return SendClientMessage(playerid, -1, "You don't have that amount of money to bet.");
    if(GetPlayerMoney(Player) < Bet) return SendClientMessage(playerid, -1, "This player has not enough money to bet.");
    return 1;
}
Not tested. The weapon parameters take the name, you need to use this function on the strings:
If the weapon string is " " (a space) it was left blank.

pawn Код:
new WeaponNames[][] = {
    {"Fist"}, {"Brass Knuckles"}, {"Golf Club"}, {"Nightstick"}, {"Knife"},
    {"Baseball Bat"}, {"Shovel"}, {"Pool Cue"}, {"Katana"}, {"Chainsaw"},
    {"Purple Dildo"}, {"Small White Vibrator"}, {"Big White Vibrator"},
    {"Small Silver Vibrator"}, {"Flowers"}, {"Cane"}, {"Grenade"}, {"Teargas"},
    {"Molotov Cocktail"}, {" "}, {" "}, {" "}, {"Colt 45 (9mm)"}, {"Silenced Pistol"},
    {"Desert Eagle"}, {"Shotgun"}, {"Sawn-off Shotgun"},
    {"Combat Shotgun"}, {"Micro Uzi (Mac 10)"}, {"MP5"}, {"AK-47"}, {"M4"}, {"Tec9"},
    {"Country Rifle"},{"Sniper Rifle"}, {"Rocket Launcher (RPG)"},
    {"Heat-Seeking Rocket Launcher"},{"Flamethrower"}, {"Minigun"},
    {"Satchel Charges"}, {"Detonator"},{"Spray Can"}, {"Fire Extinguisher"},
    {"Camera"}, {"Night Vision Goggles"}, {"Thermal Goggles"},
    {"Parachute"}
};

stock GetWeaponModelIDFromName(wname[])
{
    for(new i = 0; i < sizeof(WeaponNames); i++)
    {
        if(strfind(WeaponNames[i], wname, true) != -1) return i;
    }
    return -1;
}
Also I split the the checks up a bit so it's easier to read.
Reply
#3

Can I make it so if a weapon string is blank it will give the 'none' message as a weapon name?
Reply
#4

Change

uis[32]S( )[32]S( )[32]

to

uis[32]S(None)[32]S(None)[32]
Reply
#5

Quote:
Originally Posted by MP2
Посмотреть сообщение
Change

uis[32]S( )[32]S( )[32]

to

uis[32]S(None)[32]S(None)[32]
for some reason it request the weapon 2 and 3

pawn Код:
if(ReturnWeaponIDOrName(gWeap1) == -1) return SendClientMessage(playerid, 0xE54500F1, "Sorry, weapon not found.");
    if(!strlen(gWeap2))
    {
       SetPVarInt(playerid, "Weap2", 0);
       SetPVarInt(Player,   "Weap2", 0);
    }
    else
    {
       if(ReturnWeaponIDOrName(gWeap2) == -1) return SendClientMessage(playerid, 0xE54500F1, "Sorry, weapon on slot 2 not found.");
       SetPVarInt(playerid, "Weap2", 1);
       SetPVarInt(Player,   "Weap2", 1);
    }
    if(!strlen(gWeap3))
    {
       SetPVarInt(playerid, "Weap3", 0);
       SetPVarInt(Player,   "Weap3", 0);
    }
    else
    {
       if(ReturnWeaponIDOrName(gWeap3) == -1) return SendClientMessage(playerid, 0xE54500F1, "Sorry, weapon on slot 3 not found.");
       SetPVarInt(playerid, "Weap3", 1);
       SetPVarInt(Player,  "Weap3", 1);
    }
Reply
#6

Why are you using !strlen? That's to check if the string is 0 length, but it's not, it's 'None'. Use strcmp.
Reply
#7

Cannot fix it. If weapon 2 or 3 is not set it shows nothing instead of none.
Reply
#8

It doesn't work. Still the same.
Reply
#9

Wrong post, sorry.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)