Raised This Month: $51 Target: $400
 12% 

[HELP] How do I loop set_task for only a few seconds.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GoldNux
Senior Member
Join Date: Mar 2018
Old 04-21-2018 , 13:26   [HELP] How do I loop set_task for only a few seconds.
Reply With Quote #1

I would like to print the players money to chat every second for 9 seconds. (freeze time)
I have tried using 9 different set tasks but I know this is not good to do, and it doesent print anything when I do this.

Is there a way to loop a function during freezetime only?
I want to do this so that the money stays updated when players make a purchase.
Hooking an event instead does not work for this, if someone buys more then the others that player obviously prints more.
I'm not sure if this will look good in the end, because I'm not sure looping set_task will make them print in the same order, but I think so.

Thanks.
__________________
Try my version of de_dust2, I think it's great and you should check it out!
https://gamebanana.com/mods/83731

Last edited by GoldNux; 04-21-2018 at 13:32.
GoldNux is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-21-2018 , 13:36   Re: [HELP] How do I loop set_task for only a few seconds.
Reply With Quote #2

Why print the same data 9 times in chat. Wouldn't a HUD be better?
PHP Code:

#include <amxmodx>

new g_pFreezeTime;

public 
plugin_init() 
{
    
register_event"HLTV" "FreezeTimeStart" "a" "1=0" "2=0" );
    
    
g_pFreezeTime get_cvar_pointer"mp_freezetime" );
}

public 
FreezeTimeStart()
{
    
set_task1.0 "ShowInfo" , .flags="a" , .repeat=get_pcvar_numg_pFreezeTime ) );
}

public 
ShowInfo()
{
    
client_printprint_chat "freeze time data" );

__________________

Last edited by Bugsy; 04-21-2018 at 13:38.
Bugsy is online now
GoldNux
Senior Member
Join Date: Mar 2018
Old 04-21-2018 , 13:56   Re: [HELP] How do I loop set_task for only a few seconds.
Reply With Quote #3

Quote:
Originally Posted by Bugsy View Post
Why print the same data 9 times in chat. Wouldn't a HUD be better?
PHP Code:

#include <amxmodx>

new g_pFreezeTime;

public 
plugin_init() 
{
    
register_event"HLTV" "FreezeTimeStart" "a" "1=0" "2=0" );
    
    
g_pFreezeTime get_cvar_pointer"mp_freezetime" );
}

public 
FreezeTimeStart()
{
    
set_task1.0 "ShowInfo" , .flags="a" , .repeat=get_pcvar_numg_pFreezeTime ) );
}

public 
ShowInfo()
{
    
client_printprint_chat "freeze time data" );

I know this will sound stupid, but I don't like the HUD font.
I'm trying to keep my plugins in the background and have the server look as if it has not been tampered with.

Thank you for helping me out!
__________________
Try my version of de_dust2, I think it's great and you should check it out!
https://gamebanana.com/mods/83731

Last edited by GoldNux; 04-21-2018 at 13:56.
GoldNux is offline
GoldNux
Senior Member
Join Date: Mar 2018
Old 04-21-2018 , 14:21   Re: [HELP] How do I loop set_task for only a few seconds.
Reply With Quote #4

Quote:
Originally Posted by Bugsy View Post
Why print the same data 9 times in chat. Wouldn't a HUD be better?
PHP Code:

#include <amxmodx>

new g_pFreezeTime;

public 
plugin_init() 
{
    
register_event"HLTV" "FreezeTimeStart" "a" "1=0" "2=0" );
    
    
g_pFreezeTime get_cvar_pointer"mp_freezetime" );
}

public 
FreezeTimeStart()
{
    
set_task1.0 "ShowInfo" , .flags="a" , .repeat=get_pcvar_numg_pFreezeTime ) );
}

public 
ShowInfo()
{
    
client_printprint_chat "freeze time data" );

Hm, can't get it to work.
It only prints when I have a single set_task.

Maybe I have to use show_hud...
This is what the code look like:

Code:
new g_pFreezeTime; public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     g_pFreezeTime = get_cvar_pointer( "mp_freezetime" );     register_event("HLTV", "eventNewRound", "a", "1=0", "2=0")     register_cvar("gn_syncmoney", "0") } public FreezeTimeStart() {     new players[32];     new playercount, i;     get_players(players, playercount);     for (i=0; i<playercount; i++)     set_task( 1.0 , "updatePlayerEconomy" , .flags="a" , .repeat=get_pcvar_num( g_pFreezeTime ) ); } public updatePlayerEconomy(id) {     if (!is_user_hltv(id) && cs_get_user_team(id) == CS_TEAM_T || cs_get_user_team(id) == CS_TEAM_CT)     {         client_cmd(id,"say_team $ %d",cs_get_user_money(id))     } }
__________________
Try my version of de_dust2, I think it's great and you should check it out!
https://gamebanana.com/mods/83731
GoldNux is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-21-2018 , 14:29   Re: [HELP] How do I loop set_task for only a few seconds.
Reply With Quote #5

