Last active
February 5, 2024 18:56
-
-
Save ziggi/5d7d8dc42f54531feba7ae924c608e73 to your computer and use it in GitHub Desktop.
Function to calculate the time elapsed between the two calls GetTickCount(), given the possibility of overflow passed values.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stock GetTickDiff(newtick, oldtick) | |
{ | |
if (oldtick > newtick) { | |
return (cellmax - oldtick + 1) - (cellmin - newtick); | |
} | |
return newtick - oldtick; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static | |
LastShot[MAX_PLAYERS]; | |
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ) | |
{ | |
new | |
current_tick = GetTickCount(); | |
interval = GetTickDiff(current_tick, LastShot[playerid]); | |
printf("Last shot interval: %i ms", interval); | |
LastShot[playerid] = current_tick; | |
return 1; | |
} |
No, can't! What are you saying? GetTickCount
isn't a const value, how current_tick
will be const?
Isn't GetTickDiff
missing code?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
current_tick
can be const ...