Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Running Attack (https://forums.graalonline.com/forums/showthread.php?t=134265298)

PrinceOfKenshin 12-18-2011 03:58 AM

Running Attack
 
Hey, I ran into a problem where I have weapon that's supposed to be allowing the player to use a sword gani while walking, basically pressing two keys at once (walking dir key, s key for attacking). Here's part of the script, which is triggered from a timeout:
PHP Code:

function onWalkCheck() {
  if (
player.ani == "e_weapon-1h-attack") {
    if(
keydown(5)) {
      
setani("e_weapon-1h-attackwalk"params[3]);
    }
  }



fowlplay4 12-18-2011 04:04 AM

1. You have to use == to check for equality, one = is for assigning a value.
2. Your code is impossible to debug without the 'bigger' picture (the code that's responsible for calling onWalkCheck()).
3. Please use PHP tags instead, and style your code properly when you post it. You can use my beautifier to do that for you: http://fp4.ca/gs2beautifier

PrinceOfKenshin 12-18-2011 04:15 AM

fixed the style and syntax errors. Here is the timeout

PHP Code:

function onTimeout() {
  
this.oldplx player.x;
  
this.oldply player.y;
  
onWalkCheck();
  if (
player.account == "DrakilorP2P") {
    
showtext(20016100"""""Classes: " player.joinedclasses);
    
changeimgvis(2004);
  }
  if (!
player.isinclass("player_combat") || !player.isinclass("methods_health")) {
    if (
player.account == "DrakilorP2P") {
      
changeimgcolors(2001001);
    }
    
setTimer(0.05);
    return;
  }
  if (
player.account == "DrakilorP2P") {
    
changeimgcolors(2000101);
  }
  if (
canAttack()) {
    if (
keydown(5)) { //S
      //if (keydown(6)) { //A
      
attack();
    }
  }
  if (
this.dashFramesLeft 0) {
    if (!
onwall2(player.vecx(player.dir) * 0.5player.vecy(player.dir) * 0.533)) {
      
player.+= vecx(player.dir) * 0.5;
      
player.+= vecy(player.dir) * 0.5;
    }
    
this.dashFramesLeft--;
  }
  if (
this.shakeFramesLeft 0) {
    
this.shakeFramesLeft--;
    if (
this.shakeFramesLeft 0) {
      
temp.random(0pi 2);
      
temp.random(00.25);
      
setfocus(player.cos(temp.a) * temp.rplayer.sin(temp.a) * temp.r);
    } else {
      
resetfocus();
    }
  }
  
setTimer(0.05);



fowlplay4 12-18-2011 04:54 AM

I think your best bet is to replace the walking gani while the player is attacking, and then set it back to the walking gani when the player is done their attack.

I.e:

PHP Code:

function attack() {
  
replaceani("walk""new_walking_ani");
  
this.scheduleevent(0.5"FixWalkingAni""");
}

function 
onFixWalkingAni() {
  
replaceani("walk""proper_walking_ani");


Your walk check seems unnecessary.

Alpho 12-20-2011 09:34 PM

We replaced the gani under the Attack function, which supprisingly resulted in the gani being replaced at all times.. That's kinda an issue, but here's what we have:

PHP Code:

function attack() {
    
this.onehands = {
      
"katana""rubyblade""blueaxe""grayblade"
    
};
    if (
player.clientr.weaponClass "blueaxe"player.attr[3] = "e_weapon-blueaxe.png";
    if (
player.clientr.weaponClass "grayblade"player.attr[3] = "e_weapon-grayblade.gif";
    if (
player.clientr.weaponClass "rubyblade"player.attr[3] = "spawn_ruby-blade.gif";
    if (
player.clientr.weaponClass ""player.attr[3] = "";
    if (
player.clientr.weaponClass in this.onehands) {
      
setani("e_weapon-1h-attack"player.attr[3]);
      
sleep(1);
    }
    elseif(
player.clientr.weaponClass == "mallet"setani("dusty_hammer""whammer1.png""lift.wav");
    elseif(
player.clientr.weaponClass == "staff"setani("esteria_weapon-trainstaff-attack1"null);
    elseif(
player.clientr.weaponClass == "destructoaxe"setani("e_destructoaxe-attack"null);
    elseif(
player.clientr.weaponClass == "goldensword"setani("e_goldensword-attack"null);
    else 
setani("e_punch"null);
 
    
//this.nextAttack = .1;
    
if (player.clientr.weaponClass == "katana"this.dashFramesLeft 5;
    if (
player.clientr.weaponClass == "mallet"this.shakeFramesLeft 5;
    
triggerServer("weapon"this.name"attack");
    
// The Gani replacement.
    
if (player.clientr.weaponClass in this.onehands) {
      
replaceani("walk""e_weapon-1h-attackwalk");
      
player.chat "replace";
      
sleep(.5);
      
replaceani("e_weapon-1h-attackwalk""walk");
    }



callimuc 12-20-2011 09:42 PM

Quote:

Originally Posted by Alpho (Post 1678813)
We replaced the gani under the Attack function, which supprisingly resulted in the gani being replaced at all times.. That's kinda an issue, but here's what we have:

PHP Code:

    if (player.clientr.weaponClass in this.onehands) {
      
replaceani("walk""e_weapon-1h-attackwalk");
      
player.chat "replace";
      
sleep(.5);
      
replaceani("e_weapon-1h-attackwalk""walk");
    } 


Because it´s in a timeout?
In case yes, you shouldn´t use sleep() in a timeout

Alpho 12-20-2011 09:53 PM

If you press the key 'S', then the Attack function is triggered. There is no timeout used here. I am just using replaceani, then a sleep which would generally be as long as the attack gani is, then replace the gani back to normal. The player chat is there so I could see that it works.

Tolnaftate2004 12-20-2011 10:09 PM

Quote:

Originally Posted by Alpho (Post 1678813)
We replaced the gani under the Attack function, which supprisingly resulted in the gani being replaced at all times.. That's kinda an issue, but here's what we have:

PHP Code:

      // blah blah ...
      
replaceani("e_weapon-1h-attackwalk""walk"); 


try
PHP Code:

replaceani("walk","walk"); 



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

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