1. Your register_event() is calling 'eventNewRound' and it should be 'FreezeTimeStart'.
2. You should call 1 set_task() in FreezeTimeStart and loop through all players within updatePlayerEconomy().
3. Include flags in get_players() to exclude bots and hltv and remove this check in updatePlayerEconomy().
4. Only call cs_get_user_team() once and set the value in a variable. Then do:
if ( CS_TEAM_T <= iTeam <= CS_TEAM_CT )
__________________

Last edited by Bugsy; 04-21-2018 at 14:31.
Bugsy is online now
GoldNux
Senior Member
Join Date: Mar 2018
Old 04-22-2018 , 07:32   Re: [HELP] How do I loop set_task for only a few seconds.
Reply With Quote #6

Quote:
Originally Posted by Bugsy View Post
1. Your register_event() is calling 'eventNewRound' and it should be 'FreezeTimeStart'.
2. You should call 1 set_task() in FreezeTimeStart and loop through all players within updatePlayerEconomy().
3. Include flags in get_players() to exclude bots and hltv and remove this check in updatePlayerEconomy().
4. Only call cs_get_user_team() once and set the value in a variable. Then do:
if ( CS_TEAM_T <= iTeam <= CS_TEAM_CT )
Thank you for being so helpful and patient!

It is working, but I can't test it with bots for some reason.
Even without the "ch" flags.

The idea is, that the chat can display a maximum of 5 chat messages.
So while playing 5 vs 5, as long as it prints every message in the same order it will look pretty good.
Very strange that my previously very similar code makes bots print it, but not this.. Oh well!

Here is the code for anyone else doing something similar in the future.
Thanks again @Bugsy I really appreciate it!
Code:
#include <amxmodx> #include <cstrike> new g_pFreezeTime; public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_event("HLTV" , "FreezeTimeStart" , "a" , "1=0" , "2=0");     g_pFreezeTime = get_cvar_pointer("mp_freezetime"); } public FreezeTimeStart() {     set_task(1.0,"updatePlayerEconomy", .flags="a", .repeat=get_pcvar_num(g_pFreezeTime)); } public updatePlayerEconomy() {     new players[32];     new playercount, i;     get_players(players, playercount, "ch");     for (i=0; i<playercount; i++)         if (cs_get_user_team(players[i]) != CS_TEAM_SPECTATOR)         {             client_cmd(players[i],"say_team $ %d",cs_get_user_money(players[i]))         } }
__________________
Try my version of de_dust2, I think it's great and you should check it out!
https://gamebanana.com/mods/83731

Last edited by GoldNux; 04-22-2018 at 08:09.
GoldNux is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 04-22-2018 , 09:54   Re: [HELP] How do I loop set_task for only a few seconds.
Reply With Quote #7

