SA-MP Forums Archive
Garage slots - 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: Garage slots (/showthread.php?tid=626526)



Garage slots - James585 - 16.01.2017

Hello I found Vehicle System but if I have two vehicles before and the first to appear first - empty - but I want there to give that player a vehicle .. The thing I do not want to have written - empty - as long as the player does not have 1 or vehicle so the first line can be 'You have no vehicles'.. Thanks

Garage:
Код:
CMD:garage(playerid, params[]){
	new string1[700],string2[100];
	for(new i;i<MAX_PLAYER_CARS;i++){
		if(ID[playerid][i]==-1){
	 		format(string2,100,"{FFFFFF}- empty -\n");
		}else{
	 		format(string2,100,"%s(%i)\n",aVehicleNames[GetVehicleModel(ID[playerid][i])-400], ID[playerid][i]);
		}
	format(string1,256,"%s%s",string1,string2);
	}
	ShowPlayerDialog(playerid,DIALOG_MENU,DIALOG_STYLE_LIST,"Garage",string1,"Select","Close");
return 1;
}

stock CreatePlayerVehicle(playerid,slot,model){
new str[100];
format(str,100,"SAF/Cars/%s.%d.cfg",PlayerName(playerid),slot);
fcreate(str);
new Float:pos[4];
GetPlayerPos(playerid,pos[0],pos[1],pos[2]);
GetPlayerFacingAngle(playerid, pos[3]);
InfrontOf(playerid,pos[0],pos[1],4);
ID[playerid][slot] = CreateVehicle(model,pos[0],pos[1],pos[2],pos[3],0,0,-1);
Model[playerid][slot] = model;
Pos[playerid][slot][0] = pos[0];
Pos[playerid][slot][1] = pos[1];
Pos[playerid][slot][2] = pos[2];
Pos[playerid][slot][3] = pos[3];
return true;
}

stock DeletePlayerVehicle(playerid,slot){
if(ID[playerid][slot] == -1) return 0;
new str[100];
format(str,100,"SAF/Cars/%s.%d.cfg",PlayerName(playerid),slot);
if(fexist(str))
fremove(str);
DestroyVehicle(ID[playerid][slot]);
ID[playerid][slot] = -1;
return true;
}

stock SavePlayerVehicles(playerid){
for(new i; i < MAX_PLAYER_CARS;i++){
if(ID[playerid][i] != -1){
new str[100],bigstr[798],Float:health;
new panels,doors,lights,tires;
GetVehicleDamageStatus(ID[playerid][i],panels,doors,lights,tires);
GetVehicleHealth(ID[playerid][i],health);
format(str,100,"SAF/Cars/%s.%d.cfg",PlayerName(playerid),i);
if(!fexist(str)) continue;
new File:file = fopen(str, io_write);
format(bigstr,798,"%d %0.3f %0.3f %0.3f %0.3f %0.3f %d %d %d %d\r\n",Model[playerid][i],Pos[playerid][i][0],Pos[playerid][i][1],Pos[playerid][i][2],Pos[playerid][i][3],health,panels,doors,lights,tires);
//              model   x     y     z     a   health panels doors lights tires
fwrite(file,bigstr);
format(bigstr,798,"%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d",	GetVehicleComponentInSlot(ID[playerid][i],0),
/*                 1  2  3  4  5  6  7  8  9  10 11 12 13 c1 c2 pj*/	GetVehicleComponentInSlot(ID[playerid][i],1),
																		GetVehicleComponentInSlot(ID[playerid][i],2),
																		GetVehicleComponentInSlot(ID[playerid][i],3),
																		GetVehicleComponentInSlot(ID[playerid][i],4),
																		GetVehicleComponentInSlot(ID[playerid][i],5),
																		GetVehicleComponentInSlot(ID[playerid][i],6),
																		GetVehicleComponentInSlot(ID[playerid][i],7),
																		GetVehicleComponentInSlot(ID[playerid][i],8),
																		GetVehicleComponentInSlot(ID[playerid][i],9),
																		GetVehicleComponentInSlot(ID[playerid][i],10),
																		GetVehicleComponentInSlot(ID[playerid][i],11),
																		GetVehicleComponentInSlot(ID[playerid][i],12),
																		GetVehicleComponentInSlot(ID[playerid][i],13),
																		Color[playerid][i][0],
																		Color[playerid][i][1],
																		Paintjob[playerid][i]);
fwrite(file,bigstr);
fclose(file);
DestroyVehicle(ID[playerid][i]);

ID[playerid][i] = -1;
}
}
}

