IsValidNPC

From Onset Developer Wiki
Revision as of 13:56, 10 November 2021 by BlueMountains (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
IsValidNPC

Type: Function
Context: Client & Server
Introduced: v1.0

Description

Check if specified NPC is valid or not.

Syntax

IsValidNPC(npc)

Parameters

  • npc
    The NPC identifier.

Return Value

  • Returns true on success.

Example

AddCommand("gotonpc", function(playerid, npcid)
	-- Admin level check here

	if npcid == nil then
		return AddPlayerChat(playerid, "Usage: /gotonpc <npc>")
	end

	if not IsValidNPC(npcid) then
		return AddPlayerChat(playerid, "Error: The parameter \"npc\" is invalid.")
	end

	local x, y, z = GetNPCLocation(npcid)
	SetPlayerLocation(playerid, x, y, z)

	AddPlayerChat(playerid, "Teleported!")
end)

See also