PDA

View Full Version : Trunk command, issues with storing, might be to do with misplaced bracket.


Dokins
01/08/2015, 02:37 AM
CMD:trunk(playerid, params[])
{
if(LoggedIn[playerid] == 0) return SendClientMessage(playerid, COLOUR_GREY, "You must be logged in to use this command.");
new item[32],usage[24], string[128], slot;
new vehicleid = GetClosestVehicle(playerid);
new engine, lights, alarm, doors, bonnet, boot, objective;
GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
if(boot == 0) return SendClientMessage(playerid, COLOUR_GREY, "You are not accessing any trunk.");
if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOUR_GREY, "You must get out of the vehicle to use this.");
if(VehicleSQLID[vehicleid] < 1) return SendClientMessage(playerid, COLOUR_GREY, "You cannot use this vehicle's trunk. (Admin Spawned/Static).");
if(sscanf(params, "s[24]S(0)[32]D(0)",usage,item, slot))
{
SendClientMessage(playerid, COLOUR_GREY, "Usage: /trunk [usage]");
SendClientMessage(playerid, COLOUR_GREY, "Usages: Store, Get, View, Weapons");
return 1;//ok take me back to the place that's not working
}

if(IsPlayerInRangeOfVehicle(playerid, vehicleid,5))
{
if(!strcmp(usage, "store", true))
{
if(sscanf(params, "s[24]s[32]",usage,item))
{
SendClientMessage(playerid, COLOUR_GREY, "Usage:/trunk store [item]");
SendClientMessage(playerid, COLOUR_GREY, "Available Items: Weed, Cocaine, Money, Armour");
return 1;

}
if(!strcmp(item, "weed", true))
{
if(sscanf(params, "s[24]s[32]d",usage,item,slot))
{
SendClientMessage(playerid, COLOUR_GREY, "Usage: /trunk store weed [amount]");
return 1;

}
if(slot > Weed[playerid]) return SendClientMessage(playerid, COLOUR_GREY, "You do not have this much weed.");
VehWeed[vehicleid] += slot;
Weed[playerid] -= slot;
format(string, sizeof(string), "You have stored a %d gram(s) of weed in your vehicle's trunk.", slot);
SendClientMessage(playerid, COLOUR_BLUE, string);
format(string, sizeof(string), "* %s has stored some drugs in the vehicle's trunk *", GetNameEx(playerid));
ProxDetector(30.0, playerid, string, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE);
}
if(!strcmp(item, "cocaine", true))
{
if(sscanf(params, "s[24]s[32]d",usage,item,slot))
{
SendClientMessage(playerid, COLOUR_GREY, "Usage: /trunk store cocaine [amount]");
return 1;

}
if(slot > Cocaine[playerid]) return SendClientMessage(playerid, COLOUR_GREY, "You do not have this much cocaine.");
VehCoke[vehicleid] += slot;
Cocaine[playerid] -= slot;
if(VehicleSQLID[vehicleid] > 0)
{
MySQL_SetInteger(VehicleSQLID[vehicleid], "VehCoke", VehCoke[vehicleid], "vehicles");
MySQL_SetInteger(PlayerSQLID[playerid], "Cocaine", Cocaine[playerid], "accounts");
}
format(string, sizeof(string), "You have stored a %d gram(s) of cocaine in the vehicle's trunk.", slot);
SendClientMessage(playerid, COLOUR_BLUE, string);
format(string, sizeof(string), "* %s has stored some drugs in the vehicle's trunk. *", GetNameEx(playerid));
ProxDetector(30.0, playerid, string, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE);
}
if(!strcmp(item, "money", true))
{
if(sscanf(params, "s[24]s[32]d",usage,item,slot))
{
SendClientMessage(playerid, COLOUR_GREY, "Usage: /trunk store money [amount]");
return 1;
printf("MONEY AMOUNT CLEARED SSCANF");
printf("VEH ID %d", vehicleid);
}
printf("VEH ID %d", vehicleid);
if(slot > PlayerMoney[playerid]) return SendClientMessage(playerid, COLOUR_GREY, "You do not have this much money.");
if(slot < 1 || slot > 100000) return SendClientMessage(playerid, COLOUR_GREY, "The amount must be between $0 and $100,000");
VehCash[vehicleid] += slot;
PlayerMoney[playerid] -= slot;
GivePlayerMoney(playerid, -slot);
if(VehicleSQLID[vehicleid] > 0)
{
MySQL_SetInteger(VehicleSQLID[vehicleid], "VehCash", VehCash[vehicleid], "vehicles");
MySQL_SetInteger(PlayerSQLID[playerid], "Money", PlayerMoney[playerid], "accounts");
}
format(string, sizeof(string), "You have stored $%s in the vehicle, there is now a total of $%s in the vehicle's trunk.", AddCommas(slot), AddCommas(VehCash[vehicleid]));
SendClientMessage(playerid, COLOUR_BLUE, string);
format(string, sizeof(string), "* %s has stored some money in the vehicle's trunk *", GetNameEx(playerid));

ProxDetector(30.0, playerid, string, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE);
}
if(!strcmp(item, "armour", true))
{
GetPlayerArmour(playerid, PlayerArmour[playerid]);
new Float: armour;
if(sscanf(params, "s[24]s[32]f",usage,item,armour))
{
SendClientMessage(playerid, COLOUR_GREY, "Usage: /trunk store armour [amount]");
return 1;
}

if(armour < 1 || armour > 100)return SendClientMessage(playerid, COLOUR_GREY, "Amount must be between 0 and 100");
if(armour > PlayerArmour[playerid])return SendClientMessage(playerid, COLOUR_GREY, "You do not have this much armour");

VehArmour[vehicleid] += armour;
PlayerArmour[playerid] -= armour;
SetPlayerArmour(playerid, -armour);
if(VehicleSQLID[vehicleid] > 0)
{
MySQL_SetFloat(vehicleid, "VehArmour", VehArmour[vehicleid], "vehicles");
MySQL_SetFloat(PlayerSQLID[playerid], "Armour", PlayerArmour[playerid], "accounts");
}

format(string, sizeof(string), "You have stored %d of armour, there is now a total of: %d armour in the vehicle's trunk.", floatround(armour), floatround(VehArmour[vehicleid]));
SendClientMessage(playerid, COLOUR_BLUE, string);
format(string, sizeof(string), "* %s has stored some armour in the vehicle's trunk. *", GetNameEx(playerid));
ProxDetector(30.0, playerid, string, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE);
}
}//close store
if(!strcmp(usage, "get", true))
{
if(sscanf(params, "s[24]s[32]D(0)",usage,item, slot))
{
SendClientMessage(playerid, COLOUR_GREY, "Usage: /trunk get [item]");
SendClientMessage(playerid, COLOUR_GREY, "Available Items: Weed, Cocaine, Money, Armour");
return 1;

}
if(!strcmp(item, "weed", true))
{
if(VehicleSQLID[vehicleid] > 0)
{
VehWeed[vehicleid] = MySQL_GetValue(VehicleSQLID[vehicleid], "VehWeed", "vehicles");
Weed[playerid] = MySQL_GetValue(PlayerSQLID[playerid], "weed", "accounts");
}
if(sscanf(params, "s[24]s[32]d",usage,item,slot))
{
SendClientMessage(playerid, COLOUR_GREY, "Usage: /trunk get weed [amount]");

return 1;

}
if(slot > VehWeed[vehicleid]) return SendClientMessage(playerid, COLOUR_GREY, "There is not this much weed stored in the vehicle.");
VehWeed[vehicleid] -= slot;
Weed[playerid] += slot;
if(VehicleSQLID[vehicleid] > 0)
{
MySQL_SetInteger(VehicleSQLID[vehicleid], "VehWeed", VehWeed[vehicleid], "vehicles");
MySQL_SetInteger(PlayerSQLID[playerid], "Weed", Weed[playerid], "accounts");
}
format(string, sizeof(string), "You have taken %d gram(s) of weed from the vehicle's trunk.", slot);
SendClientMessage(playerid, COLOUR_BLUE, string);
format(string, sizeof(string), "* %s has taken some drugs from the vehicle's trunk. *", GetNameEx(playerid));
ProxDetector(30.0, playerid, string, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE);
}
if(!strcmp(item, "cocaine", true))
{
if(VehicleSQLID[vehicleid] > 0)
{
VehCoke[vehicleid] = MySQL_GetValue(VehicleSQLID[vehicleid], "VehCoke", "vehicles");
Cocaine[playerid] = MySQL_GetValue(PlayerSQLID[playerid], "Cocaine", "accounts");
}
if(sscanf(params, "s[24]s[32]d",usage,item,slot))
{
SendClientMessage(playerid, COLOUR_GREY, "Usage: /trunk get cocaine [amount]");
return 1;

}
if(slot > VehCoke[vehicleid]) return SendClientMessage(playerid, COLOUR_GREY, "You do not have this much cocaine.");
VehCoke[vehicleid] -= slot;
Cocaine[playerid] += slot;
if(VehicleSQLID[vehicleid] > 0)
{
MySQL_SetInteger(VehicleSQLID[vehicleid], "VehCoke", VehCoke[vehicleid], "vehicles");
MySQL_SetInteger(PlayerSQLID[playerid], "Cocaine", Cocaine[playerid], "accounts");
}
format(string, sizeof(string), "You have taken %d gram(s) of cocaine from the vehicle's trunk.", slot);
SendClientMessage(playerid, COLOUR_BLUE, string);
format(string, sizeof(string), "* %s has taken some drugs from the vehicle's trunk. *", GetNameEx(playerid));
ProxDetector(30.0, playerid, string, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE);
}
if(!strcmp(item, "money", true))
{
if(sscanf(params, "s[24]s[32]d",usage,item,slot))
{
SendClientMessage(playerid, COLOUR_GREY, "Usage: /trunk get money [amount]");
return 1;

}
if(VehCash[vehicleid] < slot) return SendClientMessage(playerid, COLOUR_GREY, "There is not this much money stored in the vehicle.");
if(slot < 1 || slot > 100000) return SendClientMessage(playerid, COLOUR_GREY, "The amount must be between $0 and $100,000");
VehCash[vehicleid] -= slot;
PlayerMoney[playerid] += slot;
GivePlayerMoney(playerid, slot);
if(VehicleSQLID[vehicleid] > 0)
{
MySQL_SetInteger(VehicleSQLID[vehicleid], "VehCash", VehCash[vehicleid], "vehicles");
MySQL_SetInteger(PlayerSQLID[playerid], "Money", PlayerMoney[playerid], "accounts");
}
format(string, sizeof(string), "You have taken $%s from the vehicle, there is now a total of: $%s in the vehicle's trunk.", AddCommas(slot), AddCommas(VehCash[vehicleid]));
SendClientMessage(playerid, COLOUR_BLUE, string);
format(string, sizeof(string), "* %s has taken some money from the vehicle's trunk. *", GetNameEx(playerid));
ProxDetector(30.0, playerid, string, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE);
}
if(!strcmp(item, "armour", true))
{
new Float: armour;
if(sscanf(params, "s[24]s[32]f",usage,item,armour))
{
SendClientMessage(playerid, COLOUR_GREY, "Usage: /trunk get armour [amount]");
return 1;

}
if(armour > VehArmour[vehicleid]) return SendClientMessage(playerid, COLOUR_GREY, "There is not this much armour stored in the vehicle.");
if(PlayerArmour[playerid] + armour > 100) return SendClientMessage(playerid, COLOUR_GREY, "You may only have a maximum of 100 armour.");
VehArmour[vehicleid] -= armour;
PlayerArmour[playerid] += armour;
SetPlayerArmour(playerid, PlayerArmour[playerid]);
if(VehicleSQLID[vehicleid] > 0)
{
MySQL_SetFloat(vehicleid, "VehArmour", VehArmour[vehicleid], "vehicles");
MySQL_SetFloat(PlayerSQLID[playerid], "Armour", PlayerArmour[playerid], "accounts");
}
format(string, sizeof(string), "You have taken %d of armour from the vehicle's trunk, there is now a total of: %d armour in the vehicle's trunk.", armour, floatround(VehArmour[vehicleid]));
SendClientMessage(playerid, COLOUR_BLUE, string);
format(string, sizeof(string), "* %s has taken some armour from the vehicle's trunk. *", GetNameEx(playerid));
ProxDetector(30.0, playerid, string, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE);
}
}
if(!strcmp(usage, "view", true))
{
new weaponamount, furniamount;
for(new x = 1; x < MAX_WEAPONS; x++)
{
if(VehWepStored[x] == VehicleSQLID[vehicleid])
{
weaponamount ++;
}
if(VehFurniStored[x] == VehicleSQLID[vehicleid])
{
furniamount ++;
}
}
//0xBCDE00FF
//0x43B0FFFF
SendClientMessage(playerid,0xFFD99FFF, "____________________Vehicle Trunk____________________");
format(string, sizeof(string), "Money: {B0FFFF}$%s", AddCommas(VehCash[vehicleid]));
SendClientMessage(playerid, 0xFFD99FFF, string);
format(string, sizeof(string), "Armour: {B0FFFF}%d", floatround(VehArmour[vehicleid]));
SendClientMessage(playerid, 0xFFD99FFF, string);
format(string, sizeof(string), "Cocaine: {B0FFFF}%d gram(s)", VehCoke[vehicleid]);
SendClientMessage(playerid, 0xFFD99FFF, string);
format(string, sizeof(string), "Weed: {B0FFFF}%d gram(s)", VehWeed[vehicleid]);
SendClientMessage(playerid, 0xFFD99FFF, string);
format(string, sizeof(string), "Amount of weapons: {B0FFFF}%d. (Use /vgetwep to see what weapons are in the vehicle.)", weaponamount);
SendClientMessage(playerid, 0xFFD99FFF, string);
format(string, sizeof(string), "Amount of furniture: {B0FFFF}%d. (Use /vgetfurni to see what furniture is in the vehicle.)", furniamount);
SendClientMessage(playerid, 0xFFD99FFF, string);
SendClientMessage(playerid,0xFFD99FFF, "____________________Vehicle Trunk____________________");
}
if(!strcmp(usage, "weapons", true))
{
new amount = 0, string1[500], model = GetVehicleModel(vehicleid) - 400;
for(new x = 1; x < MAX_WEAPONS; x++)
{
if(VehWepStored[x] == VehicleSQLID[vehicleid])
{
WeaponEnum[playerid][amount][wepid] = x;
if(amount == 0 && WepSerial[x] == 0)
{
format(string1, sizeof(string1),"%s (%d Ammo) Serial: None.",WeaponNames[WepModel[x]], WepAmmo[x]);
}
if(amount == 0 && WepSerial[x] > 0)
{
format(string1, sizeof(string1),"%s (%d Ammo) Serial: %d",WeaponNames[WepModel[x]], WepAmmo[x], WepSerial[x]);
}
if(amount > 0)
{
if(WepSerial[x] > 0)
{
format(string1, sizeof(string1),"%s\n%s (%d Ammo) Serial: %d",string1, WeaponNames[WepModel[x]], WepAmmo[x], WepSerial[x]);
}
else
{
format(string1, sizeof(string1),"%s\n%s (%d Ammo) Serial: None.",string1, WeaponNames[WepModel[x]], WepAmmo[x]);
}

}
amount++;
strcpy(Pdialogstring[playerid], string1, 500);
}
}
if(amount == 0) return SendClientMessage(playerid, COLOUR_GREY, "There are no weapons in this vehicle.");
format(string, sizeof(string), "%s Weapons", VehicleNames[model]);
ShowPlayerDialog(playerid, DIALOG_SHOWWEP, DIALOG_STYLE_LIST, string, Pdialogstring[playerid],"Close", "");
}
}
return 1;
}


