PDA

View Full Version : Lua: Getting qglobals in event_death_complete


Darkscis
04-09-2016, 10:39 AM
Wondering if anyone can assist with this. I have a default.pl quest set to assign a quest global credit when a mob is killed in a zone. The zones i am using it in (Befallen & Crushbone) also have a lot of .lua scripts already created so I am trying to convert this section to lua as well so I can copy/paste it into the other scripts.

Perl quest:
sub EVENT_DEATH_COMPLETE {
#Prevent pets or charmed NPCs from loading the default.pl
if (!$npc || $npc->GetOwnerID() || $npc->GetSwarmOwner())
{
return;
}

#Checking if the reborn_credits global is defined for this character
if (defined ($client->GetGlobal("reborn_credits"))) {
#Adding 1 point/credit to the reborn_credits global
my $total = $client->GetGlobal("reborn_credits");
$total += 1;
$client->SetGlobal("reborn_credits", $total, 5, "F");
$client->Message(5, "You have gained a Reborn armor credit! You currently have $total.");
}
}

This is what I have so far for the Lua version, however GetGlobal is always returning "Undefined". SetGlobal works fine, it's only commented out for the moment because it is just setting the qglobal to 0 over and over.
function event_death_complete(e)
local total = 0;
if(e.other:GetGlobal("reborn_credits") ~= "Undefined") then
total = tonumber(e.other:GetGlobal("reborn_credits"));
end
-- total = total + 1;
-- e.other:SetGlobal("reborn_credits", tostring(total), 5, "F");
e.other:Message(5, "You have gained a Reborn armor credit! You currently have "..total..".");
end

ghanja
04-09-2016, 09:23 PM
I had crazy absent minded drivel here.

NatedogEZ
04-09-2016, 10:12 PM
This is lua Ghanja not perl :)

ghanja
04-09-2016, 10:15 PM
This is lua Ghanja not perl :)

Ohhh, yeah ok, I see what I did there now. Welp, going back to the Perl forums where I should stay then. :p

NatedogEZ
04-09-2016, 10:30 PM
I would suggest using `event_killed_merit` BTW! :)


function event_killed_merit(e)
local total = 0;
local qglobals = eq.get_qglobals(e.other);
if (qglobals["reborn_credits"] == nil) then
total = 1;
else
total = tonumber(qglobals["reborn_credits"]) + 1;
end

e.other:SetGlobal("reborn_credits", tostring(total), 5, "F");
e.other:Message(5, "You have gained a Reborn armor credit! You currently have "..total..".");
end

Darkscis
04-10-2016, 07:50 PM
Perfect, many thanks NatedogEZ!

Will give this a go tonight. I did use event_killed_merit in my perl example but couldn't get it to work (think I was using the old qglobal{} method instead of $client->) and eventually swapped over to death_complete. Just never swapped back after working it all out.