This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

Set_task doesnt work properly


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Apocalyman
Member
Join Date: Nov 2022
Old 10-01-2023 , 13:47   Set_task doesnt work properly
Reply With Quote #1

Hello! I try to use this first writes code with set_task to stop the first writes after a certain amount of time with: set_task(25.0, "StopFWServer")

and it doesnt work! the code is this:
Code:
#include < amxmodx >
#include < amxmisc >
#include < cstrike >
#include < hamsandwich >
#include < ColorChat > // amx 1.9.0 this include not support anymore
 
#define FW_ACCESS ADMIN_KICK
 
new CTRounds[33] = 0
 
new bool: FW_Started = false
new FWTime
new NumberSelected
 
public plugin_init()  
{
    register_clcmd("say","HandleSay")
    RegisterHam(Ham_Spawn,"player","PlayerRespawned", 1)
    set_task(10.0,"Ratio",_,_,_,"b")
}

public client_disconnect( id ) // if you running server with lastest amx version 1.9.0 change this line - client_disconnect -> 
{
	CTRounds[ id ] = 0;
}
 
public Ratio()
{
    new CTCounter, TCounter
    new players[32],pnum
    get_players(players,pnum)
    for(new i = 0;i<pnum;i++)
    {
        new cid = players[i]
        switch(cs_get_user_team(cid))
        {
            case CS_TEAM_T:
            {
                TCounter++
            }
            case CS_TEAM_CT:
            {
                CTCounter++
            }
        }
    }
     
     
    if(CTCounter == 0 && TCounter >= 2)
    {
        StartFWRatio()
        set_task(25.0, "StopFWServer")
    }
    else if(CTCounter == 1 && TCounter >= 7)
    {
        StartFWRatio()
    }
    else if(CTCounter == 2 && TCounter >= 16)
    {
        StartFWRatio()
    }
    else if(CTCounter == 3 && TCounter >= 21)
    {
        StartFWRatio()
    }
}

public PlayerRespawned(id)
{
    if(!is_user_alive(id))
    {
        return 1;
    }

    if(cs_get_user_team(id) == CS_TEAM_CT)
    {
        if(CTRounds[id] == 9)
        {
            cs_set_user_team(id,CS_TEAM_T)
            ExecuteHamB(Ham_CS_RoundRespawn, id)
            new szName[32];
            get_user_name(id,szName,31)
            ColorChat(0,TEAM_COLOR,"^4[ ^1Apoc ^4] ^3%s^1 his was^4 10 ^1rounds in CT.",szName)
            CTRounds[id] = 0
            StartFWRounds
             // Restart the round
        }
        else
        {    
            CTRounds[id]++
            ColorChat(id,TEAM_COLOR,"^4[ ^1Apoc ^4] ^1You have been CT [^4%d^1/10] Rounds!",CTRounds[id])
             
        }
    }
    else
    {
        CTRounds[id] = 0
    }
    return 0;
}

public HandleSay(id)
{
    new StrNumberSelected[22]
    num_to_str(NumberSelected, StrNumberSelected, 21)
    new szMessage[128], szArg1[38], szArg2[38];
    read_argv(1, szMessage, charsmax(szMessage));
    parse(szMessage, szArg1, charsmax(szArg1), szArg2, charsmax(szArg2));
    
    if(equali(szArg1,"/fw") || equali(szArg1,"/first") || equali(szArg1,"!first") || equali(szArg1,"!fw"))
    {
        if(get_user_flags(id) & FW_ACCESS)
        {
            StartFW(id)
        }
    }
    else if(equali(szArg1,"/stopfw") || equali(szArg1,"!stopfw"))
    {
        if(get_user_flags(id) & FW_ACCESS)
        {
            StopFW(id)
        }
    }
    else if(equali(szArg1, StrNumberSelected))
    {
        if(FW_Started == true)
        {
            if(cs_get_user_team(id) == CS_TEAM_T)
            {
                FW_Started = false
                set_hudmessage(random_num(1, 255), random_num(1, 255), random_num(1, 255))
                new szName[32]
                get_user_name(id, szName, 31)
                cs_set_user_team(id, CS_TEAM_CT); // Always switch to CT team
                ExecuteHamB(Ham_CS_RoundRespawn, id)
                show_hudmessage(0,"%s has won the first write!",szName)
                ColorChat(0, TEAM_COLOR, "^4[ ^1Apoc ^4] ^3%s^4 Won ^1the ^4first writes^1!", szName)
                 // Restart the round
            }
            else
            {
                ColorChat(id, TEAM_COLOR, "^4[ ^1Apoc ^4] ^1You are a^4 Guard^1 already!")
            }
        }
    }
    else if(equali(szArg1,"/rounds"))
    {
        new player = cmd_target(id, szArg2, 0)
        if(!(player))
        {
            ColorChat(id, TEAM_COLOR, "^4[ ^1Apoc ^4] ^1There is no player named^3 %s^1", szArg2)
            return 1;
        }
        new szName[32]
        get_user_name(player, szName, 31)
        if(cs_get_user_team(player) != CS_TEAM_CT)
        {
            ColorChat(id, TEAM_COLOR, "^4[ ^1Apoc ^4] ^1The player^3 %s^1 is not in CT team!", szName)
            return 1;
        }
        ColorChat(id, TEAM_COLOR, "^4[ ^1Apoc ^4] ^1The player^3 %s^1 Left^4 Rounds ^1[^4%d^1/10]^4 rounds!", szName, CTRounds[player])
    }
    return 0;
}