PHP Code:
public updatePlayerEconomy()
{
    new 
players[32], playercountplayerplayer2szName[32];
    
get_players(playersplayercount"h");
    for (new 
ijiPTeamiPMoneyplayercounti++)
    {
        
player players[i];
        
        if (
CS_TEAM_T <= (iPTeam=cs_get_user_team(player)) <= CS_TEAM_CT)
        {
            
iPMoney cs_get_user_money(player);
            
get_user_name(playerszNamecharsmax(szName));
            for(
0playercountj++)
            {
                   
player2 players[j];
                   if(
iPTeam != cs_get_user_team(player2)) continue;
                   
client_print(player2print_chat"%s => $%d"szNameiPMoney)
             }
        }

__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 04-22-2018 at 09:56.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
GoldNux
Senior Member
Join Date: Mar 2018
Old 04-22-2018 , 10:42   Re: [HELP] How do I loop set_task for only a few seconds.
Reply With Quote #8

Quote:
Originally Posted by Natsheh View Post
PHP Code:
public updatePlayerEconomy()
{
    new 
players[32], playercountplayerplayer2szName[32];
    
get_players(playersplayercount"h");
    for (new 
ijiPTeamiPMoneyplayercounti++)
    {
        
player players[i];
        
        if (
CS_TEAM_T <= (iPTeam=cs_get_user_team(player)) <= CS_TEAM_CT)
        {
            
iPMoney cs_get_user_money(player);
            
get_user_name(playerszNamecharsmax(szName));
            for(
0playercountj++)
            {
                   
player2 players[j];
                   if(
iPTeam != cs_get_user_team(player2)) continue;
                   
client_print(player2print_chat"%s => $%d"szNameiPMoney)
             }
        }

Thanks Natsheh for taking care of that.

I get some issues on these lines:

if (CS_TEAM_T <= (iPTeam=cs_get_user_team(player)) <= CS_TEAM_CT)
if (iPTeam != cs_get_user_team(player2)) continue;

WARNING [36]: tag mismatch
WARNING [36]: tag mismatch
WARNING [36]: tag mismatch
WARNING [43]: tag mismatch

Not sure what is wrong.
__________________
Try my version of de_dust2, I think it's great and you should check it out!
https://gamebanana.com/mods/83731
GoldNux is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-22-2018 , 10:53   Re: [HELP] How do I loop set_task for only a few seconds.
Reply With Quote #9

Since cs_get_user_team() returns a CsTeams type, you need to define the iPTeam variable as CsTeams. You were also missing a closing bracket. Natsheh, you should avoid calling cs_get_user_team() multiple times for the same player.

I didn't look at your code beyond this, not sure if it does what you expect. Give it a try.

Code:
public updatePlayerEconomy() {     new players[ 32 ] , playercount , player , player2 , szName[ 32 ]     new iPMoney , CsTeams:iPTeam[ 33 ];         get_players(players, playercount, "h");         for(new i ; i < playercount; i++)     {         player = players[i];                 if ( !iPTeam[ player ] )             iPTeam[ player ] = cs_get_user_team( player );                     if (CS_TEAM_T <= iPTeam[ player ] <= CS_TEAM_CT)         {             iPMoney = cs_get_user_money(player);             get_user_name(player, szName, charsmax(szName));                     for ( new j = 0 ; j < playercount ; j++ )             {                 player2 = players[j];                                 if ( !iPTeam[ player2 ] )                     iPTeam[ player2 ] = cs_get_user_team( player2 );                                     if ( iPTeam[ player ] == iPTeam[ player2 ] )                 {                     client_print( player2 , print_chat , "%s => $%d" , szName , iPMoney );                 }             }         }     } }
__________________

Last edited by Bugsy; 04-22-2018 at 11:28.
Bugsy is online now
GoldNux
Senior Member
Join Date: Mar 2018
Old 04-22-2018 , 12:08   Re: [HELP] How do I loop set_task for only a few seconds.
Reply With Quote #10

Quote:
Originally Posted by Bugsy View Post
Since cs_get_user_team() returns a CsTeams type, you need to define the iPTeam variable as CsTeams. You were also missing a closing bracket. Natsheh, you should avoid calling cs_get_user_team() multiple times for the same player.

I didn't look at your code beyond this, not sure if it does what you expect. Give it a try.

CODE...
Natshehs contribution opened up the posibility to use client_print_color, before I had an issue using it.
Even when setting the "CT" and "TERRORIST" flag, it still printed to both teams.

I wrote something that change the color of the money, to indicate what you can afford.
It is working great, but I don't think my code is very optimized.
Maybe someone can take a look?

I will later combine this with the get equipment code you wrote.

Anyways, here is the color chat code.
I know I should store get_* in variables, but when I do I get warnings and errors.
I'm obviously not doing it right.

Code:
#include <cromchat> public updatePlayerEconomy() {     new players[32], playercount, player, player2, szName[32];     get_players(players, playercount, "h");     for(new i, j, CsTeams:iPTeam, iPMoney; i < playercount; i++)     {         player = players[i];                 if (CS_TEAM_T <= (iPTeam=cs_get_user_team(player)) <= CS_TEAM_CT)         {             iPMoney = cs_get_user_money(player);             get_user_name(player, szName, charsmax(szName));                         for(j = 0; j < playercount; j++)             {                 player2 = players[j];                 if (iPTeam != cs_get_user_team(player2)) continue;                 {                     if (cs_get_user_team(player2) == CS_TEAM_T && !is_user_hltv(player2) && cs_get_user_team(player2) != CS_TEAM_SPECTATOR)                     {                         if (iPMoney < 3000)                             CC_SendMessage(player2, "%s:&x07 $ %d", szName, iPMoney)                         else if (iPMoney > 3000 && iPMoney < 3500)                             CC_SendMessage(player2, "%s:&x01 $ %d", szName, iPMoney)                         else if (iPMoney > 3500 && iPMoney < 10000)                             CC_SendMessage(player2, "%s:&x04 $ %d", szName, iPMoney)                         else if (iPMoney > 10000)                             CC_SendMessage(player2, "%s:&x06 $ %d", szName, iPMoney)                     }                     else if (cs_get_user_team(player2) == CS_TEAM_CT && !is_user_hltv(player2) && cs_get_user_team(player2) != CS_TEAM_SPECTATOR)                     {                         if (iPMoney < 3250)                             CC_SendMessage(player2, "%s:&x07 $ %d", szName, iPMoney)                         else if (iPMoney > 3250 && iPMoney < 4100)                             CC_SendMessage(player2, "%s:&x01 $ %d", szName, iPMoney)                         else if (iPMoney > 4100 && iPMoney < 10000)                             CC_SendMessage(player2, "%s:&x04 $ %d", szName, iPMoney)                         else if (iPMoney > 10000)                             CC_SendMessage(player2, "%s:&x06 $ %d", szName, iPMoney)                     }                 }             }         }     } }
__________________
Try my version of de_dust2, I think it's great and you should check it out!
https://gamebanana.com/mods/83731

Last edited by GoldNux; 04-22-2018 at 12:43.
GoldNux is offline
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 14:11.


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