Sell car problem
#1

Heey guys ! I tried to make a /sellcartomarket command but while trying to sell boats on another location, the script just tells me im not near a car dealership. I'm pretty confused any help would be Muuucch apreciated !

Код:
CMD:sellcartomarket(playerid, params[])
{
   	if(!IsPlayerLoggedIn(playerid) || PlayerInfo[playerid][pAsshole] == 1) return SendClientMessage(playerid, COLOR_GREY, "You are not allowed to use command.");
	if(!IsPlayerInRangeOfPoint(playerid, 2, 545.6661,-1292.2437,17.2422)) return SendClientMessage(playerid, COLOR_GREY, "You are not near the vehicles dealership.");
	if(!PlayerInfo[playerid][pVeh] && !PlayerInfo[playerid][pVVeh]) return SendClientMessage(playerid, COLOR_GREY, "You don't own a vehicle.");
	if(GetPlayerVehicleID(playerid) != PlayerInfo[playerid][pVeh] && GetPlayerVehicleID(playerid) != PlayerInfo[playerid][pVVeh]) return SendClientMessage(playerid, COLOR_GREY, "You must be in the vehicle you wish to sell to the dealership.");
	if(sscanf(params, "s[8]", params)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /sellcartomarket [confirm]");
	// Start of Payback
	new price;
	if(!strcmp(params, "confirm", true))
	// BMX ($600)\nFaggio ($4,000)\nFreeway ($6,000)\nSanchez ($4,000)\nQuad ($6,000)\nPCJ-600 ($20,000)\nFCR-900 ($25,000)
	if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 481) price = 600;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 462) price = 4000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 446) price = 4000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 452) price = 4000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 453) price = 4000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 454) price = 4000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 484) price = 4000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 493) price = 4000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 463) price = 6000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 468) price = 4000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 471) price = 6000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 461) price = 20000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 521) price = 25000; // End of Bikes
	// Comet ($30,000)\nFeltzer ($26,000)\nStallion ($26,000)\nWindsor ($28,000)\nSentinel ($24,000)\nManana ($22,000)
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 480) price = 30000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 533) price = 26000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 439) price = 26000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 555) price = 28000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 405) price = 24000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 410) price = 22000; // End of Normal Vehicles
	// Huntley ($22,000)\nLandstalker ($24,000)\nSandking ($30,000)
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 579) price = 22000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 400) price = 24000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 495) price = 30000; // End of Off-Road vehicles
	// Sultan ($60,000)\nBanshee ($65,000)\nBuffalo ($70,000)\nBullet ($90,000)\nCheetah ($80,000)\nJester ($70,000)\nTurismo ($110,000)\nSuper GT(200,000$)\nInfernus($300,000)
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 560) price = 60000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 429) price = 65000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 402) price = 70000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 541) price = 90000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 415) price = 80000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 559) price = 70000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 451) price = 110000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 506) price = 200000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 411) price = 300000; // End of Sport vehicles
	// Blade($25,000)\nBroadway ($35,000)\nRemington ($30,000)\nSavanna ($25,000)\nSlamvan ($27,000)\nTornado ($24,000)\nVoodo ($30,000)
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 536) price = 25000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 575) price = 35000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 534) price = 30000;
	else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 567) price = 25000;
    else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 535) price = 27000;
    else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 576) price = 24000;
    else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 412) price = 30000;

	GiveDodMoney(playerid, (75*price)/100);
	neon[playerid] = 1;
	vneon[playerid] = 1;
	// End of Payback
	if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pVeh])
	{
	    DestroyObject(GetPVarInt(playerid, "neon"));
   		DestroyObject(GetPVarInt(playerid, "neon1"));
	    DestroyObject(GetPVarInt(playerid, "neon2"));
    	DestroyObject(GetPVarInt(playerid, "neon3"));
    	DestroyObject(GetPVarInt(playerid, "neon4"));
    	DestroyObject(GetPVarInt(playerid, "neon5"));
    	DestroyObject(GetPVarInt(playerid, "neon6"));
    	DestroyObject(GetPVarInt(playerid, "neon7"));
    	DestroyObject(GetPVarInt(playerid, "neon8"));
    	DestroyObject(GetPVarInt(playerid, "neon9"));
    	DestroyObject(GetPVarInt(playerid, "neon10"));
    	DestroyObject(GetPVarInt(playerid, "neon11"));
    	DestroyObject(GetPVarInt(playerid, "nb1"));
    	DestroyObject(GetPVarInt(playerid, "nb2"));
    	DestroyObject(GetPVarInt(playerid, "nb3"));
    	DestroyObject(GetPVarInt(playerid, "nb4"));
    	DestroyObject(GetPVarInt(playerid, "nb5"));
    	DestroyObject(GetPVarInt(playerid, "nb6"));
    	neon[playerid] = 1;
		DestroyVehicle(PlayerInfo[playerid][pVeh]);
		PlayerInfo[playerid][pVeh] = 0;
	    PlayerInfo[playerid][vModel] = 0;
		PlayerInfo[playerid][vX] = 0;
		PlayerInfo[playerid][vY] = 0;
		PlayerInfo[playerid][vZ] = 0;
		PlayerInfo[playerid][vA] = 0;
		PlayerInfo[playerid][vC1] = 0;
		PlayerInfo[playerid][vC2] = 0;
		PlayerInfo[playerid][pTWeed] = 0;
		PlayerInfo[playerid][pTcocaine] = 0;
		PlayerInfo[playerid][pTGun][0] = 0;
		PlayerInfo[playerid][pTGunAmmo][0] = 0;
		PlayerInfo[playerid][pTGun][1] = 0;
		PlayerInfo[playerid][pTGunAmmo][1] = 0;
		PlayerInfo[playerid][pvTWeed] = 0;
		PlayerInfo[playerid][pvTcocaine] = 0;
		PlayerInfo[playerid][pvTGun][0] = 0;
		PlayerInfo[playerid][pvTGunAmmo][0] = 0;
		PlayerInfo[playerid][pvTGun][1] = 0;
		PlayerInfo[playerid][pvTGunAmmo][1] = 0;
		SendClientMessage(playerid, COLOR_GREEN, " You have sold your vehicle to the dealership. (75 percent of the original price was paid back)");
        --PlayerCars;
	}
	else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pVVeh])
	{
	    DestroyObject(GetPVarInt(playerid, "vneon"));
   		DestroyObject(GetPVarInt(playerid, "vneon1"));
	    DestroyObject(GetPVarInt(playerid, "vneon2"));
    	DestroyObject(GetPVarInt(playerid, "vneon3"));
    	DestroyObject(GetPVarInt(playerid, "vneon4"));
    	DestroyObject(GetPVarInt(playerid, "vneon5"));
    	DestroyObject(GetPVarInt(playerid, "vneon6"));
    	DestroyObject(GetPVarInt(playerid, "vneon7"));
    	DestroyObject(GetPVarInt(playerid, "vneon8"));
    	DestroyObject(GetPVarInt(playerid, "vneon9"));
    	DestroyObject(GetPVarInt(playerid, "vneon10"));
    	DestroyObject(GetPVarInt(playerid, "vneon11"));
    	DestroyObject(GetPVarInt(playerid, "vnb1"));
    	DestroyObject(GetPVarInt(playerid, "vnb2"));
    	DestroyObject(GetPVarInt(playerid, "vnb3"));
    	DestroyObject(GetPVarInt(playerid, "vnb4"));
    	DestroyObject(GetPVarInt(playerid, "vnb5"));
    	DestroyObject(GetPVarInt(playerid, "vnb6"));
    	vneon[playerid] = 1;
		DestroyVehicle(PlayerInfo[playerid][pVVeh]);
		PlayerInfo[playerid][pVVeh] = 0;
	    PlayerInfo[playerid][vVModel] = 0;
		PlayerInfo[playerid][vVX] = 0;
		PlayerInfo[playerid][vVY] = 0;
		PlayerInfo[playerid][vVZ] = 0;
		PlayerInfo[playerid][vVA] = 0;
		PlayerInfo[playerid][vVC1] = 0;
		PlayerInfo[playerid][vVC2] = 0;
		SendClientMessage(playerid, COLOR_GREEN, " You have sold your vehicle to the dealership. (75 percent of the original price was paid back)");
        --PlayerCars;
	}
	return 1;
}
Thanks a lot
Reply
#2

