Difference between revisions of "SetNPCPropertyValue"

From Onset Developer Wiki
(Created page with "{{Info|Function|Server & Client|1.0}} {{FuncDescription|Sets a property value for this entity. Useful to store information for individual entities which can be accessed on cl...")
 
 
Line 15: Line 15:
  
 
== Example ==
 
== Example ==
__EDIT_ME__
+
<syntaxhighlight lang="Lua>
 +
-- client side example
 +
AddEvent("OnNPCStreamIn", function(npcid)
 +
local clothing_preset = GetNPCPropertyValue(npcid, "ClothingPreset")
 +
SetNPCClothingPreset(npcid, clothing_preset)
 +
end)
 +
 
 +
-- server side example
 +
-- somewhere you create NPC and assign value
 +
local npcid = CreateNPC(x, y, z, h)
 +
SetNPCClothingPreset(npcid, "ClothingPreset", 2)
 +
</syntaxhighlight>
  
 
{{RelatedFunctions}}
 
{{RelatedFunctions}}
__EDIT_ME__
+
{{Template:NPCFunctions}}

Latest revision as of 09:32, 30 June 2020

SetNPCPropertyValue

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

Description

Sets a property value for this entity. Useful to store information for individual entities which can be accessed on client and server and across different packages.

Syntax

SetNPCPropertyValue(npc, PropertyName, Value, bSync)
Client Syntax
SetNPCPropertyValue(npc, PropertyName, Value)

Parameters

  • npc
    The npc identifier
  • PropertyName
    Name of the property variable
  • Value
    Value can be a boolean, integer, float, string or table
  • bSync (optional)
    Enable automatic network sync for this property value.

Return Value

  • Returns true on success.

Example

-- client side example
AddEvent("OnNPCStreamIn", function(npcid)
	local clothing_preset = GetNPCPropertyValue(npcid, "ClothingPreset")
	SetNPCClothingPreset(npcid, clothing_preset)
end)

-- server side example
-- somewhere you create NPC and assign value
local npcid = CreateNPC(x, y, z, h)
SetNPCClothingPreset(npcid, "ClothingPreset", 2)

See also