Advertisement
Rochet2

PingPong Eluna mthread State messages

Apr 28th, 2014
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.10 KB | None | 0 0
  1. --[[
  2. Start by logging in and typing .test
  3. See console for ping pong messages between global state and map the player was on
  4. ]]
  5.  
  6.  
  7. local mapid, instanceid = -1, -1
  8. if(GetMap()) then
  9.     mapid, instanceid = GetMap():GetMapId(), GetMap():GetInstanceId()
  10. end
  11.  
  12. local function SendMsg(m, i, msg)
  13.     print(mapid.." "..instanceid.." Sending "..tostring(msg).." to "..m.." "..i)
  14.     SendStateMsg(m, i, mapid, instanceid, msg)
  15. end
  16.  
  17. local function OnPing(event, m, i, msg)
  18.     print(mapid.." "..instanceid.." Received "..tostring(msg).." from "..m.." "..i)
  19.     --Send delayed ping or pong depending on which was received
  20.     CreateLuaEvent(function() SendMsg(m, i, msg == "PING" and "PONG" or "PING") end, 5000, 1)
  21. end
  22.  
  23. if(GetMap()) then
  24.     RegisterServerEvent(31, OnPing)
  25. else
  26.     RegisterServerEvent(31, OnPing)
  27.    
  28.     local function OnCommand(event, player, command)
  29.         if(command ~= "test") then
  30.             return
  31.         end
  32.        
  33.         SendMsg(player:GetMapId(), player:GetInstanceId(), "PING")
  34.         return false
  35.     end
  36.     RegisterPlayerEvent(42, OnCommand) -- on command
  37. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement