Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   fun with ladders and attachplayertoobj(). well, not really. (https://forums.graalonline.com/forums/showthread.php?t=72423)

calani 02-24-2007 01:00 AM

fun with ladders and attachplayertoobj(). well, not really.
 
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:
PHP Code:

// 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? ("@id@")");
  
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==falseattachplayertoobj(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? ("@id@")"); )

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.

PHP Code:

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

Change to:

PHP Code:

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


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:
PHP Code:

// 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? ("@id@")");
  
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==falseattachplayertoobj(0,id);
    
player.y+=.3;  // shoot!
    // do stuff
  
} else if (player.attached == truedetachplayer();
  
message(player.attached);
  
setTimer(.1);



Drat, you beat me to it!

Chompy 02-24-2007 01:17 AM

The wiki says this

NPC Code:

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

Quote:

Originally Posted by Chompy (Post 1281469)
The wiki says this

NPC Code:

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

Quote:

Originally Posted by xXziroXx (Post 1281470)
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

Quote:

Originally Posted by Stefan (Post 1282034)
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*


All times are GMT +2. The time now is 05:50 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.