SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 29/05/2019, 05:48 PM   #1
teresgezer
Little Clucker
 
Join Date: Nov 2018
Posts: 10
Reputation: 0
Default Vehicles don't destroy itself after user disconnect (I'm making a vehicle system using Y/ini)

Am I doing something wrong? I don't really get what is my mistake here. Here's the code:

OnPlayerSpawn:
Code:
public OnPlayerSpawn(playerid)
{
    if(fexist(VehPath(playerid,1)))
    {
        VehNum = 1;
        INI_ParseFile(VehPath(playerid,1), "LoadVehicle_%s", .bExtra = true, .extra = playerid);
        if(VehicleInfo1[playerid][VehicleOwned] == true) {
        	new VehicleID,Float:VehPosX,Float:VehPosY,Float:VehPosZ,Float:VehZAngle,VehCol1,VehCol2;
        	VehicleID = VehicleInfo1[playerid][CarID];
        	VehPosX = VehicleInfo1[playerid][CarPosX];
        	VehPosY = VehicleInfo1[playerid][CarPosY];
        	VehPosZ = VehicleInfo1[playerid][CarPosZ];
        	VehZAngle = VehicleInfo1[playerid][CarZAngle];
        	VehCol1 = VehicleInfo1[playerid][CarCol1];
        	VehCol2 = VehicleInfo1[playerid][CarCol2];
        	
			VehicleInfo1[playerid][Car] = CreateVehicle(VehicleID,VehPosX,VehPosY,VehPosZ,VehZAngle,VehCol1,VehCol2,-1,0);
			
			new INI:File1 = INI_Open(VehPath(playerid,1));
			INI_SetTag(File1,"data");
			INI_WriteBool(File1,"VehicleOwned",VehicleInfo1[playerid][VehicleOwned]);
 			INI_WriteInt(File1,"CarID",VehicleInfo1[playerid][CarID]);
 			INI_WriteInt(File1,"Car",VehicleInfo1[playerid][Car]);
	 		INI_WriteFloat(File1,"CarPosX",VehicleInfo1[playerid][CarPosX]);
	 		INI_WriteFloat(File1,"CarPosY",VehicleInfo1[playerid][CarPosY]);
	 		INI_WriteFloat(File1,"CarPosZ",VehicleInfo1[playerid][CarPosZ]);
	 		INI_WriteFloat(File1,"CarZAngle",VehicleInfo1[playerid][CarZAngle]);
	 		INI_WriteInt(File1,"CarCol1",VehicleInfo1[playerid][CarCol1]);
	 		INI_WriteInt(File1,"CarCol2",VehicleInfo1[playerid][CarCol2]);
	 		INI_Close(File1);
	 		
			if(VehicleInfo1[playerid][Car] != INVALID_VEHICLE_ID) {printf("Spawned car ID:%i,Pos:X:%f,Y:%f,Z:%f, successfuly",VehicleID,VehPosX,VehPosY,VehPosZ);}
		}
    } else {
        new INI:File1 = INI_Open(VehPath(playerid, 1));
        INI_SetTag(File1,"data");
        INI_WriteBool(File1,"VehicleOwned",false);
        INI_WriteInt(File1,"CarID",0);
        INI_WriteFloat(File1,"CarPosX",0);
        INI_WriteFloat(File1,"CarPosY",0);
        INI_WriteFloat(File1,"CarPosZ",0);
        INI_WriteFloat(File1,"CarZAngle",0);
        INI_WriteInt(File1,"CarCol1",0);
        INI_WriteInt(File1,"CarCol2",0);
        INI_Close(File1);
    }
    
    if(fexist(VehPath(playerid,2)))
    {
        VehNum = 2;
        INI_ParseFile(VehPath(playerid,2), "LoadVehicle_%s", .bExtra = true, .extra = playerid);
        if(VehicleInfo2[playerid][VehicleOwned] == true) {
        	new VehicleID,Float:VehPosX,Float:VehPosY,Float:VehPosZ,Float:VehZAngle,VehCol1,VehCol2;
        	VehicleID = VehicleInfo2[playerid][CarID];
        	VehPosX = VehicleInfo2[playerid][CarPosX];
        	VehPosY = VehicleInfo2[playerid][CarPosY];
        	VehPosZ = VehicleInfo2[playerid][CarPosZ];
        	VehZAngle = VehicleInfo2[playerid][CarZAngle];
        	VehCol1 = VehicleInfo2[playerid][CarCol1];
        	VehCol2 = VehicleInfo2[playerid][CarCol2];
			VehicleInfo2[playerid][Car] = CreateVehicle(VehicleID,VehPosX,VehPosY,VehPosZ,VehZAngle,VehCol1,VehCol2,-1,0);
			if(VehicleInfo2[playerid][Car] != INVALID_VEHICLE_ID) {printf("Spawned car ID:%i,Pos:X:%f,Y:%f,Z:%f, successfuly",VehicleID,VehPosX,VehPosY,VehPosZ);}
		}
	} else {
        new INI:File2 = INI_Open(VehPath(playerid, 2));
        INI_SetTag(File2,"data");
        INI_WriteBool(File2,"VehicleOwned",false);
        INI_WriteInt(File2,"CarID",0);
        INI_WriteFloat(File2,"CarPosX",0);
        INI_WriteFloat(File2,"CarPosY",0);
        INI_WriteFloat(File2,"CarPosZ",0);
        INI_WriteFloat(File2,"CarZAngle",0);
        INI_WriteInt(File2,"CarCol1",0);
        INI_WriteInt(File2,"CarCol2",0);
        INI_Close(File2);
    }
    
    if(fexist(VehPath(playerid,3)))
    {
        VehNum = 3;
        INI_ParseFile(VehPath(playerid,3), "LoadVehicle_%s", .bExtra = true, .extra = playerid);
        if(VehicleInfo3[playerid][VehicleOwned] == true) {
        	new VehicleID,Float:VehPosX,Float:VehPosY,Float:VehPosZ,Float:VehZAngle,VehCol1,VehCol2;
        	VehicleID = VehicleInfo3[playerid][CarID];
        	VehPosX = VehicleInfo3[playerid][CarPosX];
        	VehPosY = VehicleInfo3[playerid][CarPosY];
        	VehPosZ = VehicleInfo3[playerid][CarPosZ];
        	VehZAngle = VehicleInfo3[playerid][CarZAngle];
        	VehCol1 = VehicleInfo3[playerid][CarCol1];
        	VehCol2 = VehicleInfo3[playerid][CarCol2];
			VehicleInfo3[playerid][Car] = CreateVehicle(VehicleID,VehPosX,VehPosY,VehPosZ,VehZAngle,VehCol1,VehCol2,-1,0);
			if(VehicleInfo3[playerid][Car] != INVALID_VEHICLE_ID) {printf("Spawned car ID:%i,Pos:X:%f,Y:%f,Z:%f, successfuly",VehicleID,VehPosX,VehPosY,VehPosZ);}
		}
	} else {
        new INI:File3 = INI_Open(VehPath(playerid, 3));
        INI_SetTag(File3,"data");
        INI_WriteBool(File3,"VehicleOwned",false);
        INI_WriteInt(File3,"CarID",0);
        INI_WriteFloat(File3,"CarPosX",0);
        INI_WriteFloat(File3,"CarPosY",0);
        INI_WriteFloat(File3,"CarPosZ",0);
        INI_WriteFloat(File3,"CarZAngle",0);
        INI_WriteInt(File3,"CarCol1",0);
        INI_WriteInt(File3,"CarCol2",0);
        INI_Close(File3);
    }
	return 1;
}
OnPlayerDisconnect:
Code:
public OnPlayerDisconnect(playerid, reason)
{
	new Float:PosX1,
		Float:PosY1,
		Float:PosZ1,
		Float:ZAngle1;

	new	Float:PosX2,
		Float:PosY2,
		Float:PosZ2,
		Float:ZAngle2;
		
	new	Float:PosX3,
		Float:PosY3,
		Float:PosZ3,
		Float:ZAngle3;
		
	GetVehiclePos(VehicleInfo1[playerid][Car],PosX1,PosY1,PosZ1);
	GetVehicleZAngle(VehicleInfo1[playerid][Car],ZAngle1);
	
	GetVehiclePos(VehicleInfo2[playerid][Car],PosX2,PosY2,PosZ2);
	GetVehicleZAngle(VehicleInfo2[playerid][Car],ZAngle2);
	
	GetVehiclePos(VehicleInfo3[playerid][Car],PosX3,PosY3,PosZ3);
	GetVehicleZAngle(VehicleInfo3[playerid][Car],ZAngle3);

    new INI:File1 = INI_Open(VehPath(playerid,1));
    INI_SetTag(File1,"data");
    INI_WriteBool(File1,"VehicleOwned",VehicleInfo1[playerid][VehicleOwned]);
    INI_WriteInt(File1,"CarID",VehicleInfo1[playerid][CarID]);
    INI_WriteInt(File1,"Car",VehicleInfo1[playerid][Car]);
    INI_WriteFloat(File1,"CarPosX",PosX1);
    INI_WriteFloat(File1,"CarPosY",PosY1);
    INI_WriteFloat(File1,"CarPosZ",PosZ1);
    INI_WriteFloat(File1,"CarZAngle",ZAngle1);
    INI_WriteInt(File1,"CarCol1",VehicleInfo1[playerid][CarCol1]);
    INI_WriteInt(File1,"CarCol2",VehicleInfo1[playerid][CarCol2]);
    INI_Close(File1);
	
    new INI:File2 = INI_Open(VehPath(playerid,2));
    INI_SetTag(File2,"data");
    INI_WriteBool(File2,"VehicleOwned",VehicleInfo2[playerid][VehicleOwned]);
    INI_WriteInt(File2,"CarID",VehicleInfo2[playerid][CarID]);
    INI_WriteInt(File2,"Car",VehicleInfo2[playerid][Car]);
    INI_WriteFloat(File2,"CarPosX",PosX2);
    INI_WriteFloat(File2,"CarPosY",PosY2);
    INI_WriteFloat(File2,"CarPosZ",PosZ2);
    INI_WriteFloat(File2,"CarZAngle",ZAngle2);
    INI_WriteInt(File2,"CarCol1",VehicleInfo2[playerid][CarCol1]);
    INI_WriteInt(File2,"CarCol2",VehicleInfo2[playerid][CarCol2]);
    INI_Close(File2);
    
    new INI:File3 = INI_Open(VehPath(playerid,3));
    INI_SetTag(File3,"data");
    INI_WriteBool(File3,"VehicleOwned",VehicleInfo3[playerid][VehicleOwned]);
    INI_WriteInt(File3,"CarID",VehicleInfo3[playerid][CarID]);
    INI_WriteInt(File3,"Car",VehicleInfo3[playerid][Car]);
    INI_WriteFloat(File3,"CarPosX",PosX3);
    INI_WriteFloat(File3,"CarPosY",PosY3);
    INI_WriteFloat(File3,"CarPosZ",PosZ3);
    INI_WriteFloat(File3,"CarZAngle",ZAngle3);
    INI_WriteInt(File3,"CarCol1",VehicleInfo3[playerid][CarCol1]);
    INI_WriteInt(File3,"CarCol2",VehicleInfo3[playerid][CarCol2]);
    INI_Close(File3);

    DestroyVehicle(VehicleInfo1[playerid][Car]);
    if(VehicleInfo1[playerid][Car] == INVALID_VEHICLE_ID) {print("Car 1 Sucessfully Deleted");}
	return 1;
}
Any help would be appreciated
teresgezer is offline   Reply With Quote
Old 29/05/2019, 08:51 PM   #2
Dokins
High-roller
 
