Re: Fight Time Restrictions

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
Fireal
Posts: 11
Joined: Sun May 21, 2017 5:51 pm

Fight Time Restrictions

Post by Fireal »

Hey everyone, still plugging away at a game I'm working on and I'm trying to figure out the best way to approach a fight restriction based on time. Basically, a user can only fight once every 15 minutes. And until the timer is expired they can't click on a "Fight!" button. Now, I understand everyone has issues with energy/time related limitations in games but I'm using it for more of a realistic approach rather than a monetary one. I mean if you get in a fight you are pretty damn tired, you aren't going to rush in to fights back to back. Makes no sense to me. Plus it allows a user to take time to strategize a bit before a fight.

I am using pure php, jquery, and mysql. I am tossing around one approach and I'm curious to hear how anyone of you would approach this.

Idea 1:
Basically when a user clicks fight, it will insert a timestamp of the current time plus 15 minutes into the fighters table under 'nextFightTime'. Then use a db call to check if that time has passed before allowing the user to click again. Of course I would include jquery somewhere for the actual countdown. Just not sure if this is the most efficient.

Anyways thanks in advance for the advice guys.
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: Fight Time Restrictions

Post by Jackolantern »

I would say your Idea 1 is how to handle it. Once the player is committed to a fight, go ahead and make the timestamp in the database. Then after the fight, any time the page reloads and you need to display the countdown timer, check that timestamp in the database and determine how long it will be before they can fight again and use that to pass the time left into the JS code to start showing the timer (you could use PHP to write the value directly into the JS script). This way the server knows how long it will be before the player can fight again. You will no doubt have some smarty-pants players who mess with the JS and turn the timer to 0 with the Dev Tools and then try to fight only to see that the server knows how long they have to wait.

As far as the mechanics of it, I think it would be cool if how long the player has to wait was kind of in their control. For example, if they push their fighter harder, take more damage over and over, the time goes up. If they do some other activities they can rebound from a fight more quickly. This could be a source of strategy to your game and would help keep the fight cooldown time from feeling arbitrary.

Hope this helps. Best of luck and let us know if you have any more questions!
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Fight Time Restrictions

Post by hallsofvallhalla »

Yup thats exactly the way I would do it too. Good idea on the different timings. Especially if it is a one hit one kill type thing.
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

Re: Fight Time Restrictions

Post by KyleMassacre »

I will concur with Jack and Halls. By doing it this way you can expand a little as well. For example

Code: Select all

$numTimes = 3;
$count = $db->query(“select count(userId) from fightTable where userId = ? and fightTime <= ?”,$userId, time());
if($count >= $numTimes) {
  // show message saying they can’t fight
} else {
  // insert into fight table
  // trigger a fight
}
williamnorman
Posts: 1
Joined: Fri Aug 10, 2018 8:30 am

Re: Fight Time Restrictions

Post by williamnorman »

This could be a certain source of strategy to the game and would help keep the fight cooldown time from feeling voluntary.
annemanike
Posts: 2
Joined: Sun Jun 28, 2020 2:08 am

Re: Fight Time Restrictions

Post by annemanike »

your approach of implementing a time restriction for fights in your game to add realism and strategic thinking is a valid one. Idea 1 seems reasonable, as it utilizes a timestamp in the database to track the next available fight time and checks it with a database call. Additionally, incorporating jQuery for the countdown can enhance the user experience. However, it's important to consider potential optimizations based on your specific game requirements and user load to ensure efficiency.ApplinkedAptoide TV[B612 apkAndroid Camera
Post Reply

Return to “Beginner Help and Support”