Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   Is this script right? (https://forums.graalonline.com/forums/showthread.php?t=74275)

ff7chocoboknight 05-29-2007 09:08 PM

Is this script right?
 
I just need the script looked over for errors. It's a harpoon weapon.
PHP Code:

//#CLIENTSIDE
function onCreated() {
  
client.max_harpo_ammo 10;
  
client.harpo_ammo=10;
  
this.harpo_on 0;
}
function 
onWeaponFired() {
  if (
this.harpo_on 0) {
    
this.harpo_on 1;
    if (
this.harpo_on && client.harpo_ammo 0) {
      
replaceani("walk""graalaxy_harpoon_walk");
      
replaceani("graalaxy_harpoon_empty_walk""graalaxy_harpoon_walk");
      
replaceani("idle""graalaxy_harpoon_idle");
      
replaceani("graalaxy_harpoon_empty_idle""graalaxy_harpoon_idle");
      
replaceani("sword""graalaxy_harpoon_shoot");
      
replaceani("graalaxy_harpoon_empty_shoot""graalaxy_harpoon_shoot");
    } else if (
this.harpo_on && client.harpo_ammo 0) {
      
replaceani("walk""graalaxy_harpoon_empty_walk");
      
replaceani("graalaxy_harpoon_walk""graalaxy_harpoon_empty_walk");
      
replaceani("idle""graalaxy_harpoon_empty_idle");
      
replaceani("graalaxy_harpoon_idle""graalaxy_harpoon_empty_idle");
      
replaceani("sword""graalaxy_harpoon_empty_shoot");
      
replaceani("graalaxy_harpoon_shoot""graalaxy_harpoon_empty_shoot");
    }
  } else if (
this.harpo_on 1) {
    
this.harpo_on 0;
    
replaceani("graalaxy_harpoon_walk""walk");
    
replaceani("graalaxy_harpoon_empty_walk""walk");
    
replaceani("graalaxy_harpoon_idle""idle");
    
replaceani("graalaxy_harpoon_empty_idle""idle");
    
replaceani("graalaxy_harpoon_shoot""sword");
    
replaceani("graalaxy_harpoon_empty_shoot""sword");
  }
}
function 
onKeyPressed(keycodekeychar) {
  if (
this.harpo_on && keychar "r") {
    if (
client.harpo_ammo 0) {
      
setani("graalaxy_harpoon_reload"" ");
      
client.harpo_ammo client.max_harpo_ammo;
    }
  }
  if (
keychar "s" && client.harpo_ammo 0) {  
  
client.harpo_ammo -= 1;
  
setshootparams("damage"3);
  
temp.shootangle getangle(vecx(player.dir), vecy(player.dir));
  
shoot(player.x+vecx(player.dir), player.y+vecy(player.dir), player.ztemp.shootangle00"graalaxy_harpoon_arrow"NULL);
  }



Chompy 05-29-2007 09:09 PM

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
client.max_harpo_ammo 10;
  
client.harpo_ammo=10;
  
this.harpo_on 0;
}
function 
onWeaponFired() {
  if (
this.harpo_on 0) {
    
this.harpo_on 1;
    if (
this.harpo_on && client.harpo_ammo 0) {
      
replaceani("walk""graalaxy_harpoon_walk");
      
replaceani("graalaxy_harpoon_empty_walk""graalaxy_harpoon_walk");
      
replaceani("idle""graalaxy_harpoon_idle");
      
replaceani("graalaxy_harpoon_empty_idle""graalaxy_harpoon_idle");
      
replaceani("sword""graalaxy_harpoon_shoot");
      
replaceani("graalaxy_harpoon_empty_shoot""graalaxy_harpoon_shoot");
    } else if (
this.harpo_on && client.harpo_ammo 0) {
      
replaceani("walk""graalaxy_harpoon_empty_walk");
      
replaceani("graalaxy_harpoon_walk""graalaxy_harpoon_empty_walk");
      
replaceani("idle""graalaxy_harpoon_empty_idle");
      
replaceani("graalaxy_harpoon_idle""graalaxy_harpoon_empty_idle");
      
replaceani("sword""graalaxy_harpoon_empty_shoot");
      
replaceani("graalaxy_harpoon_shoot""graalaxy_harpoon_empty_shoot");
    }
  } else if (
this.harpo_on 1) {
    
this.harpo_on 0;
    
replaceani("graalaxy_harpoon_walk""walk");
    
replaceani("graalaxy_harpoon_empty_walk""walk");
    
replaceani("graalaxy_harpoon_idle""idle");
    
replaceani("graalaxy_harpoon_empty_idle""idle");
    
replaceani("graalaxy_harpoon_shoot""sword");
    
replaceani("graalaxy_harpoon_empty_shoot""sword");
  }
}
function 
onKeyPressed(keycodekeychar) {
  if (
this.harpo_on && keychar "r") {
    if (
client.harpo_ammo 0) {
      
setani("graalaxy_harpoon_reload"" ");
      
client.harpo_ammo client.max_harpo_ammo;
    }
  }
  if (
keychar "s" && client.harpo_ammo 0) {  
  
client.harpo_ammo -= 1;
  
setshootparams("damage"3);
  
temp.shootangle getangle(vecx(player.dir), vecy(player.dir));
  
shoot(player.x+vecx(player.dir), player.y+vecy(player.dir), player.ztemp.shootangle00"graalaxy_harpoon_arrow"NULL);
  }


You missed a quote
But, bad practise is using "=" inside if statements, change them to "=="

xXziroXx 05-29-2007 09:12 PM

Wrong again.

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
client.max_harpo_ammo 10;
  
client.harpo_ammo=10;
  
this.harpo_on 0;
}
function 
onWeaponFired() {
  if (
this.harpo_on 0) {
    
this.harpo_on 1;
    if (
this.harpo_on == && client.harpo_ammo 0) {
      
replaceani("walk""graalaxy_harpoon_walk");
      
replaceani("idle""graalaxy_harpoon_idle");
      
replaceani("sword""graalaxy_harpoon_shoot");
    } else if (
this.harpo_on == && client.harpo_ammo == 0) {
      
replaceani("walk""graalaxy_harpoon_empty_walk");
      
replaceani("idle""graalaxy_harpoon_empty_idle");
      
replaceani("sword""graalaxy_harpoon_empty_shoot");
    }
  } else if (
this.harpo_on == 1) {
    
this.harpo_on 0;
    
replaceani("walk""walk");
    
replaceani("idle""idle");
    
replaceani("sword""sword");
  }
}
function 
onKeyPressed(keycodekeychar) {
  if (
this.harpo_on == && keychar == "r") {
    if (
client.harpo_ammo == 0) {
      
setani("graalaxy_harpoon_reload"" ");
      
client.harpo_ammo client.max_harpo_ammo;
    }
  }
  if (
keychar == "s" && client.harpo_ammo 0) {  
  
client.harpo_ammo -= 1;
  
setshootparams("damage"3);
  
temp.shootangle getangle(vecx(player.dir), vecy(player.dir));
  
shoot(player.x+vecx(player.dir), player.y+vecy(player.dir), player.ztemp.shootangle00"graalaxy_harpoon_arrow"NULL);
  }



ff7chocoboknight 05-29-2007 09:13 PM

Ziro, what was the error?

Quote:

Originally Posted by Chompy (Post 1313031)
But, bad practise is using "=" inside if statements, change them to "=="

Does it change anything?

xXziroXx 05-29-2007 09:20 PM

For example.

1) replaceani("walk", "graalaxy_harpoon_walk");
That replaces the WALKING ani with graalaxy_harpoon_walk.
2) replaceani("graalaxy_harpoon_walk", "graalaxy_harpoon_empty_walk");
That tries to replace a DEFAULT ani named graalaxy_harpoon_walk, which obviously doesn't exist.
3) replaceani("walk", "graalaxy_harpoon_empty_walk");
That does the trick! And to replace the harpoon walk ani to the default walk ani...
4) replaceani(walk", "walk");

Chompy 05-29-2007 09:21 PM

Quote:

Originally Posted by xXziroXx (Post 1313032)
Wrong again.

Huh?

ff7chocoboknight 05-29-2007 09:22 PM

nice, but now it doesn't change the ganis when u run out of ammo

Inverness 05-29-2007 10:41 PM

Quote:

Originally Posted by Chompy (Post 1313031)
You missed a quote
But, bad practise is using "=" inside if statements, change them to "=="

Double equal signs are used for comparison, while a single is used for assignment.

cbk1994 05-31-2007 01:33 AM

if ( var = true )

could set var to true. There is a limited protection for this so whole scripts don't get screwed up.

I would recommend disabling the players weapons for this script, then custom scripting the onKeyPressed() instead of replacing the anis of sword, etc.

I personally would disagree with this:

PHP Code:

if (this.harpo_on == && keychar == "r") { 

I don't like that styling much, but it's purely personal preference. Most people think that so long as they are related that's okay. You could also do something like this:

PHP Code:

function onKeyPressedkeycodekeychar )
{
  if ( 
this.harpo_on == false )
  {
    return 
false;
  }
  if ( 
keychar == "r" )
  {
    if ( 
client.harpo_ammo != )
    {
      return 
false;
    }
    
    
// Set gani, change ammo, etc.
  
}


Also, I advise against using client.harpoon_ammo; you could use a this. variable, and then have it base encoded, and unencode it for checks. Something like this:

PHP Code:

function setAmmoammo )
{
  
this.ammo base64encodeammo );
}
function 
getAmmo()
{
  return 
base64decodethis.ammo );


