Jump to content

How to incorporate Attack Speed with PHP + Websockets


Monkuar
Go to solution Solved by kicken,

Recommended Posts

Since I got my websocket PHP server running nicely with my MYSQL, I can now have some fun :)

 

Attack speed is very simple, but I need your help with the unixtimestamp.

 

For example, There is a field name called "last_attack" and each time a user attacks a mob and a skill was performed; it will be updated with:

time();

Then I disable the attack button for 2 seconds client side, but I also check that value against time() serverside as well.

 

Now let's say the user's attack speed is 1.30%

 

I want to make that Attack Speed check, to check it dynamically.

 

It should now check only if the attack was less than 1.7 seconds ago instead of 2 seconds. How do I split up the unixtimestamp to work with percents?

Edited by Monkuar
Link to comment
Share on other sites

 

MYSQLI.

 

But I can grab the unixtimestamp and check it with PHP code though. I'm just using mysql to securely store the last_attack field. 

 

Wait, would I have to use http://php.net/manual/en/function.microtime.php instead?

 

Why does the PHP document say microseconds? "microtime() returns the current Unix timestamp with microseconds. This function is only available on operating systems that support the gettimeofday() system call."

 

Is microseconds the same as milliseconds I assume?

Edit: Wait, nevermind micro is 1 millionth of a second. I'm herp derping hard.

Edited by Monkuar
Link to comment
Share on other sites

  • Solution

Yes, you will have to use something with more resolution than time(). Unix timestamps / time() cannot identify periods of less than 1 second, so you'd have either 1 second or 2 seconds, 1.7 seconds is not possible using timestamps.

 

microtime() would work, or if you're mysql server's version is new enough using native datetime type and functions will give you fractional seconds as well.

  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.