- General
(https://forums.alliedmods.net/forumdisplay.php?f=7)
- - Get task time
(https://forums.alliedmods.net/showthread.php?t=310467)
CrazY.
09-04-2018 18:29
Get task time
Hello, my suggestion is to add a native to get task time with flags:
Code:
enum GetTaskTimeFlags (<<= 1){
GetTaskTime_None = 0,
GetTaskTime_Remaining = 1,
GetTaskTime_RepeatTimes,
GetTaskTime_RepeatTime,
};
/**
* Returns the time of a task.
*
* @param iTaskId Task id to search for
* @param iOutside Will also search tasks from other plugins if nonzero
* @param bitsFlags Optional flags (enum GetTaskTimeFlags); valid flags are:
* GetTaskTime_None - Returns how long time the task has gone (default)
* GetTaskTime_Remaining - Returns remaining time to the callback be called
* GetTaskTime_RepeatTimes - Returns total repeat times
* GetTaskTime_RepeatTime - Returns current repeat time
*/
native get_task_time_ex(iTaskId = 0, iOutside = 0, GetTaskTimeFlags:bitsFlags = GetTaskTime_None);
Arkshine
09-05-2018 02:15
Re: Get task time
Do you have a usage example where it would be useful to have that native?
CrazY.
09-05-2018 09:52
Re: Get task time
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 timenew 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);
}
Black Rose
09-05-2018 12:04
Re: Get task time
Your examples doesn't represent real obstacles you face when programming. All you've done is built examples around your suggested function. "It might be good" is really not a reason to do unnecessary work.
Natsheh
09-09-2018 10:01
Re: Get task time
All this is achievable by using variables.
And i dont think the flags should be called with bitsum.
klippy
09-09-2018 11:33
Re: Get task time
Quote:
Originally Posted by Natsheh
(Post 2614395)
All this is achievable by using variables.
And i dont think the flags should be called with bitsum.