User Tag List

Page 3 of 4 FirstFirst 1 2 3 4 LastLast
Results 15 to 21 of 25

Thread: [Eluna] Simple World Chat System

  1. #15
    Enthusiast
    Join Date
    Sep 2013
    Posts
    21
    XP
    2,422
    Level
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Rochet2 View Post
    did you use .reload eluna
    ?

    I dont think the script is designed to be reloadable.

    Yes, reboot the server to run?

  2. #16
    Moderator / Eluna Dev <span style='color: #FF0000'><span class='glow_8B0000'>Rochet2</span></span>'s Avatar
    Join Date
    Apr 2013
    Location
    Finland
    Posts
    1,860
    XP
    13,487
    Level
    35
    Thanks
    95
    Thanked 591 Times in 418 Posts
    Quote Originally Posted by Clastor View Post
    Yes, reboot the server to run?
    yes
    Awards:
    Support LOL Scripter Facepalm! Raffle Winner
    rochet2.github.io - Home of great codes

  3. #17
    Esteemed Member <span style='color: #4169E1'>Grandelf</span>'s Avatar
    Join Date
    Oct 2014
    Posts
    104
    XP
    64,547
    Level
    78
    Thanks
    18
    Thanked 110 Times in 45 Posts
    I was looking over the script and noticed that players are added to the table,
    whenever they login. This concept seems nice enough, because you don't have to worry
    about the data (table) in the actual script.

    However, a player is always stored whether he uses the world chat or not.
    This means that if a player doesn't use the world chat, the data stored is
    pretty much useless. No nitpicking here, just sharing some thoughts which might
    improve the script =P.

    So you could actually achieve the exact same result, without storing data
    that isn't used. We can do this by using an __index metamethod.
    You could replace:
    Code:
    local ACCT = {};
    With:
    Code:
    local ACCT = setmetatable({}, {
    	__index = function (t, k)
    		t[k] = {
    			chat = 0,
    			time = os.time()
    		}
    		return t[k];
    	end
    });
    What this does is basically checking if a certain index exists. If it doesn't,
    the function will create the table with the given index and return it.
    If I'd run this code now: 'print(ACCT[1].chat)' it would actually print '0' instead
    of giving an error that the index doesn't exist.

    So rather than storing the data whenever a player enters world, the data is stored
    whenever it is requested (ACCT[index that doesn't exist yet]).
    With this in place, you could remove the login hook and the script would still work.
    As a bonus, reloading the Lua Engine doesn't break the script anymore.

    Again no nitpicking, just sharing some thoughts ;).

    Grandelf

  4. The Following 2 Users Say Thank You to Grandelf For This Useful Post:


  5. #18
    Original Poster
    Mad Scientist <span style='color: #008000'><span class='glow_006400'>slp13at420</span></span>'s Avatar



    Join Date
    Dec 2013
    Location
    Idaho
    Posts
    2,492
    XP
    20,134,792
    Level
    500
    Thanks
    1,089
    Thanked 330 Times in 212 Posts
    I gottcha lol just wrap it up in the On Chat hoop check and make if needed like I do in guild warz for the location id's.
    i'll update this
    Achievements:
    Shopper Got a Sticky! Member 1 year registered Level XL Level D
    Awards:
    Pot Head LOL Raffle Winner Top Tagger Donator Hangman Scripter Repacker Drunk Support Member of Staff Da Bomb!
    "Cuz PvP's better with a bag 'o' weed"
    !! King Spade !!

    -Guild Plot System-
    Grumbo'z Guild Warz


    -VIP System-
    Grumbo'z VIP System

  6. #19
    Esteemed Member <span style='color: #4169E1'>Grandelf</span>'s Avatar
    Join Date
    Oct 2014
    Posts
    104
    XP
    64,547
    Level
    78
    Thanks
    18
    Thanked 110 Times in 45 Posts
    You could do that as well, if you use the metatable however, you don't have to.

  7. #20
    Original Poster
    Mad Scientist <span style='color: #008000'><span class='glow_006400'>slp13at420</span></span>'s Avatar



    Join Date
    Dec 2013
    Location
    Idaho
    Posts
    2,492
    XP
    20,134,792
    Level
    500
    Thanks
    1,089
    Thanked 330 Times in 212 Posts
    ok re-organized it to support the `.reload Eluna` command and updated the main post :D

    Code:
    
    -- by slp13at420 of EmuDevs.com
    -- a mutation of FoeReaper's world chat with basic bells an whistles.
    -- simple world chat WITHOUT the '#chat' command...WTF you say?
    -- just change to /say channel 
    -- turn it on
    -- and chat away.
    -- names are clickable for whispers and sub menu.
    
    local WorldChat = {};
    local channel_name = "World Chat";
    local on = "#chat on";
    local off = "#chat off";
    local duration = 5; -- in seconds.
    
    local Colors =  { -- colors for names and misc
    	[0] = "|cff3399FF", -- blue for alliance name
    	[1] = "|cffFF0000", -- red for horde name
    	[3] = "|cff000000", -- black for [channel name]
    	[4] = "|cff00cc00", -- green for "message"
    	[5] = "|cff3399ff", -- good responce
    	[6] = "|cffFF0000", -- bad responce
    		};
    	
    local function ChatSystem(event, player, msg, type, lang, channel)
    
    local acct_id = player:GetAccountId();
    
    	if not(WorldChat[acct_id])then
    	
    		WorldChat[acct_id] = {
    						chat = 0,
    						time = GetGameTime()-duration,
    		};
    	end
    	
    	if(lang ~= -1)then
    	
    		if(msg ~= "")then
    			
    			if(msg ~= "Away")then
    				
    					if(msg == off)then
    						WorldChat[acct_id].chat = 0;
    						player:SendBroadcastMessage(Colors[5].."World chat off.|r")
    					return false;
    					end
    				
    					if(msg == on)then
    						WorldChat[acct_id].chat = 1;
    				    	player:SendBroadcastMessage(Colors[5].."World chat on.|r")
    				    return false;
    					end
    					
    					if(WorldChat[acct_id].chat == 1)then -- 0 = world chat off :: 1 = world chat on
    	
    						local time = GetGameTime();
    
    						if(time-WorldChat[acct_id].time >= duration)then
    						
    								local t = table.concat{"[", Colors[3], channel_name, "|r]", "[", Colors[player:GetTeam()],"|Hplayer:", player:GetName(),  "|h", player:GetName(), "|h", "|r]:", Colors[4], msg, "|r"};
    								SendWorldMessage(t);
    								WorldChat[acct_id].time = time;
    						else
    					    		player:SendBroadcastMessage(Colors[6].."World chat spam timer detected.|r")
    						end				
    
    					return false;
    					end
    			end
    		end
    	end
    end
    	
    RegisterPlayerEvent(18, ChatSystem)
    
    print("Grumbo'z World Chat loaded.")
    
    I did some random `.reload Eluna` command's and it seem to run smooooooth
    altho ofc if you use `.reload Eluna` those who are using world chat will revert back to local chat until they turn it back on.

    :D enjoy :D

    TBH I never worked with metatables before.
    Last edited by slp13at420; 03-18-2016 at 01:28 PM.
    Achievements:
    Shopper Got a Sticky! Member 1 year registered Level XL Level D
    Awards:
    Pot Head LOL Raffle Winner Top Tagger Donator Hangman Scripter Repacker Drunk Support Member of Staff Da Bomb!
    "Cuz PvP's better with a bag 'o' weed"
    !! King Spade !!

    -Guild Plot System-
    Grumbo'z Guild Warz


    -VIP System-
    Grumbo'z VIP System

  8. The Following User Says Thank You to slp13at420 For This Useful Post:


  9. #21
    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
    In the original script I later rewrote the cache to be created when the player actually sent a chat message rather than on login, due to the exact same "bug" (Oversight) you were having :P

  10. The Following User Says Thank You to Foereaper For This Useful Post:


Thread Information

Users Browsing this Thread

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

Tags for this Thread

Posting Permissions

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