|
Member
|
01-10-2020
, 13:12
Re: [Req]Money Reward
|
#4
|
Quote:
Originally Posted by OciXCrom
The plugin above won't work after mapchange or if the player was kicked or disconnected for a short time.
Use this:
PHP Code:
#include <amxmodx> #include <cromchat> #include <cstrike> #include <nvault>
#if !defined client_disconnected #define client_disconnected client_disconnect #endif
#if !defined MAX_PLAYERS const MAX_PLAYERS = 32 #endif
#if !defined MAX_NAME_LENGTH const MAX_NAME_LENGTH = 32 #endif
#if !defined MAX_AUTHID_LENGTH const MAX_AUTHID_LENGTH = 64 #endif
const MAX_NUM_LENGTH = 8 const Float:TIME_FREQ = 60.0
// Reset the player's time if he isn't in the server longer than this many seconds const Float:MAX_OUT_TIME = 300.0
enum _:TimeRewards { Minutes[MAX_NUM_LENGTH], XP }
// Add as many rewards as you like in this list new const g_eTimeRewards[][TimeRewards] = { /* "<minutes required>" <money reward> */ { "20", 16000 } }
new Trie:g_tTimeRewards new g_szAuthId[MAX_PLAYERS + 1][MAX_AUTHID_LENGTH], g_iPlayedTime[MAX_PLAYERS + 1], g_iVault
public plugin_init() { register_plugin("Simple Time Rewards", "1.0", "OciXCrom") g_iVault = nvault_open("CRXSimpleTimeRewards") g_tTimeRewards = TrieCreate()
for(new i; i < sizeof(g_eTimeRewards); i++) { TrieSetCell(g_tTimeRewards, g_eTimeRewards[i][Minutes], g_eTimeRewards[i][XP]) }
CC_SetPrefix("&x04[Time Rewards]") }
public plugin_end() { nvault_close(g_iVault) TrieDestroy(g_tTimeRewards) }
public client_connect(id) { new szPlayedTime[MAX_NUM_LENGTH], iTimeStamp get_user_authid(id, g_szAuthId[id], charsmax(g_szAuthId[])) nvault_lookup(g_iVault, g_szAuthId[id], szPlayedTime, charsmax(szPlayedTime), iTimeStamp)
g_iPlayedTime[id] = get_systime() - iTimeStamp > MAX_OUT_TIME ? 0 : str_to_num(szPlayedTime) set_task(TIME_FREQ, "increase_played_time", id, .flags = "b") }
public client_disconnected(id) { new szPlayedTime[MAX_NUM_LENGTH] num_to_str(g_iPlayedTime[id], szPlayedTime, charsmax(szPlayedTime)) nvault_set(g_iVault, g_szAuthId[id], szPlayedTime) remove_task(id) }
public increase_played_time(id) { new szPlayedTime[MAX_NUM_LENGTH], iMoney num_to_str(++g_iPlayedTime[id], szPlayedTime, charsmax(szPlayedTime))
if(TrieGetCell(g_tTimeRewards, szPlayedTime, iMoney)) { new szName[MAX_NAME_LENGTH] get_user_name(id, szName, charsmax(szName)) CC_SendMessage(0, "&x03%s &x01received &x04%i$ for playing &x04%i &x01minutes.", szName, iMoney, g_iPlayedTime[id]) cs_set_user_money(id, cs_get_user_money(id) + iMoney) } }
|
why will not work? if i use that plugin from 4 years and i don't have problems?
your code is too useless...you call some things for nothing, why to don't save the trees?
Last edited by Adryyy; 01-10-2020 at 13:13.
Reason: filters...
|
|
|
|