Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 08-23-2009, 06:23 PM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
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);

__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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