Jump to content

Map Editor Tutorial - Creating Member Scripts


R4bitF00t

Recommended Posts

logo.png.2daaf617449a0c9e1c637ec4ce05d03a.png

Hello again!

Script groups are a great tool for map makers. While they make referencing and scripting with multiple entities much easier, the script group, by default, is pretty rigid. You lose access to the individual units, or you need to create separate scripts for them, and take care that they do not clash with the script group's script.

That's why the original devs implemented member scripts. These scripts offer you access to all the units inside a script group, and allow them to act almost as separate entities again, while preserving the ability to work with them as a group.

 

If you encounter any issues, don't hesitate to ask in Skylords Reborn Map Making Discord.

 

 Content

splitter.png.b88958376f2b49606f513de34d9a3733.png

  • Setting Up a Script Group
  • Member Script Usage
  • Creating Member Scripts
  • OnIdleGoHomeEvent
  • Next Chapter

 

 Setting Up a Script Group

splitter.png.b88958376f2b49606f513de34d9a3733.png

Before we can make a member script, we of course need a script group to create it for.

In our Map Editor Tutorial map, I've prepared these units and tagged them spawn_defender1 to spawn_defender6.

image.png

I will create my script group through the _scriptgroups.lua file. But feel free to use the in-editor Script Group Editor.
In the _scriptgroups.lua, I've created a group called sg_spawn_defenders and assigned the spawn defenders to it .

image.png

 

Since I want these units to respawn, I will create a script named sg_spawn_defenders.lua and add an OnRespawnEvent.

image.png

Now, the units will respawn. But with a small twist - they will only respawn once ALL of the units in the script group have died.
While there is nothing inherently wrong with that, and this behaviour may be desired in some cases, we usually want our spawn defenders to be more responsive.
This can also lead to exploits, such as leaving one of the units alive to prevent the respawn of the remaining defenders.

Quote

Note: As a general map design rule, enemy camp defenders should respawn individually - using member scripts. While attack waves should respawn as a group.

Giving camp defenders individual respawns makes them more responsive to player attacks and prevents some easy exploits.

Making attack waves respawn as a group means, that the attack group will always attack in full force, instead of a small trickle of singular squads.

As you might have guessed, we will remedy this by creating a member script.

 

 Member Script Usage

splitter.png.b88958376f2b49606f513de34d9a3733.png

Member scripts need some further setup, but when finished, they can offer vastly improved functionality and control over units in a script group.

Before I get to the creation of member scripts, I will give you some examples what you can do with them.

  • make squads in a script group respawn individually, instead of as a group
     
  • make squads in a group return to their original placement after respawning
     
  • make squads in a script group behave as individuals, instead of as a group - instead of copying the same script for multiple entities, you can just use a member script to have multiple units have the same behaviour
     
  • easily keep track of how many units in the script group have died

 

 Creating Member Scripts

splitter.png.b88958376f2b49606f513de34d9a3733.png

Creating the member script is extremely easy.
We will just
copy the sg_spawn_defenders.lua script, and rename the copy to sg_spawn_defenders_member.lua.

image.png

Please note that you NEED to name the member script as scriptgroupname_member.lua.
This lets the game know, that you have created a member script for that specific script group.
You also
NEED the script group's original script file.

Now, when we have the member script created, we need to clean up the original script.
Just open the script, and since we don't want this script to do anything, just
leave in an empty state - this is not optional.

image.png

And our member script will have the OnRespawnEvent inside it.

image.png

With only these few steps, we have made it so that, the units in the script group will respawn as individuals, instead of having to wait for the rest of the group to die.

 

 OnIdleGoHomeEvent

splitter.png.b88958376f2b49606f513de34d9a3733.png

Maybe you've noticed, that in the official campaign maps, the respawned units will return to their starting positions, instead of just standing around the spawner.
This is a great little detail that not only makes the camp feel more alive, and look more visually appealing when players try to destroy the camp again, it also preserves the camp defenders' strategic placement.

Ideally, when designing a camp, you want to place the defenders in a strategic manner - ranged units in the back, melee units in the front, maybe have them defend a chokepoint.
When the units don't return to their original starting positions, it can negatively impact the camp's balance.

We can fix this issue by adding one more event into our member script - the OnIdleGoHomeEvent.
This event simply tells the units to return to a "home" position when they are idle for some time.

image.png

We can leave everything as-is, except the TargetTag parameter.
This parameter tells us,
where "home" is.
We will set this to
StartPos.

The StartPos parameter references the entities original placement - as it was placed in the editor.
This parameter only works
in scripts, that are named after a tagged entity or a script group.
And more importantly -
also in member scripts

image.png

With this one extra event, that works almost from the box, we can see that the units will return to their originally designated positions upon respawning.

image (62).jpg

In the end, you should end up with these scripts in your script1 folder.

image.png

sg_spawn_defenders_member.luasg_spawn_defenders.lua_scriptgroups.lua

 

 Next Chapter

splitter.png.b88958376f2b49606f513de34d9a3733.png

This concludes the member scripts chapter. First of our advanced topics.
Just remember that you can create a fun and interesting map without ever needing member scripts. They can help the map feel better to play but are in no way necessary.

In the next chapter, we will look at how we can use actual LUA language in our scripts to save ourselves a lot of time.

 

 Scripting Complex Events and Loops (Coming Soon)

 

Middle_splitter.png.a770f452e94ed383c001e9d7af974010.png

Edited by R4bitF00t
Metagross31 likes this
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Terms of Use