Created
August 29, 2019 10:16
-
-
Save Y-Less/292038a8c53319567e24253f438ae8d5 to your computer and use it in GitHub Desktop.
Idea for error codes.
This file contains hidden or 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
#define ERROR_COUNT // NO VALUE, so it merely exists. | |
enum Error: // Generic function errors. | |
{ | |
OK = 0, | |
ERR_NONE = 0, | |
ERR_PARAM_0, | |
ERR_PARAM_1, | |
ERR_PARAM_2, | |
ERR_PARAM_3, | |
ERR_PARAM_4, | |
ERR_PARAM_5, | |
ERR_PARAM_6, | |
ERR_PARAM_7, | |
ERR_PARAM_8, | |
ERR_PARAM_9, | |
ERR_PARAM_10, | |
ERR_PARAM_11, | |
ERR_PARAM_12, | |
ERR_PARAM_13, | |
ERR_PARAM_14, | |
ERR_PARAM_15, | |
ERR_PARAM_16, | |
ERR_PARAM_17, | |
ERR_PARAM_18, | |
ERR_PARAM_19, | |
ERR_PARAM_20, | |
ERR_PARAM_21, | |
ERR_PARAM_22, | |
ERR_PARAM_23, | |
ERR_PARAM_24, | |
ERR_PARAM_25, | |
ERR_PARAM_26, | |
ERR_PARAM_27, | |
ERR_PARAM_28, | |
ERR_PARAM_29, | |
ERR_PARAM_30, | |
ERR_PARAM_31, | |
ERR_OVERFLOW, | |
ERR_UNDERFLOW, | |
_ERR_PARAMS_DONE, | |
} | |
#undef ERROR_COUNT | |
#define ERROR_COUNT (_ERR_PARAMS_DONE) | |
enum Error: // Player errors. | |
{ | |
ERR_PLAYER_NOT_CONNECTED = ERROR_COUNT, | |
ERR_PLAYER_CONNECTED, | |
ERR_PLAYER_INSUFFICIENT_FUNDS, | |
ERR_PLAYER_DEAD, | |
ERR_PLAYER_SPAWNED, | |
ERR_PLAYER_IN_VEHICLE, | |
ERR_PLAYER_NOT_IN_VEHICLE, | |
ERR_PLAYER_NO_WEAPON, | |
_ERR_PLAYER_1_DONE, | |
} | |
#undef ERROR_COUNT | |
#define ERROR_COUNT (_ERR_PLAYER_1_DONE) | |
// Use: | |
// | |
// return Error:-2; | |
// | |
// For custom errors. | |
Error:GivePlayerMoneyClamped(playerid, money, min = 0, max = cellmax, bool:approx = false) | |
{ | |
if (!IsPlayerConnected(playerid)) return ERR_PLAYER_NOT_CONNECTED; | |
new cur = GetPlayerMoney(playerid), diff; | |
if (money < 0) | |
{ | |
diff = min - cur; | |
if (money < diff) | |
{ | |
if (approx) | |
{ | |
GivePlayerMoney(playerid, diff); | |
return OK; | |
} | |
return ERR_OVERFLOW; | |
} | |
} | |
else | |
{ | |
diff = max - cur; | |
if (diff < money) | |
{ | |
if (approx) | |
{ | |
GivePlayerMoney(playerid, diff); | |
return OK; | |
} | |
return ERR_OVERFLOW; | |
} | |
} | |
GivePlayerMoney(playerid, money); | |
return OK; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment