ID:144669
 

what i need to do is make it so npcs dont wander to far off there area or into higher lvl areas so heres what i got so far

Code for npcs


Wolf
name = "Wolf"
icon = 'Enemies.dmi'
icon_state="wolf"
hp=100
maxhp=100
level=5
str=75
def=40
agil=30
cash=20
exp=4
src.Bars()
npc = 1

code for the turf


npc_cannot_walk
name = ""
icon_state = "1"
density = 0
Entered(mob/M)
if(M.npc==1)
density = 1

and the var is in
mob/var/npc = 0 under the man vars of players

and it dont get errors it jsut the npcs walk trhough it


also i dont get errors the npcs just walk through it and
Silveraaron wrote:
what i need to do is make it so npcs dont wander to far off there area or into higher lvl areas so heres what i got so far

Code for npcs
> Wolf
> name = "Wolf"
> icon = 'Enemies.dmi'
> icon_state="wolf"
> hp=100
> maxhp=100
> level=5
> str=75
> def=40
> agil=30
> cash=20
> exp=4
> src.Bars()
> npc = 1
>
> code for the turf
>
>
> npc_cannot_walk
> name = ""
> icon_state = "1"
> density = 0
> Entered(mob/M)
> if(M.npc==1)
> density = 1

and the var is in
mob/var/npc = 0 under the man vars of players

and it dont get errors it jsut the npcs walk trhough it


also i dont get errors the npcs just walk through it and


Instead of setting its density to 0, which mean the next monsters won't be abvle to enter it, but use a return of 0.
>   npc_cannot_walk
> name = ""
> icon_state = "1"
> density = 0
> Entered(mob/M)
> if(M.npc)
> return 0


the if(M.npc) is robust coding. For True and False vars
if(condition==1) or if(condition== 0)
instead do:
if(condition) (true) and if(!condtiion) (false)

For more, look up "Green Programming" in Byondscape.

In response to Mechanios
Close but no cigar, Mechanios, he's using the Entered() proc. The NPC is already IN that turf, you don't want that. Second, it would be easier to use areas.

area
var
combat_level
Enter(var/atom/movable/O)
if(istype(O,/mob/npc))
var/area/a = npc.loc.loc
if(a&&a.combat_level!=src.combat_level)
return 0
return ..()
In response to Ter13
He's right. You must use enter when preveting something from entering the space. Using entered, it has already in the turf and thereby leaving all that stuff ineffective. Enter is what use should you here.
In response to Pyro_dragons
UP(unkown person helped me)

npc_cannot_walk
name = ""
icon_state = "1"
density = 0
Enter(mob/M)
if(ismob(M) && !M.npc)
return ..()


so i got it gusy thanx
In response to Silveraaron
That's a HORRID code example! You are casting an object that may not be a /mob as a /mob, you aren't returning at all possible paths, and on top of that, your design method is flawed in its inception!

We'll see you in a few days when you figure out it isn't working...
In response to Ter13
Oh, my bad. I thought Entered was always before Enter. I'll remember that.
In response to Ter13
Ter13 wrote:
That's a HORRID code example! You are casting an object that may not be a /mob as a /mob, you aren't returning at all possible paths, and on top of that, your design method is flawed in its inception!

We'll see you in a few days when you figure out it isn't working...

Actually, that code worked. It's okay to call the object /mob because it's not actually assuming it's a mob until it checks, and it never uses anything at a lower level like /atom/movable. If the object is not a mob or is not the right kind, it is not allowed in; null is the default return value, which is a no.

The only modification I'd make is that many kinds of objs, like projectiles, you'd probably want to allow.

Lummox JR
In response to Mechanios
Why would it be? When you Enter a turf, you have Entered it. Entered is in past tense. If you have Entered something, you have been able to Enter it in the past.