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__}..." |
No edit summary |
||
(2 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
{{Info|Function|Server|1.0}} | {{Info|Function|Client & Server|1.0}} | ||
{{FuncDescription| | {{FuncDescription|Check if specified NPC is valid or not.}} | ||
{{FuncSyntax|IsValidNPC(npc)}} | {{FuncSyntax|IsValidNPC(npc)}} | ||
{{FuncParameters}} | {{FuncParameters}} | ||
{{FuncParam|npc| | {{FuncParam|npc|The NPC identifier.}} | ||
{{FuncReturnValue| | {{FuncReturnValue|Returns '''true''' on success.}} | ||
== Example == | == Example == | ||
<syntaxhighlight lang="Lua> | |||
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) | |||
</syntaxhighlight> | |||
{{RelatedFunctions}} | {{RelatedFunctions}} | ||
{{Template:NPCFunctions}} |
Latest revision as of 13:56, 10 November 2021
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
- GetStreamedNPC
- GetNPCLocation
- SetNPCOutline
- SetNPCPropertyValue
- GetNPCPropertyValue
- CreateNPC
- DestroyNPC
- IsValidNPC
- GetAllNPC
- GetNPCCount
- IsNPCStreamedIn
- SetNPCLocation
- GetNPCLocation
- SetNPCHealth
- GetNPCHealth
- SetNPCAnimation
- SetNPCHeading
- GetNPCHeading
- SetNPCTargetLocation
- SetNPCFollowPlayer
- SetNPCFollowVehicle
- SetNPCRagdoll
- SetNPCRespawnTime