Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Mirror (https://forums.graalonline.com/forums/showthread.php?t=134270121)

Kirko 11-01-2015 06:10 PM

Mirror
 
Since testbed back I'm trying to make some new stuff and thought I could try to make a mirror but I no idea on how I would make the tiles show on the mirror. The only way I could think of is to make a screenshot of a specific spot of where I want a mirror.
I thought I would ask here if anyone has any idea how to do this. I just seem to stuck on the tile issue. I sorta have an idea on how to show the player in the mirror with showani possibly but want to get the hard things out of the way first.

Cubes 11-06-2015 12:24 PM

just use a npc that mimics the players gani and look.

fowlplay4 11-06-2015 07:16 PM

Get the tile data: this.level.tiles[tx, ty]

Use these functions:

PHP Code:

gettileset(); // returns the current tileset image

//credit to dusty
function TilesToImage(t) {
  if (
t.type() == 0) {
    
temp.px = (int(t%16)*16)+(int(t/512)*256);
    
temp.py = (int(t/16)*16)%512;
    return {
px,py};
  } else if (
t.type() == 3) {
    
temp.imgarray = new[0];
    for (
temp.t) {
      
temp.px = (int(i%16)*16)+(int(i/512)*256);
      
temp.py = (int(i/16)*16)%512;
      
imgarray.add({px,py}); 
    }
    return 
imgarray;
  } else return -
1;


use stretchy = -1; to flip an the tile image.

Just make your mirror image dimensions match the tiles so you don't have to do any clipping.

Kirko 11-07-2015 06:11 PM

Quote:

Originally Posted by fowlplay4 (Post 1737727)
Get the tile data: this.level.tiles[tx, ty]

Use these functions:

PHP Code:

gettileset(); // returns the current tileset image

//credit to dusty
function TilesToImage(t) {
  if (
t.type() == 0) {
    
temp.px = (int(t%16)*16)+(int(t/512)*256);
    
temp.py = (int(t/16)*16)%512;
    return {
px,py};
  } else if (
t.type() == 3) {
    
temp.imgarray = new[0];
    for (
temp.t) {
      
temp.px = (int(i%16)*16)+(int(i/512)*256);
      
temp.py = (int(i/16)*16)%512;
      
imgarray.add({px,py}); 
    }
    return 
imgarray;
  } else return -
1;


use stretchy = -1; to flip an the tile image.

Just make your mirror image dimensions match the tiles so you don't have to do any clipping.

Thanks, tiles show now!! Just gotta make them appear in correct spot now.

edit: I got everything to work but just looks weird to me.
Only problem I have is only yourself will show on mirror and when you swing your sword the gani doesn't play fully.
https://gyazo.com/9e7307948b06d80594ae8893710f22fe.png

fowlplay4 11-07-2015 09:05 PM

Do a check so you aren't updating the ani every time your script times out.

e.g. if (ani != player.ani) ani = player.ani;

Kirko 11-08-2015 02:30 PM

Quote:

Originally Posted by fowlplay4 (Post 1737733)
Do a check so you aren't updating the ani every time your script times out.

e.g. if (ani != player.ani) ani = player.ani;

Thanks it works!
I Still got one or two small problems but I'll try to figure it out on my own.

xXziroXx 11-08-2015 04:04 PM

I'd suggest drawing a black polygon or something at the bottom of the mirror to visually separate it from the ground.

Kirko 11-08-2015 04:59 PM

1 Attachment(s)
Quote:

Originally Posted by xXziroXx (Post 1737735)
I'd suggest drawing a black polygon or something at the bottom of the mirror to visually separate it from the ground.

I did something a little different. I made a image instead and then just stretched the x and y to fit the size of the mirror I gave. I attached image below.

this is how it came out.
https://gyazo.com/83ff9af9cf515ed0c55cf38a089b7fa7.png


Also for gani not showing fully you could do this also
PHP Code:

player.ani.name "[" player.anistep "]" 

I'm guessing all it does is get the exact frame of your gani and starts from there instead of the beginning.

BlueMelon 11-08-2015 05:23 PM

Include a video or gif! Looks good!

Tim_Rocks 11-08-2015 08:46 PM

Really cool guys!

xAndrewx 11-12-2015 01:43 PM

I had to do it this way for the players on Era-

HTML Code:

function onTimeout() {
  temp.timer = 1;
  if (player.x in |this.x - 15, this.x + 15| &&
      player.y in |this.y - 10, this.y + 15|)
    temp.timer = 0.05;
 
  if ((player.x + 1.5) in |this.x + 1.5, this.x + (this.width - 1.5)| &&
      player.y in |this.y + 3, this.y + 6|) {
    temp.dir = (player.dir == 0? 2: (player.dir == 2? 0: player.dir));
    temp.x = player.x;
    temp.y = this.y + 4 - ((player.y - thiso.y) - 2);
    temp.ani = player.ani;
   
    with (findimg(200)) {
      this.x = temp.x;
      this.y = temp.y;
     
      if (this.ani != temp.ani)
        this.ani = temp.ani;
       
      this.layer = 2;
      this.dir = temp.dir;
      playerlook = false;
      actor.head = playero.head;
      actor.body = playero.body;     
      actor.colors[0] = playero.colors[0];
      actor.colors[1] = playero.colors[1];
      actor.colors[2] = playero.colors[2];
      actor.colors[3] = playero.colors[3];
      actor.colors[4] = playero.colors[4];
      actor.attr[1] = playero.attr[1];
      actor.shield = playero.shield;
    }   
  } else {
    hideimg(200);
  }
  setTimer(temp.timer);
}


Kirko 07-26-2016 06:40 PM

oops I never posted the code :o

been a while since I made it so I decided to rewrite it just now to shorten it up.
Only problem is that it only shows your character
PHP Code:


//#CLIENTSIDE
function onPlayerEnters() {
  
setshape(1this.mirror_width 16this.mirror_height 16);
  
showTiles();
  
onTimeOut();
}

function 
onTimeOut() {
  if (
player.x in |thiso.1.5thiso.this.mirror_width 1.5| && 
      
player.y in |thiso.this.mirror_height 1.5+ (this.mirror_height 2) - 2|){ 
    
with (findimg(50)) {
      
player.x;
      
thiso.+ (thiso.playero.y) + thiso.mirror_height 2.5;
      
layer 1;
      
      
ani player.ani.name "[" player.anistep "]";
      
dir player.dir == player.dir == player.dir;
      
head   player.head;
      
shield player.shield;
      for (
temp.0temp.5temp.++) colors[i] = player.colors[i];
      for (
temp.0temp.20temp.++) attr[i] = player.attr[i];
    }
  } else
    
hideimg(50);
    
  
setTimer(0.05);
}

function 
showTiles(){
  
temp.mw this.mirror_width;
  
temp.mh this.mirror_height;

  
temp.area temp.mw temp.mh;
  
temp.y    this.temp.mh 1;
  
  for(
temp.0temp.temp.areatemp.++) {
    
temp.+= (temp.temp.mw) == 0;

    
with (findimg(201 temp.i)) {
      
= (thiso.x) + ((temp.temp.mw) * 1);
      
= (thiso.temp.mh 1) - (int(temp.temp.mh) * 1);
      
      
image gettileset();
      
partx TilesToImage(this.level.tiles[xtemp.y])[0];
      
party TilesToImage(this.level.tiles[xtemp.y])[1];
      
partw parth 16;
      
stretchy = -1;
      
layer 0;
    }
  }
}

//credit to dusty 
function TilesToImage(t) {
  if (
t.type() == 0) {
    
temp.px = (int(t%16)*16)+(int(t/512)*256);
    
temp.py = (int(t/16)*16)%512;
    return {
px,py};
  } else if (
t.type() == 3) {
    
temp.imgarray = new[0];
    for (
temp.t) {
      
temp.px = (int(i%16)*16)+(int(i/512)*256);
      
temp.py = (int(i/16)*16)%512;
      
imgarray.add({px,py}); 
    }
    return 
imgarray;
  } else return -
1;



callimuc 07-27-2016 02:06 PM

Quote:

Originally Posted by Kirko (Post 1739334)
Only problem is that it only shows your character

PHP Code:

for (temp.plplayers) {
  if (!
temp.pl.x in .... || !temp.pl.y in ...) continue;
  
with (findimg(200+temp.count)) {

  }


Used continue so it would still display the characters to all players, even if they aren't in the mirror. Don't know if you only want to show your own character on purpose. If not, this would fix it :)

MysticalDragon 07-27-2016 10:50 PM

Kirko I'm amazed by you, you have come a long way my friend.

Kirko 07-28-2016 11:53 PM

Quote:

Originally Posted by callimuc (Post 1739341)
PHP Code:

for (temp.plplayers) {
  if (!
temp.pl.x in .... || !temp.pl.y in ...) continue;
  
with (findimg(200+temp.count)) {

  }


Used continue so it would still display the characters to all players, even if they aren't in the mirror. Don't know if you only want to show your own character on purpose. If not, this would fix it :)

Thanks!


Quote:

Originally Posted by MysticalDragon (Post 1739350)
Kirko I'm amazed by you, you have come a long way my friend.

:blush:


All times are GMT +2. The time now is 11:52 AM.

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