Raised This Month: $ Target: $400
 0% 

[How-To] OnDayExecute();


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DDR Khat
SourceMod Donor
Join Date: Feb 2006
Old 10-22-2008 , 06:36   [How-To] OnDayExecute();
Reply With Quote #1

How would it be possible to manage something to that affect?
Reading through the wikis and c++ references, from what I understand, I would want to use Gettime() then afterwards use FormatTime() to get the relevant day out of the system. then apparently I would have to pass %A to get the report of the day from the time.
Would this give a string "Sunday" ?

I am ultimately looking to do something along the lines of;
Code:
OnDayExecute("Sunday")
{
	//things here
}
-----------------
Resolution
-----------------
Thanks to toazron1 and SAMURAI16
Code:
#include <sourcemod> #include <sdktools> new bool:g_Enabled = false; #define MAXTRIGGERS 1 static String:trigger[MAXTRIGGERS][] = { "speech" } public Plugin:myinfo = {         name = "Sunday Plugin",         author = "DDRKhat",         description = "A plugin that only executes stuff on Sunday!",         version  = "1.0",         url = "" }     public OnConfigsExecuted() {     checkToday() } public OnPluginStart() {         RegConsoleCmd("say", Command_Say);     RegConsoleCmd("say_team", Command_Say); } public checkToday() {         new String:today[16];         fn_GetDay(today);         if(StrEqual(today,"Sunday"))         {                 g_Enabled = true;     }     else     {         g_Enabled = false;     } } public Action:Command_Say(id, args) {     new String:text[192],String:input[192];     new success = 0;     GetCmdArgString(text, sizeof(text));     GetLiteralString(text,input,192);     for(new x=0; x<MAXTRIGGERS; x++)     {         if(StrEqual(input, trigger[x]))         {             success = 1;             break;         }     }     if(!success)     {         return Plugin_Continue;     }     if (!g_Enabled)     {         PrintToChat(id, "[SM]: Sorry today is not sunday!");     }     else     {         //Do stuff because its Sunday     }     return Plugin_Handled; } stock GetLiteralString(const String:cmd[],String:buffer[],maxlength) {     strcopy(buffer,strlen(cmd)+1,cmd);     ReplaceString(buffer,maxlength,"\"","");     TrimString(buffer); } stock fn_GetDay(String:output[]) {         new String:day[16];         FormatTime(day,sizeof(day),"%A",GetTime());         strcopy(output,sizeof(day),day); }
__________________
Nothing but a whisper in the wind~~

Last edited by DDR Khat; 10-23-2008 at 18:24. Reason: Help Fulfilled
DDR Khat is offline
SAMURAI16
BANNED
Join Date: Sep 2006
Old 10-22-2008 , 07:56   Re: [Help] OnDayExecute();
Reply With Quote #2

if you want a function like OnDayExecute( ) (a forward actually), you need to create your own forward wich requires a custom .inc

I made a stock wich returns current day
Code:
stock fn_GetDay(String:output[]) {     new String:day[16];     FormatTime(day,sizeof(day),"%A",GetTime());         strcopy(output,sizeof(day),day); }

How to use it:
Code:
public example() {     new String:today[16];     fn_GetDay(today);         PrintToChatAll("today is :  %s",today); } stock fn_GetDay(String:output[]) {     new String:day[16];     FormatTime(day,sizeof(day),"%A",GetTime());         strcopy(output,sizeof(day),day); }

