G2k1
|
![Kamaeru's Avatar](image.php?s=da426e5f7b231ad78f2afa5259e4b144&u=1176&dateline=1499575378) |
Join Date: Dec 2001
Posts: 1,040
|
|
Quote:
Originally Posted by maximus_asinus
I'm trying to use attachplayertoobj.
|
Ok I actually figured that out recently. You have to set the positions for entering/exiting as a square area. Something like this in the case of a bridge I scripted for Dustari:
NPC Code:
function onCreated() {
this.isbridge = true;
dontBlock();
drawoverplayer();
}
//#CLIENTSIDE
function onCreated() {
this.bridgeWidth = 12;
this.bridgeHeight = 9;
this.bindPositions = {
{3, {-1,3.5}, {1,4.5}}, // {dirToBindOn, {x1,y1}, {x2, y2}}
{1, {11,3.5}, {13,4.5}}
};
this.tilesOver = {
22,22,22,22,22,22,22,22,22,22,22,22,
22,22,22,22,22,22,22,22,22,22,22,22,
22,22,22,22,22,22,22,22,22,22,22,22,
0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
22,22,22,22,22,22,22,22,22,22,22,22,
22,22,22,22,22,22,22,22,22,22,22,22,
22,22,22,22,22,22,22,22,22,22,22,22,
22,22,22,22,22,22,22,22,22,22,22,22,
};
this.tilesUnder = {
22,22,22,22,0 ,0 ,0 ,0 ,22,22,22,22,
22,22,22,22,0 ,0 ,0 ,0 ,22,22,22,22,
22,22,22,22,0 ,0 ,0 ,0 ,22,22,22,22,
22,22,22,22,0 ,0 ,0 ,0 ,22,22,22,22,
22,22,22,22,0 ,0 ,0 ,0 ,22,22,22,22,
22,22,22,22,0 ,0 ,0 ,0 ,22,22,22,22,
22,22,22,22,0 ,0 ,0 ,0 ,22,22,22,22,
22,22,22,22,0 ,0 ,0 ,0 ,22,22,22,22,
22,22,22,22,0 ,0 ,0 ,0 ,22,22,22,22,
};
setShape2(this.bridgeWidth, this.bridgeHeight, this.tilesUnder);
setImg("g2k1_dustari_castlebridge.png");
}
function onPlayerEnters() { this.setTimer(0.05); }
function onTimeout() {
temp.pcx = player.x + 1.5;
temp.pcy = player.y + 2;
temp.inzone = 0;
for (temp.i: this.bindPositions) {
temp.cdir = temp.i[0];
temp.cx1 = this.x + temp.i[1][0];
temp.cx2 = this.x + temp.i[2][0];
temp.cy1 = this.y + temp.i[1][1];
temp.cy2 = this.y + temp.i[2][1];
if (temp.pcx in |temp.cx1, temp.cx2| && temp.pcy in |temp.cy1, temp.cy2|) {
if (player.attached && player.dir != temp.cdir)
leaveBridge();
else if (!player.attached && player.dir == temp.cdir)
enterBridge();
temp.inzone = 1;
}
}
this.setTimer(0.05);
}
function leaveBridge() {
drawunderplayer();
setShape2(this.bridgeWidth, this.bridgeHeight, this.tilesUnder);
detachPlayer();
sleep(.2);
drawoverplayer();
}
function enterBridge() {
setShape2(this.bridgeWidth, this.bridgeHeight, this.tilesOver);
attachPlayerToObj(0, id);
}
The important thing to look at being this.bindpositions because it is what tells the timeout function where to check. It took me a while to figure this out, but this script can be modified to create a nice illusion of layering in many situations. |
__________________
3DS friendcode: 1118-0226-7975
|
|