Problems with code - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Problems with code (
/showthread.php?tid=488199)
Problems with code -
horsemeat - 17.01.2014
The code runs but stops it also telling you unknown command an suggestions?
pawn Код:
CMD:removecar(playerid, params[])
{
new vehicleid,string[256];
if(IsPlayerInAnyVehicle(playerid))
{
new playerstate = GetPlayerState(playerid);
if(playerstate != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, RED, "You have to be in the driver seat inorder to remove this vehicle");
vehicleid = GetPlayerVehicleID(playerid);
}
else
{
if(sscanf(params,"i",vehicleid)) return SendClientMessage(playerid, RED, "SYNTAX /removecar [vehicleid]");
}
new carid = jbcarid[vehicleid];
if((carstate[carid])==1)
{
if((cartype[carid])==2)//mark
{
new halfprice = VehicleManufactureingPrice(carmodelid[carid]) / 2;
dealershipcash[cardealershipid[carid]] = dealershipcash[cardealershipid[carid]] + halfprice;
format(string,sizeof(string),"You have remove the cars for $%i",halfprice);
SendClientMessage(playerid, LIGHTBLUE,string);
print("this print works here");//remove
if((requeststockstate[carmodelid[carid]][cardealershipid[carid]])==1||(requeststockstate[carmodelid[carid]][cardealershipid[carid]])==2)
{
print("this does not work");
new totalcarscash = (VehicleManufactureingPrice(carmodelid[carid]) * requeststock[carmodelid[carid]][cardealershipid[carid]]) / 2;
format(string,sizeof(string),"You also canceled your request for %i car(s) for $%i",requeststock[carmodelid[carid]][cardealershipid[carid]],totalcarscash);
SendClientMessage(playerid,RED,string);
dealershipordercash[choicedealershipid[playerid]] = dealershipordercash[choicedealershipid[playerid]] - totalcarscash;
dealershipcash[choicedealershipid[playerid]] = dealershipcash[choicedealershipid[playerid]] + totalcarscash;
}
else if((requeststockstate[carmodelid[carid]][cardealershipid[carid]])==3)
{
for(new factoryid;factoryid < MAX_FACTORIES;factoryid++)
{
if((factorystate[factoryid])==1)
{
for(new count;count < FACTORYMAXORDERSATONCE;count++)
{
if((factorystockstate[count][factoryid])==1)
{
if((factorydealershipid[count][factoryid])==cardealershipid[carid])
{
if((factorydealerstockmodelid[count][factoryid])==carmodelid[carid])
{
factorycash[factoryid] = factorycash[factoryid] + ((factorystockcurrent[count][factoryid] * VehicleManufactureingPrice(carmodelid[carid]))/2);
carstock[carid] = carstock[carid] + factorystockcurrent[count][factoryid];
factorystockcurrent[count][factoryid] = 0;
factorydealershipid[count][factoryid] = 0;
factorystock[count][factoryid] = 0;
factorystockstate[count][factoryid] = 0;
factorydealerstockmodelid[count][factoryid] = 0;
factorystock[count][factoryid] = 0;
factoryordercost[count][factoryid] = 0;
}
}
}
}
}
}
new totalcarscash = (VehicleManufactureingPrice(carmodelid[carid]) * requeststock[carmodelid[carid]][cardealershipid[carid]]) / 2;
format(string,sizeof(string),"You also canceled your request for %i car(s) for $%i",requeststock[carmodelid[carid]][cardealershipid[carid]],totalcarscash);
dealershipordercash[choicedealershipid[playerid]] = dealershipordercash[choicedealershipid[playerid]] - totalcarscash;
dealershipcash[choicedealershipid[playerid]] = dealershipcash[choicedealershipid[playerid]] + totalcarscash;
}
requeststock[carmodelid[carid] - 400][cardealershipid[carid]] = 0;
requeststockstate[carmodelid[carid] - 400][cardealershipid[carid]] = 0;
SaveDealershipData(cardealershipid[carid]);
DestroyVehicle(car[carid]);
Delete3DTextLabel(carlabel[carid]);
DeleteCarData(carid);
}
else
{
SendClientMessage(playerid,RED,"You car only remove dealership vehicles");
}
}
else
{
if(IsPlayerAdmince(playerid,2))
{
DestroyVehicle(vehicleid);
SendClientMessage(playerid, RED, "You have destroyed the car");
}
else
{
SendClientMessage(playerid, RED, "You have to be admin inorder to remove a car that is not a jbcar");
}
}
return 1;
}
Re: Problems with code -
Jstylezzz - 17.01.2014
This is like, a shitload of code. If we're going to examine every line of code, we'll have something to do for the rest of the day.
Try to add debug code throughout the command, like this
pawn Код:
print("Debug: 1");
//some code
//some more code
print("Debug: 2");
//e.t.c..
If you execute the command and look in the server_log.txt/the console, you'll notice several Debug: <number> statements appear.
Check the code near the last one that appeared. If you post the code with your print functions all over it here, and tell us what number appeared in the console last, we'll be able to help you better.
Re: Problems with code -
horsemeat - 18.01.2014
it happens some were between here
pawn Код:
print("this print works here");//remove
if((requeststockstate[carmodelid[carid]][cardealershipid[carid]])==1||(requeststockstate[carmodelid[carid]][cardealershipid[carid]])==2)
{
print("this does not work");
Re: Problems with code -
Jstylezzz - 18.01.2014
Can you show me the array (by your usage it looks like an array) requeststockstate?
Re: Problems with code -
horsemeat - 27.01.2014
O figured it out requeststockstate first parameter is a vehicle modelid and goes up to 212 and the modelid I was inputting was an actual model id so I forgot to add the -400