17.06.2010, 16:10
Код:
dcmd_sellweapon(playerid, params[]) { if(Jailed[playerid] == 1) { SendClientMessage(playerid, COLOR_ERROR, "You cannot use this command in jail"); return 1; } if(gTeam[playerid] != TEAM_GUNS) { SendClientMessage(playerid, COLOR_ERROR, "Only Weapon Dealers can sell weapons"); return 1; } new x_nr[64]; new giveplayerid; if(sscanf(params, "ui", giveplayerid, x_nr)) { SendClientMessage(playerid, COLOR_ERROR, "USAGE: /sellweapon (id) [WEAPON.No]"); return 1; } if(!IsNumeric(x_nr)) { SendClientMessage(playerid, COLOR_ERROR, "USAGE: /sellweapon (id) [WEAPON.No] Weapon No. Must be a number"); return 1; } if(Jailed[giveplayerid] == 1) { SendClientMessage(playerid, COLOR_ERROR, "You cannot sell weapons to a prisoner"); return 1; } if(OfferedGuns[giveplayerid] == 0) { SendClientMessage(playerid, COLOR_ERROR,"No Weapon Dealer has offered to sell this player weapons. Use /sellweapons id first"); return 1; } new workername[24]; new costumername[24]; new string[256]; GetPlayerName(playerid,workername, 24); GetPlayerName(giveplayerid, costumername, 24); if(GetDistanceBetweenPlayers(playerid,giveplayerid) > 15) { format(string, sizeof(string), "%s(%d) Is not close enough. You cannot sell weapons to that player",costumername,giveplayerid); SendClientMessage(playerid, COLOR_ERROR, string); return 1; } new oscore; if(IsPlayerConnected(playerid)) { if(strcmp(x_nr,"1",true) == 0) { if(GetPlayerMoney(giveplayerid) <= 2499) { SendClientMessage(giveplayerid, 0xA9A9A9AA, "|_Weapon Sale Failed_|"); format(string, sizeof(string), "%s(%d) Has tried to sell you a Silenced 9mm weapon. You cannot afford $2500",workername,playerid); SendClientMessage(giveplayerid, COLOR_ERROR, string); SendClientMessage(playerid, 0xA9A9A9AA, "|_Weapon Sale Failed_|"); format(string, sizeof(string), "%s(%d) cannot afford that weapon",costumername,giveplayerid); SendClientMessage(playerid, COLOR_ERROR, string); return 1; } GivePlayerWeapon(giveplayerid,23,100); GivePlayerMoney(giveplayerid, -2500); GivePlayerMoney(playerid,1500); SendClientMessage(giveplayerid, 0xA9A9A9AA, "|_Weapon Purchased_|"); format(string, sizeof(string), "%s(%d) Has sold you a Silenced 9mm weapon with 100 Ammo for $2500",workername,playerid); SendClientMessage(giveplayerid, 0x00C7FFAA, string); SendClientMessage(playerid, 0xA9A9A9AA, "|_Weapon Sold_|"); format(string, sizeof(string), "%s(%d) Has purchased a Silenced 9mm weapon from you. You receive a $1500 bonus",costumername,giveplayerid); SendClientMessage(playerid, 0x00C7FFAA, string); oscore = GetPlayerScore(playerid); SetPlayerScore(playerid, oscore +1); } else if(strcmp(x_nr,"2",true) == 0) { if(GetPlayerMoney(giveplayerid) <= 999) { SendClientMessage(giveplayerid, 0xA9A9A9AA, "|_Weapon Sale Failed_|"); format(string, sizeof(string), "%s(%d) Has tried to sell you a Tec9 weapon. You cannot afford $1000",workername,playerid); SendClientMessage(giveplayerid, COLOR_ERROR, string); SendClientMessage(playerid, 0xA9A9A9AA, "|_Weapon Sale Failed_|"); format(string, sizeof(string), "%s(%d) cannot afford that weapon",costumername,giveplayerid); SendClientMessage(playerid, COLOR_ERROR, string); return 1; } GivePlayerWeapon(giveplayerid,32,500); GivePlayerMoney(giveplayerid, -1000); GivePlayerMoney(playerid,1500); SendClientMessage(giveplayerid, 0xA9A9A9AA, "|_Weapon Purchased_|"); format(string, sizeof(string), "%s(%d) Has sold you a Tec9 weapon with 500 Ammo for $1000",workername,playerid); SendClientMessage(giveplayerid, 0x00C7FFAA, string); SendClientMessage(playerid, 0xA9A9A9AA, "|_Weapon Sold_|"); format(string, sizeof(string), "%s(%d) Has purchased a Tec9 weapon from you. You receive a $1500 bonus",costumername,giveplayerid); SendClientMessage(playerid, 0x00C7FFAA, string); oscore = GetPlayerScore(playerid); SetPlayerScore(playerid, oscore +1); } else if(strcmp(x_nr,"3",true) == 0) { if(GetPlayerMoney(giveplayerid) <= 3499) { SendClientMessage(giveplayerid, 0xA9A9A9AA, "|_Weapon Sale Failed_|"); format(string, sizeof(string), "%s(%d) Has tried to sell you a Sawnoff Shotgun weapon. You cannot afford $3500",workername,playerid); SendClientMessage(giveplayerid, COLOR_ERROR, string); SendClientMessage(playerid, 0xA9A9A9AA, "|_Weapon Sale Failed_|"); format(string, sizeof(string), "%s(%d) cannot afford that weapon",costumername,giveplayerid); SendClientMessage(playerid, COLOR_ERROR, string); return 1; } GivePlayerWeapon(giveplayerid,26,30); GivePlayerMoney(giveplayerid, -3500); GivePlayerMoney(playerid,1500); SendClientMessage(giveplayerid, 0xA9A9A9AA, "|_Weapon Purchased_|"); format(string, sizeof(string), "%s(%d) Has sold you a Sawnoff Shotgun weapon with 30 Ammo for $3500",workername,playerid); SendClientMessage(giveplayerid, 0x00C7FFAA, string); SendClientMessage(playerid, 0xA9A9A9AA, "|_Weapon Sold_|"); format(string, sizeof(string), "%s(%d) Has purchased a Sawnoff Shotgun weapon from you. You receive a $1500 bonus",costumername,giveplayerid); SendClientMessage(playerid, 0x00C7FFAA, string); oscore = GetPlayerScore(playerid); SetPlayerScore(playerid, oscore +1); } else if(strcmp(x_nr,"4",true) == 0) { if(GetPlayerMoney(giveplayerid) <= 14999) { SendClientMessage(giveplayerid, 0xA9A9A9AA, "|_Weapon Sale Failed_|"); format(string, sizeof(string), "%s(%d) Has tried to sell you a Sniper Rifle weapon. You cannot afford $15000",workername,playerid); SendClientMessage(giveplayerid, COLOR_ERROR, string); SendClientMessage(playerid, 0xA9A9A9AA, "|_Weapon Sale Failed_|"); format(string, sizeof(string), "%s(%d) cannot afford that weapon",costumername,giveplayerid); SendClientMessage(playerid, COLOR_ERROR, string); return 1; } GivePlayerWeapon(giveplayerid,34,30); GivePlayerMoney(giveplayerid, -15000); GivePlayerMoney(playerid,1500); SendClientMessage(giveplayerid, 0xA9A9A9AA, "|_Weapon Purchased_|"); format(string, sizeof(string), "%s(%d) Has sold you a Sniper Rifle weapon with 30 Ammo for $15000",workername,playerid); SendClientMessage(giveplayerid, 0x00C7FFAA, string); SendClientMessage(playerid, 0xA9A9A9AA, "|_Weapon Sold_|"); format(string, sizeof(string), "%s(%d) Has purchased a Sniper Rifle weapon from you. You receive a $1500 bonus",costumername,giveplayerid); SendClientMessage(playerid, 0x00C7FFAA, string); oscore = GetPlayerScore(playerid); SetPlayerScore(playerid, oscore +1); } else if(strcmp(x_nr,"5",true) == 0) { if(GetPlayerMoney(giveplayerid) <= 7999) { SendClientMessage(giveplayerid, 0xA9A9A9AA, "|_Weapon Sale Failed_|"); format(string, sizeof(string), "%s(%d) Has tried to sell you a AK47 weapon. You cannot afford $8000",workername,playerid); SendClientMessage(giveplayerid, COLOR_ERROR, string); SendClientMessage(playerid, 0xA9A9A9AA, "|_Weapon Sale Failed_|"); format(string, sizeof(string), "%s(%d) cannot afford that weapon",costumername,giveplayerid); SendClientMessage(playerid, COLOR_ERROR, string); return 1; } GivePlayerWeapon(giveplayerid,30,200); GivePlayerMoney(giveplayerid, -8000); GivePlayerMoney(playerid,1500); SendClientMessage(giveplayerid, 0xA9A9A9AA, "|_Weapon Purchased_|"); format(string, sizeof(string), "%s(%d) Has sold you a AK47 weapon with 200 Ammo for $8000",workername,playerid); SendClientMessage(giveplayerid, 0x00C7FFAA, string); SendClientMessage(playerid, 0xA9A9A9AA, "|_Weapon Sold_|"); format(string, sizeof(string), "%s(%d) Has purchased a AK47 weapon from you. You receive a $1500 bonus",costumername,giveplayerid); SendClientMessage(playerid, 0x00C7FFAA, string); oscore = GetPlayerScore(playerid); SetPlayerScore(playerid, oscore +1); } else if(strcmp(x_nr,"6",true) == 0) { if(GetPlayerMoney(giveplayerid) <= 499) { SendClientMessage(giveplayerid, 0xA9A9A9AA, "|_Weapon Sale Failed_|"); format(string, sizeof(string), "%s(%d) Has tried to sell you Armor. You cannot afford $500",workername,playerid); SendClientMessage(giveplayerid, COLOR_ERROR, string); SendClientMessage(playerid, 0xA9A9A9AA, "|_Weapon Sale Failed_|"); format(string, sizeof(string), "%s(%d) cannot afford Armor",costumername,giveplayerid); SendClientMessage(playerid, COLOR_ERROR, string); return 1; } SetPlayerArmour(giveplayerid, 100); GivePlayerMoney(giveplayerid, -500); GivePlayerMoney(playerid,1500); SendClientMessage(giveplayerid, 0xA9A9A9AA, "|_Weapon Purchased_|"); format(string, sizeof(string), "%s(%d) Has sold you Armor for $500",workername,playerid); SendClientMessage(giveplayerid, 0x00C7FFAA, string); SendClientMessage(playerid, 0xA9A9A9AA, "|_Weapon Sold_|"); format(string, sizeof(string), "%s(%d) Has purchased Armor from you. You receive a $1500 bonus",costumername,giveplayerid); SendClientMessage(playerid, 0x00C7FFAA, string); oscore = GetPlayerScore(playerid); SetPlayerScore(playerid, oscore +1); } else { SendClientMessage(playerid, COLOR_ERROR, "USAGE: /sellweapon (id) (WEAPON.No)"); return 1; } } return 1; }
When a gundealer types /sellweapons, it shows a list to the player who wants to buy, this player tells the gundealer the number he wants to buy, and the gundealers responds with /sellweapon [id of the buyer] [id of the weapon]. The problem is, that it always sells number 1 to the player, even if another number is typed as weapon id.
I think the problem is in the sscanf part. What do you think, and how to solve it?
By the way, just to make clear, i got this command out of the LVRCR script.