I realise this is a lot to look at but everything works except storing, I can get items from the vehicle but cannot store them. I can't see any misplaced brackets and the code isn't incorrect and I've tried to printf at some areas and they don't return.


STORE AREA.

if(!strcmp(usage, "store", true))
{
if(sscanf(params, "s[24]s[32]",usage,item))
{
SendClientMessage(playerid, COLOUR_GREY, "Usage:/trunk store [item]");
SendClientMessage(playerid, COLOUR_GREY, "Available Items: Weed, Cocaine, Money, Armour");
return 1;

}
if(!strcmp(item, "weed", true))
{
if(sscanf(params, "s[24]s[32]d",usage,item,slot))
{
SendClientMessage(playerid, COLOUR_GREY, "Usage: /trunk store weed [amount]");
return 1;

}
if(slot > Weed[playerid]) return SendClientMessage(playerid, COLOUR_GREY, "You do not have this much weed.");
VehWeed[vehicleid] += slot;
Weed[playerid] -= slot;
format(string, sizeof(string), "You have stored a %d gram(s) of weed in your vehicle's trunk.", slot);
SendClientMessage(playerid, COLOUR_BLUE, string);
format(string, sizeof(string), "* %s has stored some drugs in the vehicle's trunk *", GetNameEx(playerid));
ProxDetector(30.0, playerid, string, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE);
}
if(!strcmp(item, "cocaine", true))
{
if(sscanf(params, "s[24]s[32]d",usage,item,slot))
{
SendClientMessage(playerid, COLOUR_GREY, "Usage: /trunk store cocaine [amount]");
return 1;

}
if(slot > Cocaine[playerid]) return SendClientMessage(playerid, COLOUR_GREY, "You do not have this much cocaine.");
VehCoke[vehicleid] += slot;
Cocaine[playerid] -= slot;
if(VehicleSQLID[vehicleid] > 0)
{
MySQL_SetInteger(VehicleSQLID[vehicleid], "VehCoke", VehCoke[vehicleid], "vehicles");
MySQL_SetInteger(PlayerSQLID[playerid], "Cocaine", Cocaine[playerid], "accounts");
}
format(string, sizeof(string), "You have stored a %d gram(s) of cocaine in the vehicle's trunk.", slot);
SendClientMessage(playerid, COLOUR_BLUE, string);
format(string, sizeof(string), "* %s has stored some drugs in the vehicle's trunk. *", GetNameEx(playerid));
ProxDetector(30.0, playerid, string, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE);
}
if(!strcmp(item, "money", true))
{
if(sscanf(params, "s[24]s[32]d",usage,item,slot))
{
SendClientMessage(playerid, COLOUR_GREY, "Usage: /trunk store money [amount]");
return 1;
printf("MONEY AMOUNT CLEARED SSCANF");
printf("VEH ID %d", vehicleid);
}
printf("VEH ID %d", vehicleid);
if(slot > PlayerMoney[playerid]) return SendClientMessage(playerid, COLOUR_GREY, "You do not have this much money.");
if(slot < 1 || slot > 100000) return SendClientMessage(playerid, COLOUR_GREY, "The amount must be between $0 and $100,000");
VehCash[vehicleid] += slot;
PlayerMoney[playerid] -= slot;
GivePlayerMoney(playerid, -slot);
if(VehicleSQLID[vehicleid] > 0)
{
MySQL_SetInteger(VehicleSQLID[vehicleid], "VehCash", VehCash[vehicleid], "vehicles");
MySQL_SetInteger(PlayerSQLID[playerid], "Money", PlayerMoney[playerid], "accounts");
}
format(string, sizeof(string), "You have stored $%s in the vehicle, there is now a total of $%s in the vehicle's trunk.", AddCommas(slot), AddCommas(VehCash[vehicleid]));
SendClientMessage(playerid, COLOUR_BLUE, string);
format(string, sizeof(string), "* %s has stored some money in the vehicle's trunk *", GetNameEx(playerid));

ProxDetector(30.0, playerid, string, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE);
}
if(!strcmp(item, "armour", true))
{
GetPlayerArmour(playerid, PlayerArmour[playerid]);
new Float: armour;
if(sscanf(params, "s[24]s[32]f",usage,item,armour))
{
SendClientMessage(playerid, COLOUR_GREY, "Usage: /trunk store armour [amount]");
return 1;
}

if(armour < 1 || armour > 100)return SendClientMessage(playerid, COLOUR_GREY, "Amount must be between 0 and 100");
if(armour > PlayerArmour[playerid])return SendClientMessage(playerid, COLOUR_GREY, "You do not have this much armour");

VehArmour[vehicleid] += armour;
PlayerArmour[playerid] -= armour;
SetPlayerArmour(playerid, -armour);
if(VehicleSQLID[vehicleid] > 0)
{
MySQL_SetFloat(vehicleid, "VehArmour", VehArmour[vehicleid], "vehicles");
MySQL_SetFloat(PlayerSQLID[playerid], "Armour", PlayerArmour[playerid], "accounts");
}

format(string, sizeof(string), "You have stored %d of armour, there is now a total of: %d armour in the vehicle's trunk.", floatround(armour), floatround(VehArmour[vehicleid]));
SendClientMessage(playerid, COLOUR_BLUE, string);
format(string, sizeof(string), "* %s has stored some armour in the vehicle's trunk. *", GetNameEx(playerid));
ProxDetector(30.0, playerid, string, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE);
}
}//close store