Dokins's Avatar
 
Join Date: Jun 2010
Posts: 1,640
Reputation: 53
Default Re: Vehicles don't destroy itself after user disconnect (I'm making a vehicle system using Y/ini)

I only see you destroying one vehicle.

Code:
DestroyVehicle(VehicleInfo1[playerid][Car]);
Where are the other vehicles being destroyed?
__________________
Bullworth Roleplay - Using the actual map from the Bully game.

Coming soon.

DISCORD:
https://discord.gg/zPHtrF
Dokins is offline   Reply With Quote
Old 30/05/2019, 11:12 AM   #3
teresgezer
Little Clucker
 
Join Date: Nov 2018
Posts: 10
Reputation: 0
Default Re: Vehicles don't destroy itself after user disconnect (I'm making a vehicle system using Y/ini)

I'm trying to get at least one vehicle to get deleted for now, once I find a solution I'll apply it to the other two
teresgezer is offline   Reply With Quote
Old 30/05/2019, 11:44 AM   #4
Deflect
Little Clucker
 
Deflect's Avatar
 
Join Date: May 2019
Posts: 11
Reputation: 7
Default Re: Vehicles don't destroy itself after user disconnect (I'm making a vehicle system using Y/ini)

I really don't see the problem, if you only set it to ONE it will only remove ONE what exactly are you trying to solve?
Deflect is offline   Reply With Quote
Old 30/05/2019, 12:20 PM   #5
teresgezer
Little Clucker
 
