attachplayertoobj help

Ok, so I’ve tried getting this to work, but I don’t know how to find out an NPC’s index so that I can attach the player to it. Any help please? (This is for a moving dungeon platform, I’ve already got the script for the moving to work.)

npcs[ index ].id the server id of the npc //Can I get help with this?

attachplayertoobj type,id; attachs the player to an npc (type=0) //And this?

Suggest you use the ‘move’ command for moving your platform, it’s the smoothest :smiley:

Use this command:
attachplayertoobj 0,id;

Have a look at graal2001 pirate ships, shows you can use if(playerattached) when doing tests for your ‘move’ command.

Remember that playerx/playery will change to 0,0 when they are in the top left corner of your object once attached! (if you are using playerx/playery for your platform script)

if (created) {
  setimg pirateship1.png;
  drawunderplayer;
  noplayeronwall;
  this.mdir = -1;
  this.speed = 3;
  setstring this.warp,abcdefghijklmnopqrstuvwxy;

  timeout = 0.1;
}
if (created || initialized) {
  setshape 1,14*16,20*16;
}
if (actionmoveship) {
  if (mdir>=0) {
    mdir = int(strtofloat(#p(0)));
    if (mdir>=0 && mdir<=3) {
      setplayerprop #c,Aye Sir!;
      this.mdir = mdir;
    }
  }
}
if (playerchats) {
  setstring this.textp,#a;
  this.testx = playerx;
  this.testy = playery;
  this.testx2 = x;
  this.testy2 = y;
}
if (playerchats && (playerx in |x,x+14|) && (playery in |y,y+20|)) {
  if (strequals(#c,stop)) {
    setplayerprop #c,Aye Sir!;
    this.mdir = -1;
  } else if (strequals(#c,leave)) {
    setplayerprop #c,Aye Sir!;
    detachplayer;
    if (x<25) {
      playerdir = 3;
      playerx = x+12;
    } else {
      playerdir = 1;
      playerx = x-1;
    }
  }
}
if (timeout) {
  if (this.mdir>=0) {
    dir = this.mdir;
    dist = this.speed;
    newx = x + vecx(dir)*dist;
    newy = y + vecy(dir)*dist;

    levxmove = (newx<-4? -1 : newx>54? 1 : 0);
    levymove = (newy<-4? -1 : newy>52? 1 : 0);
    warped = false;

    if (levxmove!=0 || levymove!=0) {
      // Level warp
      if (startswith(world,#L)) {
        levx = indexof(#e(5,1,#L),#s(this.warp))+1;
        levy = strtofloat(#e(7,2,#L));
        if (levx>=1 && levy>=1 &&
            (levx+levxmove in |1,25|) && (levy+levymove in |1,25|)) {
          setstring this.dest,world#e(levx+levxmove-1,1,#s(this.warp))-;
          if (levy+levymove<10) setstring this.dest,#s(this.dest)0;
          setstring this.dest,#s(this.dest)#v(levy+levymove).nw;

          warpto #s(this.dest),(levxmove<0? 54 : levxmove>0? -4 : x),
            (levymove<0? 52 : levymove>0? -4 : y);
          warped = true;
        }
      }
    }

    if (warped==false) {
      if (!onwater2(newx+4.1,newy+4.1,5.8,7.8) || 
          onwall2(newx+4.1,newy+4.1,5.8,7.8)) 
        this.mdir = -1; // stop
      else
        move vecx(dir)*dist,vecy(dir)*dist,1,1;
    }
  }
  timeout = 1;
}

//#CLIENTSIDE
if (created) {
  setshape2 14,20,{
     0, 0, 0, 0,22,22,22,22,22,22, 0, 0, 0, 0,
     0, 0, 0,22,22,22,22,22,22,22,22, 0, 0, 0,
     0, 0, 0,22,22,22,22,22,22,22,22, 0, 0, 0,
     0, 0,22,22, 3, 3, 0, 0, 3, 3,22,22, 0, 0,
     0, 0,22, 0, 3, 3, 0, 0, 3, 3, 0,22, 0, 0,
     0, 0,22, 0, 0, 0, 0, 0, 0, 0, 0,22, 0, 0,
     0, 0,22, 0, 0, 0, 0, 0, 0, 0, 0,22, 0, 0,
     0, 8,22, 0, 0, 0,22,22, 0, 0, 0,22, 8, 0,
     8, 8,22, 0, 0, 0, 0, 0, 0, 0, 0,22, 8, 8,
     8, 8,22, 0, 0, 0, 0, 0, 0, 0, 0,22, 8, 8,
     8, 8,22, 0, 0, 0, 0, 0, 0, 0, 0,22, 8, 8,
     8, 8,22,22, 0, 0, 0, 0, 0, 0,22,22, 8, 8,
     8, 0,22,22,22, 0,22,22, 0,22,22,22, 0, 8,
     0, 0,22,22,22,22,22,22,22,22,22,22, 0, 0,
     0, 0,22,22,22,22,22,22,22,22,22,22, 0, 0,
     0, 0, 0,22,22,22,22,22,22,22,22, 0, 0, 0,
     0, 0, 0, 0,22,22,22,22,22,22, 0, 0, 0, 0,
     0, 0, 0, 0, 0,22,22,22,22, 0, 0, 0, 0, 0,
     0, 0, 0, 0, 0, 0,22,22, 0, 0, 0, 0, 0, 0,
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  };
  dontblock;
}
if (playerenters || timeout) {
  if (playerattached) {
    if ((strequals(#m,grab) || strequals(#m,pull)) && playerdir==2) {
      mdir = -1;
      for (i=0; i<4; i++)
        if (keydown(i)) mdir = i;
      if (mdir>=0)
        triggeraction playerx+1.5,playery+2,moveship,#v(mdir);
    }
  } else {
    if (playery+2 in |y+7,y+11| &&
       ((playerx+2.5 in |x+2,x+4| && playerdir==3) ||
        (playerx+0.5 in |x+10,x+12| && playerdir==1))) {
      attachplayertoobj 0,id;
      playerx += vecx(playerdir)*2;
    }
  }
  showimg 200,boat-mass2.png,x,y-8;
  timeout = 0.05;
}
if (playertouchsme) {
  if (!playerattached && strequals(#s(client.race),bomy)) {
    attachplayertoobj 0,id;
    playerx = x+5.5;
    playery = y+4.5;
  }
}

[QUOTE=Agret;55539]
Suggest you use the ‘move’ command for moving your platform, it’s the smoothest :smiley:

Use this command:
attachplayertoobj 0,id;

Have a look at graal2001 pirate ships, shows you can use if(playerattached) when doing tests for your ‘move’ command.

Remember that playerx/playery will change to 0,0 when they are in the top left corner of your object once attached! (if you are using playerx/playery for your platform script)

[CODE]
if (created) {
setimg pirateship1.png;
drawunderplayer;
noplayeronwall;
this.mdir = -1;
this.speed = 3;
setstring this.warp,abcdefghijklmnopqrstuvwxy;

timeout = 0.1;
}
if (created || initialized) {
setshape 1,1416,2016;
}
if (actionmoveship) {
if (mdir>=0) {
mdir = int(strtofloat(#p(0)));
if (mdir>=0 && mdir<=3) {
setplayerprop #c,Aye Sir!;
this.mdir = mdir;
}
}
}
if (playerchats) {
setstring this.textp,#a;
this.testx = playerx;
this.testy = playery;
this.testx2 = x;
this.testy2 = y;
}
if (playerchats && (playerx in |x,x+14|) && (playery in |y,y+20|)) {
if (strequals(#c,stop)) {
setplayerprop #c,Aye Sir!;
this.mdir = -1;
} else if (strequals(#c,leave)) {
setplayerprop #c,Aye Sir!;
detachplayer;
if (x<25) {
playerdir = 3;
playerx = x+12;
} else {
playerdir = 1;
playerx = x-1;
}
}
}
if (timeout) {
if (this.mdir>=0) {
dir = this.mdir;
dist = this.speed;
newx = x + vecx(dir)*dist;
newy = y + vecy(dir)*dist;

levxmove = (newx<-4? -1 : newx>54? 1 : 0);
levymove = (newy<-4? -1 : newy>52? 1 : 0);
warped = false;

if (levxmove!=0 || levymove!=0) {
  // Level warp
  if (startswith(world,#L)) {
    levx = indexof(#e(5,1,#L),#s(this.warp))+1;
    levy = strtofloat(#e(7,2,#L));
    if (levx>=1 && levy>=1 &&
        (levx+levxmove in |1,25|) && (levy+levymove in |1,25|)) {
      setstring this.dest,world#e(levx+levxmove-1,1,#s(this.warp))-;
      if (levy+levymove<10) setstring this.dest,#s(this.dest)0;
      setstring this.dest,#s(this.dest)#v(levy+levymove).nw;

      warpto #s(this.dest),(levxmove<0? 54 : levxmove>0? -4 : x),
        (levymove<0? 52 : levymove>0? -4 : y);
      warped = true;
    }
  }
}

if (warped==false) {
  if (!onwater2(newx+4.1,newy+4.1,5.8,7.8) || 
      onwall2(newx+4.1,newy+4.1,5.8,7.8)) 
    this.mdir = -1; // stop
  else
    move vecx(dir)*dist,vecy(dir)*dist,1,1;
}

}
timeout = 1;
}

//#CLIENTSIDE
if (created) {
setshape2 14,20,{
0, 0, 0, 0,22,22,22,22,22,22, 0, 0, 0, 0,
0, 0, 0,22,22,22,22,22,22,22,22, 0, 0, 0,
0, 0, 0,22,22,22,22,22,22,22,22, 0, 0, 0,
0, 0,22,22, 3, 3, 0, 0, 3, 3,22,22, 0, 0,
0, 0,22, 0, 3, 3, 0, 0, 3, 3, 0,22, 0, 0,
0, 0,22, 0, 0, 0, 0, 0, 0, 0, 0,22, 0, 0,
0, 0,22, 0, 0, 0, 0, 0, 0, 0, 0,22, 0, 0,
0, 8,22, 0, 0, 0,22,22, 0, 0, 0,22, 8, 0,
8, 8,22, 0, 0, 0, 0, 0, 0, 0, 0,22, 8, 8,
8, 8,22, 0, 0, 0, 0, 0, 0, 0, 0,22, 8, 8,
8, 8,22, 0, 0, 0, 0, 0, 0, 0, 0,22, 8, 8,
8, 8,22,22, 0, 0, 0, 0, 0, 0,22,22, 8, 8,
8, 0,22,22,22, 0,22,22, 0,22,22,22, 0, 8,
0, 0,22,22,22,22,22,22,22,22,22,22, 0, 0,
0, 0,22,22,22,22,22,22,22,22,22,22, 0, 0,
0, 0, 0,22,22,22,22,22,22,22,22, 0, 0, 0,
0, 0, 0, 0,22,22,22,22,22,22, 0, 0, 0, 0,
0, 0, 0, 0, 0,22,22,22,22, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,22,22, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
dontblock;
}
if (playerenters || timeout) {
if (playerattached) {
if ((strequals(#m,grab) || strequals(#m,pull)) && playerdir==2) {
mdi

…is there something wrong with that?

I didn’t feel like learning a whole new command so I just changed the x with a variable. The script works fine this is what I got.

// NPC made by Kondie timereverywhere; if (created || playerenters) { setimg block.png; dontblock; drawunderplayer; } if (playertouchsme && s=30) { attachplayertoobj 0,id; } if (playertouchsme && s=0) { detachplayer; } if (created || timeout){ timereverywhere; for (s=0;s<=30;s+=.2){x=s;sleep .05;} sleep 4; for (s=30;s>=0;s-=.2){x=s;sleep .05;} timeout = 4; }