public StartFW(id)
{
    if(!FW_Started)
    {
        FW_Started = true
        FWTime = 6
        set_task(1.0,"CheckTime",1992,_,_,"b")
        new szAdmin[32]
        get_user_name(id,szAdmin,31)
        ColorChat(0,TEAM_COLOR,"^4[ ^1Apoc ^4] ^1Admin^3 %s ^4started ^1the first writes",szAdmin)
        
    }
    else
    {
        ColorChat(id,TEAM_COLOR,"^4[ ^1Apoc ^4] ^1First writes is already ^4activated!")
    }
    return 1;
}
public StartFWRatio()
{
    if(!FW_Started)
    {
        FW_Started = true
        FWTime = 6
        set_task(1.0,"CheckTime",1992,_,_,"b")
        ColorChat(0,TEAM_COLOR,"^4[ ^1Apoc ^4] ^1Auto^4 First Writes ^1started")
    }
}
public StartFWRounds()
{
    if(!FW_Started)
    {
        FW_Started = true
        FWTime = 9
        set_task(1.0,"CheckTime",1992,_,_,"b")
    }
}
public StopFW(id)
{
    if(FW_Started)
    {
        FW_Started = false
         
        new szName[32]
        get_user_name(id,szName,31)
        ColorChat(0,TEAM_COLOR,"^4[ ^1Apoc ^4] ^1Admin ^3%s ^4stopped ^1first writes!",szName)
         
    }
}

public StopFWServer(id)
{
    if(FW_Started)
    {
        FW_Started = false
         
        new szName[32]
        get_user_name(id,szName,31)
        ColorChat(0,TEAM_COLOR,"^4[ ^1Apoc ^4] ^3The Server ^4stopped ^1the first writes!",szName)
         
    }
}
 
public CheckTime()
{
     
    if(FWTime > 1)
    {
        if(FW_Started)
        {
            FWTime--
            set_hudmessage(random_num(1, 255), random_num(1, 255), random_num(1, 255), -1.0, 0.30, 0, 4.0, 4.0)
            show_hudmessage(0,"The first writes will start in %d seconds!",FWTime)
            new Num[10]
            num_to_word(FWTime,Num,9)
            client_cmd(0,"spk fvox/%s",Num)
        }
        else
        {
            remove_task(1992)
        }
    }
    else if(FWTime == 1)
    {
        FWTime--
        set_hudmessage(random_num(1, 255), random_num(1, 255), random_num(1, 255), -1.0, 0.30, 0, 4.0, 4.0)
        NumberSelected = random_num(1,10000)
        new szText[100]
        formatex(szText,99,"The chosen number is: %d",NumberSelected)
        show_hudmessage(0,szText)
        ColorChat(0,TEAM_COLOR,"^4[ ^1Apoc ^4] ^1The ^4chosen ^1number is: ^4%d",NumberSelected)
        remove_task(1992)
    }
}
The time just stops the function randomly and never happens at the wanted time. Please let me know why. Thanks!
Apocalyman is offline
 



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 08:27.


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