Jump to content
  • Advertisement
Sign in to follow this  

Executing scripts on dynamicly loaded NPCs?

This topic is 3565 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm currently developing a little scripted game. The project I was doing before sort of ran out of hand and got turned into a bigger project. I'm currently up to a point where I can start adding NPCs in the game. Now, since I don't want these NPCs to be of the static kind, I want to give them the chance to have scripts. However, I haven't completely figured out how yet. First, I could put the Lua scripts for each NPC type into a seperate script file on disk, and just refer from the NPC template to it, as in OnAttacked="mynpc.OnAttacked". The biggest pro of this that's it simple to update any NPC scripts. Downside is that it now has 2 files: A template and a script Alternatively, I could add the script to the NPC template, but this has the downside that it's more difficult to reload the scripts during runtime(As it would force me to reload the NPC template). And as a last one, I could make all scripts part of the handler in the NPC template, as in(Using XML as an example, as I ahven't decided upon the format yet):
local hpAttacker = attacker["hp"];
if (hp > attacked["hp"]) then
Any ideas on a good approach here? I know this is somewhat personal preference, but I'm curious. Toolmaker

Share this post

Link to post
Share on other sites
I recommend splitting scripts and NPC attribute templates. This has the major benefit of allowing NPCs of similar types, but unique attributes to share their scripts. That will make it easier to change all the actions of several NPCs that share scripts without having to edit the NPC templates individually.

The added overhead of multiple files is a small hinderance. The several project I've worked on have all followed this method.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!