Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * GetPlayerO2 Include
- * Written by Mauzen, 19.8.2012
- * Version 1.0
- */
- // O2 used up/regenerated per second
- #define O2_CONSUMPTION (2.7) // 100.0% / 40-3 seconds
- // Checks the last updated animations to get if the player is swimming/diving
- #define IsPlayerWaterDiving(%1) (1540 <= O2_lastAnim[%1] && O2_lastAnim[%1] <= 1544)
- #define IsPlayerSwimming(%1) (O2_lastAnim[%1] == 1538 || O2_lastAnim[%1] == 1539)
- // Stores the animation id of each player on the last update
- new O2_lastAnim[MAX_PLAYERS];
- // Stores the ms time when a player started, or finished to dive for O2 calculation
- new O2_diveStart[MAX_PLAYERS];
- // Stores the O2 level at certain syncing points
- // This does NOT contain the correct and actual O2 value all the time, use GetPlayerO2
- new Float:O2_level[MAX_PLAYERS];
- forward Float:GetPlayerO2(playerid);
- stock Float:GetPlayerO2(playerid) {
- new Float:curO2;
- // If O2 wasnt touched yet, return 100%
- if (O2_diveStart[playerid] == 0) return 100.0;
- // Calculation when player is currently diving
- if (IsPlayerWaterDiving(playerid)) {
- // Player can dive 3 seconds without losing O2
- if (tickcount() - O2_diveStart[playerid] < 3000) return O2_level[playerid];
- // Use O2 level at the point of starting diving - o2 consumption * total diving time
- curO2 = O2_level[playerid] - ((tickcount() - O2_diveStart[playerid] - 3000) / 1000.0) * O2_CONSUMPTION;
- // limit at 0.0
- if (curO2 < 0.0) curO2 = 0.0;
- } else {
- // Calculation when player is currently breathing
- // Use O2 level at the point of ending the last dive + o2 consumption * total breathing time
- curO2 = O2_level[playerid] + ((tickcount() - O2_diveStart[playerid]) / 1000.0) * O2_CONSUMPTION;
- // limit at 100.0
- if (curO2 > 100.0) curO2 = 100.0;
- }
- return curO2;
- }
- public OnPlayerUpdate(playerid) {
- static O2_newAnim;
- O2_newAnim = GetPlayerAnimationIndex(playerid);
- // Debug output for testing
- new txt[64];
- format(txt, 64, "Anim: %f", GetPlayerO2(playerid));
- SendClientMessage(playerid, -1, txt);
- // Animation changed
- if (O2_lastAnim[playerid] != O2_newAnim) {
- // Player was not diving, now dives
- if (!IsPlayerWaterDiving(playerid) && (1540 <= O2_newAnim && O2_newAnim <= 1544)) {
- // Set the current O2 level as base for the dive calculation
- O2_level[playerid] = GetPlayerO2(playerid);
- // Save the time when diving started
- O2_diveStart[playerid] = tickcount();
- SendClientMessage(playerid, -1, "Now diving");
- } else
- // Player was diving, now comes upgrade
- if (IsPlayerWaterDiving(playerid) && !(1540 <= O2_newAnim && O2_newAnim <= 1544)) {
- // Set the current O2 level as base for the breathing calculation
- O2_level[playerid] = GetPlayerO2(playerid);
- // Save the time when regeneration started
- O2_diveStart[playerid] = tickcount();
- SendClientMessage(playerid, -1, "Now coming up");
- }
- // Update the new/last animation variable
- O2_lastAnim[playerid] = O2_newAnim;
- }
- return CallLocalFunction("O2_OnPlayerUpdate", "i", playerid);
- }
- #if defined _ALS_OnPlayerUpdate
- #undef OnPlayerUpdate
- #else
- #define _ALS_OnPlayerUpdate
- #endif
- #define OnPlayerUpdate O2_OnPlayerUpdate
- forward O2_OnPlayerUpdate(playerid);
Advertisement
Add Comment
Please, Sign In to add comment