Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Sword/Gani Script - Help (https://forums.graalonline.com/forums/showthread.php?t=134266444)

Fysez 05-15-2012 09:39 PM

Sword/Gani Script - Help
 
I've got the whole Gani part working. Problem is,
Once I equip and use the item,
It doesn't allow me to un-equip?
PHP Code:

//#CLIENTSIDE
function onWeaponFired() {
if (
this.on false) {
this.on true;
setani("Gani"null);
replaceani("idle""Gani");
replaceani("walk""Gani2");
this.on true;
}else if (!
this.on){
setani("idle"null);
replaceani("idle""idle");
replaceani("walk""walk");
}



Starfire2001 05-15-2012 09:56 PM

Quote:

Originally Posted by Fysez (Post 1694753)
I've got the whole Gani part working. Problem is,
Once I equip and use the item,
It doesn't allow me to un-equip?
PHP Code:

//#CLIENTSIDE
function onWeaponFired() {
if (
this.on false) {
this.on true;
setani("Gani"null);
replaceani("idle""Gani");
replaceani("walk""Gani2");
this.on true;
}else if (!
this.on){
setani("idle"null);
replaceani("idle""idle");
}



A few things.

if (this.on = false)
should be
if(this.on == false)
= sets values, == checks for equivalency.

Even if that was fixed it still wouldn't work, !this.on is the same thing as this.on == false, so you are checking if the weapon is off in both your if statements.

Also your aren't setting this.on back to false at any point, so once you unequip it once its going think its still on and you won't be able to reequip it. And you aren't resetting your walk gani to walk when you turn it off.

Fysez 05-15-2012 10:07 PM

Quote:

Originally Posted by Starfire2001 (Post 1694755)
A few things.

if (this.on = false)
should be
if(this.on == false)
= sets values, == checks for equivalency.

Even if that was fixed it still wouldn't work, !this.on is the same thing as this.on == false, so you are checking if the weapon is off in both your if statements.

Also your aren't setting this.on back to false at any point, so once you unequip it once its going think its still on and you won't be able to reequip it. And you aren't resetting your walk gani to walk when you turn it off.

PHP Code:

//#CLIENTSIDE
function onWeaponFired() {
if (
this.on == false) {
this.on == true;
setani("Gani"null);
replaceani("idle""Gani");
replaceani("walk""Gani2");


}else if (
this.on == true){
this.on == false;
setani("idle"null);
replaceani("idle""idle");
replaceani("walk""walk");
}


Doesn't necessarily work either

CujoDaMan 05-15-2012 10:28 PM

Try this, it should work

PHP Code:

//#CLIENTSIDE
function onWeaponFired() {
  if (
this.use == 0) {
  
setani("Gani"null);
  
replaceani("idle""Gani");
  
replaceani("walk""Gani2");
  
this.use = 1;
  } else {
   
setani("idle"null);
   
replaceani("idle""idle");
   
replaceani("walk""walk");
   
this.use = 0;
  }



cbk1994 05-15-2012 10:39 PM

As Starfire2001 just said, a single equals sign is for assignment, while two are for testing equality.

Styling your code, as you should have done before posting:

PHP Code:

//#CLIENTSIDE
function onWeaponFired() {
  if (
this.on == false) {
    
this.on == true;
    
setani("Gani"null);
    
replaceani("idle""Gani");
    
replaceani("walk""Gani2");
  } else if (
this.on == true) {
    
this.on == false;
    
setani("idle"null);
    
replaceani("idle""idle");
    
replaceani("walk""walk");
  }


Removing some redundant stuff like "== true" and fixing your assignment (you would have known that if you'd read the tutorial I've linked to you several times now)

PHP Code:

//#CLIENTSIDE
function onWeaponFired() {
  if (! 
this.on) {
    
this.on true;
    
setani("Gani"null);
    
replaceani("idle""Gani");
    
replaceani("walk""Gani2");
  } else if (
this.on) {
    
this.on false;
    
setani("idle"null);
    
replaceani("idle""idle");
    
replaceani("walk""walk");
  }


It should work now. If it doesn't, list the steps you've used to try to debug it.

Fysez 05-15-2012 10:54 PM

PHP Code:

//#CLIENTSIDE
function onWeaponFired() {
  if (
this.on == false) {
    
this.on == true;
    
setani("Gani"null);
    
replaceani("idle""Gani");

  } else if (
this.on == true) {
    
this.on == false;
    
setani("idle"null);
    
replaceani("idle""idle");

  }


Cujo's method did not work at all, But rather made it so I could not equip it at all. CBK, your's did the same. So I tried this and it seemed to work for Equipping, But then again, Not un-equipping. Not only am I back to where i started, But you all just confused me x.x lol

cbk1994 05-15-2012 10:57 PM

Did you even read what I said?

If you're copying and pasting, remember to remove the space at the end of the clientside line.

callimuc 05-15-2012 11:02 PM

Quote:

Originally Posted by Fysez (Post 1694763)
PHP Code:

//#CLIENTSIDE
function onWeaponFired() {
  if (
this.on == false) {
    
this.on == true;
    
setani("Gani"null);
    
replaceani("idle""Gani");

  } else if (
this.on == true) {
    
this.on == false;
    
setani("idle"null);
    
replaceani("idle""idle");

  }


Cujo's method did not work at all, But rather made it so I could not equip it at all. CBK, your's did the same. So I tried this and it seemed to work for Equipping, But then again, Not un-equipping. Not only am I back to where i started, But you all just confused me x.x lol

Use the == only in the if statement. While setting the value just use = . So this should work

PHP Code:

//#CLIENTSIDE
function onWeaponFired() {
  if (
this.wearing == false) {
    
this.wearing true;
    
replaceani("idle""gani");
    
replaceani("walk""gani2");
  }
  else if (
this.wearing == true) {
    
this.wearing false;
    
replaceani("gani""idle");
    
replaceani("gani2""walk");
  }



Fysez 05-15-2012 11:03 PM

Quote:

Originally Posted by cbk1994 (Post 1694764)
Did you even read what I said?

If you're copying and pasting, remember to remove the space at the end of the clientside line.

'= false' helps me more than that of '! this.on'. If I wish to use it like that, So be it. But '! this.on' won't fix the problem i've asked help for x,x

I'd rather learn than not learn, and do "Style" instead. x.x

Fysez 05-15-2012 11:22 PM

Quote:

Originally Posted by callimuc (Post 1694765)
Use the == only in the if statement. While setting the value just use = . So this should work

PHP Code:

//#CLIENTSIDE
function onWeaponFired() {
  if (
this.wearing == false) {
    
this.wearing true;
    
replaceani("idle""gani");
    
replaceani("walk""gani2");
  }
  else if (
this.wearing == true) {
    
this.wearing false;
    
replaceani("gani""idle");
    
replaceani("gani2""walk");
  }



Doesn't work either.

cbk1994 05-15-2012 11:33 PM

Quote:

Originally Posted by Fysez (Post 1694766)
'= false' helps me more than that of '! this.on'. If I wish to use it like that, So be it. But '! this.on' won't fix the problem i've asked help for x,x

I'd rather learn than not learn, and do "Style" instead. x.x

You can do whatever you want on the "== true" stuff—there are a lot of people who take a long time to understand why it's so silly, so I'll give you a pass on that. But there is no excuse for not styling your code as you write it or for posting unindented code.

Fysez 05-15-2012 11:43 PM

Quote:

Originally Posted by cbk1994 (Post 1694770)
You can do whatever you want on the "== true" stuff—there are a lot of people who take a long time to understand why it's so silly, so I'll give you a pass on that. But there is no excuse for not styling your code as you write it or for posting unindented code.

There is, Because I can write it as I please.
All I ask is for help on a script to make it work.
Not how to style and make my script look all pretty and sparkly.

cbk1994 05-16-2012 01:17 AM

Quote:

Originally Posted by Fysez (Post 1694772)
There is, Because I can write it as I please.
All I ask is for help on a script to make it work.
Not how to style and make my script look all pretty and sparkly.

Do not expect help in this forum if you won't even take the time to make your code readable and get defensive every time someone with more experience than you gives you advice.

fowlplay4 05-16-2012 01:30 AM

I fail to see how you're having an issue with a toggle but I can tell if you plan to make multiple weapons that use this same kind of system, you'll be incurring a bad time.

Toggles are very basic and typically done like this:

PHP Code:

//#CLIENTSIDE
function onWeaponFired() {
  if (
this.on) {
    
player.chat "I am no longer on.";
    
this.on false;
  } else {
    
player.chat "I am on.";
    
this.on true;
  }


If you completed my 'Staff Boots Challenge' on my tutorial you would have created a working toggle script.

Fysez 05-17-2012 11:43 PM

Quote:

Originally Posted by fowlplay4 (Post 1694784)
I fail to see how you're having an issue with a toggle but I can tell if you plan to make multiple weapons that use this same kind of system, you'll be incurring a bad time.

Toggles are very basic and typically done like this:

PHP Code:

//#CLIENTSIDE
function onWeaponFired() {
  if (
this.on) {
    
player.chat "I am no longer on.";
    
this.on false;
  } else {
    
player.chat "I am on.";
    
this.on true;
  }


If you completed my 'Staff Boots Challenge' on my tutorial you would have created a working toggle script.

I used that to test it, But it wasn't working on my script.

So I made a seperate Test one with only that code, as a test.
Every time I pressed D, it said "I am no longer on.", It doesn't work either.
It would not turn on.

fowlplay4 05-17-2012 11:48 PM

Quote:

Originally Posted by Fysez (Post 1694952)
I used that to test it, But it wasn't working on my script.

So I made a seperate Test one with only that code, as a test.
Every time I pressed D, it said "I am no longer on.", It doesn't work either.
It would not turn on.

If you have a custom script to trigger WeaponFired (triggering multiple times instead of once) then it's broken.


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

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