ID:1330934
 
(See the best response by Kitsueki.)
Code:


Problem description:

Let's get this out the way, the game is a side-scroller, so the map transitions in a different way, like to go from above ground into a sewer you press like enter/space or something. How would i achieve that.

Next, let's say I want a zombie to chase me from map to map, until either it's A. Killed or B. Distracted by something else(another player & sound)
and if so how would I go about doing it without destroying my CPU usage. I was thinking maybe an active/inactive variable for a car , like lets say the alarm variable is active on a car, so the zombies get drawn to it until the alarm variable is inactive then they go back to normal business.

I'm a beginner programmer, like I can do maps but I just wanted a general idea in the direction I should take for these types of things, or if someone can start me off with a bit of side notes
//yo
type things.
Best response
Well, what I'd probably do in this case is to be very precise. Break everything up into steps, and think about it as logically as you can.

You need a root level, basic behavior. This behavior roams, chills out, or whatever else the zombie does without any special conditions.

After that, implement the checks for the special condition. Is prey in range of the zombie? Pursue the closest candidate. Prey can be whatever you design it to be, so I'd probably have a separate proc for checking that.

mob/zombie/proc/behavior()
while(src)
// do default idling
var atom/movable/prey = findPrey()
if(istype(prey))
pursuePrey(prey)


Now, findPrey() can narrow things down as much as you like. Notice how I typecasted prey to be /atom/movable, so that it can prey on both mobs and objs.

In pursuePrey(), simply order it to approach whatever it's after. Each time behavior() loops around, it'll re-adjust it's prey and pursue it then.

Hope this helps guide you. :)
//AI for zombies, like them being attracted to active items(cars/gun) then when a mob(you)come around it comes after you.


var/mob/player/m
var/obj/o

obj/
var/active = 0
var/inactive = 0


//mob/zombie/proc/Attack()
//if(bounds_dist(src, m) < 3)






/*mob/proc
returnPlayers() {for(var/mob/player/m in oview(m)) {return m}}
mob/proc
ai() {var/mob/player/target = returnPlayer(src); if(target) {step_towards(src,target)} step_rand(src);sleep(5);ai()}*/


mob/zombie/proc/defaultidle()
for(m in oview(src)) {step_towards(src, m);break}
step_rand(src)


mob/zombie/proc/findPrey()
var/list/surroundings = new()
for(m in oview(src))//how would I also make it add the object that is active in the list, this has MORE PRIORITY then the mob only for a certain time 10 seconds,so it would go to the active object and forget about the mob(delete the mob from the list until mob comes back)
surroundings.Add(m)
if(m in oview(src))
step_towards(src, m)
;break
step_rand(src)

//attacking crap goes here I presume?


mob/zombie/proc/pursuePrey()
for(m in oview(src))
if(m in oview(src))
step_towards(src, m)
;break
step_rand(src)
//Attack()
//for(var/mob/player/m in the surroundings list, even if they just ran by and not in view still go after them, until they're in view of another active object and objects too)




mob/zombie/proc/behavior()
while(src)
defaultidle()
var atom/movable/prey = findPrey()
if(istype(prey))//how would I define the mob as prey in the list I created above? sorry im noob at this...
pursuePrey(prey)


Sorry for my nooby programming, this is just my mindset on how I'd try to get this going, even though I'm not sure if I'm doing it correctly. Also I think I'm doing it totally wrong, because it looks like my defaultidle proc is doing what all the other procs would pretty much do. So there's no point in stepping toward the mob in multiple strings since it's already doing it, so that means I'd have to change up behavior proc to include objs since I wouldn't need find prey and the rest of them right?

OR would it be easier to shrink it all down to this,which I think is the exact same thing as all that uptop

var/mob/player/m
var/obj/o

mob/zombie/proc/defaultidle()
for(m in oview(src)) {step_towards(src, m);break}
step_rand(src)
for(o in oview(src)) {step_towards(src, o);break}
step_rand(src)





mob/zombie/proc/behavior()
icon = 'Walker.dmi'
while(src)
defaultidle()
var atom/movable/prey = findPrey()
if(istype(prey))
pursuePrey(prey)




If I shrink it down to this how will the behavior proc then work with also objects aswell like the cars, or will I not need the behavior proc anymore, so I can test it out by mapping the zombie and using me as the mob?
Ah, indeed.. I'll explain a bit more on it. Don't worry, this place is here to help, so we'll figure it out.

Each of these procs should be working together.

mob
Zombie
proc

behavior()
var atom/movable/target
while(src)
target = findPrey() // we'll find our target
if(istype(target))
pursuePrey(target) // now pursue it
sleep(50) // just a figure

findPrey()
var atom/movable/target
for(var/atom/movable/a in oview())
var obj/car/o // lets typecast a variable for whether it's an /obj/car
if(get_dist(src, a) < get_dist(src, target))
if(istype(a, /obj/car)) // check the type so we can handle /obj/car instances
o = a
if(o.alarm) // if an /obj's alarm variable is set to be true
target = o // we only want cars with alarms going off right?
if(ismob(a)) // mobs don't have any special conditions I assume
target = a
return target // once we have the target filtered, return it to our calling proc

pursuePrey(atom/movable/a)
step_to(src, a)
if(get_dist(src, a) == 0) // I believe it should be 0 at point blank, not sure
attack(a)

attack(atom/movable/a)
// whatever attack stuff you do


There's the gist of this little code, at the bare minimum. It filters out a target from those provided in oview(). It may need some adjustment due to a lack of testing, but I don't see any issues from reading it.

