Cant delete vehicle object
#1

Hi. i tryed to search it, but didnt find anything that could help me.

Im a begginner scripter, what i want to do is to attach a object(smoke) everytime i accelerate(hold) and remove it when i release accelerator.

I already made the attachment work, but cant make it dissapear when i release the accel.

here is the code.

Код:
#include <a_samp>

#define PRESSED(%0) \
	(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
	
#define RELEASED(%0) \
	(((newkeys & (%0)) != (%0)) && ((oldkeys & (%0)) == (%0)))
	

public OnFilterScriptInit()
{
	
	print("\n--------------------------------------");
	print(" Diesel smoke FS");
	print("--------------------------------------\n");
	return 1;
}

public OnFilterScriptExit()
{
	return 1;
}


public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	

	if (GetVehicleModel(GetPlayerVehicleID(playerid)) == 436)

	        {
            	new fumo=CreateObject(18723,0,0,-1000,0,0,0,100);
				new neon = CreateObject(18647,0,0,-1000,0,0,0,100);
			
				if (PRESSED(KEY_SPRINT))
					{
						SendClientMessage(playerid, 0x00FF00FF, "pressed");
						AttachObjectToVehicle(fumo, GetPlayerVehicleID(playerid), 0.000000,0.000000,0.000000,94.499977,0.000000,0.000000);
						AttachObjectToVehicle(neon, GetPlayerVehicleID(playerid), -0.449999,0.000000,1.350000,0.000000,0.000000,0.000000);
					}
					else if (RELEASED(KEY_SPRINT))
					{
						SendClientMessage(playerid, -1, "UN-pressed");
                                                DestroyObject(GetPVarInt(playerid, "fumo"));
						DestroyObject(GetPVarInt(playerid, "neon"));
					//	DestroyObject(fumo);

					//	DestroyObject(neon);
					}
				return 1;
			}


	return 1;
}
Reply
#2

it's not pressing, it's holding, pressing detects that you performed a key and then released it, meanwhile holding detects that you performed a key and still didn't release it;

https://sampwiki.blast.hk/wiki/OnPlayer..._holding_a_key

just replace "pressed" with "holding" in the first check, and make sure to define holding
Reply
#3

Right, now i got this, with holding defined, but it still doesnt remove smoke(fumo) and neon when release.

Код:
#define HOLDING(%0) \
	((newkeys & (%0)) == (%0))
	
#define RELEASED(%0) \
	(((newkeys & (%0)) != (%0)) && ((oldkeys & (%0)) == (%0)))


public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{


	if (GetVehicleModel(GetPlayerVehicleID(playerid)) == 436)

	        {
            	new fumo=CreateObject(18723,0,0,-1000,0,0,0,100);
				new neon = CreateObject(18647,0,0,-1000,0,0,0,100);

				if (HOLDING(KEY_SPRINT))
					{
						SendClientMessage(playerid, 0x00FF00FF, "pressed");
						AttachObjectToVehicle(fumo, GetPlayerVehicleID(playerid), 0.000000,0.000000,0.000000,94.499977,0.000000,0.000000);
						AttachObjectToVehicle(neon, GetPlayerVehicleID(playerid), -0.449999,0.000000,1.350000,0.000000,0.000000,0.000000);
					}
					else if (RELEASED(KEY_SPRINT))
					{
						SendClientMessage(playerid, -1, "UN-pressed");
                                                DestroyObject(GetPVarInt(playerid, "fumo"));
						DestroyObject(GetPVarInt(playerid, "neon"));
					//	DestroyObject(fumo);

					//	DestroyObject(neon);
					}
				return 1;
			}


	return 1;
}
Reply
#4

Local variables are destroyed when the function ends. In this case it means you lose the handle to those objects as soon as the function ends. The objects exist but you have absolutely no way to identify and destroy them. Use global variables or static locals instead.
Reply
#5

That is beautiful to say, but i dont get it about local and global variables.

When i try to put the "new smoke = createboject.... under the #defines, the compiler crashes.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)