Join Date: Nov 2018
Posts: 10
Reputation: 0
Default Re: Vehicles don't destroy itself after user disconnect (I'm making a vehicle system using Y/ini)

For now I'm trying to remove only one vehicle, but after the player disconnects, the vehicle doesn't disappear. And when the player reconnects, the vehicle duplicates.
teresgezer is offline   Reply With Quote
Old 30/05/2019, 12:39 PM   #6
Dokins
High-roller
 
Dokins's Avatar
 
Join Date: Jun 2010
Posts: 1,640
Reputation: 53
Default Re: Vehicles don't destroy itself after user disconnect (I'm making a vehicle system using Y/ini)

I see.

I believe you need to store the playerid before the player actually disconnects.

Something like this, I have this in my code for removing vehicles and it works fine.

pawn Code:
new player = playerid;
RemovePlayerVehicles(player);
__________________
Bullworth Roleplay - Using the actual map from the Bully game.

Coming soon.

DISCORD:
https://discord.gg/zPHtrF
Dokins is offline   Reply With Quote
Old 30/05/2019, 01:00 PM   #7
teresgezer
Little Clucker
 
Join Date: Nov 2018
Posts: 10
Reputation: 0
Default Re: Vehicles don't destroy itself after user disconnect (I'm making a vehicle system using Y/ini)

