SA-MP Forums Archive
Vehicle ownership. - 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: Vehicle ownership. (/showthread.php?tid=399413)



Vehicle ownership. - eFlex - 14.12.2012

Hi everybody, i have a little problem. i just convert another person script to my own.(vehicle ownership system). but now then i enter to the car i cant get the message. Maybe i know where is the problem can you help me?

Look:

first we have array

Code:
new Buylist[][ahModel] = {
	{"'93 Mazda 929",2,551,-1,16000,2500,-2124.7522,-920.2127,31.7855,90.8669},//naujos merit
	{"'90 Mercedes-Benz 300c",1,533,-1,12000,3000,-2135.0916,-773.1703,31.7398,272.2505},//oky  feltzer
	{"'69 Jaguar E-Type",2,555,-1,30000,8000,-2148.7935,-791.5977,31.7400,80.3108},//oky windsor
	{"'65 Chevy Impala",3,536,-1,40000,10000,-2149.7070,-862.9374,31.7398,87.5111},//oky blade
	{"'61 Harley Davidson",4,586,-1,28000,8000,-2133.1375,-875.1807,31.7398,93.8477},//oky freeway
	{"'97 Honda Accord Universalas",5,561,-1,20000,8000,-2148.6738,-892.2283,31.7400,85.2190},//okystratum
	{"'60 Chevy Corvair",6,549,-1,5000,500,-2147.8169,-914.1721,31.7396,87.5486},//oky tampa
	{"'92 Honda Civic",7,565,-1,50000,10000,-2134.5444,-922.9490,31.7396,99.5995},//oky flash
	{"'83 Range Rover",6,579,-1,25000,5000,-2148.3333,-935.1721,31.7395,90.3452},//oky huntley
	{"'76 Mrcedes-BenzW123",5,445,-1,15000,4500,-2134.5964,-947.2864,31.7398,91.5294},//oky admiral
	{"'75 Oldsmobile Cutclass",4,439,-1,15000,4500,-2148.9180,-953.3674,31.7401,87.6122},//oky stallion
	{"'80 Pontiac Safari",3,479,-1,10000,2200,-2149.4507,-965.1276,31.7401,267.8426},//oky regina
	{"'92 Nissan Skyline R32",2,562,-1,80000,25000,-2134.0403,-964.7849,31.7398,269.9281},//oky elegy
	{"'00 Honda CR125",1,468,-1,18000,4000,-2124.5525,-793.6357,31.8368,86.7720},//oky sanchez
	{"'93 Ford Thunderbird",0,526,-1,10000,2000,-2125.7090,-888.8859,31.8372,87.9612},//oky fortune
	{"'90 Subaru Impreza",1,560,-1,80000,30000,-2134.7397,-885.5211,31.8361,90.5818},//oky sultan
	{"'89 Pontiac Boneville",2,550,-1,40000,10000,-2124.8137,-875.9531,31.7515,84.5394},//oky sunrise
	{"'85 Toyota Corolla AE86",3,496,-1,60000,15000,-2125.5286,-941.5941,31.7487,262.5145},//oky blista
	{"'87 Ford Taurus Universalas",4,458,-1,18000,4700,-2134.0952,-935.0886,31.7490,269.8785},//oky solair
	{"'93 Dodge Viper GTS",5,429,-1,53000,7500,-2133.5522,-821.3208,31.9020,91.2664},//oky banshee
	{"'88 Kawasaki Ninja",6,522,-1,120000,25000,-2124.6973,-828.1970,31.7289,87.6375},//oky NRG
	{"'84 Chevrolet Camaro",7,402,-1,80000,20000,-2124.7949,-965.2316,31.7271,90.8724},//oky buffalo
	{"'04 Ford GT",6,541,-1,100000,30000,-2134.1665,-959.2578,31.8552,90.9235},//oky bullet
	{"'93 Ferrari 512",5,415,-1,50000,12500,-2133.2583,-929.2598,31.8548,90.8708},//oky cheetah
	{"'92 Honda NSX",2,411,-1,148000,40000,-2124.6711,-775.7874,31.7901,87.6297},//oky infernus
	{"'86 Dodge Ram Van",1,482,-1,10000,2600,-2150.0134,-879.0632,31.9588,91.1483},//oky burrito
	{"'80 Pontiac Firebird",0,603,-1,20000,5000,-2133.5720,-892.1269,31.9477,272.5138},//oky phoenix
	{"'90 Lotus Esprit",1,506,-1,59500,18000,-2149.2234,-944.0571,31.7610,90.4159},//oky super gt
	{"'91 Ferrari F40",2,451,-1,90000,27000,-2149.7764,-772.5632,31.8783,90.2903},//oky turismo
	{"'87 Ford Tempo",3,410,-1,999,99,-2149.4680,-841.0437,31.8783,90.4016},//oky manana
	{"'89 Chevrolet Blazer",4,489,-1,17000,4700,-2149.6003,-923.1365,31.8783,89.1061},//oky rancher
	{"'85 Honda Prelude",5,436,-1,15000,3500,-2148.0862,-799.6622,32.1363,90.7906},//oky previon
	{"'89 Vauxhall Cavalier",6,527,-1,12000,1200,-2149.5142,-844.7898,32.3985,90.3956},//oky cadrona
	{"'70 Porsche 911",2,480,-1,45000,14321,-2124.7800,-950.1567,31.7980,90.0225},//naujos comet
	{"'90 Eagle Talon",2,558,-1,25000,7000,-2134.1558,-905.0515,31.6539,270.3837},//naujos uranus
	{"'65 Chevy Nova Universalas",2,404,-1,15000,1500,-2148.6953,-766.4816,31.7586,270.1725},//naujos perenial
	{"'97 Chevy Astro",2,418,-1,20000,1500,-2133.7063,-834.2076,32.1168,91.1281},//naujos moonbeam
	{"'80 Buick Lesabre",2,546,-1,16000,2600,-2125.2725,-799.6155,31.7478,269.3737},//naujos intruder
	{"'94 Infiniti Q45",2,585,-1,20000,3700,-2133.7720,-840.8123,31.6083,89.4620},//naujos emperor
	{"'67 VW Bus",2,483,-1,28000,5800,-2148.7061,-811.7426,32.0200,268.9229},//naujos camper
	{"'93 Mazda RX-7",2,477,-1,72000,20000,-2133.8762,-757.5200,31.7767,268.8975}//naujos zr-350
	
};
then, function that tell us is car where tou are sitting is on sale.

