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); }
|