The online racing simulator
[Help] Cruise !buyfood
(5 posts, started )
[Help] Cruise !buyfood
hi
i'm develop a Buy and Sell commands but i have a lil problem

i want that a user can buy max 20(foods)
but if he bought 15 already and he bought a another 15(foods) then he will exceed the limit of 20 foods. but the max is 20
could u guys help me pls
thx

see the code below



case "!buyfood":
if (Connections[GetConnIdx(MSO.UCID)].Instore == 1)
{
int foods = int.Parse(StrMsg[1]);

if (foods > 20 || Connections[GetConnIdx(MSO.UCID)].foods >= 20)
{
InSim.Send_MTC_MessageToConnection("^1Wrong amount", MSO.UCID, 0);
}
else
{
Connections[GetConnIdx(MSO.UCID)].foods += foods;
Connections[GetConnIdx(MSO.UCID)].Cash -= foods * Connections[GetConnIdx(MSO.UCID)].Food;
InSim.Send_MTC_MessageToConnection("^7U bought " + foods + " Foods", MSO.UCID, 0);
InSim.Send_MTC_MessageToConnection("^7U paid " + foods * Connections[GetConnIdx(MSO.UCID)].Food, MSO.UCID, 0);
}
}
break;

Try this:
case "!buyfood":
if (Connections[GetConnIdx(MSO.UCID)].Instore == 1)
{
int foods = int.Parse(StrMsg[1]);

if (foods > 20 || Connections[GetConnIdx(MSO.UCID)].foods + foods > 20)
{
InSim.Send_MTC_MessageToConnection("^1You can only carry 20 units of food!", MSO.UCID, 0);
}
else
{
Connections[GetConnIdx(MSO.UCID)].foods += foods;
Connections[GetConnIdx(MSO.UCID)].Cash -= foods * Connections[GetConnIdx(MSO.UCID)].Food;
InSim.Send_MTC_MessageToConnection("^7You bought " + foods + " units of food.", MSO.UCID, 0);
InSim.Send_MTC_MessageToConnection("^7You paid " + (foods * Connections[GetConnIdx(MSO.UCID)].Food), MSO.UCID, 0);
}
}
break;

thx it works
So, how many foods do you have?
#5 - PoVo

[Help] Cruise !buyfood
(5 posts, started )
FGED GREDG RDFGDR GSFDG