how to make cooldown in lua? menu

User Tag List

Results 1 to 8 of 8
  1. #1
    Pieterkii's Avatar Member
    Reputation
    7
    Join Date
    Jan 2009
    Posts
    89
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to make cooldown in lua?

    This is my .playall npc
    Code:
    function Music_OnGossipTalk(pUnit, event, player, pMisc)
    pUnit:GossipCreateMenu(100, player, 1)
    pUnit:GossipMenuAddItem(0, "*Rock*", 1, 0)
    pUnit:GossipMenuAddItem(0, "*holy life -srinty bpeers*", 2, 0)
    pUnit:GossipMenuAddItem(0, "*Drums*", 3, 0)
    pUnit:GossipMenuAddItem(0, "*MURLOC*", 4, 0)
    pUnit:GossipMenuAddItem(0, "Wooot? Illidan??", 5, 0)
    pUnit:GossipSendMenu(player)
    end
    
    
    function Music_OnGossipSelect(pUnit, event, player, id, intid, code, pMisc)
    if (intid == 1) then
    pUnit:SendChatMessage(14, 0, "Rock this party DANCE everybody!")
    pUnit:PlaySoundToSet(11803)
    pUnit:GossipComplete(player)
    end
    
    if (intid == 2) then
    pUnit:SendChatMessage(12, 0, "Make it HOT! in this club.....")
    pUnit:PlaySoundToSet(11699)
    pUnit:GossipComplete(player)
    end
    
    if (intid == 3) then
    pUnit:PlaySoundToSet(11704)
    pUnit:GossipComplete(player)
    end
    
    if (intid == 4) then
    pUnit:SendChatMessage(12, 0, "Dont STOP move your body!")
    pUnit:PlaySoundToSet(11802)
    pUnit:GossipComplete(player)
    end
    
    if (intid == 5) then
    pUnit:SendChatMessage(14, 0, "Everybody DANCE now!")
    pUnit:PlaySoundToSet(11466)
    pUnit:GossipComplete(player)
    end
    end
    
    RegisterUnitGossipEvent(ID, 1, "Music_OnGossipTalk")
    RegisterUnitGossipEvent(ID, 2, "Music_OnGossipSelect")
    i need someone to show me how to add a cooldown so if a player chooses a song....after 3 hours again someone will be able 2 choose the song....

    how to make cooldown in lua?
  2. #2
    Jotox's Avatar Contributor
    Reputation
    250
    Join Date
    Mar 2008
    Posts
    282
    Thanks G/R
    0/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here, what you need is a table to keep track of player cooldowns.

    ...It's a tad bit hard to explain, so I'll just write it for you :S
    Code:
    Cooldowns = {};
    NUM_MINUTES = 60*3;	--3 hours
    
    function Music_OnGossipTalk(pUnit, event, player, pMisc)
    pUnit:GossipCreateMenu(100, player, 1)
    pUnit:GossipMenuAddItem(0, "*Rock*", 1, 0)
    pUnit:GossipMenuAddItem(0, "*holy life -srinty bpeers*", 2, 0)
    pUnit:GossipMenuAddItem(0, "*Drums*", 3, 0)
    pUnit:GossipMenuAddItem(0, "*MURLOC*", 4, 0)
    pUnit:GossipMenuAddItem(0, "Wooot? Illidan??", 5, 0)
    pUnit:GossipSendMenu(player)
    end
    
    
    function Music_OnGossipSelect(pUnit, event, player, id, intid, code, pMisc)
    
    if Cooldowns[player:GetName()] and ( os.difftime( os.time(), Cooldowns[player:GetName()] ) < 60*NUM_MINUTES ) then
    pUnit:SendChatMessage(14, 0, "You have to wait "..( NUM_MINUTES - (os.difftime( os.time(), Cooldowns[player:GetName()] ) / 60)  ).." more minutes to play a song again.")
    return;
    end
    
    Cooldowns[player:GetName()] = os.time();
    
    if (intid == 1) then
    pUnit:SendChatMessage(14, 0, "Rock this party DANCE everybody!")
    pUnit:PlaySoundToSet(11803)
    pUnit:GossipComplete(player)
    end
    
    if (intid == 2) then
    pUnit:SendChatMessage(12, 0, "Make it HOT! in this club.....")
    pUnit:PlaySoundToSet(11699)
    pUnit:GossipComplete(player)
    end
    
    if (intid == 3) then
    pUnit:PlaySoundToSet(11704)
    pUnit:GossipComplete(player)
    end
    
    if (intid == 4) then
    pUnit:SendChatMessage(12, 0, "Dont STOP move your body!")
    pUnit:PlaySoundToSet(11802)
    pUnit:GossipComplete(player)
    end
    
    if (intid == 5) then
    pUnit:SendChatMessage(14, 0, "Everybody DANCE now!")
    pUnit:PlaySoundToSet(11466)
    pUnit:GossipComplete(player)
    end
    end
    
    RegisterUnitGossipEvent(ID, 1, "Music_OnGossipTalk")
    RegisterUnitGossipEvent(ID, 2, "Music_OnGossipSelect")
    Last edited by Jotox; 07-28-2009 at 09:50 AM.

  3. #3
    Pieterkii's Avatar Member
    Reputation
    7
    Join Date
    Jan 2009
    Posts
    89
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i love u! +REP

  4. #4
    Pieterkii's Avatar Member
    Reputation
    7
    Join Date
    Jan 2009
    Posts
    89
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this coding is for every1 who wants to choose a song rite?...i dont want permanent music on the server...so if i choose a song at 2:00, u/ me will be able to choose 1 at 5:00 again rite?

  5. #5
    Jotox's Avatar Contributor
    Reputation
    250
    Join Date
    Mar 2008
    Posts
    282
    Thanks G/R
    0/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes.

    The way it works is every time a player chooses a song, it records an entry in the "Cooldowns" table. The entry has the player's name and the exact second that he chose the song.

    Then, when a player tries to choose another song, it searches for an entry in the table that has the player's name.

    If an entry with the player's name is found, and the time associated with the entry is less than 3 hours ago, the player can't play another song.

  6. #6
    Pieterkii's Avatar Member
    Reputation
    7
    Join Date
    Jan 2009
    Posts
    89
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    does that mean that No'one will be able to use it in the next 3 hours??? i hope so...cause thats what i wanted..otherwise other people would come and it would be a constant noise 0.0

  7. #7
    Jotox's Avatar Contributor
    Reputation
    250
    Join Date
    Mar 2008
    Posts
    282
    Thanks G/R
    0/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, no... I did it on a player by player basis

    No one using it for 3 hours is much simpler >_<...
    Code:
    local Cooldown = 0;
    NUM_MINUTES = 60*1;	--1 hour <----PIETERKII, EDIT TO CHANGE THE COOLDOWN
    
    function Music_OnGossipTalk(pUnit, event, player, pMisc)
    pUnit:GossipCreateMenu(100, player, 1)
    if ( os.difftime( os.time(), Cooldown ) < 60*NUM_MINUTES ) then
    pUnit:GossipMenuAddItem(0, "This is still on cooldown. You have to wait"..( NUM_MINUTES - (os.difftime( os.time(), Cooldown) / 60)  ).." more minutes to play a song again.", 99, 0)
    else
    pUnit:GossipMenuAddItem(0, "*Rock*", 1, 0)
    pUnit:GossipMenuAddItem(0, "*holy life -srinty bpeers*", 2, 0)
    pUnit:GossipMenuAddItem(0, "*Drums*", 3, 0)
    pUnit:GossipMenuAddItem(0, "*MURLOC*", 4, 0)
    pUnit:GossipMenuAddItem(0, "Wooot? Illidan??", 5, 0)
    end
    pUnit:GossipSendMenu(player)
    end
    
    
    function Music_OnGossipSelect(pUnit, event, player, id, intid, code, pMisc)
    
    if intid==99 then
    pUnit:GossipComplete(player);
    return;
    end
    
    if ( os.difftime( os.time(), Cooldown ) < 60*NUM_MINUTES ) then
    pUnit:SendChatMessage(14, 0, "You have to wait "..( NUM_MINUTES - (os.difftime( os.time(), Cooldown) / 60)  ).." more minutes to play a song again.")
    return;
    end
    
    Cooldown = os.time();
    
    if (intid == 1) then
    pUnit:SendChatMessage(14, 0, "Rock this party DANCE everybody!")
    pUnit:PlaySoundToSet(11803)
    pUnit:GossipComplete(player)
    end
    
    if (intid == 2) then
    pUnit:SendChatMessage(12, 0, "Make it HOT! in this club.....")
    pUnit:PlaySoundToSet(11699)
    pUnit:GossipComplete(player)
    end
    
    if (intid == 3) then
    pUnit:PlaySoundToSet(11704)
    pUnit:GossipComplete(player)
    end
    
    if (intid == 4) then
    pUnit:SendChatMessage(12, 0, "Dont STOP move your body!")
    pUnit:PlaySoundToSet(11802)
    pUnit:GossipComplete(player)
    end
    
    if (intid == 5) then
    pUnit:SendChatMessage(14, 0, "Everybody DANCE now!")
    pUnit:PlaySoundToSet(11466)
    pUnit:GossipComplete(player)
    end
    end
    
    RegisterUnitGossipEvent(ID, 1, "Music_OnGossipTalk")
    RegisterUnitGossipEvent(ID, 2, "Music_OnGossipSelect")
    There's the code. I changed it to 1 hour, since... well, imo, 3 hours is a bit much for songs that last 3 minutes at most :P

  8. #8
    Pieterkii's Avatar Member
    Reputation
    7
    Join Date
    Jan 2009
    Posts
    89
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ty you are my star!

Similar Threads

  1. LUA help, how to make npc cast a spell at a certain HP???
    By pioneer1337 in forum World of Warcraft Emulator Servers
    Replies: 3
    Last Post: 03-30-2008, 06:27 PM
  2. [Guide] How to make LUA portals easy and noobie too!
    By Ellenor in forum WoW EMU Guides & Tutorials
    Replies: 15
    Last Post: 03-05-2008, 09:10 PM
  3. How to make lua scripted portals
    By *Alexz* in forum WoW EMU Guides & Tutorials
    Replies: 9
    Last Post: 02-18-2008, 06:05 PM
  4. [Scripting Idea] How to make a great boss event in LUA!
    By Arthas117 in forum WoW EMU Guides & Tutorials
    Replies: 3
    Last Post: 02-03-2008, 07:41 AM
  5. How to make game objects teleport with LUA!
    By Le Froid in forum WoW EMU Guides & Tutorials
    Replies: 4
    Last Post: 01-02-2008, 06:59 PM
All times are GMT -5. The time now is 03:43 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search