Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Looking for a solution (https://forums.graalonline.com/forums/showthread.php?t=134268452)

brokk 07-09-2013 09:08 PM

Looking for a solution
 
Hello. I need some help. I have a showImg shadow and I want it to follow player and it does. But the problem I am running into is when the player jumps, the shadow also follows the player's y value so there is no sense in depth when jumping. (Keep in mind player can move in all 4 directions just like default movement.)

So I come to you forums in need of help.
Some information on the jump action:
The player's y value goes -0.5 when jumps for a time of (0.5)
The player's y value goes +0.5 when falling for a time of (0.5)
So the jump is (1) total in time.
The Jump and Fall are just ran through a looping script.

Jumping works perfect, the shadow just doesn't like to.



I've tried:
1. Keeping the y value at one point once the player has left the ground.
Problem: When you move up or down while jumping, the shadow
jumps when you land.

2. A bunch of sleeps();
Problem: Glitchy

3. A butt load of scheduleEvents()
Problem: Even more glitchy.

PHP Code:

//#CLIENTSIDE
function onCreated(){
 
setTimer(0.05);
 }
 
function 
onTimeOut(){
 
setTimer(0.05);
//SHADOW
 
if (player.canjump true){
//THIS IS WHERE PLAYER IS ON GROUND. WORKS FINE
  
showImg(20"shadow.png"player.x+0.5player.y+1.5);
  
changeImgVis(201);
  
findImg(20).layer 0;
 }
//PLAYER IS IN AIR HERE, BUT TOOK OUT WHAT I HAD
 
if (player.canjump false){
 }
}



function 
onKeyPressed(codekey){
 if (
key == "s"){  //'s' JUMPS. THE ACTION IS DONE ON ANOTHER SCRIPT
  
if (canjump true){
  
//I DONT KNOW WHAT TO DO HERE. I TRIED A LOT AND FAIL EVERYTIME
    
showImg(20"shadow.png"player.x+0.5player.y+1.5);
    
changeImgVis(201);
    
findImg(20).layer 0;
    
//DELETED IDEA
    
}
   }
  } 


Emera 07-09-2013 09:43 PM

The player's z property changes when jumping (I believe) so try changing the z property of that image object to match the player's z property.

brokk 07-09-2013 09:50 PM

Quote:

Originally Posted by Emera (Post 1720438)
The player's z property changes when jumping (I believe) so try changing the z property of that image object to match the player's z property.

I've never messed with any Z values... You may have to go more in depth with me... I'm sorry

BlueMelon 07-09-2013 09:53 PM

Take a look at the changeimgzoom(id,factor) function.

brokk 07-09-2013 11:06 PM

Quote:

Originally Posted by BlueMelon (Post 1720440)
Take a look at the changeimgzoom(id,factor) function.

Though that will make the shadow smaller, it will not change the distance from the player and the shadow when jumping.

BlueMelon 07-09-2013 11:16 PM

Quote:

Originally Posted by brokk (Post 1720441)
Though that will make the shadow smaller, it will not change the distance from the player and the shadow when jumping.

Ah ok then what you want to mess around with is the player.z variable. It's exactly what you want I think.

callimuc 07-10-2013 12:15 AM

first off: why are you using that kind of shadow instead of the default one in the ganis?
seccond thing: watch your if() statements

brokk 07-10-2013 12:59 AM

Quote:

Originally Posted by callimuc (Post 1720443)
first off: why are you using that kind of shadow instead of the default one in the ganis?
seccond thing: watch your if() statements

Because I need the shadow to display a "sense" of depth. If the shadow stayed with the player, it would just look like the player is rolling up and down..

cbk1994 07-10-2013 01:00 AM

Quote:

Originally Posted by callimuc (Post 1720443)
seccond thing: watch your if() statements

To clarify, he's talking about stuff like this:

PHP Code:

 if (player.canjump true){ 

A single equals sign is used for assignment. A double equals sign is for comparison. GS2 tolerates misuse to some degree (it shouldn't...) which is why your script still works, but you should instead do:

PHP Code:

 if (player.canjump == true){ 


brokk 07-10-2013 02:18 AM

Quote:

Originally Posted by cbk1994 (Post 1720446)
To clarify, he's talking about stuff like this:

PHP Code:

 if (player.canjump true){ 

A single equals sign is used for assignment. A double equals sign is for comparison. GS2 tolerates misuse to some degree (it shouldn't...) which is why your script still works, but you should instead do:

PHP Code:

 if (player.canjump == true){ 


Yeah I fixed the 'if' statements. But I still can't find a solution to my problem :(

BlueMelon 07-10-2013 11:37 AM

Have you tried using the player.z variable for your jump?

callimuc 07-10-2013 01:45 PM

This is something that could work. Not 100% sure but I can't see something wrong


PHP Code:

//#CLIENTSIDE

const JUMP_HEIGHT 1//Player can jump one tile high

function onKeyPressed(codekey) {
    
//Won't change the player.canJump as you could keep it as a check
    //If the player could jump in theory for other scripts
  
if (key == "s" && player.canJump == true && player.== 0) {

      
//Create the shadow image
    
showImg(20"shadow.png"player.x+0.5player.y+1.5);
    
changeImgVis(201);
    
findImg(20).layer 0;
      
      
//I rathered to make it into one for() loop and have if statements
      //Inside of it instead of creating 2 loops, probably just a personal
      //Preference
    
for (temp.0temp.JUMP_HEIGHT*2temp.+= 0.05) {

        
//Since i took the JUMP_HEIGHT times 2, I can create such a check
      
if (temp.JUMP_HEIGHT) {
        
player.+= 0.05//Move the player up
      
}
      else {
        
player.-= 0.05//Move the player down
      
}
    }

      
//failsafe reset the player.z
    
player.0;

      
//hide the shadow as you will probably move back to the original one
    
hideImg(20);
  }



brokk 07-10-2013 04:36 PM

Quote:

Originally Posted by callimuc (Post 1720455)
This is something that could work. Not 100% sure but I can't see something wrong


PHP Code:

//#CLIENTSIDE

const JUMP_HEIGHT 1//Player can jump one tile high

function onKeyPressed(codekey) {
    
//Won't change the player.canJump as you could keep it as a check
    //If the player could jump in theory for other scripts
  
if (key == "s" && player.canJump == true && player.== 0) {

      
//Create the shadow image
    
showImg(20"shadow.png"player.x+0.5player.y+1.5);
    
changeImgVis(201);
    
findImg(20).layer 0;
      
      
//I rathered to make it into one for() loop and have if statements
      //Inside of it instead of creating 2 loops, probably just a personal
      //Preference
    
for (temp.0temp.JUMP_HEIGHT*2temp.+= 0.05) {

        
//Since i took the JUMP_HEIGHT times 2, I can create such a check
      
if (temp.JUMP_HEIGHT) {
        
player.+= 0.05//Move the player up
      
}
      else {
        
player.-= 0.05//Move the player down
      
}
    }

      
//failsafe reset the player.z
    
player.0;

      
//hide the shadow as you will probably move back to the original one
    
hideImg(20);
  }



I had just read read this this morning but I figured it out last night! thanks though!

I just simply change the z value of the player and the shadow stays at (player.x), and (player.y-player.z)

Works like a charm. I never knew about the z factor til yesterday so I would like to thank you graal forums for making life a lot easier on me lol


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

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