Raised This Month: $ Target: $400
 0% 

ammo/money for staying active


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 03-20-2021 , 10:55   Re: ammo/money for staying active
Reply With Quote #4

Here's what I use for my rank system, just change the natives inside. It works on mapchange and disconnect for less than 5 minutes.

Code:
#include <amxmodx>
#include <cromchat>
#include <crxranks>
#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

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 }

new const g_eTimeRewards[][TimeRewards] =
{
	/* "<minutes required>" <XP reward> */
	{ "60", 50 },
	{ "90", 100 }
}

new Trie:g_tTimeRewards
new g_szAuthId[MAX_PLAYERS + 1][64], g_iPlayedTime[MAX_PLAYERS + 1], g_iVault

public plugin_init()
{
	register_plugin("CRXRanks: Time Rewards", "1.0", "OciXCrom")
	g_iVault = nvault_open("CRXRanksTimeRewards")
	g_tTimeRewards = TrieCreate()

	for(new i; i < sizeof(g_eTimeRewards); i++)
	{
		TrieSetCell(g_tTimeRewards, g_eTimeRewards[i][Minutes], g_eTimeRewards[i][XP])
	}

	crxranks_get_chat_prefix(CC_PREFIX, charsmax(CC_PREFIX))
}

public plugin_end()
{
	nvault_close(g_iVault)
	TrieDestroy(g_tTimeRewards)
}

public client_authorized(id)
{
	new szPlayedTime[MAX_NUM_LENGTH], iTimeStamp
	get_user_authid(id, g_szAuthId[id], charsmax(g_szAuthId[]), 1)
	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], iXP
	num_to_str(++g_iPlayedTime[id], szPlayedTime, charsmax(szPlayedTime))

	if(TrieGetCell(g_tTimeRewards, szPlayedTime, iXP))
	{
		new szName[MAX_NAME_LENGTH]
		get_user_name(id, szName, charsmax(szName))
		CC_SendMessage(0, "&x03%s &x01received &x04%i &x01XP for playing &x04%i &x01minutes.", szName, iXP, g_iPlayedTime[id])
		crxranks_give_user_xp(id, iXP)
	}
}
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:50.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode