Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   My attempt at a grappling hook (https://forums.graalonline.com/forums/showthread.php?t=134265495)

Gunderak 01-02-2012 05:06 PM

My attempt at a grappling hook
 
I have made a pretty poor grappling hook and done it a weird way but oh well lol it still works. I was wondering if anyone would happen to have any knowledge on how to make it so you could hit a player and press a to reel them towards you maybe lmao.
Also how would I detect if it hits lets say for instance a bush? then it could change the bush tiles to cut down bush tiles, I know how that is done, Via tiles and updateboard.
But the detection of specific tiles I'm unsure of.
Here's my script so far.
PHP Code:

//#CLIENTSIDE
function onCreated() {
  
this.pullin false;
  
this.shooting false;
  
this.pullable false;
}

function 
onWeaponFired() {
  
hideimgs(20010000);
  
this.dir player.dir;
  
this.sx player.1;
  
this.sy player.1.5;
  
this.shooting true;
  
onTimeout();
}

function 
onTimeout() {
  if (
this.shooting == true) {
    
showpoly(1, {
      
player.1player.1.5this.sxthis.sy
    
});
      
findimg(1).layer 0;
      
findimg(1).red 0;
      
findimg(1).green 1;
      
findimg(1).blue 0;
      
this.sx2 this.sx;
      
this.sy2 this.sy;
      if (
this.dir == && !onwall(this.sxthis.sy 0.5)) {
        
this.sy -= 0.5;
      }
      if (
this.dir == && !onwall(this.sx 0.5this.sy)) {
        
this.sx -= 0.5;
      }
      if (
this.dir == && !onwall(this.sxthis.sy 0.5)) {
        
this.sy += 0.5;
      }
      if (
this.dir == && !onwall(this.sx 0.5this.sy)) {
        
this.sx += 0.5;
      }
      
freezeplayer(1);
      if(
this.sx2 == this.sx && this.sy2 == this.sy){
      
Hit();
      
settimer(0);
      
findimg(1).red 1;
      
findimg(1).green 0;
      
findimg(1).blue 0;
      return;
      }
  }
  if (
this.pullin == true) {
    
freezeplayer(1);
    
showpoly(1, {
      
player.1player.1.5this.sxthis.sy
    
});
      
findimg(1).layer 0;
      
findimg(1).red 1;
      
findimg(1).green 0;
      
findimg(1).blue 0;
    if (
this.dir == && player.this.sy) {
      
player.-= 0.5;
    }
    if (
this.dir == && player.this.sy) {
      
player.+= 0.5;
    }
    if (
this.dir == && player.this.sx) {
      
player.-= 0.5;
    }
    if (
this.dir == && player.this.sx) {
      
player.+= 0.5;
    }
    if (
player.== this.sy) {
      if (
this.dir == || this.dir == 2) {
        
this.pullin false;
        
freezeplayer(0);
        
hideimg(1);
      }
    }
    if (
player.== this.sx) {
      if (
this.dir == || this.dir == 3) {
        
this.pullin false;
        
freezeplayer(0);
        
hideimg(1);
      }
    }
  }
  
settimer(0.05);
}

function 
Hit() {
  
this.pullable true;
  
player.chat "Press A to reel in!";
}

function 
onKeyPressed(codekey) {
  if (
key == "a" && this.pullable == true) {
    
this.pullable false;
    
this.shooting false;
    
this.pullin true;
    
onTimeout();
  }



Emera 01-02-2012 05:08 PM

You should really post a video, an image or something so we can see what your scripts actually do.

callimuc 01-02-2012 05:44 PM

Quote:

Originally Posted by Gunderak (Post 1680417)
Also how would I detect if it hits lets say for instance a bush? then it could change the bush tiles to cut down bush tiles, I know how that is done, Via tiles and updateboard.

http://forums.graalonline.com/forums...hp?t=134257988
http://forums.graalonline.com/forums...hp?t=134258695
http://forums.graalonline.com/forums...ad.php?t=73784

Tricxta 01-02-2012 10:15 PM

Quote:

Originally Posted by Gunderak (Post 1680417)
PHP Code:

      this.sx2 this.sx;
      
this.sy2 this.sy;
      if (
this.dir == && !onwall(this.sxthis.sy 0.5)) {
        
this.sy -= 0.5;
      }
      if (
this.dir == && !onwall(this.sx 0.5this.sy)) {
        
this.sx -= 0.5;
      }
      if (
this.dir == && !onwall(this.sxthis.sy 0.5)) {
        
this.sy += 0.5;
      }
      if (
this.dir == && !onwall(this.sx 0.5this.sy)) {
        
this.sx += 0.5;
      }
...
    if (
this.dir == && player.this.sy) {
      
player.-= 0.5;
    }
    if (
this.dir == && player.this.sy) {
      
player.+= 0.5;
    }
    if (
this.dir == && player.this.sx) {
      
player.-= 0.5;
    }
    if (
this.dir == && player.this.sx) {
      
player.+= 0.5;
    } 


I always criticise people for this so don't worry you're not alone.
Instead of writing all these seperate statement it's possible to compact them
PHP Code:

for (temp.04i++){
  if (
this.dir == temp.&& !onwall(this.sx vecx(this.dir) * 0.5this.sy vecy(this.dir) * 0.5)){
    
this.sx += vecx(this.dir) * 0.5;
    
this.sy += vecy(this.dir) * 0.5;
  }


Another good trick to remember is if you want to invert your direction instead of touching the direction you can just do vecx(dir)*-1 since I figured you're not so hot with math.

Also callimuc is correct in advising you to use updateboard although in my past the respawn method for those tiles becomes a bit messy which is something to keep in mind. None the less... you're on the right track so far, keep at it :)

Gunderak 01-03-2012 04:35 AM

I'm ok with maths lol.. I know that *-1 would be the opposite of *0.5
But thanks, I'm thinking on also adding a grab function so the player presses a button to toggle modes. Modes: Grab, Pull
Grab will grab a player and pull them in, Pull will grab an object and allow you to reel in.
And thanks for the for loop didn't even think of doing sone thing like that.

oo_jazz_oo 01-03-2012 05:01 AM

Quote:

Originally Posted by Gunderak (Post 1680507)
I'm ok with maths lol.. I know that *-1 would be the opposite of *0.5

Wut.

Multiplying something by -1 would just return the negative of that number.
Multiplying by .5 is the same as dividing a number by 2...

I dont see how those two things are opposite.

Tricxta 01-03-2012 06:47 AM

I beleive he was referring to my the 0.5 in my example.
0.5 * -1 = -0.5
-0.5 * -1 = 0.5

Is what I think he meant, oh well...

Also I just spotted this:
PHP Code:

    showpoly(1, {
      
player.1player.1.5this.sxthis.sy
    
});
      
findimg(1).layer 0;
      
findimg(1).red 0;
      
findimg(1).green 1;
      
findimg(1).blue 0

it would be alot cleaner if you just did it with a with statement:
PHP Code:

with (findimg(1)){
  
polygon = {player.1player.1.5this.sxthis.sy};
  
layer 0;
  
red 0;
  
green 1;
  
blue 0;



Loriel 01-07-2012 03:32 AM

Quote:

Originally Posted by oo_jazz_oo (Post 1680512)
Wut.

Multiplying something by -1 would just return the negative of that number.
Multiplying by .5 is the same as dividing a number by 2...

I dont see how those two things are opposite.

-1 goes left, 0.5 goes right. That's the opposite direction!


All times are GMT +2. The time now is 05:59 AM.

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