This way it's harder to hack--though if it's a good hacker, they could just modify the code, hehe.

Nice script though; better than I used to do for guns.

(I used to modify sprites.png, and then change the arrows so they looked like bullets, then shoot arrows at everyone! Hah!)

Knightmare1 08-13-2007 07:37 AM

ah yes true, but- that script would be like a sword that ghost bullets shoot out of, there is no paramater for the shoot() function.

zokemon 08-13-2007 06:20 PM

Talk about thread revivification.

BonzaiXxXSRStudios 10-12-2007 10:54 PM

2 months later...tell me about it. ;D

xAndrewx 10-12-2007 11:46 PM

HTML Code:

//#CLIENTSIDE
function onCreated() {
  client.max_harpo_ammo = client.harpo_ammo =10;
}

function onWeaponFired() {
  this.gunOn = !this.gunOn;
  if (this.gunOn == true) {
    if (client.harpo_ammo > 0) {
      temp.gani = {"_walk", "_idle", "_shoot"};
    } else {
      temp.gani = {"_empty_walk", "_empty_idle", "_empty_shoot"};
    }
  } else {
  temp.gani = {"walk", "idle", "sword"};
  }
  temp.base = {"walk", "idle", "sword"};
  for (temp.i: temp.base) {
    temp.syn = (temp.gani[temp.base.index(temp.i)].starts("_")? "graalaxy_harpoon_": null);
    replaceani(temp.i, temp.syn.trim() @ temp.gani[temp.base.index(temp.i)]);
  }
}

slight mods


All times are GMT +2. The time now is 08:03 PM.

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