Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Tiles Triggering Actions (https://forums.graalonline.com/forums/showthread.php?t=134269289)

blackbeltben 06-09-2014 05:00 PM

Tiles Triggering Actions
 
I want to do a check to see if the player is in a certain tile.
How would I check?
For this example, I just want to use the top left tile (1x1)

PHP Code:

onTimeOut(){
 
setTimer(0.05);
 if 
/*Check if player is in certain tile (1x1)*/ {
  
player.chat "Found Tile!";
 }



Jakov_the_Jakovasaur 06-09-2014 05:07 PM

PHP Code:

temp.playerTile tiles[player.1.5player.2]; 

theres also tiletype:

PHP Code:

temp.playerTiletype tiletype(player.1.5player.2); 

Quote:

0: non-blocking, foreground
1: non-blocking
2: hurting underground
3: chair
4: bed1 (upper part)
5: bed2
6: swamp
7: lava swamp
8: near water
9: near lava
10: desert
11: water
12: lava
20: throw-through
21: jump stone
22: blocking
23: blocking, foreground

blackbeltben 06-09-2014 05:17 PM

Quote:

Originally Posted by Jakov_the_Jakovasaur (Post 1727955)
PHP Code:

temp.playerTile tiles[player.1.5player.2]; 

theres also tiletype:

PHP Code:

temp.playerTiletype tiletype(player.1.5player.2); 




Do you think you could use it in an example for me, I'm having trouble understanding.. I was never good at tile stuff.

I'm using this for the check but I get errors. I guess I'm not using it in right context..

PHP Code:

 if ((temp.playerTiletype == 23(player.x+1.5player.y+2)){
  
player.chat "found";
 } 


Jakov_the_Jakovasaur 06-09-2014 05:26 PM

temp.playerTiletype = tiles[player.x + 1.5, player.y + 2]; is just defining a temporary variable as whatever is returned by tiles[player.x + 1.5, player.y + 2], which will be unset once the current function process ends

all you need to do is:

PHP Code:

if (tiles[player.1.5player.2] == 1x1) {
 
player.chat "Found Tile!";



blackbeltben 06-09-2014 06:18 PM

Quote:

Originally Posted by Jakov_the_Jakovasaur (Post 1727957)
temp.playerTiletype = tiles[player.x + 1.5, player.y + 2]; is just defining a temporary variable as whatever is returned by tiles[player.x + 1.5, player.y + 2], which will be unset once the current function process ends

all you need to do is:

PHP Code:

if (tiles[player.1.5player.2] == 1x1) {
 
player.chat "Found Tile!";




error: unexpected symbol x1 at line 68: if (tiles[player.x + 1.5, player.y + 2] == 1x1) {

Don't think the check you gave me is correct..

Jakov_the_Jakovasaur 06-09-2014 06:50 PM

i didnt realise graal doesnt like using 1x1 directly like that, i usually change the tile values to their actual hexadecimal value, in this case 17:

PHP Code:

if (tiles[player.1.5player.2] == 17) { 
 
player.chat "Found Tile!"



blackbeltben 06-09-2014 07:06 PM

Quote:

Originally Posted by Jakov_the_Jakovasaur (Post 1727965)
i didnt realise graal doesnt like using 1x1 directly like that, i usually change the tile values to their actual hexadecimal value, in this case 17:

PHP Code:

if (tiles[player.1.5player.2] == 17) { 
 
player.chat "Found Tile!"



A couple things...

1. Nothing is happening when I collide with the tile... Not sure if I'm missing something.

2. How did you come up with 17 for 1x1 tile?

Jakov_the_Jakovasaur 06-09-2014 07:24 PM

i just realised that the first tile should be 0x0 rather than 1x1 as mentioned in your first post, 1x1 probably isnt even valid

should definitely work if you do:

PHP Code:

if (tiles[player.1.5player.2] == 0

taking a closer look at your snippet of code in the first post, its worth mentioning that it should be something like this if it isnt already:

PHP Code:

//#CLIENTSIDE
function onCreated()
  
this.onTimeout();

function 
onTimeout() {
  if (
tiles[player.1.5player.2] == 0) {
    
player.chat "Found Tile!";
  }
  
this.setTimer(0.05);


if something doesnt work as expected then you can also attempt to debug it like so:

PHP Code:

player.chat tiles[player.1.5player.2]; 


blackbeltben 06-09-2014 07:35 PM

Quote:

Originally Posted by Jakov_the_Jakovasaur (Post 1727967)
i just realised that the first tile should be 0x0 rather than 1x1 as mentioned in your first post, 1x1 probably isnt even valid

should definitely work if you do:

PHP Code:

if (tiles[player.1.5player.2] == 0

taking a closer look at your snippet of code in the first post, its worth mentioning that it should be something like this if it isnt already:

PHP Code:

//#CLIENTSIDE
function onCreated()
  
this.onTimeout();

function 
onTimeout() {
  if (
tiles[player.1.5player.2] == 0) {
    
player.chat "Found Tile!";
  }
  
this.setTimer(0.05);


if something doesnt work as expected then you can also attempt to debug it like so:

PHP Code:

player.chat tiles[player.1.5player.2]; 




Yay it works :)

But can you explain how you did get 17 though? How do I calculate what tiles are equal to what value?

Jakov_the_Jakovasaur 06-09-2014 07:54 PM

there are plenty of online tools that can do it, for example:

http://www.binaryhexconverter.com/he...imal-converter

0x would unambiguously state that the following value is hexadecimal and the number before the x represents a count of 16s before it, so 1x1 is basically 16 + 1, 2x1 is 32 + 1 aka 33, 2xF is 32 + 15 aka 47 etc

whereas if you used the true hexadecimal value for 17 which is '11' that would appear more ambiguous

blackbeltben 06-09-2014 10:13 PM

Quote:

Originally Posted by Jakov_the_Jakovasaur (Post 1727969)
there are plenty of online tools that can do it, for example:

http://www.binaryhexconverter.com/he...imal-converter

0x would unambiguously state that the following value is hexadecimal and the number before the x represents a count of 16s before it, so 1x1 is basically 16 + 1, 2x1 is 32 + 1 aka 33, 2xF is 32 + 15 aka 47 etc

whereas if you used the true hexadecimal value for 17 which is '11' that would appear more ambiguous


I really appreciate the help ;)

But I have one more question to add to this

What can I do so I don't have to do this..
PHP Code:

if ((tiles[player.x+1.5player.y+3] != 0) || (tiles[player.x+1.5player.y+3] != 32) || (tiles[player.x+1.5player.y+3] != 66) || /*etc*/){ 

just have all the tile values in one check

fowlplay4 06-10-2014 03:13 AM

PHP Code:

temp.tile tiles[player.x+1.5player.y+3];
temp.badtiles = {0,1,2,3,4};
if (
temp.tile in temp.badtiles) {
  
player.chat "this is a bad tile";
} else {
  
player.chat "this is not a bad tile";



blackbeltben 06-10-2014 02:00 PM

Quote:

Originally Posted by fowlplay4 (Post 1727982)
PHP Code:

temp.tile tiles[player.x+1.5player.y+3];
temp.badtiles = {0,1,2,3,4};
if (
temp.tile in temp.badtiles) {
  
player.chat "this is a bad tile";
} else {
  
player.chat "this is not a bad tile";



Could I do something like..

on created
PHP Code:

function onCreated(){
 
player.blocktiles = (1,2,3,4,5,etc);


on check
PHP Code:

if (tiles[player.x+1.5player.y+3] != player.blocktiles){ 

Obviously I don't think this will work as written. But I want to do it similar to that way.. How can I go about this?

fowlplay4 06-10-2014 03:51 PM

PHP Code:

function onCreated() {
  if (!
isBlocking(tiles[player.x+1.5,player.y+3])) {
    
player.chat "this tile is not blocking";
  }
}

function 
isBlocking(tile) {
  
temp.blocktiles = {1,2,3,4,5};
  return (
tile in temp.blocktiles);



blackbeltben 06-11-2014 11:28 AM

Quote:

Originally Posted by Jakov_the_Jakovasaur (Post 1727969)
there are plenty of online tools that can do it, for example:

http://www.binaryhexconverter.com/he...imal-converter

0x would unambiguously state that the following value is hexadecimal and the number before the x represents a count of 16s before it, so 1x1 is basically 16 + 1, 2x1 is 32 + 1 aka 33, 2xF is 32 + 15 aka 47 etc

whereas if you used the true hexadecimal value for 17 which is '11' that would appear more ambiguous


I'm having trouble figuring out the value for each tile. I used the calculator to figure out what this tile it:

Location: Farthest to the left. Second from the top
Possible Formulas: 2xa, ax2, 1xb, bx1

I put all these in calculator and none of the values are detecting

Jakov_the_Jakovasaur 06-11-2014 04:44 PM

Quote:

Originally Posted by blackbeltben (Post 1728008)
I'm having trouble figuring out the value for each tile. I used the calculator to figure out what this tile it:

Location: Farthest to the left. Second from the top
Possible Formulas: 2xa, ax2, 1xb, bx1

I put all these in calculator and none of the values are detecting

http://i.imgur.com/OoMwGWp.png

+

Quote:

Originally Posted by Jakov_the_Jakovasaur (Post 1727967)

if something doesnt work as expected then you can also attempt to debug it like so:

PHP Code:

player.chat tiles[player.1.5player.2]; 



blackbeltben 06-14-2014 06:52 PM

Blocking NPCs
 
I have my tiles working correctly thanks to you two :)

on Created:
PHP Code:

function isBlocking(tile) {
  
temp.blocktiles = {0,16,1024,1025,1026,1027,1028,1029};
  return (
tile in temp.blocktiles);


And the check:
PHP Code:

 if (!isBlocking(tiles[player.x+1.5,player.y+3])){
   
player.+= 1;
  } 

So if the player is not touching the blocking tiles, the player will fall
(for platformer system)


Now I want to go advanced and make collision with certain NPCs..

So I was wondering if someone could help me write this.


The NPC
PHP Code:

function onCreated(){
 
this.blocking true;
 
setShape(13232);
 
setImg("block.png");



The on Created:
PHP Code:

function isBlocking(tile) {
  
temp.blocktiles = {0,16,1024,1025,1026,1027,1028,1029};
  return (
tile in temp.blocktiles);
  
temp.blocknpc //Check if the temp.npc.blocking == true



The check:
PHP Code:

 if (!isBlocking(tiles[player.x+1.5,player.y+3])){
  if 
/*not colliding with npc that is blocking*/ {
   
player.+= 1;
  }
 } 


Jakov_the_Jakovasaur 06-15-2014 07:18 AM

Quote:

Originally Posted by blackbeltben (Post 1728090)
I have my tiles working correctly thanks to you two :)

on Created:
PHP Code:

function isBlocking(tile) {
  
temp.blocktiles = {0,16,1024,1025,1026,1027,1028,1029};
  return (
tile in temp.blocktiles);


And the check:
PHP Code:

 if (!isBlocking(tiles[player.x+1.5,player.y+3])){
   
player.+= 1;
  } 

So if the player is not touching the blocking tiles, the player will fall
(for platformer system)


Now I want to go advanced and make collision with certain NPCs..

So I was wondering if someone could help me write this.


The NPC
PHP Code:

function onCreated(){
 
this.blocking true;
 
setShape(13232);
 
setImg("block.png");



The on Created:
PHP Code:

function isBlocking(tile) {
  
temp.blocktiles = {0,16,1024,1025,1026,1027,1028,1029};
  return (
tile in temp.blocktiles);
  
temp.blocknpc //Check if the temp.npc.blocking == true



The check:
PHP Code:

 if (!isBlocking(tiles[player.x+1.5,player.y+3])){
  if 
/*not colliding with npc that is blocking*/ {
   
player.+= 1;
  }
 } 


something like this?

PHP Code:

function isBlocking(tile) {
  
temp.blocktiles = {0,16,1024,1025,1026,1027,1028,1029};
  return
    
tiles[player.1.5player.2in temp.blocktiles ||
    
this.checkBlockNPCs()
  ;
}

function 
checkBlockNPCs() {

  
temp.npcs findareanpcs(player.1.5player.20.06250.0625);

  for (
temp.temp.npcs
    if (
temp.n.blocking)
      return 
true;

  return 
false;


but then im not sure its a good idea to be checking just a single pixel for collisions, graal movement usually checks the width of the players body (2 tiles or 32 pixels)

blackbeltben 06-15-2014 10:47 AM

Quote:

Originally Posted by Jakov_the_Jakovasaur (Post 1728101)
something like this?

PHP Code:

function isBlocking(tile) {
  
temp.blocktiles = {0,16,1024,1025,1026,1027,1028,1029};
  return
    
tiles[player.1.5player.2in temp.blocktiles ||
    
this.checkBlockNPCs()
  ;
}

function 
checkBlockNPCs() {

  
temp.npcs findareanpcs(player.1.5player.20.06250.0625);

  for (
temp.temp.npcs
    if (
temp.n.blocking)
      return 
true;

  return 
false;


but then im not sure its a good idea to be checking just a single pixel for collisions, graal movement usually checks the width of the players body (2 tiles or 32 pixels)


What are the 0.0625s for?

Jakov_the_Jakovasaur 06-15-2014 11:00 AM

they are width and height parameters

when you use tiletype() or onwall() it is checking only a single pixel, so for that npcs check having a width + height of 0.0625 (aka 1 pixel) would match the tiletype() check


All times are GMT +2. The time now is 06:51 PM.

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