/mechanic cmd is activating different cmd -
oblexive - 15.07.2012
hey guys, iv just created a /mechanic command which will give you a few options when you type it. Im having a problem though. When the player types it everything goes alright. It asks for a playerId and the mod you want etc. But when you offer someone the mod it sells them a gun instead! I just dont get why, its like its grabbing the other command. Help is much apreciated!
/mechanic
Код:
CMD:repair(playerid, params[])
{
new string[128], playerb, price;
if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
if(PlayerInfo[playerid][pJob] != JOB_MECHANIC && PlayerInfo[playerid][pVIPJob] != JOB_MECHANIC) return SendClientMessage(playerid, COLOR_GREY, "You are not a mechanic.");
if(sscanf(params, "uii", playerb, price)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /repair [playerid] [price]");
if(playerid == playerb) return SendClientMessage(playerid, COLOR_GREY, "You can't offer a repair to yourself.");
if(!IsPlayerLoggedIn(playerb)) return SendClientMessage(playerid, COLOR_GREY, "Invalid player id.");
if(!IsPlayerNearPlayer(playerid, playerb, 2)) return SendClientMessage(playerid, COLOR_GREY, "You are too far away from that player.");
if(!IsPlayerInAnyVehicle(playerb)) return SendClientMessage(playerid, COLOR_GREY, "Player is not in a vehicle.");
new playerbvid = GetPlayerVehicleID(playerb);
new playervid = GetPlayerVehicleID(playerid);
if(playervid != playerbvid) return SendClientMessage(playerid, COLOR_GREY, "Not in the same vehicle.");
new Float:vH; GetVehicleHealth(GetPlayerVehicleID(playerb), vH);
if(vH < 250) return SendClientMessage(playerid, COLOR_GREY, "The vehicle's engine is beyond repair.");
if(SellRepairTo[playerid] == playerb) return SendClientMessage(playerid, COLOR_GREY, "You have already offered that player to repair their vehicle.");
if(price <= 0) return SendClientMessage(playerid, COLOR_GREY, "Invalid repair price.");
// Clearing old buyer
foreach(Player, i)
{
if(IsPlayerLoggedIn(i))
{
if(SellRepairTo[playerid] == i && BuyRepairFrom[i] == playerid)
{
BuyRepairFrom[i] = -1; BuyRepairPrice[i] = 0; BeenOfferedRepair[i] = 0;
}
}
}
// New buyer
SellRepairTo[playerid] = playerb;
BuyRepairFrom[playerb] = playerid;
BuyRepairPrice[playerb] = price;
BeenOfferedRepair[playerb] = 1;
format(string, sizeof(string), " You have offered %s to repair their vehicle for {0cff00}$%d.", RPN(playerb), price);
SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
format(string, sizeof(string), " %s has offered to repair your vehicle for $%d. (/accept repair) (/cancel repair)", RPN(playerid), price);
SendClientMessage(playerb, COLOR_LIGHTBLUE, string);
return 1;
}
CMD:mechanic(playerid, params[]) //mechanic
{
new string[128], playerb, price, mods[32];
new Float:vel[3]; GetVehicleVelocity(GetPlayerVehicleID(playerid), vel[0], vel[1], vel[2]);
if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
if(PlayerInfo[playerid][pJob] != JOB_MECHANIC && PlayerInfo[playerid][pVIPJob] != JOB_MECHANIC) return SendClientMessage(playerid, COLOR_GREY, "You are not a mechanic.");
if(!IsPlayerLoggedIn(playerb)) return SendClientMessage(playerid, COLOR_GREY, "Invalid player id.");
if(sscanf(params, "us[32]i", playerb, mods, price))
{
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /mechanic [playerid] [mod] [price]");
SendClientMessage(playerid, COLOR_GREY, "LEVEL 1: Nos | Hydraulics");
if(strval(RPJL(playerid, JOB_MECHANIC)) >= 2) SendClientMessage(playerid, COLOR_GREY, "LEVEL 2: ");
if(strval(RPJL(playerid, JOB_MECHANIC)) >= 3) SendClientMessage(playerid, COLOR_GREY, "LEVEL 3: ");
if(strval(RPJL(playerid, JOB_MECHANIC)) >= 4) SendClientMessage(playerid, COLOR_GREY, "LEVEL 4: ");
if(strval(RPJL(playerid, JOB_MECHANIC)) >= 5) SendClientMessage(playerid, COLOR_GREY, "LEVEL 5: ");
return 1;
}
if(playerid == playerb) return SendClientMessage(playerid, COLOR_GREY, "You can't add mods to your own vehicle");
//if(PlayerInfo[playerid][pLevel] < 2) return SendClientMessage(playerid, COLOR_GREY, "You must be at least level 2 to sell mods.");
if(!IsPlayerNearPlayer(playerid, playerb, 2)) return SendClientMessage(playerid, COLOR_GREY, "You are too far away from that player.");
if(!IsPlayerInAnyVehicle(playerb)) return SendClientMessage(playerid, COLOR_GREY, "Player is not in a vehicle.");
new playerbvid = GetPlayerVehicleID(playerb);
new playervid = GetPlayerVehicleID(playerid);
if(playervid != playerbvid) return SendClientMessage(playerid, COLOR_GREY, "Not in the same vehicle.");
if(vel[0] != 0 || vel[1] != 0 || vel[2] != 0) return SendClientMessage(playerid, COLOR_GREY, "You can't do that while the vehicle is moving.");
if(!strcmp(mods, "nos", true, 3))
{
if(SellModTo[playerid] == playerb) return SendClientMessage(playerid, COLOR_GREY, "You have already offered that player to mod their vehicle.");
//if(PlayerInfo[playerid][pMaterials] < 25) return SendClientMessage(playerid, COLOR_GREY, "You don't have enough materials for this weapon.");
BeenOfferedMod[playerb] = 14;
}
else if(!strcmp(mods, "hydraulics", true, 10))
{
//if(PlayerInfo[playerid][pMaterials] < 50) return SendClientMessage(playerid, COLOR_GREY, "You don't have enough materials for this weapon.");
BeenOfferedMod[playerb] = 2;
}
//else if(!strcmp(weapon, "rifle", true, 5))
//{
// if(strval(RPJL(playerid, JOB_WDEALER)) < 2) return SendClientMessage(playerid, COLOR_GREY, "Your Weapons Dealer level is too low to sell this weapon.");
// if(PlayerInfo[playerid][pMaterials] < 750) return SendClientMessage(playerid, COLOR_GREY, "You don't have enough materials for this weapon.");
// BeenOfferedWeapon[playerb] = 33;
//}
else
{
SendClientMessage(playerid, COLOR_GREY, "Invalid mod name.");
return 1;
}
SellModTo[playerid] = playerb;
BuyModFrom[playerb] = playerid;
BuyModPrice[playerb] = price;
format(string, sizeof(string), " You have offered %s to sell them %s for $%d.", RPN(playerb), RWN(BeenOfferedMod[playerb]), price);
SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
format(string, sizeof(string), " %s has offered to sell you %s for $%d. (/accept mechanic) (/cancel mechanic)", RPN(playerid), RWN(BeenOfferedMod[playerb]), price);
SendClientMessage(playerb, COLOR_LIGHTBLUE, string);
return 1;
}
/accept mechanic
Код:
else if(!strcmp(params, "mechanic", true))
{
if(BeenOfferedMod[playerid])
{
new playerb = BuyModFrom[playerid], price = BuyModPrice[playerid];
if(PlayerInfo[playerid][pMoney] < price) return SendClientMessage(playerid, COLOR_GREY, "You don't have that much on you right now.");
if(!IsPlayerNearPlayer(playerid, playerb, 2)) return SendClientMessage(playerid, COLOR_GREY, "You are too far away from that player.");
// Seller mods /////--- Change mods to fix car or add nos etc..
if(BeenOfferedMod[playerid] == 14)
{
AddVehicleComponent(GetPlayerVehicleID(playerid),1009);
PlayerPlaySound(playerid,1133,0.0,0.0,0.0);
format(string, sizeof(string), "* %s has installed a 2x nitros cylinder into the vehicle for $%d.", RPN(playerb), price);
SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
format(string, sizeof(string), " You have bought 2x nitro from %s for $%d.", RPN(playerb),price);
SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
}
else if(BeenOfferedMod[playerid] == 2)
{
if(GetVehicleComponentInSlot(GetPlayerVehicleID(playerid),GetVehicleComponentType(1087)) != 1087)
{
AddVehicleComponent(GetPlayerVehicleID(playerid),1087);
PlayerPlaySound(playerid,1133,0.0,0.0,0.0);
format(string, sizeof(string), "* %s has installed hydraulics system into the vehicle.", RPN(playerb));
SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
format(string, sizeof(string), " You have bought hydraulics from %s for $%d.", RPN(playerb),price);
SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
}
}
PlayerInfo[playerb][pJobSkill][JOB_MECHANIC] ++;
GiveZaiatMoney(playerid, -price);
GiveZaiatMoney(playerb, price);
GiveZaiatWeapon(playerid, BeenOfferedMod[playerid], 5);
SellModTo[playerb] = -1;
BuyModFrom[playerid] = -1;
BuyModPrice[playerid] = 0;
BeenOfferedMod[playerid] = 0;
return 1;
}
else
{
SendClientMessage(playerid, COLOR_GREY, "Nobody has offered to mod your vehicle.");
return 1;
}
}
Re: /mechanic cmd is activating different cmd -
clarencecuzz - 15.07.2012
pawn Код:
/else if(!strcmp(weapon, "rifle", true, 5))
//{
// if(strval(RPJL(playerid, JOB_WDEALER)) < 2) return SendClientMessage(playerid, COLOR_GREY, "Your Weapons Dealer level is too low to sell this weapon.");
// if(PlayerInfo[playerid][pMaterials] < 750) return SendClientMessage(playerid, COLOR_GREY, "You don't have enough materials for this weapon.");
// BeenOfferedWeapon[playerb] = 33;
//}
This is in your script... why?
EDIT: Change Repair Command from:
pawn Код:
if(sscanf(params, "uii", playerb, price))
To:
pawn Код:
if(sscanf(params, "ui", playerb, price))
Re: /mechanic cmd is activating different cmd -
oblexive - 15.07.2012
sorry repair command? I deleted that top part hehe i meant to comment it all out. But anyways, what repair command? im having trouble with either /mechanic or /accept [mechanic]
Re: /mechanic cmd is activating different cmd -
oblexive - 15.07.2012
the problem was my own stupid fault. really bad mistake on my part :/ :::
GiveZaiatWeapon(playerid, BeenOfferedMod[playerid], 5);
forgot to delete this line...
Thanks for the help