SA-MP Forums Archive
Why doesn't this work? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Why doesn't this work? (/showthread.php?tid=203078)



Why doesn't this work? - Anteino - 26.12.2010

Hi,

I'm working on a very detailed vehicle buy script. But somehow it seems to get in trouble when I add the function:
Код:
if(GetPlayerMoney(playerid) < CarArray[carid]){
			SendClientMessage(playerid, COLOR_WHITE, "You can't afford this vehicle.");
			return 1;
		}
This just stops the whole thing from working.. :S When I cut that part out, cars will allways spawn, but unfortunately there won't be checked if the player has enough money so he could buy vehicles unlimited..

Here is the whole code:
Код:
#include <a_samp>
#include "../include/gl_common.inc"
#include <string>
#include <float>

#define FILTERSCRIPT

#define COLOR_WHITE 0xFFFFFFFF
#define ADMINFS_MESSAGE_COLOR 0xFF444499

new carid = -1;
new CarArray[208];

main(){
	CarArray[0] = 20000;
	CarArray[1] = 25000;
	CarArray[2] = 45000;
	CarArray[3] = 35000;
	CarArray[4] = 15000;
	CarArray[5] = 18500;
	CarArray[7] = 50000;
	CarArray[9] = 80000;
	CarArray[10] = 22500;
	CarArray[11] = 250000;
	CarArray[12] = 40000;
	CarArray[13] = 30000;
	CarArray[14] = 35500;
	CarArray[15] = 500000;
	CarArray[18] = 35000;
	CarArray[19] = 28500;
	CarArray[20] = 50000;
	CarArray[21] = 30000;
	CarArray[22] = 25000;
	CarArray[24] = 60000;
	CarArray[26] = 23000;
	CarArray[28] = 50000;
	CarArray[29] = 150000;
	CarArray[30] = 500000;
	CarArray[31] = 150000;
	CarArray[33] = 70000;
	CarArray[34] = 450000;
	CarArray[36] = 15000;
	CarArray[37] = 175000;
	CarArray[38] = 48000;
	CarArray[39] = 20000;
	CarArray[40] = 35000;
	CarArray[42] = 50000;
	CarArray[43] = 80000;
	CarArray[45] = 25000;
	CarArray[46] = 600000;
	CarArray[47] = 5000000;
	CarArray[48] = 3750;
	CarArray[51] = 375000;
	CarArray[52] = 550000;
	CarArray[53] = 500000;
	CarArray[54] = 500000;
	CarArray[55] = 72000;
	CarArray[56] = 60000;
	CarArray[57] = 50000;
	CarArray[58] = 40000;
	CarArray[60] = 2000000;
	CarArray[61] = 150000;
	CarArray[62] = 3600;
	CarArray[63] = 120000;
	CarArray[64] = 50000;
	CarArray[66] = 36000;
	CarArray[67] = 35000;
	CarArray[68] = 8750;
	CarArray[69] = 1000000;
	CarArray[70] = 100000;
	CarArray[71] = 11000;
	CarArray[72] = 700000;
	CarArray[73] = 6500;
	CarArray[74] = 400000;
	CarArray[75] = 78000;
	CarArray[76] = 2000000;
	CarArray[77] = 450000;
	CarArray[78] = 20000;
	CarArray[79] = 25000;
	CarArray[80] = 80000;
	CarArray[81] = 260;
	CarArray[82] = 45000;
	CarArray[83] = 31000;
	CarArray[84] = 23000;
	CarArray[86] = 80000;
	CarArray[87] = 8000000;
	CarArray[89] = 30000;
	CarArray[91] = 25000;
	CarArray[92] = 38000;
	CarArray[93] = 800000;
	CarArray[95] = 150000;
	CarArray[96] = 35000;
	CarArray[98] = 50000;
	CarArray[99] = 50000;
	CarArray[100] = 45000;
	CarArray[102] = 200000;
	CarArray[104] = 45000;
	CarArray[106] = 225000;
	CarArray[107] = 40000;
	CarArray[108] = 35000;
	CarArray[109] = 380;
	CarArray[110] = 800;
	CarArray[111] = 1500000;
	CarArray[112] = 2500000;
	CarArray[113] = 5000000;
	CarArray[114] = 80000;
	CarArray[115] = 85000;
	CarArray[116] = 35000;
	CarArray[117] = 30000;
	CarArray[118] = 40000;
	CarArray[119] = 10000000;
	CarArray[120] = 50000000;
	CarArray[121] = 275000;
	CarArray[122] = 300000;
	CarArray[125] = 150000;
	CarArray[126] = 15000;
	CarArray[127] = 14000;
	CarArray[129] = 20000;
	CarArray[131] = 30000;
	CarArray[132] = 100000;
	CarArray[133] = 15000;
	CarArray[134] = 25000;
	CarArray[135] = 500000;
	CarArray[136] = 28000;
	CarArray[140] = 41000;
	CarArray[141] = 480000;
	CarArray[142] = 10000;
	CarArray[143] = 25000;
	CarArray[145] = 75000;
	CarArray[146] = 50000;
	CarArray[147] = 45000;
	CarArray[148] = 12000000;
	CarArray[149] = 17000;
	CarArray[150] = 45000;
	CarArray[151] = 35000;
	CarArray[152] = 60000;
	CarArray[153] = 25000000;
	CarArray[154] = 50000;
	CarArray[155] = 100000;
	CarArray[156] = 500000;
	CarArray[158] = 35000;
	CarArray[159] = 90000;
	CarArray[160] = 150000;
	CarArray[161] = 57000;
	CarArray[162] = 80000;
	CarArray[163] = 18000000;
	CarArray[165] = 200000;
	CarArray[166] = 60000;
	CarArray[167] = 50000;
	CarArray[168] = 6500;
	CarArray[172] = 100000;
	CarArray[173] = 100000;
	CarArray[174] = 70000;
	CarArray[175] = 65000;
	CarArray[176] = 50000;
	CarArray[177] = 30000000;
	CarArray[178] = 120000;
	CarArray[179] = 67000;
	CarArray[180] = 50000;
	CarArray[181] = 135000;
	CarArray[182] = 500000;
	CarArray[183] = 80000;
	CarArray[185] = 40000;
	CarArray[186] = 50000;
	CarArray[187] = 250000;
	CarArray[188] = 75000;
	CarArray[189] = 90000;
	CarArray[192] = 35000000;
	CarArray[193] = 6000000;
	CarArray[195] = 450000;
	CarArray[200] = 20000;
	CarArray[202] = 150000;
	CarArray[203] = 250000;
	CarArray[207] = 10000;

}

