ID:269549
 
I need help on coding ice turf, similar to the ice turf in Icon Chatterz. I've got this:
Obj/Ice
icon_state = "ice"
Entered(mob/o)
o.icy = 1
if(usr.dir == NORTH)
usr.loc=locate(usr.x,usr.y+1,usr.x)
if(usr.dir == SOUTH)
usr.loc=locate(usr.x,usr.y-1,usr.x)
if(usr.dir == EAST)
usr.loc=locate(usr.x+1,usr.y,usr.x)
if(usr.dir == WEST)
new_mob.loc=locate(usr.x-1,usr.y,usr.x)
if(usr.dir == NORTHWEST)
usr.loc=locate(usr.x-1,usr.y+1,usr.x)
if(usr.dir == NORTHEAST)
usr.loc=locate(usr.x+1,usr.y+1,usr.x)
if(usr.dir == SOUTHWEST)
usr.loc=locate(usr.x-1,usr.y-1,usr.x)
if(usr.dir == SOUTHEAST)
usr.loc=locate(usr.x+1,usr.y-1,usr.x)
Exited(mob/o)
o.icy = 0

But it doesn't do a thing..
        Entered(mob/o)
var/a = usr.dir
o.icy = 1
sleep(1)
step(usr,a)
Exited(mob/o)
o.icy = 0


Try that.

--Chwgt
Entered needs to have the proper thing defined. usr is wrong...not too sure about "new_mob" but I assume that's a mob variable which is also most likely wrong.
        Entered(atom/movable/A)
if(ismob(A))
var/mob/o=A
o.icy = 1
if(o.dir == NORTH)
o.loc=locate(o.x,o.y+1,o.x)
if(o.dir == SOUTH)
o.loc=locate(o.x,o.y-1,o.x)
if(o.dir == EAST)
o.loc=locate(o.x+1,o.y,o.x)
if(o.dir == WEST)
new_mob.loc=locate(o.x-1,o.y,o.x)

ect.
I see that you've got it defined as an obj...

Object's aren't Entered() when the player steps on the turf they are on... So it is never running your code...

It has to be defined as a turf in order for Entered() to work when the player walks onto it... (same for Exited())

If it simply HAS to be an obj, then there are ways around it, but the best way is to just program them as turfs...

If you need it to be an obj, then you need to give your turfs a special Entered() and Exited() code that calls the Entered() and Exited() procs of all objs within them...

Something like:

turf
Entered(mob/M)
for(var/obj/O in src)
O.Entered(M)
..()
Exited(mob/M)
for(var/obj/O in src)
O.Exited(M)
..()


But again, simply making all of them into turfs would be the best solution...
OnLy SoUlJaH wrote:
I need help on coding ice turf, similar to the ice turf in Icon Chatterz. I've got this:
> Obj/Ice
> icon_state = "ice"
> Entered(mob/o)
> o.icy = 1
> if(usr.dir == NORTH)
> usr.loc=locate(usr.x,usr.y+1,usr.x)
> if(usr.dir == SOUTH)
> usr.loc=locate(usr.x,usr.y-1,usr.x)
> if(usr.dir == EAST)
> usr.loc=locate(usr.x+1,usr.y,usr.x)
> if(usr.dir == WEST)
> new_mob.loc=locate(usr.x-1,usr.y,usr.x)
> if(usr.dir == NORTHWEST)
> usr.loc=locate(usr.x-1,usr.y+1,usr.x)
> if(usr.dir == NORTHEAST)
> usr.loc=locate(usr.x+1,usr.y+1,usr.x)
> if(usr.dir == SOUTHWEST)
> usr.loc=locate(usr.x-1,usr.y-1,usr.x)
> if(usr.dir == SOUTHEAST)
> usr.loc=locate(usr.x+1,usr.y-1,usr.x)
> Exited(mob/o)
> o.icy = 0
>

But it doesn't do a thing..

First of all, you are using separate references. Why even bother using usr when you passed the argument mob/o to Entered?

Next, Ice should be a turf, rather than an obj, if you want Entered to be called upon entering.

Don't use usr! There is almost always a better way of achieving the necessary call without it.

The code you have would cause your players to teleport, if it worked. You could imagine what would happen if two ice tiles were lined up next to each other, and the player entered one. By manually editing the loc variable, you are effectively changing the mob's location. However, there is no delay in doing so.

Now I can imagine that what you want is for the mob to not do the walking animation while sliding. I think that the animate_movement var would be a good candidate for preventing this.

Something such as the following should work fairly well:
turf/Ice
icon_state = "ice"
Entered(mob/o)
if(ismob(o))
o.animate_movement = 0
step(o , o.dir)
Exited(mob/o)
if(ismob(o))
o.animate_movement = 1


Hiead
In response to Hiead
Setting animate_movement to 0 sets it to "no_steps". Meaning they will suddenly jump from ice to ice. You also left out the delay you mentioned...

Also, animate_movement is having problems at the moment...
In response to DarkCampainger
Didn't know about the problems with it, and what irony as to me forgetting to add something I said needed to be added =) Anyways, I guess that means it'll have to do the animation across each turf(I'd say set the icon state to a non-animated one, but the request was to be similar to IC, and IC lets players upload their own)

I've never actually gone and dealt with animate_movement, I just know that it's there, in the Topics section when you go to Help > Help On.. (F1) in DM

Hiead
In response to Hiead
None of them worked.