IsValidNPC: Difference between revisions

From Onset Developer Wiki
Created page with "{{Info|Function|Server|1.0}} {{FuncDescription|__EDIT_ME__}} {{FuncSyntax|IsValidNPC(npc)}} {{FuncParameters}} {{FuncParam|npc|__EDIT_ME__}} {{FuncReturnValue|__EDIT_ME__}..."
 
28days (talk | contribs)
No edit summary
Line 1: Line 1:
{{Info|Function|Server|1.0}}
{{Info|Function|Server|1.0}}


{{FuncDescription|__EDIT_ME__}}
{{FuncDescription|Check if specified NPC is valid or not.}}


{{FuncSyntax|IsValidNPC(npc)}}
{{FuncSyntax|IsValidNPC(npc)}}


{{FuncParameters}}
{{FuncParameters}}
{{FuncParam|npc|__EDIT_ME__}}
{{FuncParam|npc|The NPC identifier.}}


{{FuncReturnValue|__EDIT_ME__}}
{{FuncReturnValue|Returns '''true''' on success.}}


== Example ==
== Example ==
__EDIT_ME__
<syntaxhighlight lang="Lua>
AddCommand("gotonpc", function(playerid, npcid)
if not IsPlayerAdmin(playerid) then
AddPlayerChat("You are not an admin!")
return
end
 
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)
</syntaxhighlight>


{{RelatedFunctions}}
{{RelatedFunctions}}
__EDIT_ME__
{{Template:NPCFunctions}}

Revision as of 14:08, 19 November 2019

IsValidNPC

Type: Function
Context: 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)
	if not IsPlayerAdmin(playerid) then
		AddPlayerChat("You are not an admin!")
		return
	end

	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