You'll like have to build onto this to get where you want.

behavior() is something that is always active. From there, you manage everything going on

findPrey() is the hard worker, it does all the filtering of the targets to get the proper one we want (well.. the ZOMBIE wants :o) and then returns it back to be integrated into the zombie's behavior() *wink*

pursuePrey() is the male Lion of the operation, it doesn't take care of any of the hard work.. it just fights and goes after targets. That being said, here is where the zombie actually moves and tries to attack it's target. This will require attack to be able to take in an /atom/movable object, or at least be fixed up to not falter because of it.

you can adjust what's in sleep() to fit your needs.
mob/Zombie/proc/behavior()
var atom/movable/target
while(src)
target = findPrey()
if(istype(target))
pursuePrey(target)//undefined proc
sleep(50)




mob/Zombie
proc
findPrey()
var atom/movable/target
for(var/atom/movable/a in oview())
var obj/car/o//varabile defined but not used
if(get_dist(src, a) < get_dist(src, target))
if(istype(a, /obj/car))//undefined type path
o = a//undefined type:o
if(o.alarm)//undefined type:o.alarm
target = o//undefined type: o
if(ismob(a))
target = a
return target


pursurePrey(atom/movable/a)
step_to(src,a)
if(get_dist(src, a)== 0)
attack(a)

attack(atom/movable/a)



Pretty much copied what you did and compiled after readjusting the identation etc, and it gets a few errors
in these lines, it's probably because I'm missing other programming needed outside of this probably?
I would take a look at forum_account's AI tutorial, greatly helpful if you are looking to get good looking/feeling AI and the coding practices you will learn while reading/doing the tutorial will be greatly beneficial.
Make sure your names are right :)

you have pursuePrey() and pursurePrey() in your code.
Alright guys, I feel stupid thanks l0l. Those otehrs are still undefined type path though, ill take a look at forum_accounts AI tutorial though
In response to Chaorace
If you post them, I'm sure we can try to figure something out.
They are in the code above I put //where they are telling you the error. I'm kind of stuck now though not sure how to fix them l0l.
Ah, most of them are related to /obj/car not being defined anywhere. Have you defined it?

Also, remove the declaration of o, and declare it as it's being assigned. (var obj/car/o = a)
        obj
car
icon = 'BodyPile3.dmi'
density = 1
var/alarm
alarm = 0
Thats the car turf, it's not a moable one though, because the car doesn't move aha

o is still undefined type though because car isnt defined I guess yet like you said
It looks like you have obj indented.. what is it under?
var/alarm = 0

turf
scenery
sewer
icon = 'sewer.dmi'

brick_floor
icon_state = "plainbrick1"
New()
..()
if(prob(30)) icon_state = "plainbrick2"

slime
density = 1

middle
icon_state = "slimemiddle"

New()
..()
if(prob(5)) src.slimeAnimate()

proc/slimeAnimate()
while(1)
sleep(rand(10, 70))
src.icon_state = "slimemiddle2"
sleep(rand(3))
src.icon_state = "slimemiddle"

top
icon_state = "slime1"
New()
..()
if(prob(40)) icon_state = "slime2"

bottom
icon_state = "slimebottom1"
New()
..()
if(prob(40)) icon_state = "slimebottom2"

wall_slime
icon_state = "wall2slime1"
New()
..()
if(prob(40)) icon_state = "wall2slime2"

walls
density = 1

wallpipe
wp1/icon_state = "wallpipe1"
wp2/icon_state = "wallpipe2"
wp3/icon_state = "wallpipe3"
wp4/icon_state = "wallpipe4"
wp5/icon_state = "wallpipe5"
wp6/icon_state = "wallpipe6"

top
icon_state = "topwall1"
New()
..()
if(prob(40)) icon_state = "topwall2"

//DENSITY_Turf //time saver for whoever doesn't want to cut up confusing 16x16 tiles. I think it might work using this to overlay over the art. Just an idea, if not FML.
// DENSITY
// icon = ""
// density = 1

Dead_Bodies
body_pile1
icon = 'Body Piles.dmi'
density = 0
var/bound_width = 54
var/bound_height = 26
body_pile2
icon = 'BodyPile2.dmi'
density = 0


//alarm() Calls alarm proc
Trash_Cans
density = 1
icon = 'TrashCans.dmi'
BloodyCans
bc1/icon_state = "DeadBodyCan"
bc2/icon_state = "BloodCan"
bc3/icon_state = "NormalCan"
FullBloodyCan
icon = 'TrashCans2.dmi'


obj
car
icon = 'BodyPile3.dmi'
density = 1
var/alarm
alarm = 0


Pretty much every icon programmed in right now, since it's a brand new project
You would access it as type /turf/FullBloodyCan/obj/car

If I may suggest it, I refrain from using any of the names from built in types in my paths. That car is a turf, not an obj. Object and obj are different meanings. Object is a physical piece of data, obj is a type of object.
Ah there we go no errors now. Name from built in types, what would be an exmaple?
In response to Chaorace
/datum
/list
/icon
/world
/atom
/atom/movable
/area
/turf
/mob
/obj

I believe those are all the built in types. I might have forgotten one or two.

Edit:
/client
oh okay, so neever use those in my paths?
I believe that would be wise, to avoid confusion :)
OKay, so now when I program in the zombie mob, do i make it it's own uhh. mob i guess, and link the behavior() proc to it? Like this?

mob
zombie
icon = '.dmi'
behavior()


Page: 1 2