IsValidNPC: Difference between revisions

From Onset Developer Wiki
No edit summary
No edit summary
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
{{Info|Function|Server|1.0}}
{{Info|Function|Client & Server|1.0}}


{{FuncDescription|Check if specified NPC is valid or not.}}
{{FuncDescription|Check if specified NPC is valid or not.}}
Line 13: Line 13:
<syntaxhighlight lang="Lua>
<syntaxhighlight lang="Lua>
AddCommand("gotonpc", function(playerid, npcid)
AddCommand("gotonpc", function(playerid, npcid)
if not IsPlayerAdmin(playerid) then
-- Admin level check here
AddPlayerChat("You are not an admin!")
return
end


if npcid == nil then
if npcid == nil then

Latest revision as of 13:56, 10 November 2021

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