ID:1649811
 
Keywords: ai, enemy
(See the best response by FKI.)
Code:
mob/Enemy
New()
src.FindTarget()
return ..()

proc
SetAIStats(var/Lev, var/MaxHP, var/MaxMP, var/MaxMPR, var/Str, var/Def, var/Agi, var/MaxMPA)
src.Level = Lev
src.MaxHealth = MaxHP
src.MaxMana = MaxMP
src.MaxManaPower = MaxMPR
src.Strength = Str
src.Defense = Def
src.Agility = Agi
src.MaxManaAn = MaxMPA
src.Health = src.MaxHealth
src.Rei = src.MaxRei
src.ManaPower = MaxManaPower

Animals
Spider
icon = 'Graphics/TestBase.dmi'
New()
src.SetAIStats(1, 100, 100, 200, 15, 15, 20, 10)
return ..()


Problem description: I always did my Enemy System like this but now since
I've been reading tutorials, snippets and etc.. I am wondering if this is a correct way to keep doing or there's a better way to improve it.

I personally feel your approach is tired, as you have to either keep up with the proc's order of arguments, or used named args when using the proc. The former is an easy way to do something unintentional since all it takes is a misplace of a number to do so. The latter is safer but requires more time typing.

I recommend taking an approach similar to the pattern seen in Ter's Sunday Post #3. I think it'll help you manage your different types of AI much more elegantly in the long-run.

Let me know if you have any questions and I'll do my best to assist you.
Ter's post is the reason I am in this situation, I can't seem to fully understand it, but I've been messing around and what about this. I had this idea after re-reading his post..

mob/Enemy
var/Value_1 = 0, Value_2 = 1
New()
src.FindTarget()
return ..()
Animals
Spider
icon = 'Icon.dmi'


So then in the Map Editor, I would just create a New Instance of Spider, set up those Enemy values to him and the mob values. Is that a better solution ?
I think the post you may be thinking of is Post #2 on using the map editor. The link in my last post has to do with using a factory-like system to manage items, and I'm suggesting for you to do something similar to manage your bots.

You can also handle stats through datum which are very clear and efficient getting rid of all that MAXhp and CURhp nonsense.
In response to FKI
FKI wrote:
I think the post you may be thinking of is Post #2 on using the map editor. The link in my last post has to do with using a factory-like system to manage items, and I'm suggesting for you to do something similar to manage your bots.

Nope I read Post #3 and in the end he talked about that I could modify the list in the Map Editor, that's why I came with the solution above. I've been trying. If it's not ask too much, could you do a brief PSEUDO Code, just something really really small so I can guide myself, otherwise it's okay I'll keep try and probably post a result here. Thank you.

Wissam wrote:
You can also handle stats through datum which are very clear and efficient getting rid of all that MAXhp and CURhp nonsense.

Something like this ?

stat
var/value = 0
var/max_value = 0

New(n)
if(n)
value = n
max_value = n

From Lummox JR ?
This is my best I wouldn't like to go back to that old system sadly but it seems I can't get a hand into this...

mob/Enemy

Enemy
parent_type = /NPC

var/mob/Enemy/M = new /mob/Enemy

New(var/list/Properties)
for(var/P in Properties)
M.vars[P] = Properties[P]

// Just example
GetName()
return M.name

// Just example
SetName(var/N as text)
M.name = N

NPC
var
MobType

proc
FindTarget()
GetName()
SetName(var/N as text)
GetType()
In response to BloodyJr
Best response
Yes, something like that is correct. I am using something very similarly structured myself.

item
parent_type = /obj
var/id

equip
proc/equip(mob/user)
proc/unequip(mob/user)

apparel

weapon
proc/use(mob/user)

projectile
use(mob/user)
// [user] throws projectiles.
melee
use(mob/user)
// ...


The above is basically how I would structure a tree for an item type. The trick is to write it in a general style so that other specific details that don't have to be hard-coded, are not.

From here, you want an easy way of managing how your items are created. You would go about doing this in a similar manner by modifying our item type's new and defining some prototypes that hold our items' information:

item/New(atom/location, item_id)
..(location)

if(item_id)
var/item_prototype/p = global.item_prototypes[item_id]
if(p)
p.mold(src)

var/global/list/item_prototypes = list(
"shirt" = new/item_prototype("shirt", /item/equip/apparel, list("icon" = 'shirt.dmi', "icon_state" = "shirt_state")),
"pants" = new/item_prototype("pants", /item/equip/apparel, list("icon" = 'pants.dmi', "icon_state" = "pants_state")),
)

item_prototype
parent_type = /prototype

prototype
var/id
var/tmp/instance_type
var/tmp/list/modifications

proc/mold(atom/a)
for(var/m in modifications)
if(m in a.vars)
a.vars[m] = modifications[m]

New(id, instance_type, list/modifications)
src.id = id
src.instance_type = instance_type
src.modifications = modifications


As you can see, it has the potential to do exactly what you were doing in your original post and more, without that ugly proc with 20 arguments.
Alright everything good now, except when I edit the ID on the Instance Editor and when I run the game. It doesn't seem to work, no icons or density, I even changed the density on the list to check. I am even trying with your example.

EDIT: Well thanks! Nothing on the map while running the game. The variables on the global list seem not work.