Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Healing clientr.mudmp (https://forums.graalonline.com/forums/showthread.php?t=134260564)

iSlayer 09-18-2010 02:39 PM

Healing clientr.mudmp
 
Well I'm trying to heal a players MP in my server but I can only get it working when the weapon is equiped?? Heres the code


PHP Code:

function onActionServerSide() {
 if (
params[0] == "heal") {
  
clientr.mudmp += "1";
 }
}
  
//#CLIENTSIDE
function onCreated() {
  if (
clientr.mudmp <= "99") {
  
triggerserver("gui",this.name,"heal");
  
setTimer(1);
 }
}
function 
onTimeout() {
  if (
clientr.mudmp <= "99") {  
  
triggerserver("gui",this.name,"heal");
  
setTimer(1);
 }
} 


xAndrewx 09-18-2010 02:44 PM

PHP Code:

function onActionServerSide() {
  if (
params[0] == "heal") {
    if (
clientr.mudmp < 100) {  
      
clientr.mudmp++;
    }
  }
}
  
//#CLIENTSIDE
function onCreated() {
  
setTimer(1);
}

function 
onTimeout() {
  if (
clientr.mudmp < 100) {  
    
triggerserver("gui",this.name,"heal");
 }
  
setTimer(1);
} 


cbk1994 09-18-2010 02:49 PM

Suggestion: put the following in a class and join in to the player

PHP Code:

function onCreated() {
  
this.setTimer(1);
}

// this should really be optimized to stop the timer if ≥100 and
// restart it when they use mana and it needs to regen
function onTimeOut() {
  if (
this.clientr.mudmp < 100) {
    
this.clientr.mudmp ++;
  }
  
  
this.setTimer(1);
} 

Not only is it much more secure, it also cuts down on wasted bandwidth (and is much simpler) :). Not many people take advantage of the ability of timeouts to be used on the player object.

iSlayer 09-18-2010 02:56 PM

alright now last question if I fire the spell fast enough I go into negative values, how can i stop that

PHP Code:

thiso.weapontabs = {"Weapons"};
this.image = "pa_mud-maceofthedead.png";   

function 
onActionServerSide() {
 if (
params[0] == "removemp") {
  
clientr.mudmp -= "5";
 }
}

//#CLIENTSIDE
function GraalControl.onKeyDown(code, key) {
  if (
key == "d" && player.weapon == this && ! this.d) {
    
sleep(0.1);
    
this.onTimeOut();
    
this.d = true;
    
player.attr[2] = "";
  }
}

function 
onTimeOut() {
  if (
player.weapon != this) {
    return;
  }
  if (
clientr.mudmp >= "7") {
  
setshootparams("5");
  
shoot(player.x + vecx(player.dir), player.y + vecy(player.dir), playerz, (playerdir + 1) * pi / 2 + random( -0.2, 0.2), NULL, NULL, "islayer_earthspell", 2);
  
play("shock.wav");
  
triggerserver("gui",this.name,"removemp");
  }

}

function 
GraalControl.onKeyUp(code, key) {
  if (
key == "d" && player.weapon == this) {
    
this.setTimer(0);
    
this.d = false;
  }
} 


cbk1994 09-18-2010 03:38 PM

Quote:

Originally Posted by iSlayer (Post 1601366)
alright now last question if I fire the spell fast enough I go into negative values, how can i stop that

PHP Code:

player.clientr.mudmp = max(0, player.clientr.mudmp - 5); 

You should check serverside before firing the spell anyway.

Also don't enclose numbers in quotes--"5" and 5 are not the same thing, although they may work interchangeably. It's bad practice.


All times are GMT +2. The time now is 07:00 AM.

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