• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

[SOLVED] How to call event in other function

Status
Not open for further replies.

mjafko

Epic Member
Helou Emodev's.

Have have a question. Well I want to run PLAYER_EVENT_ON_UPDATE_ZONE when player Login so in PLAYER_EVENT_ON_LOGIN. I just want to get zone id and with it XpByZone, when player login.

Code:
local XpByZone  = 1;

function PLAYER_EVENT_ON_LOGIN ( event, player )

	local GUID = player:GetGUIDLow();
		QueryRow = CharDBQuery ( "SELECT guid FROM bla WHERE guid = '" .. GUID .. "' " );
		
			if( QueryRow == nil ) then
				CharDBQuery( "INSERT INTO bla VALUES ('" .. GUID .. "', 1 , 1) ");
					player:SendBroadcastMessage( "BLAA!" )
			end
end

function PLAYER_EVENT_ON_CHARACTER_DELETE (event, guid)

	CharDBQuery( "DELETE FROM bla WHERE guid = '" .. guid .. "' " );
end

function PLAYER_EVENT_ON_UPDATE_ZONE (event, player, newZone, newArea)
	if ( player:GetZoneId() == 5010) then
			XpByZone = 5;
		elseif ( player:GetZoneId() == 5003 ) then
			XpByZone = 10;
		else
			XpByZone = 0;
	end
end

Greeting's, Marko-
 

Tommy

Founder
Why not use :GetZoneId() in the login hook? Unless I'm not following what you mean.

Why are you using the enumerator data type names for function names instead of your own? And why do you use :GetZoneId() in zone update hook when "newZone" is a thing?

Cleaned up a bit. Not really sure what you want.
Code:
local XpByZone  = 1;

local function OnLogin(event, player)
    local guidLow= player:GetGUIDLow()
    local QueryRow = CharDBQuery("SELECT guid FROM bla WHERE guid='"..guidLow.."'")
    if(QueryRow == nil) then
        CharDBQuery( "INSERT INTO bla VALUES ('"..guidLow.."', 1 , 1)")
        player:SendBroadcastMessage("BLAA!")
    end
end

local function OnCharDelete(event, guid)
    CharDBQuery("DELETE FROM bla WHERE guid='".. guid .."'")
end

local function OnUpdateZone(event, player, newZone, newArea)
    if (newZone == 5010) then
        XpByZone = 5
    elseif (newZone == 5003 ) then
        XpByZone = 10
    else
        XpByZone = 0
    end
end
 

mjafko

Epic Member
Hellou Tommy.

Problem is I want to set right "XpByZone" on login. And I don't want to type all this "if" in " function OnLogin" also.

So ye I can do in "function OnLogin", "player:GetZoneId()", but with this I still can't set right "XpByZone" without writing
" if (newZone == 5010) then
XpByZone = 5
elseif (newZone == 5003 ) then
XpByZone = 10
else
XpByZone = 0
end"

And I don't want this if to be into login function
 

Grandelf

Esteemed Member
Not entirely sure what you want, but if you want to get rid of the if statements, you could make a table.
Code:
local tab = {
	[5010] = 5,
	[5003] = 10
};
Then in the OnUpdateZone function, you could do this.
Code:
local function OnUpdateZone(event, player, newZone, newArea)
	XpByZone = tab[newZone] or 0;
end

Edit:
I think I finally understand what you mean, you want to call the OnUpdateZone function from the OnLogin function?
This should do the trick:
Code:
local XpByZone  = 1;

local function OnLogin(event, player)
    local guidLow= player:GetGUIDLow()
    local QueryRow = CharDBQuery("SELECT guid FROM bla WHERE guid='"..guidLow.."'")
    if(QueryRow == nil) then
        CharDBQuery( "INSERT INTO bla VALUES ('"..guidLow.."', 1 , 1)")
        player:SendBroadcastMessage("BLAA!")
    end
    [COLOR="#FF0000"]OnUpdateZone(player:GetZoneId());[/COLOR]
end

local function OnCharDelete(event, guid)
    CharDBQuery("DELETE FROM bla WHERE guid='".. guid .."'")
end

local function OnUpdateZone([COLOR="#FF0000"]newZone[/COLOR])
    if (newZone == 5010) then
        XpByZone = 5
    elseif (newZone == 5003 ) then
        XpByZone = 10
    else
        XpByZone = 0
    end
end
 
Last edited:

mjafko

Epic Member
Thank you. This "OnUpdateZone" was what I look for.

Thank you 1000x :)
Sorry for english.

Greeting's, Marko!
 
Status
Not open for further replies.
Top