11.07.2012, 08:34
You're using sscanf a bit wrong:
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.
Also I split the the checks up a bit so it's easier to read.
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;
}
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;
}