Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Bit of a Problem (https://forums.graalonline.com/forums/showthread.php?t=75010)

killerogue 06-30-2007 08:53 PM

Bit of a Problem
 
PHP Code:

public function applyStatChange(statamt) {
  
temp.string 0;
  
tem.plyr 0;
  
  
plyr findPlayer(this.account);
  
  if (
makevar("plyr.clientr.mud." stat) == NULL) return;

  if (
amt != NULL) {
    if (
amt == (abs(amt))) {
      if (
stat == "hp" || "mp") {
        if ((
makevar("plyr.clientr.mud." stat) + amt) <= makevar("plyr.clientr.mud.max" stat)) {
          
makevar("plyr.clientr.mud." stat) += abs(amt);
        }
        else {
          
makevar("plyr.clientr.mud." stat) = makevar("plyr.clientr.mud.max" stat);
        }
      }  
    }
    else {
      if ((
makevar("plyr.clientr.mud." stat) - amt) > 0) {
        echo(
"setting a negative");
        
makevar("plyr.clientr.mud." stat) -= abs(amt);
      }
      else if ((
makevar("plyr.clientr.mud." stat) - amt) <= 0) { 
        echo(
"changing to zero");
        
makevar("plyr.clientr.mud." stat) = 1;
      }
    }
  }
  
reflect("player"3);
  echo(
this.mp);


The adding portion of it works perfectly fine, doesn't go over the max amount or anything like that. However as for the subtracting portion, it tends to go over to -599 before it sets it back to 1 the next time I update. What could be the issue?

Inverness 06-30-2007 09:22 PM

PHP Code:

public function applyStatChange(statamt) {
  
temp.limited = {"hp""mp"};
  
temp.max 0;
  
temp.min 0;

  if (
amt.type() != 0) return; // not a number
  
with (findPlayer(this.account)) {
    
clientr.mud.(@ stat) += amt;
    if (
stat in limited) {
      
max clientr.mud.(@ "max" stat);
      
min clientr.mud.(@ "min" stat);
      if (
clientr.mud.(@ stat) > max)
        
amt max;
      if (
clientr.mud.(@ stat) < min)
        
amt min;
    }
  }



Tolnaftate2004 06-30-2007 09:31 PM

Quote:

Originally Posted by killerogue (Post 1324278)
PHP Code:

      if (stat == "hp" || "mp") { 


Does not do what you think it does.

Quote:

Originally Posted by killerogue (Post 1324278)
PHP Code:

      if ((makevar("plyr.clientr.mud." stat) - amt) > 0) { 


If amt is negative.... -amt is positive, so (makevar("plyr.clientr.mud." @ stat) - amt) is adding. So, change the - to + and voila.

Inverness 06-30-2007 09:31 PM

Or just use mine as base.

Tolnaftate2004 06-30-2007 09:39 PM

Quote:

Originally Posted by Inverness (Post 1324298)
Or just use mine as base.

It's probably a bad idea to have variables with names min and max.

Inverness 06-30-2007 09:47 PM

Quote:

Originally Posted by Tolnaftate2004 (Post 1324302)
It's probably a bad idea to have variables with names min and max.

Easy enough to change.

zokemon 06-30-2007 10:12 PM

tem.plry = 0;? :P

Inverness 06-30-2007 10:14 PM

Quote:

Originally Posted by zokemon (Post 1324320)
tem.plry = 0;? :P

I noticed that too :P
*coughrookiecough*


All times are GMT +2. The time now is 11:50 PM.

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