ID:140762
 
mob/Monster
Class="Monster" //placing a variable here will effect all types of mobs created under it
var/mob/Target //this variable will only exist for Monsters, and is by default typed as a mob
Hobgoblin
//since the following variables are tabbed in under the Hobgolin, they will only effect this 1 monster
icon='Hobgoblin.dmi'
Gold=2 //the gold you set on a monster will determine how much it gives when you kill it
Exp=1 //same goes for exp, the amount you set here will determine how much this monster is worth
Level=1 //these next few lines setup the basic stats for the monster
MaxHP=15 //since these variables are already defined elsewhere you dont need to mark them again here
var/ExtraVariable=0 //but if you wanted to define a new variable just for this monster you could
MaxMP=10
Str=3
Def=1
Hobgoblin_Level_2 //this guy is just a demo to show u how to code more then 1 monster
icon='Hobgoblin.dmi'
Gold=3
Exp=2
Level=2
MaxHP=20
MaxMP=15
Str=10
Def=5
New() //this is what happens when a new monster is created
src.HP=src.MaxHP //sets the monsters HP and MP to max
src.MP=src.MaxMP
spawn()
src.Wander() //when calling a proc that loops inside another proc you should ALWAYS spawn it
return ..() //this allows multiple New() procs to be ran on this mob, but make sure its at the end!
proc/Wander() //creates a new proc for Monster type mobs named Wander
while(src) //will loop as long as this mob exists
if(src.Target) //if the monster found a target do this
if(get_dist(src,src.Target)>1 && !step_to(src,src.Target,1)) //if they cant reach their target
src.Target=null;continue //then restart the loop without a target
src.dir=get_dir(src,src.Target) //make them face the target
src.Fight() //makes the monster attack!(coding shown below)
if(!ListCheck(src.Target,oview(5))) //ListCheck is a proc i created! you can find it in the Procedures.dm file
//note: placing a ! before an if means you want the oposite result, in this case if src.Target isnt in oview
src.Target=null //if their target wandered away, then null it out, which sets it to nothing basicaly
sleep(rand(10,15))
else
sleep(rand(15,25)) //then wait a random amount of time before taking another action

if(!src.Target) //if this mob doesnt already have a target
for(var/mob/M in oview(5)) //check for any targets within 5 blocks
if(M.key) //if any of the mobs around u are a player, then we'll target them
if(step_to(src,M,1)) //will make sure they can actualy reach the target
//(note: the step_to proc only knows how to check around dense turfs/areas)
src.Target=M //this sets the monsters target to the player it found
sleep(5)
break //as soon as it finds a target it can stop looking
proc/Fight()
for(var/mob/M in get_step(src,src.dir)) //finds any mobs directly in front of the monster
if(M.key)
flick("Attack[src.icon_state]",src)
var/damage=src.Str-M.Def //a simple damage calculation
damage=max(0,damage+rand(-1,1)) //make sure damage isnt negative and varry it a little
M.HP -= damage //subtract the damage off the victim's HP
M.DamageShow(damage,200,0,0) //flashes the damage on the screen
M.DeathCheck(src) //runs the DeathCheck proc on the victim of the attack
//(The DeathCheck proc can be found in the Procedures.dm file)


Problem description:

It's weird, I got this STRAIGHT from a Lib and it's not working in my game..

No errors or anything they just don't attack?

Got it from: http://www.byond.com/games/Falacy/RPGStarter

please help ... :(

That's your problem - the library is known for being terrible.
Start here
In response to Vic Rattlehead
Vic Rattlehead wrote:
That's your problem - the library is known for being terrible.
Start here

the library works fine... just not in my game!!


HELP!

I get no errors at all.. the mob does not seem to be targetting the player because when I used admin edit on the mob, the text was blank for "target" when I was near the mob, yet it moved towards me
In response to Karnaji
I think the problem here is that you're using an RPG Library. It's best to make rpgs from scratch.

Only use libraries when it comes to advanced systems like multi-tiles and expression evaluators
In response to Mista-mage123
this doesn't help me? why isnt this working lol
In response to Karnaji
Working fine doesn't mean it's riddled with poor programming (considering who made it, I can already tell and I've been cursed enough to look through it before)
In response to Karnaji
We don't know why it's not working because we didn't make the library you're depending on to make your game work

You're asking the wrong people; you should contact the maker of that Library, or just make an rpg engine yourself. It's honestly not that hard
In response to Mista-mage123
Mista-mage123 wrote:
We don't know why it's not working because we didn't make the library you're depending on to make your game work

You're asking the wrong people; you should contact the maker of that Library, or just make an rpg engine yourself. It's honestly not that hard

I don't know how to make monsters target players and attack them, otherwise I would ><
In response to Karnaji
mob
monster
var/mob/target
New()
.=..()
spawn() AI()
proc/AI()
dragon
AI() //this proc can be overwrote for any subtype of /mob/monster
//incase a monster should act differently from others
while(src) //aslong as the dragon is existing
walk_rand(src, 2) //make the dragon walk
for(var/mob/m in oview(src, 5))
//find a mob within a 5 tile distance
if(m) src.target=m


An example of how a monster would find another player in it's AI cycle.
In response to Vic Rattlehead
if(m) in that loop is silly, because the for() loop ensures that m is valid. You may have meant to write if(m.key) or if(m.client) though, which would check if it's a player.

Additionally: the while() loop needs a sleep() somewhere to limit how often it executes.
In response to Garthor
I thought I forgot something in the loop, I assumed (sorry!) walk_rand()'s delay would be enough.

I haven't gotten around to making an AI system yet (and I didn't really intend for that to be used), so I didn't do any tests to see where sleep() would be needed.
In response to Vic Rattlehead
sleep() would be needed because otherwise you are just repeating that loop as often physically possible, which will understandably slow down your game. IE:

mob/proc/heartbeat()
while(src)
src << "THUMP"
sleep(10)


walk_rand() won't cause a sleep, it just runs on its own.
In response to Garthor
I see, I didn't know that.
Also, another question about walk_rand(), does it have to be called recursively in while() like that, or can it be outside of the while() loop?
In response to Vic Rattlehead
Vic Rattlehead wrote:
I see, I didn't know that.
Also, another question about walk_rand(), does it have to be called recursively in while() like that, or can it be outside of the while() loop?

walk_rand() persists
step_rand() is one time

As with all step / walk procs.
In response to AJX
still need help