Do I need to put it on the OnPlayerDisconnect function?
teresgezer is offline   Reply With Quote
Old 30/05/2019, 01:11 PM   #8
teresgezer
Little Clucker
 
Join Date: Nov 2018
Posts: 10
Reputation: 0
Default Re: Vehicles don't destroy itself after user disconnect (I'm making a vehicle system using Y/ini)

Quote:
Originally Posted by Dokins View Post
I see.

I believe you need to store the playerid before the player actually disconnects.

Something like this, I have this in my code for removing vehicles and it works fine.

pawn Code:
new player = playerid;
RemovePlayerVehicles(player);
Sadly, it still doesn't work...
teresgezer is offline   Reply With Quote
Old 31/05/2019, 05:33 PM   #9
teresgezer
Little Clucker
 
Join Date: Nov 2018
Posts: 10
Reputation: 0
Default Re: Vehicles don't destroy itself after user disconnect (I'm making a vehicle system using Y/ini)

Does anyone know what might have caused the issue?
teresgezer is offline   Reply With Quote
Old 08/08/2019, 05:40 PM   #10
teresgezer
Little Clucker
 
Join Date: Nov 2018
Posts: 10
Reputation: 0
Default Re: Vehicles don't destroy itself after user disconnect (I'm making a vehicle system using Y/ini)

BUMP
teresgezer is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disconnect destroy vehicle justjamie Scripting Help 5 24/05/2016 07:04 PM
[HELP] Create Vehicle.OK Destroy Vehicles.Fail iryston Scripting Help 5 16/08/2014 12:12 PM
[FilterScript] [FS]Destroy Vehicle System snipe69 Filterscripts 46 11/09/2011 06:26 PM
/veh (vehicle spawner admin cmd) won't destroy vehicles Andy_McKinley Help Archive 7 25/04/2010 09:55 AM
3d Labels not deleting on user disconnect ded Help Archive 6 05/12/2009 02:42 PM


All times are GMT. The time now is 01:11 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.