Forums have messed up my paste. Here's the pastebin: http://pastebin.com/yCDKLi81



the sscanf returns correctly (/trunk store money [amount]) but when I enter the amount nothing happens.

Scenario
01/08/2015, 05:48 AM
So you're saying none of the printf()'s you've added are even showing up in the console at all?

Dokins
01/08/2015, 11:33 AM
You're back?! Hey. Also the printf's didn't show up when I placed them under "money" or "weed"* or anything under store, however view,get and weapons work

Dokins
02/08/2015, 11:46 AM
Bump

dominik523
02/08/2015, 11:50 AM
So what happens when you try to store something? Does it actually take your money/weed/etc from you but it doesnt put it in the vehicle or?

EDIT: Sorry haven't seen the last part after the pastebin.
Okay, so I would try to do it like this:
new amount, option[32];
// uppercase i means it's an optional specifier so if you don't enter anything after the option, amount will be set to a zero by default
if(sscanf(params, "s[32]I(0)", option, amount)) return SendClientMessage(playerid, COLOR_GREY, "Usage: /store [option]");

if(!strcmp(option, "weed"))
{
if(!amount) return SendClientMessage(playerid, COLOR_GREY, "Usage: /store [option] [amount]");
// store the weed
}

Scenario
02/08/2015, 03:19 PM
Try adding this print above the strcmp() line for "store".

printf("Value of usage: %s", usage);
Let me know what the console returns.

Dokins
02/08/2015, 03:50 PM
Hey, sorry! It doesn't actually do anything, It worked before and I'm maintaining it's probably to do with a misplaced bracket.

Realcop, any chance you could come on Skype?