AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved get_timeleft function (https://forums.alliedmods.net/showthread.php?t=326087)

beginnercs 07-17-2020 19:21

get_timeleft function
 
*sorry for my bad english, i'm using google translator

Hello guys, I think this is the right section for my question, I'm trying to code a plugin, my first question I was able to solve, can be seen here

https://forums.alliedmods.net/showthread.php?t=326024

now what i want to do is make this plugin run when the map time runs out.
I'm not able to use the get_timeleft function
currently the code looks like this

Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <colorchat>
#include <csstats>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

new cvar_ranks

public plugin_init(){
        register_plugin(PLUGIN, VERSION, AUTHOR)
        cvar_ranks = register_cvar("topranks", "1")
        register_clcmd("tempadm", "tempadmin")
}
public tempadmin(id){
       
        if(!(get_user_flags(id) & ADMIN_USER))
        return PLUGIN_CONTINUE
        new stats[8], bodyhits[8]
        new iRank,rank
        rank = get_pcvar_num(cvar_ranks)
        iRank = get_user_stats(id, stats, bodyhits)
        if(iRank <= rank){
        new name[32]
        get_user_name(id, name, 31)       
        server_cmd("amx_tempadmin ^"%s^" ^"7^" ^"bcdefghijut^"", name)
        ColorChat(0, print_center, "^3The player ^4%s ^3won the ^4Admin", name)
        return PLUGIN_CONTINUE
        }
        else
        {
   
        }
        return PLUGIN_CONTINUE
}

it works with a command on the console and makes the first one in top15 as admin, so that part of the code is right, but I can't get it to run when the map time runs out.
I tried like that

Code:

public plugin_init(){
        register_plugin(PLUGIN, VERSION, AUTHOR)
        cvar_ranks = register_cvar("topranks", "1")
        new gmtm
        gmtm = get_timeleft()
        if(gmtm == 1)
        set_task(1.0,"tempadmin");

but without success...

I also tried like this:

Code:

public plugin_init(){
        register_plugin(PLUGIN, VERSION, AUTHOR)
        cvar_ranks = register_cvar("topranks", "1")
        register_clcmd("tempadm", "tempadmin")
        new gmtm
        gmtm = get_timeleft()
        if(gmtm == 1)
        server_cmd("tempadm")
}

but also without success
could someone help me how should i do?

fysiks 07-17-2020 22:29

Re: get_timeleft function
 
First, you need to understand that plugin_init() is called only once when the plugin is initialized.

It sounds like you probably need the event when the scoreboard comes up (which occurs before the map changes). This can be done by hooking "intermission":

Code:

plugin_init()
{
    register_event("30", "Event_SVC_INTERMISSION", "a")
}

public Event_SVC_INTERMISSION()
{
    // Scoreboard was just shown, you call your functions here
}


beginnercs 07-23-2020 14:24

Re: get_timeleft function
 
Quote:

Originally Posted by fysiks (Post 2710554)
First, you need to understand that plugin_init() is called only once when the plugin is initialized.

It sounds like you probably need the event when the scoreboard comes up (which occurs before the map changes). This can be done by hooking "intermission":

Code:

plugin_init()
{
    register_event("30", "Event_SVC_INTERMISSION", "a")
}

public Event_SVC_INTERMISSION()
{
    // Scoreboard was just shown, you call your functions here
}


Thanks for the help, but I couldn't make it work the way you proposed, but I did make it work like this:

Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <colorchat>
#include <csstats>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

new cvar_ranks
new cvar_time

public plugin_init(){
        register_plugin(PLUGIN, VERSION, AUTHOR)
        cvar_ranks = register_cvar("toprank", "1")
        cvar_time = register_cvar("timemap", "15")
        register_clcmd("tempadm", "tempadmin")
        set_task(1.0,"timer_task",_,"",0,"b");
}
public timer_task(){
        new gmtm = get_timeleft()
        new ctime = get_pcvar_num(cvar_time)
        if(gmtm == ctime){
        server_cmd("amx_execall tempadm")
        }
}
public tempadmin(id){
        client_cmd(id,"clear")
        if(!(get_user_flags(id) & ADMIN_USER))
        return PLUGIN_CONTINUE
        new stats[8], bodyhits[8]
        new rank = get_pcvar_num(cvar_ranks)
        new iRank = get_user_stats(id, stats, bodyhits)
        if(iRank <= rank){
        new name[32]
        get_user_name(id, name, 31)       
        server_cmd("amx_tempadmin ^"%s^" ^"7^" ^"bcdefghijut^"", name)
        ColorChat(0, print_center, "^3The player ^4%s ^3won the ^4Admin", name)
        ColorChat(0, print_center, "^3The player ^4%s ^3won the ^4Admin", name)
        ColorChat(0, print_center, "^3The player ^4%s ^3won the ^4Admin", name)
        ColorChat(0, print_center, "^3The player ^4%s ^3won the ^4Admin", name)
        set_hudmessage(0, 255, 0, -1.0, -1.0)
        show_hudmessage(0, "The player %s won the Admin",name)
        return PLUGIN_CONTINUE
        }
        else
        {
   
        }
        return PLUGIN_CONTINUE
}

I don't know if it's the best way, but it works well,
now i'm trying to make the plugin ignore the existing top15 administrators

HamletEagle 07-24-2020 11:01

Re: get_timeleft function
 
You should put the code from timer_task inside plugin_cfg forward and instead of doing server_cmd with "tempadm" just call the function directly.


All times are GMT -4. The time now is 13:54.

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