Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local RequiredGameTime = 300 -- in seconds
- local T = {}
- do
- for _, pPlayer in pairs(GetPlayersInWorld()) do
- T[tostring(pPlayer)] = GetGameTime()
- end
- end
- local function LogIn(event, pPlayer)
- local str = tostring(pPlayer)
- if(not T[str]) then
- T[str] = GetGameTime()
- end
- end
- local function LogOut(event, pPlayer)
- T[tostring(pPlayer)] = nil
- end
- function EnoughPlayed(pPlayer)
- local str = tostring(pPlayer)
- if(not T[str]) then
- T[str] = GetGameTime(); return 0
- end
- local Time = GetGameTime()-T[str]
- if(Time < RequiredGameTime) then
- return RequiredGameTime-Time
- end
- return false
- end
- function ResetPlayedTime(pPlayer)
- T[tostring(pPlayer)] = GetGameTime()
- end
- RegisterServerHook(4, LogIn) -- SERVER_HOOK_ENTER_WORLD
- RegisterServerHook(13, LogOut) -- SERVER_HOOK_LOGOUT
- --[[
- Example of use:
- function Hello(pUnit, event, pPlayer)
- pUnit:GossipCreateMenu(1, pPlayer, 0)
- pUnit:GossipMenuAddItem(0, "Test1", 1, 0)
- local ReqTime = EnoughPlayed(pPlayer) -- Get needed time in seconds or false if ok to show
- if(not ReqTime) then -- This checks if the player has played 5 min for example
- pUnit:GossipMenuAddItem(0, "HAS PLAYED 5 MIN OR MORE", 2, 0)
- else
- pUnit:GossipMenuAddItem(0, "You still need to play "..(math.ceil(ReqTime/60)).." more minutes", 3, 0)
- end
- pUnit:GossipMenuAddItem(0, "Test2", 4, 0)
- pUnit:GossipSendMenu(pPlayer)
- end
- function Select(pUnit, event, pPlayer, id, intid, code)
- if(intid == 2) then
- -- do stuff
- pPlayer:SendBroadcastMessage("You have played 5 minutes and recieved a reward")
- ResetPlayedTime(pPlayer)
- elseif(intid == 3) then
- Hello(pUnit, event, pPlayer)
- return
- end
- pPlayer:GossipComplete()
- end
- RegisterUnitGossipEvent(190000, 1, Hello)
- RegisterUnitGossipEvent(190000, 2, Select)
- ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement