Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-24-2007, 01:00 AM
calani calani is offline
Scriptess
calani's Avatar
Join Date: Aug 2003
Location: asmgarden.gmap
Posts: 606
calani is on a distinguished road
Send a message via AIM to calani
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
__________________
Reply With Quote
  #2  
Old 02-24-2007, 01:06 AM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
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?
__________________
Reply With Quote
  #3  
Old 02-24-2007, 01:08 AM
calani calani is offline
Scriptess
calani's Avatar
Join Date: Aug 2003
Location: asmgarden.gmap
Posts: 606
calani is on a distinguished road
Send a message via AIM to calani
yes, they are always different.
and by layed class I mean a putnpc2().
__________________
Reply With Quote
  #4  
Old 02-24-2007, 01:13 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
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(); 
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #5  
Old 02-24-2007, 01:14 AM
calani calani is offline
Scriptess
calani's Avatar
Join Date: Aug 2003
Location: asmgarden.gmap
Posts: 606
calani is on a distinguished road
Send a message via AIM to calani
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!
__________________
Reply With Quote
  #6  
Old 02-24-2007, 01:17 AM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
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..
__________________
Reply With Quote
  #7  
Old 02-24-2007, 01:21 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Quote:
Originally Posted by Chompy View Post
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?
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #8  
Old 02-24-2007, 01:23 AM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by xXziroXx View Post
Did you even read the two posts before the one you just posted?
Yeah, I just realised xD
__________________
Reply With Quote
  #9  
Old 02-25-2007, 04:04 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
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
Reply With Quote
  #10  
Old 02-26-2007, 03:08 AM
Kristi Kristi is offline
Bowie's Deciple
Kristi's Avatar
Join Date: Dec 2003
Location: Boston, MA
Posts: 748
Kristi has a spectacular aura aboutKristi has a spectacular aura about
Send a message via AIM to Kristi Send a message via MSN to Kristi
Quote:
Originally Posted by Stefan View Post
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;
__________________
Reply With Quote
  #11  
Old 03-14-2007, 07:06 PM
calani calani is offline
Scriptess
calani's Avatar
Join Date: Aug 2003
Location: asmgarden.gmap
Posts: 606
calani is on a distinguished road
Send a message via AIM to calani
much better.
*adds*
__________________
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 03:27 AM.


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