Used

From ZDoom Wiki
Jump to navigation Jump to search


Actor

virtual bool Used (Actor user)

Usage

Used to execute some code upon interacting with an actor by using it. It is called when the player presses use against the actor, provided it does not have the USESPECIAL flag set and the action special assigned to it is not UsePuzzleItem. Although, if the actor satisfies one or both of these conditions, but its action special activation process fails, the function gets a chance to be called still.

Parameters

  • Actor user
A pointer to the using actor.

Return value

  • bool - signifies the success or failure of the use action (returning true and false respectively). By default the return value is not tied to anything and doesn't cause the actor to do anything (Verification needed), but custom logic can be attached to it.

Examples

This odd barrel explodes immediately when the player uses it while possessing the BFG.

class OddBarrel : ExplosiveBarrel
{
    override bool Used (Actor user)
    {
        if (user && user.CountInv("BFG9000"))
        {
            A_Die();
            return true;
        }

        return false;
    }
}

This version of the tech lamp can be manually switched on and off by pressing Use next to it:

class SwitchableLamp : TechLamp
{
	bool lamp_on; //Used to track whether the lamp is on

	override bool Used (Actor user)
	{
		if (!lamp_on)
		{
			// Attach dynamic light, play a standard switch sound
			// and move to the LampOn state label:
			A_AttachLight('lamplight', DynamicLight.PulseLight, "DDDDFF", 96, 99, DYNAMICLIGHT.LF_ATTENUATE, (0,0,72), 0.4);
			A_StartSound("switches/normbutn");
			SetStateLabel("LampOn");
		}
		else
		{
			// Remove the light, play the sound, change states:
			A_RemoveLight('lamplight');
			A_StartSound("switches/normbutn");
			SetStateLabel("Spawn");
		}
		// flip the value of lamp_on:
		lamp_on = !lamp_on;
		return true;
	}

	States
	{
	Spawn:
		TLMP C -1;
		stop;
	LampOn:
		// This is how the regular TechLamp looks:
		TLMP ABCD 4 Bright;
		Loop;
	}
}