User Tag List

Page 1 of 3 1 2 3 LastLast
Results 1 to 7 of 17

Thread: Command Timer

  1. #1
    Sexy Member
    Join Date
    Jun 2014
    Location
    United State
    Posts
    81
    XP
    9,503
    Level
    29
    Thanks
    11
    Thanked 5 Times in 5 Posts

    Command Timer

    I'm trying to make a custom kick command (.vkick) that vip players can use every 2 hours.

    Code:
                    uint32 Cooldown = 10;		
    		uint32 RemainingTime = Cooldown-time(NULL);
    
    		std::string RemainingTimeStr = secsToTimeString(uint32(RemainingTime), true);
    		std::string CooldownTotalStr = secsToTimeString(Cooldown, true);
    
    		if (RemainingTime < 0)
    		{
    			RemainingTime = 0;
    			target->GetSession()->KickPlayer();
    		}
    		
    		if (Cooldown - RemainingTime != 0)
    		{
    			handler->PSendSysMessage("Kick Command Remaining Cooldown: %s ", RemainingTimeStr.c_str());
    		}
    Is what I have and is confusing the hell out of me with all these time factors.

  2. #2
    Founder <span style='color: #FF4500'>Tommy</span>'s Avatar
    Join Date
    Apr 2013
    Posts
    7,391
    XP
    3,449,104
    Level
    378
    Thanks
    889
    Thanked 1,856 Times in 1,119 Posts
    Well the way you have it now it won't work because it will allow the player to keep using it over and over again no matter what. The reason for that is because you need to save the last time they used the command in a map, single player class variable or related, instead of setting all the values inside the command function.

  3. #3
    Original Poster
    Sexy Member
    Join Date
    Jun 2014
    Location
    United State
    Posts
    81
    XP
    9,503
    Level
    29
    Thanks
    11
    Thanked 5 Times in 5 Posts
    I'm not sure how to add it to a map :x, you said related and hopefully one of those ways is adding a table in the DB.
    I added the column "KickCooldown" to account_access that holds the x integer cooldown remaining.

    > New VIPs that use this will get their own new row when used for the first time.
    > When used, and has no cooldown, it will kick the target and add a cooldown.
    > If cooldown is present, it returns false and gives remaining cooldown timer.


    >>> Or at least thats how I'd like it to be set up xx


    Code:
                    QueryResult result = LoginDatabase.PQuery("SELECT `KickCooldown` FROM `auth`.`account_access` where `id`=%u", handler->GetSession()->GetAccountId());
    
    		Field* field = result->Fetch();
    		uint32 timer = field[0].GetUInt32();
    
    		if (!result) // When command is executed from New VIPs.
    			LoginDatabase.PExecute("INSERT INTO `account_access` (`id`, `gmlevel`, `KickCooldown`) VALUES (%u, 1, 0);", target->GetSession()->GetAccountId());
    
    		if (timer == 0) // VIP has no Cooldown
    		{
    			/* Kick the Player */
    			target->GetSession()->KickPlayer();
    
    			/* ADD a cooldown for this member */
    			LoginDatabase.PExecute("UPDATE account_access SET KickCooldown = 10000 WHERE id = %u;",handler->GetSession()->GetAccountId());
    			
    			/* Display Server Message (if any)*/
    			if (sWorld->getBoolConfig(CONFIG_SHOW_KICK_IN_WORLD))
    				sWorld->SendWorldText(LANG_COMMAND_KICKMESSAGE_WORLD, (handler->GetSession() ? handler->GetSession()->GetPlayerName().c_str() : "Server"), playerName.c_str(), kickReasonStr.c_str());
    			else
    				handler->PSendSysMessage(LANG_COMMAND_KICKMESSAGE, playerName.c_str());
    			return true;
    		}
    		else if (timer >= 1) // VIP has a cooldown remaining.
    		{
    			uint32 Cooldown = timer - time(NULL);
    			std::string curRespawnDelayStr = secsToTimeString(uint32(Cooldown), true);
    
    			handler->PSendSysMessage("Remaining Cooldown:%s", curRespawnDelayStr.c_str());
    			return false;
    		}

    I'm think though, that the time will always sit at "10000" and never actually "countdown". I tried to reference as much information from .npc info (Respawn) as I could.
    Last edited by Visa; 09-14-2016 at 04:20 PM.

  4. #4
    Mad Scientist <span style='color: #008000'><span class='glow_006400'>slp13at420</span></span>'s Avatar



    Join Date
    Dec 2013
    Location
    Idaho
    Posts
    2,484
    XP
    20,134,707
    Level
    500
    Thanks
    1,087
    Thanked 329 Times in 211 Posts
    Check out our Community Premium system --> http://emudevs.com/showthread.php/57...Premium-System

    I wrote it so the Premium rank can have an expiration timer.

    When I added the command `.prem npc info` I included a spam timer for it. (LINE:1745)

    when I added the Premium chat system I included a spam timer for it also. (LINE:877)
    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

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



    Join Date
    Dec 2013
    Location
    Idaho
    Posts
    2,484
    XP
    20,134,707
    Level
    500
    Thanks
    1,087
    Thanked 329 Times in 211 Posts
    for best results I would store the current time to the sql DB and a map/table when the command is executed then every time an attempt was made to use the command again I would just compare the current time to the time stored in the (map/table)+delay. if the current time is (greater than/equal too) the stored time + delay then allow the use of the command and update the time stored in the sql DB AND update the map/table.
    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. #6
    Mad Scientist <span style='color: #008000'><span class='glow_006400'>slp13at420</span></span>'s Avatar



    Join Date
    Dec 2013
    Location
    Idaho
    Posts
    2,484
    XP
    20,134,707
    Level
    500
    Thanks
    1,087
    Thanked 329 Times in 211 Posts
    during login I would query the value from the sql. if it exists then store it to the map/db else create a unique entry for the char/toon (GUIDLow is good for a key) then store `0` to the map/table so you can check if stored time is 0 then do stuff since its never been used.

    Upon logout you can erase.(map/table[id]) so it free's up ram.
    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

  7. #7
    Original Poster
    Sexy Member
    Join Date
    Jun 2014
    Location
    United State
    Posts
    81
    XP
    9,503
    Level
    29
    Thanks
    11
    Thanked 5 Times in 5 Posts
    I think I might be getting closer? I understand part of this but when it comes to determining how the time is stored for the API of the game and how to correlate that with the time that I'm using it becomes more difficult.

    Code:
                    QueryResult result = LoginDatabase.PQuery("SELECT `KickCooldown` FROM `auth`.`account_access` where `id`=%u",                                             handler->GetSession()->GetAccountId());
    
    		Field* field = result->Fetch();
    		uint32 current_cooldown = field[0].GetUInt32(); // Value in the DB (Currently what they have)
    		uint32 full_cooldown = 10; // The full cooldown that is applied.
    
    		uint64 current_time = sWorld->GetGameTime();
    		uint32 account_id = handler->GetSession()->GetAccountId();
    
    		if (current_time < full_cooldown - current_cooldown)
    		{
    			// This result means he has no cooldown and is free to use ??
    		}
    
    		if (current_cooldown >= 1)
    		{
    			// This result means he has a cooldown and cannot use ??
    		}

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
  •