Jump to content

How to incorporate Attack Speed with PHP + Websockets


Monkuar

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?

  On 12/3/2014 at 7:33 PM, Barand said:

 

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.