Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Spell System (https://forums.graalonline.com/forums/showthread.php?t=87573)

Switch 08-23-2009 06:23 PM

Spell System
 
I've had this for a while, and I've finally wanted to release it for those newer RPG servers looking for a spell system. I'm not sure how much more efficient this is over other means of doing it, but it's a start and is documented for easily changing it.

In a weapon given to everyone called "-System/Spells" or similar (which will require that you change all "-System/Spells" to whatever you name it):
PHP Code:

function onActionServerside(cmd,p1) {
  if (
cmd == "TakeMana")
    
mana.flag.here -= p1//input wherever you store the mana flag at 'mana.flag.here'
}
//#CLIENTSIDE
public function fireSpell(stats) { //fired from the spell weapon
  
temp.spellName stats[0];
  
temp.action stats[1];
  
temp.cast stats[2];
  
temp.ani stats[3]; //projectile
  
temp.mana stats[4];
  
temp.freeze stats[5];
  
temp.power stats[6];
  
temp.cooldown stats[7];
  
  if (
mana mana.flag.here) { //input wherever you store the mana flag at 'mana.flag.here'
    
player.chat "You don't have enough mana to cast " @spellName"."//if you have a message system you can use that instead
    
return;
  }
  if (
this.("cooldown_" @spellName) != null) {
    
player.chat spellName" is still cooling down for " @this.("cooldown_" @spellName)@ " seconds."//if you have a message system you can use that instead
    
return;
  }
  
  if (
action == "hurt") { //a spell that hurts a player
    
if (cast == "projectile") { //a hurt spell that is a projectile
      
freezePlayer(freeze);
      
setAni("grab",null); //placeholder
      
sleep(freeze);
      
setShootParams("spell","hurt",power);
      
temp.angle getAngle(vecx(player.dir),vecy(player.dir)); //shoots in a straight line
      
shoot(player.x+vecx(player.dir),player.y+vecy(player.dir),player.z,angle,1,0,ani,null);
    }
  }
  if (
action == "heal") { //a spell that heals a player
    
if (cast == "projectile") { //a heal spell that is a projectile
      
freezePlayer(freeze);
      
setAni("grab",null); //placeholder
      
sleep(freeze);
      
setShootParams("spell","heal",power);
      
temp.angle getAngle(vecx(player.dir),vecy(player.dir)); //shoots in a straight line
      
shoot(player.x+vecx(player.dir),player.y+vecy(player.dir),player.z,angle,1,0,ani,null);
    }
    if (
cast == "self") { //a heal spell that is cast on yourself
      
freezePlayer(freeze);
      
setAni("grab",null);  //placeholder
      
sleep(freeze);
      
//go to health system and heal using the amount 'random(int(power[0],power[1]))'
    
}
  }    
  
triggerServer("gui","-System/Spells","TakeMana",mana);
  
makeVar("this.cooldown_" @spellname) = cooldown;
  
scheduleEvent(0.05,"Cooldown",spellName);
}

function 
onCooldown(spellName) {
  if (
this.("cooldown_" @spellName) > 0) {
    
makeVar("this.cooldown_" @spellName) -= 0.05;
    
scheduleEvent(0.05,"Cooldown",spellName);
  }
}

function 
onActionProjectile(spell,action,power) { //when being hit by a projectile
  
if (spell == "spell") { //make sure it's a spell and not some other projectile
    
if (action == "hurt")
      
//go to health system and damage using the amount 'random(int(power[0],power[1]))'
    
if (action == "heal")
      
//go to health system and heal using the amount 'random(int(power[0],power[1]))'
  
}


In spell weapons that are added from being bought/learned (I'm using "Barrel" as an example; these have to be able to be fired [D] or create your own way for firing them):
PHP Code:

//#CLIENTSIDE
function onWeaponFired() {
  
temp.stats = {
    
"Barrel"//name
    
"hurt"//action
    
"projectile"//cast
    
"woodenbarrel"//projectile animation
    
20//mana
    
2//freeze
    
{1,5}, //power
    
5//cooldown
  
};
  
findWeapon("-System/Spells").fireSpell(stats);



Switch 10-28-2009 03:53 AM

Mod mind changing both of the "random(int(power[0],power[1]))" to "int(random(power[0],power[1]))" at the bottom of the system part?

Deas_Voice 10-28-2009 09:01 AM

Quote:

Originally Posted by Switch (Post 1534641)
Mod mind changing both of the "random(int(power[0],power[1]))" to "int(random(power[0],power[1]))" at the bottom of the system part?

does it matter if int() comes first instead of random()? :redface:

Codein 10-28-2009 09:04 AM

Quote:

Originally Posted by Deas_Voice (Post 1534679)
does it matter if int() comes first instead of random()? :redface:

Yeah. random has two parameters where as int only has one.

fowlplay4 10-28-2009 05:14 PM

Should add some else's in front of the appropriate if statements, otherwise it's pretty neat.

Deas_Voice 11-07-2009 11:16 PM

why does it take longer time to cast if u fire it too fast (eg, presses D too fast)?


All times are GMT +2. The time now is 12:31 AM.

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