stock LoadPlayerVehicles(playerid){
for(new i; i < MAX_PLAYER_CARS;i++){
new str[100];
format(str,100,"SAF/Cars/%s.%d.cfg",PlayerName(playerid),i);
if(fexist(str)){
new bigstr[798];
new File:file = fopen(str,io_read);
fread(file,bigstr);
DelChar(bigstr);
new panels,doors,lights,tires;
sscanf(bigstr, "dfffffdddd", Model[playerid][i],Pos[playerid][i][0],Pos[playerid][i][1],Pos[playerid][i][2],Pos[playerid][i][3],Health[playerid][i],panels,doors,lights,tires);
fread(file,bigstr);
DelChar(bigstr);
sscanf(bigstr, "dddddddddddddddd",Mod[playerid][i][0],Mod[playerid][i][1],Mod[playerid][i][2],Mod[playerid][i][3],Mod[playerid][i][4],Mod[playerid][i][5],Mod[playerid][i][6],Mod[playerid][i][7],Mod[playerid][i][8],Mod[playerid][i][9],Mod[playerid][i][10],Mod[playerid][i][11],Mod[playerid][i][12],Mod[playerid][i][13],Color[playerid][i][0],Color[playerid][i][1],Paintjob[playerid][i]);
fclose(file);
ID[playerid][i] = CreateVehicle(Model[playerid][i],Pos[playerid][i][0],Pos[playerid][i][1],Pos[playerid][i][2],Pos[playerid][i][3],Color[playerid][i][0],Color[playerid][i][1],-1);
SetTimerEx("TunePlayerCar",150,false,"iiiiii",playerid,i,panels,doors,lights,tires);
}
}
}


stock BuyCar(playerid,model,cena,type = 1,id = -1){
if(GetMoney(playerid) < cena) return SCM(playerid,-1,"...");
GiveMoney(playerid,-cena);
new slot = -1;
if(type == 1){
slot = GetPVarInt(playerid,"VehiclesSelected");
}else{
for(new i; i < MAX_PLAYER_CARS;i++){
if(ID[playerid][i] == -1){
slot = i;
break;
}
}
}
if(slot == -1) return SCM(playerid,-1,"...");
CreatePlayerVehicle(playerid,slot,model);
return true;
}

public TunePlayerCar(playerid,slot,panels,doors,lights,tires){
//print("TunePlayerCar");
for(new i; i < 14;i++){
AddVehicleComponent(ID[playerid][slot], Mod[playerid][slot][i]);
}
SetVehicleHealth(ID[playerid][slot],Health[playerid][slot]);
UpdateVehicleDamageStatus(ID[playerid][slot],panels,doors,lights,tires);
ChangeVehiclePaintjob(ID[playerid][slot], Paintjob[playerid][slot]);
return true;
}



Re: Garage slots - azzerking - 16.01.2017

First: Do you actually expect us to help you when your code looks like that? I mean its unreadable and improperly indented, properly from the copy and paste, but you could of put a few extra seconds into making it readable for us.

Second: I have absolutely no idea what your trying to achieve here? Your grammar is pretty poor. I am struggling to understand what it is your trying to tell us? Maybe someone else can, but I certainly can't.


Re: Garage slots - James585 - 16.01.2017

Grammar is thus possible that the texts are copied with ****** translate because I'm not an Englishman or an American. I do not know English as well as you who have it in native language.

I need it when I have the 3 vehicle to be first so that it is not - empty - on the first line but last to empty slots implying for the last, and the first vehicles ..


Re: Garage slots - azzerking - 16.01.2017

So if I understand you.

You want the vehicles to be displayed in order of existing?

So it all cases, it ends up like this


- Vehicle (999) -
- Vehicle (200) -
- Vehicle (320) -
- Empty -
- Empty -


So - Empty - is always at the end of the list?


Re: Garage slots - James585 - 17.01.2017

Yes.. Please send me code


Re: Garage slots - X337 - 17.01.2017

Код:
CMD:garage(playerid, params[])
{
	new 
		i, 
		string[256]
	;
	for(i; i < MAX_PLAYER_CARS; i++) // loop
	{
		if(ID[playerid][i] == -1) // if player doesn't have car in this slot, skip it
			continue;

		format(string, 256, "%s%s(%i)\n", string, aVehicleNames[GetVehicleModel(ID[playerid][i])-400], ID[playerid][i]);
	}
	for(i; i < MAX_PLAYER_CARS; i++) // loop to make the rest of slots - empty -
	{
		strcat(string, "- empty -\n");
	}
	ShowPlayerDialog(playerid, DIALOG_MENU, DIALOG_STYLE_LIST, "Garage", string1, "Select", "Close");
	return 1;
}
However, in your DIALOG_MENU dialog response should be changed too...
Example:
Код:
OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	switch(dialogid)
	{
		// ...
		case DIALOG_MENU:
		{
			if(response)
			{
				new slot;
				for(new i; i < MAX_PLAYER_CARS; i++)
				{
					if(ID[playerid][i] == -1) // if player doesn't have car in this slot, skip it
						continue;

					if(listitem == slot)
					{
						// code if player selected vehicle slot 'slot'
						return 1;
					}
					slot++;
				}
				// code if player selected - empty - slot
			}
		}
		// ...
	}
}



Re: Garage slots - James585 - 17.01.2017

Thank you very much but

Код:
warning 215: expression has no effect
warning 215: expression has no effect
Код:
for(i; i < MAX_PLAYER_CARS; i++) // loop
for(i; i < MAX_PLAYER_CARS; i++) // loop to make the rest of slots - empty -



Re: Garage slots - X337 - 17.01.2017

Sorry, that's a mistake.
Replace them with this:
Код:
for(; i < MAX_PLAYER_CARS; i++) // loop
for(; i < MAX_PLAYER_CARS; i++) // loop to make the rest of slots - empty -



Re: Garage slots - James585 - 17.01.2017

does not work Please send a link to a simple Vehicle System with saving DOF2 or file.inc and easily add / delete player's car where you can use the command / garage (no plugins or dynamic) please