if(!IsPlayerInRangeOfPoint(playerid, 5.0, 545.6661,-1292.2437,17.2422)) return SendClientMessage(playerid, COLOR_GREY, "You are not near the vehicles dealership.");

That should work, a radius of 2.0 is fairly small and hopefully that should fix your problem
Reply
#3

Like Harrison said, adjusting the range should work.

A suggestion:
Replace the huge if - else if block with a switch case:
PHP код:
switch (GetVehicleModel(GetPlayerVehicleID(playerid)))
{
    case 
481price 600;
    case 
462446452453454484493468price 4000;
    case 
463471price 6000;
    case 
461price 20000;
    case 
410579price 22000;
    case 
405400576price 24000;
    case 
521536567price 25000;
    case 
533439price 26000;
    case 
535price 27000;
    case 
555price 28000;
    case 
480495412534price 30000;
    case 
575price 35000;

This list is not complete yet, but you get the idea.
Much shorter code and easier to adjust prices (just move the model-id's to another case and you're done).

Or create an array which holds the price for ALL vehicle-models (from model 400 to 611):
PHP код:
new VehiclePrices[212] =
{
    
24000// Model 400
    
0// Model 401 (not listed)
    
70000// Model 402
    
0// Model 403
    
0// Model 404
    
24000// Model 405
...
    
0// Model 610
    
// Model 611 (last item doesn't require a comma behind it)
}; 
And use only 1 line of code to get the price from your vehicle (instead of a huge "if - else if" or even a switch-case block):
PHP код:
price VehiclePrices[GetVehicleModel(GetPlayerVehicleID(playerid)) - 400]; 
Reply
#4

Weell guys, It works like a charm ! Thanks to you I can go forward on my project Rep!
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)