Difference between revisions of "Tips for mod coders"

From Legends of Aria Admin and Modding Wiki
Jump to: navigation, search
(Created page with "== Looking for objects == In your scripts, you will certainly be needing to find objects. Even though CS provides plenty of functions to search, it might be difficult to find...")
 
m (Looking for objects)
Line 1: Line 1:
 
== Looking for objects ==
 
== Looking for objects ==
In your scripts, you will certainly be needing to find objects. Even though CS provides plenty of functions to search, it might be difficult to find a particular object, esp. when using default templates provided by CS (and thus not modifiable).
+
In your scripts, you will certainly be needing to find objects. Even though CS provides plenty of functions to search, it might be difficult to find a particular object, esp. when using default templates provided by CS (and thus not modifiable).<br>
The best option, not to have to create a specific template for such object, is to use "Custom Object Variables".
+
The best option, not to have to create a specific template for such object, is to use "Custom Object Variables".<br>
You can either add such variables directly from the SeedObjects.xml file of your module, or do it from Unity.
+
You can either add such variables directly from the SeedObjects.xml file of your module, or do it from Unity.<br>
 
+
<br>
 
From Unity:
 
From Unity:
 
# Load your module, and its Seed Objects (cf. [[Modding Guide|modding guide]]). Leave the "Seed Objects Editor" window opened.
 
# Load your module, and its Seed Objects (cf. [[Modding Guide|modding guide]]). Leave the "Seed Objects Editor" window opened.
Line 10: Line 10:
 
# You can choose a "Name" for that object, which is going to be the "ObjVar" name in Lua
 
# You can choose a "Name" for that object, which is going to be the "ObjVar" name in Lua
 
# You can define a type and value, which is going to be the value returned when you call GetObjVar("Name")
 
# You can define a type and value, which is going to be the value returned when you call GetObjVar("Name")
 
+
<br>
The XML that will be generated will look like this in SeedObjects.xml
+
The XML that will be generated will look like this in SeedObjects.xml<br>
 
Note that the "<Name>" tag isn't of use, the Lua GetName() function isn't related to that.
 
Note that the "<Name>" tag isn't of use, the Lua GetName() function isn't related to that.
 
<syntaxhighlight lang="xml">
 
<syntaxhighlight lang="xml">
Line 24: Line 24:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
If you want to manually add it, you can edit the SeedObjects.xml file directly (making sure you don't have Unity running and seedobjects loaded) by adding the consistent <ObjVarOverrides> as shown above.
+
If you want to manually add it, you can edit the SeedObjects.xml file directly (making sure you don't have Unity running and seedobjects loaded) by adding the consistent <ObjVarOverrides> as shown above.<br>
 
+
<br>
Note: this will just manually add that objvar to the object on creation when you resetworld or start with no backup
+
Note: this will just manually add that objvar to the object on creation when you resetworld or start with no backup<br>
 
+
<br>
To search for that object, you can now easily search for the custom object variable:
+
To find that object from your Lua script, you can now easily search for the custom object variable:
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
     local myDoor = FindObject(SearchObjVar("DoorId","DoorTeam"))
 
     local myDoor = FindObject(SearchObjVar("DoorId","DoorTeam"))
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 09:49, 12 September 2018

Looking for objects

In your scripts, you will certainly be needing to find objects. Even though CS provides plenty of functions to search, it might be difficult to find a particular object, esp. when using default templates provided by CS (and thus not modifiable).
The best option, not to have to create a specific template for such object, is to use "Custom Object Variables".
You can either add such variables directly from the SeedObjects.xml file of your module, or do it from Unity.

From Unity:

  1. Load your module, and its Seed Objects (cf. modding guide). Leave the "Seed Objects Editor" window opened.
  2. Select the given Seed Object in your hierarchy or Scene view
  3. in the "Seed Object Editor", press "+" under "Custom Object Variables". This will create a new entry.
  4. You can choose a "Name" for that object, which is going to be the "ObjVar" name in Lua
  5. You can define a type and value, which is going to be the value returned when you call GetObjVar("Name")


The XML that will be generated will look like this in SeedObjects.xml
Note that the "<Name>" tag isn't of use, the Lua GetName() function isn't related to that.

<DynamicObject>
            <Name>Door</Name>
            <Id>12</Id>
            <ObjectCreationParams>tudor_door_dark -20.809 1.714 206.889 0 90 0 1 1.09 1.315</ObjectCreationParams>
             <ObjVarOverrides>
                <StringVariable Name="DoorId">DoorTeam</StringVariable>
            </ObjVarOverrides>
</DynamicObject>

If you want to manually add it, you can edit the SeedObjects.xml file directly (making sure you don't have Unity running and seedobjects loaded) by adding the consistent <ObjVarOverrides> as shown above.

Note: this will just manually add that objvar to the object on creation when you resetworld or start with no backup

To find that object from your Lua script, you can now easily search for the custom object variable:

     local myDoor = FindObject(SearchObjVar("DoorId","DoorTeam"))