Page 1 of 1

problem with /mob brain ....

PostPosted: Wed Apr 12, 2017 12:17 am
by ontheDOL
So i've been having the problem when trying to give a mob a custom brain from gameserverscripts
"there was a error creating an instance of blah blah"

I've seen this problem a bit when i've searched it ,although from many years ago, and most of the help suggests that it was spelt incorrect or script outdated etc.

If i put the brain in the actual core folder /AI , i can create it no problem... odd? . So i look in /mob command and the method for "brain" , from what i can see, only looks at GameServer scripts , it doesnt actually look in gameserverscripts!

I tried adding something similar to the method from /mob create
Code: Select all
foreach (Assembly script in ScriptMgr.GameServerScripts) { try { client.Out.SendDebugMessage(script.FullName); brain = (ABrain)script.CreateInstance(brainType, false);

but it still fails to create unfortuantly.... the only way i've got them to work from outside of the core folder was to imbed them into a custome GameNPC script and SetOwnBrain from inside there...

Re: problem with /mob brain ....

PostPosted: Wed Apr 12, 2017 4:25 am
by PlanarChaosRvrtwo
Did you checked mob class and brain of main dragons it should show you the way

do /mob indo on golestandt and that should show you how to handle the issue

Re: problem with /mob brain ....

PostPosted: Wed Apr 12, 2017 7:15 pm
by ontheDOL
i think you misunderstood my first post. The command doesnt look in GSS folder, so it doesn't matter how you have the script.

Re: problem with /mob brain ....

PostPosted: Thu Apr 13, 2017 8:34 pm
by PlanarChaosRvrtwo
ahm ok i meant more if you do ingame /mob create DOL.GS.Golestandt it adds the alb dragon so i wonder if you could use this method to solve your current problem.

Re: problem with /mob brain ....

PostPosted: Fri Apr 14, 2017 12:34 am
by ontheDOL
aye, the problem there is, /mob create is a different command ^^ , and golestant doesnt get his brain from /mob create DOL.GS.Golestandt :wink:

he gets his brain from /mob brain DOL.AI.Brain.DragonBrain
and that works becuase that brain is in the core assembly... if i put my brain in the core assembly, yes it works, in GGS, no.
i dont fully understand this line
Code: Select all
brains = (ABrain)Assembly.GetExecutingAssembly().CreateInstance(brainType, false);
, but /mob brain DOL.GS.Scripts.TestBrain does not work (maybe what im typing is wrong)

anyway i added a new command to the /mob command while i was testing...
Code: Select all
private void custombrain(GameClient client, GameNPC targetMob, string[] args) { try { ABrain brains = null; string brainType = args[2]; foreach (Assembly script in ScriptMgr.Scripts) { try { client.Out.SendDebugMessage(script.FullName); brains = (ABrain)script.CreateInstance(brainType, false); } catch (Exception e) { client.Out.SendMessage(e.ToString(), eChatType.CT_System, eChatLoc.CL_PopupWindow); } } if (brains == null) { client.Out.SendMessage("Could not find custom brain " + brainType + "!", eChatType.CT_System, eChatLoc.CL_SystemWindow); } else { targetMob.SetOwnBrain(brains); targetMob.SaveIntoDatabase(); client.Out.SendMessage(targetMob.Name + "'s brain set to " + targetMob.Brain.ToString(), eChatType.CT_System, eChatLoc.CL_SystemWindow); } } catch (Exception) { DisplaySyntax(client, args[1]); } }
using "foreach (Assembly script in ScriptMgr.Scripts)" is this command worked, and i was able to successfully load the brain to the mob from gameserverscripts. /mob custombrain DOL.GS.Scripts.TestBrain creates the brain.
I dunno why the ScriptMgr.GameServerScripts didnt work

Re: problem with /mob brain ....

PostPosted: Fri Apr 14, 2017 1:21 am
by PlanarChaosRvrtwo
for me it worked to use the command i mentioned before and reboot one time or do an /jump refresh

Re: problem with /mob brain ....

PostPosted: Fri Apr 14, 2017 1:39 am
by ontheDOL
odd... because there is nothing in that script(from what i can see), or GameDragon of which its derived from, that tells it to set its brain as DragonBrain
/shrug

Re: problem with /mob brain ....

PostPosted: Wed Apr 19, 2017 9:03 am
by Leodagan
I think brain can be set through Database NPCTemplate fields, so they are not necessarily hardcoded in custom NPC Class...

Iterating over "ScriptMgr.GameServerScripts" to create an instance should work the same as iterating over "ScriptMgr.Scripts", the first one also include the "GameServer" assembly to match core class names...

Your "foreach" loop needs a "break" statement as soon as the created instance is not "null" !
Code: Select all
foreach (Assembly script in ScriptMgr.GameServerScripts) { try { brains = (ABrain)script.CreateInstance(brainType, false); if (brains != null) break; } catch (Exception e) { } }
you can display error in the exception part, this won't trigger if the type name is unknown for the assembly, from Microsoft documentation
If the runtime is unable to find typeName in the T:System.Reflection.Assembly instance, it returns null instead of throwing an exception.
https://msdn.microsoft.com/library/145s ... .110).aspx

This also mean you should probably "break" in the exception statement... but who knows ? :D (it would mean that you hope to have 2 class with the same FullName inside different assemblies, I don't think you would be able to compile GSS with this kind of collisions anyway...)

Re: problem with /mob brain ....

PostPosted: Wed Apr 19, 2017 9:25 am
by PlanarChaosRvrtwo
I think brain can be set through Database NPCTemplate fields, so they are not necessarily hardcoded in custom NPC Class...
If you want a mob casting an dd spell 1 min after last melee hit on it you ether have to write brains or you have to revamp the npctemplate code couse the combat timer make mobs unable to cast any spells that have a cast time no matter if cast able in combat or not.

Re: problem with /mob brain ....

PostPosted: Wed Apr 19, 2017 9:50 am
by Leodagan
If you want a mob casting an dd spell 1 min after last melee hit on it you ether have to write brains or you have to revamp the npctemplate code couse the combat timer make mobs unable to cast any spells that have a cast time no matter if cast able in combat or not.
I believe you, some time ago Mob didn't even want to cast offensive instant spells (something wrong with CastTime being 0), there still is so much issues with Mob Brain and spells that the only thing I can advice to people that want to make featured mob is to use Offensive Proc or Defensive Proc Buffs, the Mob will cast these like any self-buff then it will randomly trigger spells on melee attacks or when receiving damage... (random that can be tuned in spell value I think...)

There is absolutely no way to make an efficient Mob using ranged attack once it was engaged in close combat, this would need to check the mob skills when in pursuit after enabling close range attacks, I'm sure this would need some kind of dedicated logic for a "RangedStandardMobBrain" to take advantage of distance instead of sticking to attackers.

Re: problem with /mob brain ....

PostPosted: Wed Apr 19, 2017 10:54 am
by PlanarChaosRvrtwo
There is absolutely no way to make an efficient Mob using ranged attack once it was engaged in close combat, this would need to check the mob skills when in pursuit after enabling close range attacks, I'm sure this would need some kind of dedicated logic for a "RangedStandardMobBrain" to take advantage of distance instead of sticking to attackers.
Ahm i think it could be very simple the rangedstandardmobbrain should be forced to use spell from npctemplate after 3 seconds not attacked. And for archers creating an "Token" spell with ID -1 with an spellhandler that just force the mob to use weaponslot RANGED for attack. (This is ofc just an idea im not very good at coding/scripting but it could be maybe an idea some coders can work with)

Re: problem with /mob brain ....

PostPosted: Wed Apr 19, 2017 3:50 pm
by ontheDOL
I think brain can be set through Database NPCTemplate fields, so they are not necessarily hardcoded in custom NPC Class...
aye, i was referring to an above comment..
Iterating over "ScriptMgr.GameServerScripts" to create an instance should work the same as iterating over "ScriptMgr.Scripts"

I tried GSS again and indeed it does work, not sure what i had the first time i tried and it failed... Thanks for the "break" hint :)

there still isnt no call to checkinstantspells inside the SMB
If you want a mob casting an dd spell 1 min after last melee hit on it you ether have to write brains or you have to revamp the npctemplate code couse the combat timer make mobs unable to cast any spells that have a cast time no matter if cast able in combat or not.
yup, this comes back to the combat timer bug i mentioned a while back, GameNPC.followtargetinrange? is busted for spells.

after changing some code I was able to get a mob to cast on me after 3 sec no combat, but then they dont continue to follow me after cast so i need to play around a bit more.