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 02-27-2011, 06:43 AM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
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);
  }

__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #2  
Old 02-27-2011, 10:04 AM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
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.
Reply With Quote
  #3  
Old 02-27-2011, 10:37 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
PHP Code:
this KnockbackSystem
This is backwards.
__________________
Reply With Quote
  #4  
Old 02-27-2011, 06:45 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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.
__________________
Quote:
Reply With Quote
  #5  
Old 02-27-2011, 06:50 PM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
just say 'unstick me'
__________________
Reply With Quote
  #6  
Old 02-27-2011, 08:44 PM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
@ 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?
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #7  
Old 02-27-2011, 08:53 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Jiroxys7 View Post
@ 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");
  }

__________________
Quote:
Reply With Quote
  #8  
Old 02-28-2011, 03:22 PM
TheRuckus TheRuckus is offline
Registered User
TheRuckus's Avatar
Join Date: Jan 2010
Posts: 147
TheRuckus can only hope to improve
Quote:
Originally Posted by fowlplay4 View Post
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.)
__________________


Tince thinks hes god.
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 12:20 PM.


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