Raised This Month: $32 Target: $400
 8% 

ammo/money for staying active


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
itoxicreal
Senior Member
Join Date: Jun 2018
Old 03-20-2021 , 10:05   ammo/money for staying active
Reply With Quote #1

Can anyone make a plugin for when a player is active for 10 or more minutes they receive ammopacks or money. I couldn't find any off google or I'm bad at searching
itoxicreal is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-20-2021 , 10:30   Re: ammo/money for staying active
Reply With Quote #2

Is it every 10 minutes they get stuff, or only once at 10 minutes of being connected? Is being connected and on a team enough -- what if they are AFK?
__________________
Bugsy is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 03-20-2021 , 10:31   Re: ammo/money for staying active
Reply With Quote #3

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <zombieplague>

#define PLUGIN "[ZP] PlayTime Ammopacks reward"
#define VERSION "1.0"
#define AUTHOR "Natsheh"

#if AMXX_VERSION_NUM > 182
#define client_disconnect client_disconnected
#endif

new g_cvar_leng_cvar_amount;

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    
g_cvar_len register_cvar("zp_playtime_reward_length""10");
    
g_cvar_amount register_cvar("zp_playtime_reward_amount""50");
}

public 
client_putinserver(id)
{
    
    
set_task(floatmax(get_pcvar_float(g_cvar_len), 1.0) * 60.0 "reward_player"id__"b");
}

public 
client_disconnect(id)
{
    
remove_task(id);
}

public 
reward_player(id)
{
    new 
iReward get_pcvar_num(g_cvar_amount);
    
zp_set_user_ammo_packs(idzp_get_user_ammo_packs(id) + iReward);
    
client_print(idprint_chat"You've been rewarded %d ammopacks for playing an extra %d minutes on the server!"iRewardmax(get_pcvar_num(g_cvar_len), 1));

here's my best if bugsy is interested to optimize it be my guest
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 03-20-2021 at 10:39.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
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
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 03-23-2021 , 08:51   Re: ammo/money for staying active
Reply With Quote #5

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 TIME_REQUIRED = 10 const REWARD_AMOUNT = 10 const MAX_NUM_LENGTH = 16 const Float:TIME_FREQ = 60.0 new const REWARD_NAME[] = "$" // Reset the player's time if he isn't in the server longer than this many seconds const Float:MAX_OUT_TIME = 300.0 new Trie:g_tPlayers new g_szInfo[MAX_PLAYERS + 1][MAX_AUTHID_LENGTH] new g_iPlayedTime[MAX_PLAYERS + 1] public plugin_init() {     register_plugin("Time Rewards", "1.0", "OciXCrom")     CC_SetPrefix("&x04[Time Rewards]")     g_tPlayers = TrieCreate() } public plugin_end() {     TrieDestroy(g_tPlayers) } public client_authorized(id) {     new szData[MAX_NUM_LENGTH * 2]     get_user_authid(id, g_szInfo[id], charsmax(g_szInfo[]))     if(TrieGetString(g_tPlayers, g_szInfo[id], szData, charsmax(szData)))     {         new szTime[16], szStamp[16]         parse(szData, szTime, charsmax(szTime), szStamp, charsmax(szStamp))         g_iPlayedTime[id] = get_systime() - str_to_num(szStamp) > MAX_OUT_TIME ? 0 : str_to_num(szTime)     }         set_task(TIME_FREQ, "increase_played_time", id, .flags = "b") } public client_disconnected(id) {     new szData[MAX_NUM_LENGTH * 2]     formatex(szData, charsmax(szData), "%i %i", g_iPlayedTime[id], get_systime())     TrieSetString(g_tPlayers, g_szInfo[id], szData)     remove_task(id) } public increase_played_time(id) {     if(!(++g_iPlayedTime[id] % TIME_REQUIRED))     {         new szName[MAX_NAME_LENGTH]         get_user_name(id, szName, charsmax(szName))         CC_SendMessage(0, "&x03%s &x01received &x04%i%s for playing &x04%i &x01minutes (&x04%i &x01total).", szName, REWARD_AMOUNT, REWARD_NAME, TIME_REQUIRED, g_iPlayedTime[id])         cs_set_user_money(id, cs_get_user_money(id) + REWARD_AMOUNT)     } }
__________________

Last edited by OciXCrom; 03-23-2021 at 22:53.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
itoxicreal
Senior Member
Join Date: Jun 2018
Old 03-23-2021 , 20:15   Re: ammo/money for staying active
Reply With Quote #6

Thank you ocixcrom!!
itoxicreal is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-23-2021 , 21:40   Re: ammo/money for staying active
Reply With Quote #7

OcixCrom - You are using TrieGetString() without ever calling TrieSetString(), so the condition in client_authorized() will never be true. It looks like you formatted the string in client_disconnect() in preparation to use it, but forgot.

This comes down to preference, but you can avoid the conditional #if pre-processor directives at the top by just redefining using pre-processor:
#define MAX_PLAYERS 32
#define MAX_NAME_LENGTH 32
#define MAX_AUTHID_LENGTH 64
__________________

Last edited by Bugsy; 03-23-2021 at 21:43.
Bugsy is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 03-23-2021 , 22:55   Re: ammo/money for staying active
Reply With Quote #8

Oops, missed that one line. Fixed.

Not using #if will output warnings that a symbol was redefined so that's why I prefer doing it.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-23-2021 , 23:54   Re: ammo/money for staying active
Reply With Quote #9

It doesn't for me when I re-define MAX_PLAYERS
__________________
Bugsy is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 03-24-2021 , 09:54   Re: ammo/money for staying active
Reply With Quote #10

Could've sworn this was happening at one point.

Edit - https://forums.alliedmods.net/showthread.php?t=255771

Looks like MAX_PLAYERS was 33 in older builds so yeah, I don't need the other ones but I'd rather let this one stay to prevent warnings for people that still use such builds.
__________________

Last edited by OciXCrom; 03-24-2021 at 09:54.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Reply



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 10:34.


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