View Single Post
  #1  
Old 04-09-2016, 10:39 AM
Darkscis
Sarnak
 
Join Date: Mar 2015
Posts: 62
Default Lua: Getting qglobals in event_death_complete

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:
Code:
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.
Code:
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
Reply With Quote