Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Old Scripting Engine (GS1) (https://forums.graalonline.com/forums/forumdisplay.php?f=154)
-   -   Help me weed out bad practices. (https://forums.graalonline.com/forums/showthread.php?t=134270525)

DustyPorViva 08-02-2017 12:51 AM

Quote:

Originally Posted by cbk1994 (Post 1741721)
This is a really neat trick, but I'm curious why you'd prefer this over a serverside onPlayerEnters?

Mostly picked it up from using it on gmaps, since I can throw it in a class and put it in levels on an overworld, snap it with x = int(this.x/64)*64; and it will still warp players out of specific levels on the gmap, since onPlayerEnters() doesn't work. I also just find it more reliable since it will persist even after the initial entering the level.

Kamaeru 08-02-2017 09:10 PM

Quote:

Originally Posted by DustyPorViva (Post 1741729)
Mostly picked it up from using it on gmaps, since I can throw it in a class and put it in levels on an overworld, snap it with x = int(this.x/64)*64; and it will still warp players out of specific levels on the gmap, since onPlayerEnters() doesn't work. I also just find it more reliable since it will persist even after the initial entering the level.

That's how zones are handled on 2k1 like event zones (survivor, CNR, etc), kingdoms zones, nopk zones, quest zones, etc.

maximus_asinus 08-03-2017 04:52 AM

Without having a weapon added to another player, is it possible to manipulate another player who is not in the same level as me?

maximus_asinus 08-08-2017 03:16 AM

I'm trying to use attachplayertoobj.
PHP Code:

if (created) {
  
setshape 1,256,128;
}
if (
playertouchsme) {
  
attachplayertoobj 0,id;


Offline that works flawlessly, but online if I touch the NPC my coordinates get set to 0 and I'm warped to the corner of the level. What am I doing wrong?

MysticalDragon 03-17-2018 08:26 PM

this is a bit late try doing it clientside online

Kamaeru 03-18-2018 05:24 AM

Quote:

Originally Posted by maximus_asinus (Post 1741772)
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.

MysticalDragon 03-18-2018 08:12 PM

We did the same thing on delteria but I like your method you did with the array regarding setShape2 I did that aswell. Also use [PHP] tags instead of code tags looks much cleaner.


PHP Code:

//#CLIENTSIDE
function onCreated() {
  
with (findimg(200)) {
    
this.image thiso.bridgeImage;
    
this.layer  1;
    
this.thiso.x;
    
this.thiso.y;
    
this.mode  1;
    
this.alpha 0.75;

    if (
thiso.direction == "vertical")
      
this.+= 2;
    else
      
this.+= 2;
  }

  
this.bridgeWidth  getImgWidth(this.bridgeImage) / 16;
  
this.bridgeHeight getImgHeight(this.bridgeImage) / 16;
  
this.this.bridgeWidth  + (this.direction == "horizontal" 0);
  
this.this.bridgeHeight + (this.direction == "vertical" 0);

  
// 10 16
  // 10 21

  
this.dontBlock();

  
onTimeOut();
}

function 
onBridge(temp.py) {
  if (
player.x in |this.xthis.this.w|) {
    if (
temp.py in |this.ythis.this.h|)
      return 
true
  }

  return 
false;
}

function 
isPlayerEntering(temp.py) {
  if (
player.x in |this.xthis.this.w|) {
    if (
temp.py in |this.ythis.2|)
      return 
true;

    if (
temp.py in |this.this.2this.this.h|)
      return 
true;    
  }

  return 
false;
}

function 
onTimeOut() {
  
temp.py player.vecy(player.dir) * 1.05;

  
temp.entered isPlayerEntering(temp.py);

  if (
temp.entered) {
    if (
player.attached == false) {
      
attachPlayerToObj(0this.id);
      
setshape2(this.wthis.hthis.shape);
    }
  } else if (
player.attached == true && player.attachid == this.id) {
    if (
onBridge(temp.py)) {
    } else {
      
detachplayer();  
    }
    
this.chat "attached";
  } else {
    
this.chat "na";
  }

  
setTimer(0.05);




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

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