Difference between revisions of "GameObj"

From Legends of Aria Admin and Modding Wiki
Jump to: navigation, search
(Shared Object Properties ("SharedStateEntry" entries in templates))
 
(24 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Game Object (GameObj) is a Dynamic object within the game that can occupy a position of the world, including a container. Game Objects are the most common of all Objects and can have Variables and/or [[Module | Modules]] attached to them.
+
Game Object ([http://shardsonline.com/lN2rwhz4jSVambqesEBZ/lua-reference/gameobj.html GameObj]) is a Dynamic object within the game that can occupy a position of the world, including a [[Container]]. Game Objects are the most common of all Objects and can have [[ObjVar | Variables]] and/or [[Module | Modules]] attached to them.
  
 
A potion, a monster, a door, and a sword are all examples of GameObjs.
 
A potion, a monster, a door, and a sword are all examples of GameObjs.
 +
== Basic Gameobject Data and Functions ==
 +
Official Docs and GameObj engine API: [[http://shardsonline.com/lN2rwhz4jSVambqesEBZ/lua-reference/gameobj.html Game Object Functions]]
 +
<br>This list is for overview only and it is reduced to the most basic engine functions.
 +
<br>There are many extensions to objects done by script, but these are not listed here.
 +
<br>For full function documentation please refer to the official documentation.
 +
<br>This list here is just to give you a birds eye perspective on gameobjects most basic data and the according getter/setter functions, not more.
 +
=== Basic Data ===
 +
* '''<code>Id</code>''':The unique Id of a GameObject, Ids are unique on a per cluster basis.
 +
**Getting the Id of a gameObject: <code>mId = mObj.Id</code>
 +
** Setter: Gameobject Ids cannot be set. They are created and assigned by the engine on object creation.
 +
**Referencing a gameobject from a known Id(=number):  <code>mGameObj = GameObj(mId)</code>
  
 +
* '''<code>Client Id</code>''': The type of gameobject, it defines the visual look, like Human Female Model, A Rock, a House, whatever.
 +
**Getter: <code>mClientId = mObj:GetIconId()</code> Returns the Client Id which also is the Id in the use of certain images, thats why "IconId".
 +
**Setter: <code>mObj:SetAppearanceFromTemplate(mTemplateName)</code> Sets the Client Id and appearance of the object to the Client Id set in the referenced template. Its a bit of an indirect way of setting it, instead of directly using the Client Id, but thats how it works right now (0.3.5)
  
== Object Variables ==
+
* '''<code>Name</code>''': The name of a gameobject, visible in game.
Object Variables are saved when a backup is performed. This means that after a full restart of the server, the GameObj will return to the state it was in during the backup.
+
**Getter: <code>mName = mObj:GetName()</code>
 +
**Setter: <code>mObj:SetName("Samogh the Blacksmith")</code>
  
gameObj:SetObjVar("Name", "Larry")
+
* '''<code>Hue</code>''': The hue of an object which mixes with the texture colors. You cannot force an object to be magenta, when its texture color is green.
name = gameObj:GetObjVar("Name")
+
** Getter: <code>mHue = mObj:GetHue()</code>
 +
** Setter: <code>mObj:SetHue("FF0000")</code>
  
gameObj:SetObjVar("SomeObjVarNameIChose", 53.2)
+
=== Mobiles only Data ("MobileComponent" in templates) ===
aUserNum = gameObj:GetObjVar("SomeObjVarNameIChose")
+
* '''<code>Base Movement Speed</code>''': (For mobiles) Guess what? This is how fast the mob can move. ;)
 +
** Getter: <code>mSpeed = mObj:GetBaseMoveSpeed()</code>
 +
** Setter: <code>mObj:SetBaseMoveSpeed(3)</code> Run, Forrest, run ....
  
You can save Numbers, Strings, Bools, and Tables in an ObjVar and can specify any String name of your choice.
+
* '''<code>Mobile Type</code>''': Needed for proper display of the object outline and cursor
 +
** Getter: <code>mMobType = mObj:GetMobileType()</code>
 +
** Setter: <code>mObj:SetMobileType("Friendly")</code> Make that bear a cuddly one (at least visually ...)
 +
 
 +
=== Geometry and Location Data ===
 +
 
 +
* '''<code>Location</code>''': Location of the object in the world
 +
** Getter: <code>mLoc = mObj:GetLoc()</code>
 +
** Setter: <code>mObj:SetWorldPosition(Loc(0,0,0))</code> The example positions the object at the world origin.
 +
** Setter2: <code>mObj:MoveToContainer(mBag, Loc(0,0,0))</code> Object gets put into container mBag at relative coordinates 0,0,0 inside the container.
 +
** You can use SetWorldPosition() to move an object out of a container into the world.
 +
 
 +
* '''<code>Rotation</code>''': Rotation of the object in its own local coordinate system
 +
** Getter: <code>mRot = mObj:GetRotation()</code> Returns a Loc object whith three angles in degrees which describe the object rotation around the axis x,y and z. The order of rotation is: z, y, x (The Unity standard of rotation)
 +
** Setter: <code>mObj:SetRotation(Loc(45,30,60))</code> The example sets the rotation of the object to 60° around its Z axis, 45° around its X axis and 30° around its Y axis.
 +
 
 +
* '''<code>Scale</code>''': Scaling of the object in its own local coordinate system
 +
** Getter: <code>mScale = mObj:GetScale()</code> Returns a Loc object whith three scale factors which describe the object scaling in each axis x,y and z.
 +
** Setter: <code>mObj:SetScale(Loc(2,4,2))</code> The example sets the scale of the object to 2x at its x and Z axis, and 4x at its X axis. So it is 2 times taller than wide and stretched up high (y-axis). This has been changed. Formerly (pre 0.3.5) Scale was only scalar, now its a vector.
 +
 
 +
=== Object Variables ("ObjVarComponent" in templates) ===
 +
* '''<code>Object Variables</code>''': A gameobject can have [[Object Variables]], additional data we can assign, query, change and delete from script.
 +
** Getter: <code>mValue = mObj:GetObjVar("MyVariable")</code>
 +
** Getter2: <code>mBool = mObj:HasObjVar("MyVariable")</code> Returns a boolean if the ObjVar exists on the object.
 +
** Getter3: <code>mObjVarTable = mObj:GetAllObjVars()</code> Returns a Dictionary with ObjVar names as keys and values as values
 +
** Setter: <code>mObj:SetObjVar("MyVariable", SomeValue)</code> Type of the ObjVar is the type of the value assigned.
 +
** Deletion: <code>mObj:DelObjVar("MyVariable")</code>
 +
** Caveat: SetObjVar is asynchronous, when used from another object and synchronous when used from script attached to the object itself. This means, setting an objvar on another object than the one the script is running on will not be executed immediately !!!
 +
 
 +
=== Shared Object Properties ("SharedStateEntry" entries in templates) ===
 +
* '''<code>Shared Object Properties</code>''': A gameobject can have [[Shared Object Properties]], additional data we can assign, query, change and delete from script and which is shared with the client. Generally this data is data the clients needs for certain tasks, like displaying the object properly. Which of this data can be used depends on the object type, given by its ClientId and is predefined in the engine.
 +
** Shared Object Properties can be Numbers, Strings, Booleans (Not sure about Integers and other non-Lua types here right now ~Y.)
 +
** Getter: <code>mValue = mObj:GetSharedObjectProperty("NoInteract")</code>This would return the Interaction flag for the object, a boolean in this case.
 +
** Getter2: <code>mSharedPropTable = mObj:GetAllSharedObjectProperties()</code> Returns a Dictionary with Shared Object Property names as keys and values as values
 +
** Setter: <code>mObj:SetSharedObjectProperty("Weight", -1)</code> Object cannot be lifted anymore and is "glued to the ground".
 +
** Deletion: ???
 +
** Caveat: SetSharedObjectProperty are also asynchronous, so when used from another object the same issue as described for ObjVars above is given.
 +
 
 +
=== Modules ("ScriptEngineComponent" in templates) ===
 +
* '''<code>Module</code>''': Modules, Behaviors, Scripts .... A module is one compiled chunk of Lua code running on an object. This means a Module or Behavior can contain other scripts by various means, like the require() or load() functions.
 +
** Getter: <code>mModule = GetCurrentModule()</code>Returns the name of the current running module the function is called from
 +
** Getter2: <code>mModuleList = mObj:GetAllModules()</code>Returns an array with the names of all modules currently attached to the object.
 +
** Setter: <code>mObj:AddModule("MyCoolBehaviorScript")</code>Attaches a a module to the gameObj
 +
** Deletion: <code>mObj:DelModule("MyCoolBehaviorScript")</code>Removes a module from the object
  
 
== Tips ==
 
== Tips ==
Obj variables should only contain data you are intending to persist to disk, especially since reading from an ObjVar immediately after setting it will not always return the new value.
+
* Obj variables should only contain data you are intending to persist to disk, especially since reading from an ObjVar immediately after setting it will not always return the new value.
 +
* GameObj can communicate between each other using [[SendMessage]] just like Modules.
 +
 
 +
 
 +
[[Category:Architecture]]

Latest revision as of 14:28, 1 November 2016

Game Object (GameObj) is a Dynamic object within the game that can occupy a position of the world, including a Container. Game Objects are the most common of all Objects and can have Variables and/or Modules attached to them.

A potion, a monster, a door, and a sword are all examples of GameObjs.

Basic Gameobject Data and Functions

Official Docs and GameObj engine API: [Game Object Functions]
This list is for overview only and it is reduced to the most basic engine functions.
There are many extensions to objects done by script, but these are not listed here.
For full function documentation please refer to the official documentation.
This list here is just to give you a birds eye perspective on gameobjects most basic data and the according getter/setter functions, not more.

Basic Data

  • Id:The unique Id of a GameObject, Ids are unique on a per cluster basis.
    • Getting the Id of a gameObject: mId = mObj.Id
    • Setter: Gameobject Ids cannot be set. They are created and assigned by the engine on object creation.
    • Referencing a gameobject from a known Id(=number): mGameObj = GameObj(mId)
  • Client Id: The type of gameobject, it defines the visual look, like Human Female Model, A Rock, a House, whatever.
    • Getter: mClientId = mObj:GetIconId() Returns the Client Id which also is the Id in the use of certain images, thats why "IconId".
    • Setter: mObj:SetAppearanceFromTemplate(mTemplateName) Sets the Client Id and appearance of the object to the Client Id set in the referenced template. Its a bit of an indirect way of setting it, instead of directly using the Client Id, but thats how it works right now (0.3.5)
  • Name: The name of a gameobject, visible in game.
    • Getter: mName = mObj:GetName()
    • Setter: mObj:SetName("Samogh the Blacksmith")
  • Hue: The hue of an object which mixes with the texture colors. You cannot force an object to be magenta, when its texture color is green.
    • Getter: mHue = mObj:GetHue()
    • Setter: mObj:SetHue("FF0000")

Mobiles only Data ("MobileComponent" in templates)

  • Base Movement Speed: (For mobiles) Guess what? This is how fast the mob can move. ;)
    • Getter: mSpeed = mObj:GetBaseMoveSpeed()
    • Setter: mObj:SetBaseMoveSpeed(3) Run, Forrest, run ....
  • Mobile Type: Needed for proper display of the object outline and cursor
    • Getter: mMobType = mObj:GetMobileType()
    • Setter: mObj:SetMobileType("Friendly") Make that bear a cuddly one (at least visually ...)

Geometry and Location Data

  • Location: Location of the object in the world
    • Getter: mLoc = mObj:GetLoc()
    • Setter: mObj:SetWorldPosition(Loc(0,0,0)) The example positions the object at the world origin.
    • Setter2: mObj:MoveToContainer(mBag, Loc(0,0,0)) Object gets put into container mBag at relative coordinates 0,0,0 inside the container.
    • You can use SetWorldPosition() to move an object out of a container into the world.
  • Rotation: Rotation of the object in its own local coordinate system
    • Getter: mRot = mObj:GetRotation() Returns a Loc object whith three angles in degrees which describe the object rotation around the axis x,y and z. The order of rotation is: z, y, x (The Unity standard of rotation)
    • Setter: mObj:SetRotation(Loc(45,30,60)) The example sets the rotation of the object to 60° around its Z axis, 45° around its X axis and 30° around its Y axis.
  • Scale: Scaling of the object in its own local coordinate system
    • Getter: mScale = mObj:GetScale() Returns a Loc object whith three scale factors which describe the object scaling in each axis x,y and z.
    • Setter: mObj:SetScale(Loc(2,4,2)) The example sets the scale of the object to 2x at its x and Z axis, and 4x at its X axis. So it is 2 times taller than wide and stretched up high (y-axis). This has been changed. Formerly (pre 0.3.5) Scale was only scalar, now its a vector.

Object Variables ("ObjVarComponent" in templates)

  • Object Variables: A gameobject can have Object Variables, additional data we can assign, query, change and delete from script.
    • Getter: mValue = mObj:GetObjVar("MyVariable")
    • Getter2: mBool = mObj:HasObjVar("MyVariable") Returns a boolean if the ObjVar exists on the object.
    • Getter3: mObjVarTable = mObj:GetAllObjVars() Returns a Dictionary with ObjVar names as keys and values as values
    • Setter: mObj:SetObjVar("MyVariable", SomeValue) Type of the ObjVar is the type of the value assigned.
    • Deletion: mObj:DelObjVar("MyVariable")
    • Caveat: SetObjVar is asynchronous, when used from another object and synchronous when used from script attached to the object itself. This means, setting an objvar on another object than the one the script is running on will not be executed immediately !!!

Shared Object Properties ("SharedStateEntry" entries in templates)

  • Shared Object Properties: A gameobject can have Shared Object Properties, additional data we can assign, query, change and delete from script and which is shared with the client. Generally this data is data the clients needs for certain tasks, like displaying the object properly. Which of this data can be used depends on the object type, given by its ClientId and is predefined in the engine.
    • Shared Object Properties can be Numbers, Strings, Booleans (Not sure about Integers and other non-Lua types here right now ~Y.)
    • Getter: mValue = mObj:GetSharedObjectProperty("NoInteract")This would return the Interaction flag for the object, a boolean in this case.
    • Getter2: mSharedPropTable = mObj:GetAllSharedObjectProperties() Returns a Dictionary with Shared Object Property names as keys and values as values
    • Setter: mObj:SetSharedObjectProperty("Weight", -1) Object cannot be lifted anymore and is "glued to the ground".
    • Deletion: ???
    • Caveat: SetSharedObjectProperty are also asynchronous, so when used from another object the same issue as described for ObjVars above is given.

Modules ("ScriptEngineComponent" in templates)

  • Module: Modules, Behaviors, Scripts .... A module is one compiled chunk of Lua code running on an object. This means a Module or Behavior can contain other scripts by various means, like the require() or load() functions.
    • Getter: mModule = GetCurrentModule()Returns the name of the current running module the function is called from
    • Getter2: mModuleList = mObj:GetAllModules()Returns an array with the names of all modules currently attached to the object.
    • Setter: mObj:AddModule("MyCoolBehaviorScript")Attaches a a module to the gameObj
    • Deletion: mObj:DelModule("MyCoolBehaviorScript")Removes a module from the object

Tips

  • Obj variables should only contain data you are intending to persist to disk, especially since reading from an ObjVar immediately after setting it will not always return the new value.
  • GameObj can communicate between each other using SendMessage just like Modules.