Gonan Posted February 22, 2017 Posted February 22, 2017 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. Quote
AggrorJorn Posted February 22, 2017 Posted February 22, 2017 Do you want to set the script via cpp or lua? Cpp Monster->SetScript("Scripts/enemyai.lua"); Quote
Genebris Posted February 22, 2017 Posted February 22, 2017 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. Quote
Gonan Posted February 22, 2017 Author Posted February 22, 2017 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. 1 Quote
Recommended Posts
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.