Or example 2, to check if is your required day:
Code:
public example_2() {     new String:today[16];     fn_GetDay(today);         if(StrEqual(today,"Sunday"))     {         // today is Sunday     } } stock fn_GetDay(String:output[]) {     new String:day[16];     FormatTime(day,sizeof(day),"%A",GetTime());         strcopy(output,sizeof(day),day); }
SAMURAI16 is offline
Send a message via MSN to SAMURAI16
DDR Khat
SourceMod Donor
Join Date: Feb 2006
Old 10-22-2008 , 09:04   Re: [Help] OnDayExecute();
Reply With Quote #3

Quote:
Originally Posted by SAMURAI16 View Post
if you want a function like OnDayExecute( ) (a forward actually), you need to create your own forward wich requires a custom .inc

I made a stock wich returns current day
<!-- Code Here --!>

How to use it:
<!-- More code here --!>

Or example 2, to check if is your required day:
<!-- Moar code here --!>
Or I could simply put the bits that I need at the bottom of the code, rather than making it an .INC.

so what you're telling me is I could do..

Code:
#include <sourcemod> #include <sdktools> #define MY_PLUGIN_NAME    "Sunday Plugin" #define MY_PLUGIN_VERSION "1.0.0" #define MY_PLUGIN_AUTHOR  "DDRKhat" public Plugin:myinfo = {     name        = "Sunday Plugin",     author      = "DDRKhat",     description = "A plugin that only executes stuff on Sunday!",     version     = "1.0",     url         = "" } public OnPluginStart() {     return PLUGIN_CONTINUE } public example_2() {     new String:today[16];     fn_GetDay(today);     if(StrEqual(today,"Sunday"))     {         server_print("[SM] Today is Sunday!")     } } stock fn_GetDay(String:output[]) {     new String:day[16];     FormatTime(day,sizeof(day),"%A",GetTime());     strcopy(output,sizeof(day),day); }
__________________
Nothing but a whisper in the wind~~

Last edited by DDR Khat; 10-22-2008 at 09:19.
DDR Khat is offline
SAMURAI16
BANNED
Join Date: Sep 2006
Old 10-22-2008 , 09:08   Re: [Help] OnDayExecute();
Reply With Quote #4

what the fuck ?
#include <amxmodx>
#include <amxmisc>

Here we talking about sourcemod. ROFL
SAMURAI16 is offline
Send a message via MSN to SAMURAI16
DDR Khat
SourceMod Donor
Join Date: Feb 2006
Old 10-22-2008 , 09:16   Re: [Help] OnDayExecute();
Reply With Quote #5

Quote:
Originally Posted by SAMURAI16 View Post
what the fuck ?
#include <amxmodx>
#include <amxmisc>

Here we talking about sourcemod. ROFL
I meant sourcemod XD Sorry, Natural habit to include those.. last time I did much with PAWN was AMXX.. Nice catch.
__________________
Nothing but a whisper in the wind~~
DDR Khat is offline
SAMURAI16
BANNED
Join Date: Sep 2006
Old 10-22-2008 , 10:53   Re: [Help] OnDayExecute();
Reply With Quote #6

I saw you updated code. I guess i have to say what is wrong
example_2() is never called
return PLUGIN_CONTINUE don't need to be in OnPluginStart() ; Also 'PLUGIN_CONTINUE' doesen't exists in SM; it's Plugin_Continue
SAMURAI16 is offline
Send a message via MSN to SAMURAI16
Lebson506th
Veteran Member
Join Date: Jul 2008
Old 10-22-2008 , 11:45   Re: [Help] OnDayExecute();
Reply With Quote #7

And there is no "server_print" function

PrintToChat
PrintToChatAll
PrintToServer
PrintToConsole
__________________
My Plugins
Spray Tracer by Nican, maintained by me
Simple TK Manager
DoD:S Admin Weapons

Links
Resistance and Liberation (A HL2 Multiplayer Modification)
Lebson506th is offline
toazron1
Senior Member
Join Date: Oct 2006
Old 10-22-2008 , 16:23   Re: [Help] OnDayExecute();
Reply With Quote #8

Quote:
Originally Posted by Lebson506th View Post
And there is no "server_print" function

PrintToChat
PrintToChatAll
PrintToServer
PrintToConsole
Another AMXX habit.. I have the same problem from coding so much for Natural Selection
__________________
toazron1 is offline
Send a message via AIM to toazron1
DDR Khat
SourceMod Donor
Join Date: Feb 2006
Old 10-22-2008 , 17:19   Re: [Help] OnDayExecute();
Reply With Quote #9

Well, do remember it's just a demonstration to make sure I understand, is not the code I intend to implement in the end. but.
Code:
#include <sourcemod> #include <sdktools> public Plugin:myinfo = {     name        = "Sunday Plugin",     author      = "DDRKhat",     description = "A plugin that only executes stuff on Sunday!",     version     = "1.0",     url         = "" } public OnPluginStart() {     example_2()     return PLUGIN_Continue } public example_2() {     new String:today[16];     fn_GetDay(today);     if(StrEqual(today,"Sunday"))     {         PrintToConsole("[SM] Today is Sunday!")     } } stock fn_GetDay(String:output[]) {     new String:day[16];     FormatTime(day,sizeof(day),"%A",GetTime());     strcopy(output,sizeof(day),day); }
__________________
Nothing but a whisper in the wind~~
DDR Khat is offline
Antithasys
Moderator
Join Date: Apr 2008
Old 10-23-2008 , 00:21   Re: [Help] OnDayExecute();
Reply With Quote #10

Well its Plugin_Continue not PLUGIN_Continue.

And I would make a command to return the result instead of calling it on plugin start.

Something like RegConsoleCmd and use the command callback.
Antithasys 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:32.


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