PDA

View Full Version : Need help with global/spells/spellid.lua script


silvergrin46
01-22-2015, 12:28 PM
Hello and thanks in advance for any advice you may have to offer. I am developing a rof2 server and attempting to only use lua scripts. I am in the process of converting the perl files I used on my previous server to lua.

These perl files worked fine on the previous server and were stored in quests/spells/spellid.pl. The perl files I am converting used either sub Event_Spell_Effect_Client or Sub Event_Spell_Effect_NPC and I modified them to work based on the existing perl files I examined in the same folder. Examples of these are the Halloween event spells used in toxxulia such as throw pie and retributive fire. I will be happy to post examples of these perl scripts I am trying to convert when I get back to my computer.

I need an example of how these types of scripts are written in lua so that I may have basically a dummy spell cast with a charisma modifier or just blank if possible and trigger this lua script to perform other actions such as casting another spell or to depop a mob if conditions are met.

The only information I found so far was to use function Event_Spell_Effect in the lua script but I'm not sure how to word everything properly. The normal spells on my server activate correctly as do all of my other lua scripts for player and npcs. I am storing these lua spell files on my rof2 server in globals/spells btw.

trevius
01-22-2015, 03:53 PM
Paragraphs

silvergrin46
01-23-2015, 09:17 AM
To be stored in global/spells/spellid.lua

The spell is Targettype 6 (self) and when cast is supposed to spawn an NPC.


sub EVENT_SPELL_EFFECT_CLIENT {

$ClientID = $entity_list->GetClientByID($caster_id);

my $x = $ClientID->GetX();
my $y = $ClientID->GetY();
my $z = $ClientID->GetZ();
my $h = $ClientID->GetHeading();

quest::spawn2(1079,0,0,$x+5,$y+5,$z,$h);


} #Close event

silvergrin46
01-24-2015, 10:08 AM
After alot of experimenting in game with global/spells/spellid.lua (in my example global/spells/102.lua) and casting
my test spell over and over with minor changes and #reloadquest, also reading this again from
https://github.com/EQEmu/Server/wiki/Lua-Parser#player-scripts


Spell Events

event_spell_effect

Triggered when a spell affects a target. Passes an event table as an argument:

{
Spell self;
Mob target;
Integer buff_slot;
Integer caster_id;
}
Returning a non-zero value from this function will cancel the spell effect.


It finally sank in how to word this spell file properly. I am now at least getting some reaction when activating the script and I will continue attempting to convert more complex versions of my old perl spell files to lua.



--global/spells/102.lua test spell target self
--Message is received whenever spell 102 is cast, with or without a target as spell 102 is self only spell

function event_spell_effect(e)

e.target:Message(15, "I just cast a spell FROM SPELL FILE ! ");

end

Hopefully this will help someone else out at some point.

silvergrin46
01-26-2015, 10:39 PM
Many of the functions found here seem to be read correctly upon casting my test spell:

https://github.com/EQEmu/Server/wiki/Lua-Mob

Here is an example script which all displays as it should when the spell is cast and triggers a script to be run from global/spells.

function event_spell_effect(e)

local P_LVL = e.target:GetLevel();
local P_RACE = e.target:GetBaseRace();
local P_STR = e.target:GetSTR();

local Mana = e.target:GetMana();
local ManaCost = (P_LVL*5);
local NewMana = (Mana - ManaCost);


e.target:Message(15, "My LEVEL IS: "..P_LVL);
e.target:Message(15, "My RACE IS: "..P_RACE);
e.target:Message(15, "My STR IS: "..P_STR);

e.target:Message(15, "My INITIAL MANA IS: "..Mana);
e.target:Message(15, "MANACOST TO CAST THIS SPELL IS: "..ManaCost);
e.target:Message(15, "My MANA TOTAL AFTER CASTING IS: "..NewMana);

if(NewMana < 0) then e.target:Message(5, "You do not have enough mana to use this ability.");
elseif (NewMana >= 0) then e.target:SetMana(NewMana);


end
end



What one of my goals is to have a spell cast and trigger a script that will cast another spell or trigger the global_player file to cast another spell based on the conditions I specify.

I've tried variations of Selfcast /CastSpell /CastToClient /SignalClient /SignalAllClients etc. and can not seem to get the script to recognize just who e.target really is.

I have figured out how to do so in the lua global_player file, I was just trying to avoid constant access to the player file if I can do so in a separate spell file.

iluvseq
01-27-2015, 09:29 AM
Are you trying for a 'recourse' effect? Isn't that already supported without scripting?

silvergrin46
01-27-2015, 11:42 AM
Thanks for the response. In a sense it is much like a recourse effect.
However let's say in a recourse spell - The spell Id to be recoursed is added to the main spells recourse field. When you cast the main spell it then casts the spell from the recourse field onto the caster of the main spell.

What I am trying to do is have the main spell trigger the spell script and then only cast a specific spell or perform actions based on criteria in the script instead of only one spell.

As an example:

Main spell:
Summon Mage pet
Basically a blank spell it is self targeted and beneficial with only a positive charisma spell effect in it. This spell has no duration.

When summon Mage pet is cast the spell file is triggered with a script that does the following:

Get spell caster current level

If level is 1-50 then cast spell to summon lower level pet.

If level is 51-85 then cast spell to summon higher level pet

I apologize for the long post I'm just trying to explain this right.
I'd like to be able to identify who the exported integer caster_id is in the spell file. If I cannot perform the checks for level in the above example and then cast the spell directly, then I'd like to perform the level checks and send two different signals to the player file and then cast the appropriate spells.

If I need to I will use the player file and identify each spell in the function event_cast section, perform the checks and activate the spell I want to cast from there. But with many custom spells the global_player file can get crowded fast.

silvergrin46
01-27-2015, 08:29 PM
Below is the working script that corresponds to the example I posted about the spell that triggers the cast of either a
lower/higher rank pet summon spell depending upon the level of the caster.


function event_spell_effect(e)

local P_LVL = e.target:GetLevel();

e.target:Message(15, "My CASTER_ID is: "..e.caster_id);
e.target:Message(15, "My LEVEL IS: "..P_LVL);

if(P_LVL <=50) then
e.target:CastSpell(12001, e.caster_id); -- Summons lower level Pet

elseif(P_LVL >50) then
e.target:CastSpell(12002, e.caster_id); -- Summons higher level Pet

end
end



This only works when casting the main spell via the #cast command.

From what I can figure out, when casting the main spell from a spell gem it must begin the cast and then process the script.

However, when using the #cast command it must process the script before the cast of the main spell actually takes place
because the appropriate second spell immediately begins its cast sequence when the command is activated.

I'm moving on to using the global_player.lua file for what I need until I can find another way, but I felt like sharing this information - maybe it will help someone.