Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 01-02-2012, 05:06 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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();
  }

__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #2  
Old 01-02-2012, 05:08 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
You should really post a video, an image or something so we can see what your scripts actually do.
__________________
Reply With Quote
  #3  
Old 01-02-2012, 05:44 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Quote:
Originally Posted by Gunderak View Post
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
__________________
MEEP!

Last edited by callimuc; 01-02-2012 at 05:46 PM.. Reason: Added 2 more links
Reply With Quote
  #4  
Old 01-02-2012, 10:15 PM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is a jewel in the roughTricxta is a jewel in the rough
Quote:
Originally Posted by Gunderak View Post
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
Reply With Quote
  #5  
Old 01-03-2012, 04:35 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #6  
Old 01-03-2012, 05:01 AM
oo_jazz_oo oo_jazz_oo is offline
Jazz teh Awesome
oo_jazz_oo's Avatar
Join Date: Jul 2006
Location: California
Posts: 596
oo_jazz_oo is a jewel in the roughoo_jazz_oo is a jewel in the rough
Send a message via MSN to oo_jazz_oo
Quote:
Originally Posted by Gunderak View Post
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.
__________________

Reply With Quote
  #7  
Old 01-03-2012, 06:47 AM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is a jewel in the roughTricxta is a jewel in the rough
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;

Reply With Quote
  #8  
Old 01-07-2012, 03:32 AM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Quote:
Originally Posted by oo_jazz_oo View Post
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!
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:55 PM.


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