PDA

View Full Version : fun with ladders and attachplayertoobj(). well, not really.


calani
02-24-2007, 01:00 AM
People have done this before.
I just can't figure out how they managed it, and its rather annoying.

Anyway, here's my dilemma:

I have a ladder class that attaches players to it when they get nearby (inside x-1..x+1 and y-.5..y+8) and lets them move on the ladder until they go past one of the ends, then it detaches them. This works perfectly.
However, when I lay a second ladder, the first stops attaching, but the second works just fine. If I lay a third, that one works fine, but the second one stops working. I'm using attachplayertoobj(0,id) so I'm not sure why it only works for the most-recently layed ladder. Bugging the crap out of me, too.


Anyway, here's the class:

// 2x8 ladder
//setshape=2,12
//in=-.5,8

function onCreated() {
setshape(1,2*16,12*16);
}

function onActionRemove() {
destroy();
}

//#CLIENTSIDE
function onCreated() {
message("Don't touch, m'kay? ("@[email protected]")");
setimg("");
showimg(1,"zodiac_ladder.png",x,y+2);
findimg(1).layer=1;
blockagain();
setshape2(2,12,{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,});
setTimer(.05);
}

function onPlayerchats() {
if (player.chat=="removeladders") {
this.acctlist={"calani","jerret"};
for(i=0;i<this.acctlist.size();i++) {
if (player.account==this.acctlist[i]) {
message("removing...");
triggeraction(x+1,y+1,"Remove",NULL);
}
}
} elseif (player.chat=="detach") {
detachplayer();
player.x=x+1.5;
player.y=y-1.5;
}
}

function onTimeout() {
if (player.x in |x-1,x+1| && player.y in |y-.5,y+8|) {
if (player.attached==false) attachplayertoobj(0,id);
// do stuff
} else detachplayer();
// message(player.attached);
setTimer(.1);
}


ps: the acctlist is going poof when I finish my staff sys - I'll replace it with a db query to get the current list of staff with the right to lay ladders

Chompy
02-24-2007, 01:06 AM
Hmm, whenever you place a new one, is 'id' always different? ( referring to message("Don't touch, m'kay? ("@[email protected]")"); )

Also, is it a joined class, like join("ladder"); in a level, or putnpc2?

calani
02-24-2007, 01:08 AM
yes, they are always different.
and by layed class I mean a putnpc2().

xXziroXx
02-24-2007, 01:13 AM
This causes the last created ladder to unattach the player all the time since he/she isnt close to the ladder.


if (player.x in |x-1,x+1| && player.y in |y-.5,y+8|) {
if (player.attached==false) attachplayertoobj(0,id);
// do stuff
} else detachplayer();


Change to:


if (player.x in |x-1,x+1| && player.y in |y-.5,y+8|) {
if (player.attached==false) attachplayertoobj(0,id);
// do stuff
} else if (player.attached == true) detachplayer();

calani
02-24-2007, 01:14 AM
Thanks to ziro, its fixed =)

Script ladder updated by xXziroXx (x12 or so)
Ladder Solution Guy: Fixed.
DND: oO how?
Ladder Solution Guy: if (player.x in |x-1,x+1| && player.y in |y-.5,y+8|) { ... } else detachplayer();
Ladder Solution Guy: changed to
Ladder Solution Guy: if (player.x in |x-1,x+1| && player.y in |y-.5,y+8|) { ... } else if (player.attached == true) detachplayer();
Ladder Solution Guy: since other wise the last created ladded will unattach the player since he/she isnt close to the ladded
Ladder Solution Guy: ladder*


and for those that just want to look at the fixed version:

// 2x8 ladder
//setshape=2,12
//in=-.5,8

function onCreated() {
setshape(1,2*16,12*16);
}

function onActionRemove() {
destroy();
}

//#CLIENTSIDE
function onCreated() {
message("Don't touch, m'kay? ("@[email protected]")");
setimg("");
setshape2(2,12,{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,});
setTimer(.05);
}

function onPlayerchats() {
if (player.chat=="removeladders") {
this.acctlist={"calani","jerret"};
for(this.i=0;this.i<this.acctlist.size();this.i++) {
if (player.account==this.acctlist[this.i]) {
message("removing...");
level.ladderscount=1;
triggeraction(x+1,y+1,"Remove",NULL);
}
}
} elseif (player.chat=="detach") {
detachplayer();
player.x=x+1.5;
player.y=y-1.5;
}
}

function onTimeout() {
showimg(1,"zodiac_ladder.png",x,y+2);
findimg(1).layer=0;
blockagain();
if (player.x in |x-1,x+1| && player.y in |y-.5,y+8|) {
if (player.attached==false) attachplayertoobj(0,id);
player.y+=.3; // shoot!
// do stuff
} else if (player.attached == true) detachplayer();
message(player.attached);
setTimer(.1);
}



Drat, you beat me to it!

Chompy
02-24-2007, 01:17 AM
The wiki says this


Using attachpayertoobj(0, id); the player will be attached to the current NPC.


So I think it will attach it to the current npc (the last layed npc) :o
hmm, but that shouldn't effect that..

xXziroXx
02-24-2007, 01:21 AM
The wiki says this


Using attachpayertoobj(0, id); the player will be attached to the current NPC.


So I think it will attach it to the current npc (the last layed npc) :o
hmm, but that shouldn't effect that..

Did you even read the two posts before the one you just posted?

Chompy
02-24-2007, 01:23 AM
Did you even read the two posts before the one you just posted?

Yeah, I just realised xD

Admins
02-25-2007, 04:04 PM
Hmmm I would say you should add one more check:
if (player.attachedtoobject==this) detachplayer();
or
if (player.attachid==id) detachplayer();
otherwise the ladders might detach the player from other ladders

Kristi
02-26-2007, 03:08 AM
Hmmm I would say you should add one more check:
if (player.attachedtoobject==this) detachplayer();
or
if (player.attachid==id) detachplayer();
otherwise the ladders might detach the player from other ladders

::nod:: especially with a timeout of .1;

calani
03-14-2007, 07:06 PM
much better.
*adds*