Veteran Member
Join Date: May 2015
Location: SP, Brazil
|
09-05-2018
, 09:52
Re: Get task time
|
#3
|
Hmm, few examples not complex, but this really will depend about what each one need.
Spoiler
Code:
#include <amxmdx>
#define SetPlayerBit(%1,%2) (%1 |= (1<<(%2&31)))
#define ClearPlayerBit(%1,%2) (%1 &= ~(1 <<(%2&31)))
#define CheckPlayerBit(%1,%2) (%1 & (1<<(%2&31)))
new g_fIsBanned;
public plugin_init()
{
register_plugin("Get Task Time - Example 1", "1.0", "Crazy");
register_clcmd("say banme", "CmdBanMe");
register_clcmd("say bantime", "CmdBanTime");
}
public CmdBanMe(this)
{
if (CheckPlayerBit(g_fIsBanned, this))
{
client_print(this, print_chat, "You're already banned.");
return PLUGIN_HANDLED;
}
SetPlayerBit(g_fIsBanned, this);
set_task(2.0, "TaskUnbanMe", this);
client_print(this, print_chat, "You're now banned.");
return PLUGIN_HANDLED;
}
public CmdBanTime(this)
{
if (!CheckPlayerBit(g_fIsBanned, this))
{
client_print(this, print_chat, "You're not banned.");
return PLUGIN_HANDLED;
}
client_print(this, print_chat, "Your ban will expires in [%.2f]", get_task_time_ex(this, 0, GetTaskTime_Remaining));
return PLUGIN_HANDLED;
}
public TaskUnbanMe(this)
{
ClearPlayerBit(g_fIsBanned, this);
client_print(this, print_chat, "You're no longer banned [total ban time: %.2f]", get_task_time_ex(this, 0, GetTaskTime_None));
}
Spoiler
Code:
#include <amxmdx>
const TASK_ANNOUNCE = 100;
public plugin_init()
{
register_plugin("Get Task Time - Example 2", "1.0", "Crazy");
}
public plugin_cfg()
{
set_task(5.0, "TaskShowTime". .flags = SetTask_Repeat);
set_task_ex(30.0, "TaskAnnounceWinner", TASK_ANNOUNCE, .flags = SetTask_Repeat);
}
public TaskAnnounceWinner(iTask)
{
new rgPlayers[MAX_PLAYERS], szPlayerName[32], iPlayersCount, pevPlayer;
get_players_ex(rgPlayers, iPlayersCount, GetPlayers_ExcludeHLTV);
pevPlayer = rgPlayers[random(iPlayersCount)];
get_user_name(pevPlayer, szPlayerName, charsmax(szPlayerName));
client_print(0, print_chat, "%s WON THE LOTTERY!!!", szPlayerName);
client_print(0, print_chat, "Next announce in %0.2f seconds", get_task_time_ex(TASK_ANNOUNCE, 0, GetTaskTime_Remaining));
}
public TaskShowTime(iTask)
{
client_print(0, print_chat, "A winner will be announced in %0.2f seconds", get_task_time_ex(TASK_ANNOUNCE, 0, GetTaskTime_Remaining));
}
Spoiler
Code:
#include <amxmdx>
public plugin_init()
{
register_plugin("Get Task Time - Example 3", "1.0", "Crazy");
register_event("HLTV", "EventNewRound", "a", "1=0", "2=0");
}
public EventNewRound()
{
set_task_ex(1.0, "TaskCountdown", TASK_COUNTDOWN, .flags = SetTask_RepeatTimes, .repeat = 10);
}
public TaskCountdown(iTask)
{
// Total repeat time
new iTotalRepeat = get_task_time_ex(iTask, 0, GetTaskTime_RepeatTimes);
// Current repeat (from 1 to iTotalRepeat)
new iCurrentRepeat = get_task_time_ex(iTask, 0, GetTaskTime_RepeatTime);
client_print(0, print_center, "The game will start in: %d", iTotalRepeat - iCurrentRepeat + 1);
}
__________________
|
|