Jump to content

EntityIsValid


Recommended Posts

Happy Holidays!

I would like to query the state of a breakable entity during game but when  it is already destroyed it only gives an error message.

How should this be queried correctly?

	smile_trigger =
	{
		Name = "smile_trigger",
		TriggerOnClass = CLASS.ANYPLAYER,
		OnEnter = function(ent)
		{
			if(GetEntTeam(ent) == TEAM.AXIS)
			{
				Map.SmileTriggerCount += 1;
				Util.MapDebugPrint("SmileTriggerCount = ^5" + Map.SmileTriggerCount);
				ent1 = GetGameEntityFromId(90);
				if(EntityIsValid(ent1))
				{
					print("Entity 90 is valid");
				}
				else
				{
					print("Entity 90 is'n valid");
				}
			}
		},
		OnExit = function(ent)
		{
			if(GetEntTeam(ent) == TEAM.AXIS)
			{
				Map.SmileTriggerCount -= 1;
				if(!Map.StairsWay && Map.SmileTriggerCount < 1)
				{
					SetAvailableMapGoals(TEAM.AXIS, false, "FLAG_keymad");
				}
				Util.MapDebugPrint("SmileTriggerCount = ^5" + Map.SmileTriggerCount);
			}
		},
	},

 

20241230_092813[1].jpg

Edited by vargatom
Link to comment
Share on other sites

  • Moderators

Where can we download pk3 file of this map ?

You should never use entity numbers because they depend on mods. You should use GetEntityByName instead of GetGameEntityFromId. If the entity does not have any name, then you can use TraceLine.

Functions GetEntityByName and GetGameEntityFromId return null if the entity is invalid. Correct condition is:

if(ent1)
{
	print("Entity is valid");
}

 

You must not use GetEntTeam in OnExit because it returns null if a player disconnected. Players can also change team when they are inside the region. See wiki how to count players in a region.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...