Jump to content
Leadwerks Community

Recommended Posts

Posted

I am trying to work out how to manually take control of the monsterAI.lua controlled entities, my initial thoughts are is there a way to assign a script file to the entity programmatically in a lua script. And if so can the entity be stopped, and have the script reset back to monsterAI.lua once I release manual control.

 

The Idea is to be able to tab key among my army of entities, and "mind control" them, taking over from their normal monsterAI.lua script and using my own controller.lua script. When I tab out they revert back to their normal script.

 

I haven't been able to find any API reference to setting the script file for an entity. Would this be a possibility.

Posted

I don't think you can change script in Lua, but you can swap functions because functions are variables in Lua. So you can replace AI UpdateWorld function with another one. But it probably would be easier to replace entity.

Posted

Thanks, I added a line to the Monsterai.lua Script:Start

 

System:Print("self.GetScript()="..self.entity:GetScript())

 

this gives the full path and file name of the script in the log.

Then using those results followed it with a line to load a new script

 

self.entity:SetScript("C:/Users/....................../monstera3.lua")

 

In the log this caused the old script to be deleted, the new script loaded and then executed. So looks like it can be done, with that method, though will have to check that it doesn't cause any leaks.

  • Upvote 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...