public OnPlayerCommandText(playerid, cmdtext[])
{
	new idx;
	new cmd[256];

	cmd = strtok(cmdtext, idx);

	if(strcmp("/buyvehicle", cmd, false) == 0)
	{
		ShowPlayerDialog(playerid, 0, 2, "Category", "Airplane\nBike\nBoat\nConvertible\nHelicopter\nIndustrial\nOff road\nPublic service\nSaloon (Admiral - Merit)\nSaloon (Nebula - Willard)\nSport\nStation wagon", "Choose", "Cancel");
		return 1;
	}

	return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]){
	if(response){
	    switch(dialogid){
			case 0:{
				switch(listitem){
					case 0:{
                        ShowPlayerDialog(playerid, 1, 2, "Airplane", "AT400 (30,000,000)\nBeagle (1,500,000)\nCropduster (2,500,000)\nDodo (6,000,000)\nHydra (50,000,000)\nNevada (25,000,000)\nRustler (2,000,000)\nShamal (10,000,000)\nSkimmer (2,000,000)\nStuntplane (5,000,000)", "Purchase", "Cancel");
					}
					case 1:{
                        ShowPlayerDialog(playerid, 2, 2, "Bike", "Beach Cruiser (380)\nBF-400 (135,000)\nBMX (260)\nFaggio (3,600)\nFCR-900 (275,000)\nFreeway (120,000)\nMountain Bike (800)\nNRG-500 (300,000)\nPCJ-600 (150,000)\nPizzaboy (3750)\nQuad (11,000)\nSanchez (8,750)\nWayfarer (50,000)", "Purchase", "Cancel");
					}
					case 2:{
                        ShowPlayerDialog(playerid, 3, 2, "Boat", "Coastguard (700,000)\nDinghy (6,500)\nJetmax (800,000)\nLaunch (450,000)\nMarquis (23,000)\nPredator (500,000)\nReefer (500,000)\nSpeeder (550,000)\nSquallo (600,000)\nTropic (500,000)", "Purchase", "Cancel");
					}
					case 3:{
                        ShowPlayerDialog(playerid, 4, 2, "Convertible", "Comet (80,000)\nFeltzer (15,000)\nStallion (20,000)\nWindsor (100,000)", "Purchase", "Cancel");
					}
					case 4:{
                        ShowPlayerDialog(playerid, 5, 2, "Helicopter", "Cargobob (12,000,000)\nMaverick (8,000,000)\nRaindance (18,00,000)\nSeasparrow (5,000,000)\nSparrow (1,000,000)", "Purchase", "Cancel");
					}
					case 5:{
                        ShowPlayerDialog(playerid, 6, 2, "Industrial", "Benson (50,000)\nBobcat (25,000)\nBoxville (50,000)\nBurrito (45,000)\nDFT-30 (120,000)\nFlatbed (72,000)\nLinerunner (35,000)\nMule (35,500)\nNewsvan (500,000)\nPacker (80,000)\nPicador (20,000)\nPony (30,000)\nRoadtrain (85,000)\nRumpo (35,000)\nSadler (25,000)\nTanker (80,000)\nTractor (30,000)\nUtilityvan (60,000)\nWalton (20,000)\nYankee (60,000)\nYosemite (50,000)", "Purchase", "Cancel");
					}
					case 6:{
                        ShowPlayerDialog(playerid, 7, 2, "Off road", "Bandito (6,500)\nBF Injection (60,000)\nDune (100,000)\nHuntley (67,000)\nLandstalker (20,000)\nMesa (45,000)\nMonstertruck (500,000)\nPatriot (100,000)\nRancher (30,000)\nSandking (150,000)", "Purchase", "Cancel");
					}
					case 7:{
                        ShowPlayerDialog(playerid, 8, 2, "Public Service", "Barracks (70,000)\nBus (150,000)\nCabbie (48,000)\nCoach (175,000)\nTaxi (50,000)", "Purchase", "Cancel");
					}
					case 8:{
						ShowPlayerDialog(playerid, 8, 2, "Saloon (Admiral - Merit)", "Admiral (25,000)\nBloodring banger (45,000)\nBravura (25,000)\nBuccaneer (40,000)\nCadrona (14,000)\nClover (10,000)\nElegant (40,000)\nElegy (80,000)\nEmperor (40,000)\nEsperanto (28,500)\nFortune (15,000)\nGlendale (36,000)\nGreenwood (38,000)\nHermes (40,000)\nHustler (75,000)\nIntruder (50,000)\nMajestic (30,000)\nManana (22,500)\nMerit (35,000)", "Purchase", "Cancel");
					}
					case 9:{
                        ShowPlayerDialog(playerid, 9, 2, "Saloon (Nebula - Willard)", "Nebula (35,000)\nOceanic (35,000)\nPremier (23,000)\nPrevion (15,000)\nPrimo (45,000)\nSentinel (18,500)\nStafford (50,000)\nSultan (150,000)\nSunrise (45,000)\nTampa (17,000)\nVincent (41,000)\nVirgo (25,000)\nWashington (30,000)\nWillard (20,000)", "Purchase", "Cancel");
					}
					case 10:{
						ShowPlayerDialog(playerid, 10, 2, "Sport", "Alpha (150,000)\nBanshee (150,000)\nBlista Compact (35,000)\nBuffalo (45,000)\nBullet (480,000)\nCheetah (500,000)\nClub (90,000)\nEuros (250,000)\nFlash (200,000)\nHotring racer (200,000)\nInfernus (250,000)\nJester (90,000)\nPhoenix (250,000)\nSabre (78,000)\nSuper GT (225,000)\nTurismo (375,000)\nUranus (35,000)\nZR-350 (450,000)", "Purchase", "Cancel");
					}
					case 11:{
						ShowPlayerDialog(playerid, 11, 2, "Station wagon", "Moonbeam (35,000)\nPerenniel (15,000)\nRegina (25,000)\nSolair (40,000)\nStratum (57,000)", "Purchase", "Cancel");
					}

				}
			}
			case 1:{
			    switch(listitem){
			        case 0:{
						carid = 177;
			        }
			        case 1:{
						carid = 111;
			        }
			        case 2:{
						carid = 112;
			        }
			        case 3:{
						carid = 193;
			        }
			        case 4:{
						carid = 120;
			        }
			        case 5:{
						carid = 153;
			        }
			        case 6:{
						carid = 76;
			        }
			        case 7:{
						carid = 119;
			        }
			        case 8:{
						carid = 160;
			        }
			        case 9:{
						carid = 113;
			        }
				}
			}
			case 2:{
			   switch(listitem){
			   		case 0:{
			            carid = 109;
			        }
			        case 1:{
			            carid = 181;
			        }
			        case 2:{
			            carid = 81;
			        }
			        case 3:{
			            carid = 62;
			        }
					case 4:{
						carid = 121;
					}
			        case 5:{
			            carid = 63;
			        }
			        case 6:{
			            carid = 110;
			        }
			        case 7:{
			            carid = 122;
			        }
			        case 8:{
			            carid = 61;
			        }
			        case 9:{
			            carid = 48;
			        }
			        case 10:{
			            carid = 71;
			        }
			        case 11:{
			            carid = 68;
			        }
			        case 12:{
			            carid = 186;
			        }
			   }
			}
			case 3:{
			   switch(listitem){
			   		case 0:{
			            carid = 72;
			        }
			        case 1:{
			            carid = 73;
			        }
			        case 2:{
			            carid = 93;
			        }
			        case 3:{
			            carid = 195;
			        }
					case 4:{
						carid = 84;
					}
			        case 5:{
			            carid = 30;
			        }
			        case 6:{
			            carid = 53;
			        }
			        case 7:{
			            carid = 52;
			        }
			        case 8:{
			            carid = 46;
			        }
			        case 9:{
			            carid = 54;
			        }
			   }
			}
		}
		if(GetPlayerMoney(playerid) < CarArray[carid]){
			SendClientMessage(playerid, COLOR_WHITE, "You can't afford this vehicle.");
			return 1;
		}
		new Float:X,Float:Y,Float:Z,Float:Angle,Float:pi=3.141592654,Money;
		GetPlayerFacingAngle(playerid, Angle);
		GetPlayerPos(playerid, X, Y, Z);
		new Float:rAngle = (Angle/180)*pi;
		X = X + 1.58113884*floatcos(rAngle, radian);
		Y = Y + 1.58113884*floatsin(rAngle, radian);
		Money = -GetPlayerMoney(playerid);
		GivePlayerMoney(playerid, Money);
		AddStaticVehicle(carid + 400, X, Y, Z, Angle, 0, 1);
		carid = -401;
	}
	return 1;
}
Please tell me how this can be :S?


