User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 7 of 11

Thread: Eluna and Client Addons!

  1. #1
    Founder <span style='color: #FF4500'>Foereaper</span>'s Avatar
    Join Date
    Apr 2013
    Posts
    926
    XP
    38,862
    Level
    60
    Thanks
    125
    Thanked 329 Times in 156 Posts

    Eluna and Client Addons!

    Earlier today we pushed a new hook and a new method to the repo. Secifically the hook OnAddonMessage, and the method player:SendAddonMessage. These two now allows us to create extremely powerful and easy binding for two way communication between the client (addons) and the server (scripts).



    SERVER SIDE:
    The hook is a Server hook, and is as follows:
    Code:
    ADDON_EVENT_ON_MESSAGE                  =     30,       // (event, plr, prefix, msg, type, target)
    This is registered with the normal RegisterServerEvent hook.

    The method, SendAddonMessage, allows you to send addon messages to the player.
    Code:
    PlayerObject:SendAddonMessage("Prefix", "Message", type, PlayerObject)
    The types available to use with this are as follows:
    Code:
    CHAT_MSG_PARTY                  = 2,
    CHAT_MSG_RAID                   = 3,
    CHAT_MSG_GUILD                  = 4,
    CHAT_MSG_WHISPER                = 7,
    CHAT_MSG_BATTLEGROUND           = 44,

    For this reason, I have also created a sample script, and a sample addon, so you all can see how easy you can integrate the server side Lua API with client side UI and functions.

    Server-side script:
    Code:
    -- /script SendAddonMessage("Eluna", "Ping", "GUILD")
    
    local MName = "[ServerAddonHandler]"
    print(MName.." Loaded")
    local pfx = "Eluna"
    
    function OnReceiveAddonMsg(event, plr, prefix, msg, type, target)
    	if (prefix == pfx) then
    		if (msg == "Ping") then
    			print(MName..": Ping received by "..plr:GetName().."! Sending Pong.")
    			plr:SendAddonMessage(pfx, "Pong", type, plr)
    		elseif(msg == "GoldRequest") then
    			print(MName..": Gold request received from Client.")
    			plr:ModifyMoney(100)
    		else
    			print(MName..": Received unknown msg: "..msg)
    		end
    	else
    		print(MName..": Received unknown prefix: "..prefix)
    	end
    end
    
    RegisterServerEvent(30, OnReceiveAddonMsg)
    The above code is the script that goes into your core folder. It reads the message sent from the client using SendAddonMessage. The Prefix is your addon's identifier. In this example we use Eluna. The msg is the message sent between the client and the server, and this determines what actions are to be taken. The player is also the sender of the said message. This can be used for several security checks, like checking if the individual is a GM or has the correct access or not.




    CLIENT SIDE:
    For the client you would use the standard CHAT_MSG_ADDON event: http://www.wowwiki.com/Events/C#CHAT_MSG_ADDON
    You would also use the Client-side SendAddonMessage method to communicate with the server side script: http://www.wowwiki.com/API_SendAddonMessage

    Client-side script (Addon):
    Code:
    local MName = "[ClientAddonHandler]"
    local pfx = "Eluna"
    
    local function CommHandler(self, event, prefix, msg, channel, me)
    	if (prefix == pfx) then
    		if(msg == "Pong") then
    			print(MName..": Received Pong! Sending Gold request to server!")
    			SendAddonMessage(pfx, "GoldRequest", "GUILD")
    		end
    	end
    end
    
    local ElunaComm = CreateFrame("Frame");
    ElunaComm:RegisterEvent("CHAT_MSG_ADDON");
    ElunaComm:SetScript("OnEvent", CommHandler);
    The above script is the client-side lua script. As said earlier, this uses the standard CHAT_MSG_ADDON event, and has the same arguments as the server side function. You use prefix for addon identifier, and msg for the communication between the server and the client. self in this case is the player.


    How to use the above example:

    To use the above example, download the addon and place it inside your interface/addon folder. Download the server-side script and save this inside your lua_script folder. Then go ingame and type the below:
    Code:
    /script SendAddonMessage("Eluna", "Ping", "GUILD")
    NOTE: This requires you to be in a guild, as the addon message uses the GUILD channel. This will also add 1 silver to your character.

    The above will trigger the "Eluna" identifier, with the command "Ping". "Ping" will then trigger the event "Pong", which again triggers "GoldRequest". The "GoldRequest" event then gives 1 silver to the player. Pretty straight forward, but still an example as to how this can be used extremely well for client side addons requiring server side scripts!

    You can find the downloads below:
    Server-side script: http://pastebin.com/RZvwVQiG
    Client-side addon: https://mega.co.nz/#!AsUTwaBR!cThDtn...EO0C3QKssSU-Fg

    Do mind this is an extremely simple representation, but I seriously hope we'll see some cool tools using this in the near future! Don't hesitate asking questions or come with suggestions for improvements!

    Special thanks to:
    Tommy
    Rochet
    Laurea
    StoneHarry

    https://github.com/ElunaLuaEngine/El...a08c656f9ac4e9
    https://github.com/ElunaLuaEngine/El...f70af89a1e746c

  2. The Following 10 Users Say Thank You to Foereaper For This Useful Post:


  3. #2
    Sexy Member <span style='color: #008080'><span class='glow_000000'>DarkAngel</span></span>'s Avatar
    Join Date
    Dec 2013
    Location
    Denmark
    Posts
    251
    XP
    10,471
    Level
    30
    Thanks
    67
    Thanked 50 Times in 34 Posts
    I love you.
    Awards:
    Contest Winner Raffle Winner
    Some are born great, some achieve greatness, and some have greatness thrust upon 'em.

  4. #3
    Insane Member <span style='color: #00FF00'>Parranoia</span>'s Avatar
    Join Date
    May 2013
    Posts
    365
    XP
    22,177
    Level
    45
    Thanks
    60
    Thanked 121 Times in 57 Posts
    This is pretty awesome. Nice work

  5. #4
    Moderator / Eluna Dev <span style='color: #FF0000'><span class='glow_8B0000'>Rochet2</span></span>'s Avatar
    Join Date
    Apr 2013
    Location
    Finland
    Posts
    1,871
    XP
    13,718
    Level
    35
    Thanks
    95
    Thanked 595 Times in 421 Posts
    The addon message hook was altered a little so it now has these arguments passed:
    ADDON_EVENT_ON_MESSAGE = 30, // (event, sender, type, prefix, msg, target) - target can be nil/whisper_target/guid/group/channelid
    The hook should now also work on mangos and TC all across.

    See more:
    https://github.com/ElunaLuaEngine/El...da92d4c2bb7c81
    Last edited by Rochet2; 04-13-2014 at 02:04 PM.
    Awards:
    Support LOL Scripter Facepalm! Raffle Winner

  6. #5
    Enthusiast SkittlesAreFalling's Avatar
    Join Date
    Aug 2013
    Posts
    42
    XP
    2,396
    Level
    13
    Thanks
    10
    Thanked 2 Times in 2 Posts
    This is the most useful thing in the universe, and that's an understatement.
    Achievements:
    1 year registered Member Level X

  7. #6
    Enthusiast
    Join Date
    Jun 2014
    Posts
    4
    XP
    1,573
    Level
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I've been trying to debug this for a few hours and feel like I'm missing something completely simple. But I'm running 1.12.1 Cmangos and everytime I put the command in on the client, the server receives "Recieved unknown prefix: 3" I just can't understand where it's pulling the 3 from.

    With a bit more of messing around I've discovered that my server is defining the prefix as 3, the msg as Eluna, and the type as ping. Just not quite sure why though.
    Last edited by Serrak; 06-06-2014 at 12:54 PM.
    Achievements:
    1 year registered Level X

  8. #7
    Moderator / Eluna Dev <span style='color: #FF0000'><span class='glow_8B0000'>Rochet2</span></span>'s Avatar
    Join Date
    Apr 2013
    Location
    Finland
    Posts
    1,871
    XP
    13,718
    Level
    35
    Thanks
    95
    Thanked 595 Times in 421 Posts
    Quote Originally Posted by Serrak View Post
    I've been trying to debug this for a few hours and feel like I'm missing something completely simple. But I'm running 1.12.1 Cmangos and everytime I put the command in on the client, the server receives "Recieved unknown prefix: 3" I just can't understand where it's pulling the 3 from.

    With a bit more of messing around I've discovered that my server is defining the prefix as 3, the msg as Eluna, and the type as ping. Just not quite sure why though.
    Here are the args:
    ADDON_EVENT_ON_MESSAGE = 30, // (event, sender, type, prefix, msg, target) - target can be nil/whisper_target/guid/group/channel
    https://github.com/ElunaLuaEngine/El.../HookMgr.h#L87

    Post if you still have problems.
    (Im in a rush atm)

    Seems there is a typo in the comment .. should be guild and not guid.
    Ah well.

  9. The Following User Says Thank You to Rochet2 For This Useful Post:


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •