Graal Forums

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

Jiroxys7 02-27-2011 06:43 AM

Onwall help
 
Alright, so I have a knockback system that's been plaguing me for perhaps a good year. So I've finally broken down and decided to share it to see if I can get any help with it. Jerret was kind enough to point out that I was doing part of the onwall wrong, so I fixed that and now have been currently fighting with the remaining problem in which it either stops too short, or sticks me in a wall (often I've had it stop too short, then, before adjusting anything, throwing me at the exact same angle would sometimes stick me a little bit into the wall. seemingly at random)
I've tried things like using a for loop to precalculate the distance between me and a wall. Unfortunately this came with two problems. unless I set the player's coordinates to integers (shifting the player at the beginning), the smaller decimals of the player's coordinates would stop me too short. secondly, if a player was in front of the detection before it flinged me, then that would be the limit. even if they moved.

I've also resorted to things like manually basing the onwall detection based on the player's direction as well (i.e. if you're facing this way, check for onwall here, and here. if you're facing that way, instead check for onwall there, and there.). but that also produced wonky results. Part of this headache is that I need this to be able to fling players at variable speeds. I've looked at using one of dusty's posted movement systems that i've incorporated, and importing part of the script into the knockback system, and tweaking it in from there, but that didn't go to well either. (part of the problem being that it doesn't work basing it off of the opposite of the player's direction when I tried it, and my initial idea of converting the movex and movey coordinates into directions wouldn't work as I needed to have access to 0-4, including every number in between. getdir() doesn't do this as it only gives integers, and I don't know of any other built-in way to do such a thing.)

Any help, tips, or hints would be greatly appreciated..

Here's the script:
PHP Code:

//#CLIENTSIDE
function onCreated(){
 
this KnockbackSystem;
}
 
public function 
onActionKnockback(accountaxayazadspeeddistancestuntimehurtonimpact){
    
this.kbparams = {accountaxayazadspeeddistancestuntimehurtonimpact};
    
this.kbcounter distance;
    
setTimer(0.05);
}

function 
onTimeout(){
  
doKnockback(this.kbparams[0], this.kbparams[1], this.kbparams[2], this.kbparams[3], this.kbparams[4], this.kbparams[5], this.kbparams[6], this.kbparams[7]);
  
setTimer(0.05);
}
  
function 
doKnockback(accountaxayazadspeeddistancestuntime){
  if(
this.kbcounter 0){
    
temp.to = {this.kbparams[1], this.kbparams[2]};
    
temp.angle getangle(player.to[0], player.to[1]);
    
temp.movex = (cos(angle)) * speed;
    
temp.movey = (sin(angle)) * speed;
    
temp.onwallx = (player.1) + temp.movex;
    
temp.onwally = (player.2) - temp.movey;
    
temp.oldx player.x
    
temp.oldy player.y;
    
this.kdir getdir(player.to[0],player.to[1]);
    if(
this.kdir == 0){player.dir 2;}
    elseif(
this.kdir == 1){player.dir 3;}
    elseif(
this.kdir == 2){player.dir 0;}
    elseif(
this.kdir == 3){player.dir 1;}
    
showimg(200"block.png"temp.onwallxtemp.onwally); findimg(200).alpha 0.5;
                         
   if(!
onwall(temp.onwallxtemp.onwally)){
      
player.+= temp.movex;             
      
player.-= temp.movey;
      
this.kbcounter -= 1*speed;
    }
          
    else{
      
player.temp.oldx;
      
player.temp.oldy;
      
setani("hurt",NULL);
      
this.kbcounter 0;
        if(
this.kbparams[8] > 0){
          
onActionDamage(speed);
        }
    }
          
    if(
this.kbcounter <= 0){
      
doExtraStuff();  
      return;
    }
          
    
setTimer(0.05);
  } 
      
}

function 
onActionDamage(speed){
  
WeaponSystem.onActionDamage(nullthis.kbparams[0], (client.maxhealth/100) * speed100"Physical"100nullclient.playerlevelthis.kbparams[1], this.kbparams[2], this.kbparams[3], this.kbparams[4], 11);
}
  
function 
doExtraStuff(){     
  if(
stuntime 0){
    
player.freezetime += stuntime;
  }
}
  
function 
onPlayerchats(){
  if(
player.chat == "/kbtest"){
    
onActionKnockback(nullplayer.0.5player.y0null11001);
  }



Crow 02-27-2011 10:04 AM

I didn't read everything, sorry. But here are a couple things that seem fishy, and a bit of advice, too.

First, these:
PHP Code:

temp.onwallx = (player.1.5) + temp.movex
temp.onwally = (player.2) - temp.movey

I've already changed those accordingly. You do want to use the center of the player as a base value, right? That's player.x + 1.5 and player.y + 2, not player.x + 1. Keep that in mind.

Also, you can very easily shorten your code right there:
PHP Code:

if(this.kdir == 0){player.dir 2;} 
elseif(
this.kdir == 1){player.dir 3;} 
elseif(
this.kdir == 2){player.dir 0;} 
elseif(
this.kdir == 3){player.dir 1;} 

Can be turned into this:
PHP Code:

player.dir = (this.kdir 2) % 4


And that's basically it. I'm too darn lazy to analyze your problem, sorry :( I suggest you get rid of the timeout stuff, though. Doing all that thingamajig at the top of doKnockback() every time it's being called seems a bit over the top. Just use a for-loop or something.

cbk1994 02-27-2011 10:37 AM

PHP Code:

this KnockbackSystem

This is backwards.

fowlplay4 02-27-2011 06:45 PM

You may want to read...

Dusty's movement system guide:
http://forums.graalonline.com/forums...hp?t=134258376

at least the onwall parts and try to apply it to your problem.

salesman 02-27-2011 06:50 PM

just say 'unstick me'

Jiroxys7 02-27-2011 08:44 PM

@ crow, alright, I'll try that direction thing. But I've tried the 1.5 & 2 thing already. If the player is being flung back too fast, it'll just stick you in a wall (or through 1-block walls).

@ cbk, ah, no wonder that wasn't working >_<

@ jerret, I took a look at that already, but I can't really understand some of it since I have no real way of searching for what the "%" and "?" 'math' symbols do. I asked in another thread ages ago and never got a response. Though, while I'm on the topic again, anyone care to enlighten me on what they actually mean and how they work?

fowlplay4 02-27-2011 08:53 PM

Quote:

Originally Posted by Jiroxys7 (Post 1633593)
@ jerret, I took a look at that already, but I can't really understand some of it since I have no real way of searching for what the "%" and "?" 'math' symbols do. I asked in another thread ages ago and never got a response. Though, while I'm on the topic again, anyone care to enlighten me on what they actually mean and how they work?

Modulus (%): Computes the remainder of a division operation. Which is useful for keeping a number within a certain range since it guarantees the number will never be bigger than the number you specify.

PHP Code:

function onCreated() {
  echo(
10 3);
  echo(
12 3);


Ternary (?): (statement ? trueresult : falseresult)

PHP Code:

function onCreated() {
  
temp.result true;
  echo((
temp.result "Yes" "No"));


It's more so for quick and dirty work, beats writing an if statement like this:

PHP Code:

function onCreated() {
  
temp.result true;
  if (
temp.result) {
    echo(
"Yes");
  } else {
    echo(
"No");
  }



TheRuckus 02-28-2011 03:22 PM

Quote:

Originally Posted by fowlplay4 (Post 1633596)
Modulus (%): Computes the remainder of a division operation. Which is useful for keeping a number within a certain range since it guarantees the number will never be bigger than the number you specify.

PHP Code:

function onCreated() {
  echo(
10 3);
  echo(
12 3);


Ternary (?): (statement ? trueresult : falseresult)

PHP Code:

function onCreated() {
  
temp.result true;
  echo((
temp.result "Yes" "No"));


It's more so for quick and dirty work, beats writing an if statement like this:

PHP Code:

function onCreated() {
  
temp.result true;
  if (
temp.result) {
    echo(
"Yes");
  } else {
    echo(
"No");
  }



When theres a day you don't know how to fix something a hero will rise and become the new manager of zodiac. (not like its gonna happend.)


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

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