Re: Why doesn't this work? - Haydz - 26.12.2010

pawn Код:
if(GetPlayerMoney(playerid) < CarArray[carid]) return SendClientMessage(playerid, color, "You can't afford this!");
Try this.


Re: Why doesn't this work? - Anteino - 26.12.2010

Well, I still can afford planes of 50,000,000 with my start money of 100,000 :S


Re: Why doesn't this work? - Anteino - 26.12.2010

Anybody?


Re: Why doesn't this work? - randomkid88 - 26.12.2010

Try returning 0 instead of 1.
pawn Код:
if(GetPlayerMoney(playerid) < CarArray[carid])
{
     SendClientMessage(playerid, color, "You can't afford this!");
     return  0;
}



Re: Why doesn't this work? - [WF]Demon - 26.12.2010

or you could just do this
pawn Код:
if(GetPlayerMoney(playerid) < CarArray[carid])  return SendClientMessage(playerid, color, "You can't afford this!");



Re: Why doesn't this work? - JamesC - 26.12.2010

Quote:
Originally Posted by Crodox RP
Посмотреть сообщение
or you could just do this
pawn Код:
if(GetPlayerMoney(playerid) < CarArray[carid])  return SendClientMessage(playerid, color, "You can't afford this!");
Please read other posts before you post some useless solution that the OP has already tried.


OP: This could be caused by someone else executing the command at the same time, and buying a cheaper vehicle. Because carid is a variable rather than an array it can get mixed up when another player tries to get a vehicle at the same time as you.

Solution: new carid[ MAX_PLAYERS ]; Then use carid[ playerid ];


Re: Why doesn't this work? - Anteino - 26.12.2010

Well I'm trying it offline so that couldn't be the problem..
And I read other posts but I don't seem to figure out what the problem is. And I allready tried everything posted above without result. But thanks for your advice JamesC it will sure be an improvement


Re: Why doesn't this work? - JamesC - 26.12.2010

Right, I just realized that this is going to be a filterscript. main() isn't called in filterscripts therefore all of the cells in your array are equal to 0. Use OnFilterscriptInit instead of main() to fix this.


Re: Why doesn't this work? - Babul - 26.12.2010

replace
Код:
main(){
with
Код:
public OnFilterScriptInit(){
edit: lol 2 right answers @ same time. i bet a cookie that it will work ^^