Code:
IsAutohausCar(carid)
{
	new g;
	for(g=0; g<sizeof(Buylist); g++)
	{
	    if(Buylist[g][Carid]==carid) { return g; }
	}
	return -1;
}
this function get Carid from array, and check it, but car id in array equal "-1".

and last function just vehicle function

Code:
stock Vehicle(model,Float:x,Float:y,Float:z,Float:a,color,color2)
{
	AddStaticVehicleEx(model,x,y,z,a,color,color2,172800);
	maxvehicles++;

	vehicleDB[maxvehicles][gas]=random(aEda[model-400]);
	if(IsTurgus(x,y)) vehicleDB[maxvehicles][parduodama]=false; else vehicleDB[maxvehicles][parduodama]=true;

	return maxvehicles;
}
i wrote code on player state change:


Code:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
 if(oldstate == PLAYER_STATE_DRIVER)
 {
     GameTextForPlayer(playerid," ",100,5);
 }
  if(newstate == PLAYER_STATE_DRIVER)
 {
        new vehicleid = GetPlayerVehicleID(playerid);
 		new typ;
		typ=IsAutohausCar(vehicleid);
		if(typ!=-1)
		{
		    new string[135];
		    TogglePlayerControllable(playerid,0);
		    Spectating[playerid][0]=typ;
		    SetVehicleParamsForAll(vehicleid,0,1);
			format(string,sizeof(string),"{FFFFFF}Pavadinimas: {88EE00}%s\n{FFFFFF}Kaina: {FF2200}%iLT\n{555588}NORITE PIRKTI?",Buylist[typ][Name],Buylist[typ][Price],Buylist[typ][Repair]);
			ShowPlayerDialog(playerid,4459,DIALOG_STYLE_MSGBOX,"{555588}-=Auto turgus=-",string,"Taip","Ne");
		    SetTimerEx("removcar",8000,0,"i",playerid);

		  /*  new msg[256];
			format(msg,sizeof(msg),"~n~ ~r~Modelis:~y~ %s ~n~~r~Kaina: ~y~%i LT~n~~r~Remonto kaina:~y~ %i LT~n~Isigijimui rasykite ~w~/buycar~n~~r~Islipimui rasykite ~w~/exitcar",Buylist[typ][Name],Buylist[typ][Price],Buylist[typ][Repair]);
  			GameTextForPlayer(playerid,msg,30000,3);*/
//==============================================================================
//masinosxxx
//==============================================================================
		}
		}
		return 1;
}
please help me.


Re: Vehicle ownership. - maramizo - 14.12.2012

You have to get the vehicle IDs AFTER you spawn the vehicles, let me help you.
pawn Code:
new autohauscars[41];

//Where you spawn the vehicles:
autohauscars[0] = CreateVehicle(//first vehicle)
autohauscars[1] = CreateVehicle(//second vehicle, etc.)
//Until autohauscars[41] = CreateVehicle(.

IsAutohausCar(carid)
{
    new g;
    for(g=0; g<41; g++)
    {
        if(autohauscars[g] == carid) return g;
    }
    return -1;
}
This code should work perfectly if you edit the CreateVehicles as I told you to.


Re: Vehicle ownership. - eFlex - 14.12.2012

Thanks for help, but in original script i dont need to do that...


i just place this Vehicle(533,-2124.3210,-932.2147,32.1158,90.0949,62,1); // car 1

and i'm creating a VehicleDatabase, it held jobs cars, private cars.

and you know i want to spawn a lot of vehicles, not just 41.


Re: Vehicle ownership. - maramizo - 14.12.2012

41 Is the amount of vehicles in your Autohauscars array.
You have to store the vehicle ID's AS THEY SPAWN in the variable I gave you -to be able to know their ID- then check with the variable.


Re: Vehicle ownership. - eFlex - 14.12.2012

+Rep for help, you are my hero.