Deleting Objects
#1

Hello. I have this code and am wondering why the object doesn't delete when I type /garbage. It shows me the message, but the objects still stays in my players hand.

Here is the code that allows players to collect the garbage by pressing "C". I assigned the object to a variable, hoping to delete it with the /garbage command.

Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	if(PRESSED(KEY_CROUCH))
 	{
    	if(Player[playerid][Job] == 2)
    	{
    		if(IsPlayerInRangeOfPoint(playerid, 1.5, -2097.988525, -111.037300, 35.200302)) //
   			{
   		    	if(Checkpoint[playerid] > -1)
   		    	{
   					DisablePlayerCheckpoint(playerid);
    				Checkpoint[playerid] = 1;
    				trashObject[playerid] = SetPlayerAttachedObject(playerid, 9, 1265, 5, 0.274000, -0.091999, -0.044000, -79.300033, -95.500007, -16.499979, 0.588000, 0.612000, 0.875000);
				}
			}
        }
    }
	return 1;
}
Garbage command. It works only when at the back of a Truck Master.

Код:
CMD:garbage(playerid, params[])
{
	if(Player[playerid][LoggedIn] < 1)
	{
	    ErrorMessage(playerid, "You are not logged in.");
	    return 1;
	}
	if(Player[playerid][Job] == 2)
 	{
 	
 	    if(Checkpoint[playerid] > -1)
      	{
 	    	new Float:x, Float:y, Float:z, Float:a, vehicleid;
 	    	new Float: distance = 50.0;
	 		vehicleid = GetClosestVehicle(playerid, distance);
 	    	GetVehiclePos(vehicleid, x, y, z);
			GetVehicleZAngle(vehicleid, a);
			GetOffset(x, y, z, a, 0, -4.5, 0, x, y, z);
			
			if(IsPlayerInRangeOfPoint(playerid, 2.0, x, y, z))
			{
				if(trashObject[playerid] > 0)
				{
					InformationMessage(playerid, "You throw the garbage into the back of the truck.");
					DestroyObject(trashObject[playerid]);
				}
				else
				{
    				ErrorMessage(playerid, "You have not picked up the trash yet. Press 'C' at a skip.");
			    	return 1;
				}
			}
		}
		else
		{
 			ErrorMessage(playerid, "You have not started a trash route.");
		}
	}
	else
	{
 		ErrorMessage(playerid, "You do not have a job as a Garbage Collector or a Public Transport driver.");
	}
	return 1;
}
Any help here, it'd be very much appreciated!
Reply
#2

Use RemovePlayerAttachedObject for attached objects.

EDIT:
You also don't need trashObject[playerid] anymore, but you need to store the index instead.
Reply
#3

Attached player objects aren't treated as SA-MP or per player objects, it's a totally different method. Some scripters vary on how they manage indexes, some use the next available one and some use predefined indexes for different objects.

Refer to:
https://sampwiki.blast.hk/wiki/SetPlayerAttachedObject
https://sampwiki.blast.hk/wiki/RemovePlayerAttachedObject
https://sampwiki.blast.hk/wiki/IsPlayer...ObjectSlotUsed
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)