AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Little help: (https://forums.alliedmods.net/showthread.php?t=11476)

|2eM!x 03-20-2005 17:50

Little help:
 
Since i cant find much resources on this, i decided to do it on my own. Forgive me if ive done something stupid or "forbidden" or whatever.

Ive combined a hello world, with a hp thing that two different people showed me.

Code:
#include <amxmod> #include <amxmisc> public saytime(id,level,cid) { if (!cmd_access(id,level,cid,1)) {  return PLUGIN_HANDLED } client_print(id,print_chat THETIME return PLUGIN_HANDLED } public plugin_init() { register_plugin("Saytime","0.1","jghg") register_clcmd("say /thetime","saytime") // prints the time!!! to everyone }

What i want to know, is how to do this: client_print(id,print_chat THETIME
like, get the time of the server, and also, how to do rather than one client, send to all clients...thanks guys

:D

v3x 03-20-2005 17:58

Re: Little help:
 
Try this..
Code:
#include <amxmod> #include <amxmisc> public saytime(id,level,cid) {     if (!cmd_access(id,level,cid,1)) {         return PLUGIN_HANDLED     }     new CurTime[9]     get_time("%H:%M:%S",CurTime,8)     client_print(0,print_chat,"The time is now %s",CurTime)     return PLUGIN_HANDLED } public plugin_init() {     register_plugin("Saytime","0.1","John Doe")     register_clcmd("say /thetime","saytime",ADMIN_KICK,"- say /thetime in chat") }

Edit: Woops, forgot set set the index to 0..

xeroblood 03-20-2005 18:02

This function will grab the current servers time.. So if the server is in UK and you play from US (or vice versa) then it will not be correct time for you...

from amxmodx.inc:
Code:
/* Returns time in given format. The most popular is: "%m/%d/%Y - %H:%M:%S". */ native get_time(const format[],output[],len);


Example:
Code:
new szTheTime[32] get_time("%m/%d/%Y - %H:%M:%S", szTheTime, 31 ) client_print(0,print_chat, szTheTime )

|2eM!x 03-20-2005 18:16

Okay thanks for the replies, but v3x once again, can you comment your stuff a little? I understand how it works, but somethings i dont get like
Code:
  new CurTime[9]     get_time("%H:%M:%S",CurTime,8)
What do the 9 and 8's mean?

Code:
"The time is now %s"
Would that just print - The time is now %s
?
At least thats how it would work in vb.

Also, cmd_access(id,level,cid,1)) { --whats that all? They have to have access to the command?

Thanks, i hope you dont mind me picking apart your work!

xeroblood 03-20-2005 20:49

:P v3x.. I musta been posting at same time as you!!

9 is the size of the string (meaning it can hold 9 characters), but strings in C must end with a null terminater (you never need have to add it manually in Small C), meaning the MAX amount of characters you can Use is 9 - 1, so 8 characters + 1 null-terminater is the max amount of characters the string can really hold...

So when you call the get_time function you pass it the string you want it to write too (CurTime) and you also tell it how many characters the function is allowed to write..

And the %s is a place-holder for extra values..
Think of like this: the %s will be replaced by a string, what string? the CurTime string that we just made using the get_time function.. how? because the %s is the First place-holder in the string and the CurTime variable is the First extra parameter passed to the function..

v3x 03-20-2005 21:01

Quote:

Originally Posted by xeroblood
:P v3x.. I musta been posting at same time as you!!

:roll:

I'll leave it to xeroblood to answer your questions. :)

|2eM!x 03-20-2005 22:44

cool!thanks for the great response!

|2eM!x 03-21-2005 20:54

Okay, started working on this today, heres what i got:
Code:
#include <amxmod> #include <amxmisc> public thetime(id,level,cid) {     if (!cmd_access(id,level,cid,1)) {         return PLUGIN_HANDLED     }     new CurTime[9]     get_time("%H:%M:%S",CurTime,8)     If %H is > 12 then         %H = %H - 12     client_print(0,print_center,"The time is now %s",CurTime)     return PLUGIN_HANDLED } public plugin_init() {     register_plugin("Saytime","0.1","|2eM!x")     register_clcmd("say /thetime","thetime",ADMIN_KICK,"- say /thetime in chat") }
i wanted it so that if the hour was greater than 12, than to minus twelve from it. It must be vb kicking in, but could anyone help me?

v3x 03-21-2005 21:05

Do you want it to erase it completely, or set it to 0?

Also, use comments:
Code:
// This is a comment, it doesn't affect the code :)

xeroblood 03-21-2005 21:06

Try this: (C, C++ and Small C are all very different in syntax than VB)

Code:
#include <amxmod> #include <amxmisc> public thetime(id,level,cid) {     if (!cmd_access(id,level,cid,0)) {         return PLUGIN_HANDLED     }     new szCurTime[15], szDigits[3][5]     get_time( "%H:%M:%S", szCurTime, 11 )     UAIO_ExplodeString( szDigits, 3, szCurTime, 4, ':' )     new iHours = str_to_num( szDigits[0] )     if( iHours > 12 ) iHours -= 12     client_print( 0, print_center, "The time is now %d:%s:%s", iHours, szDigits[1], szDigits[2] )     return PLUGIN_HANDLED } public plugin_init() {     register_plugin("Saytime","0.1","|2eM!x")     register_clcmd("say /thetime","thetime",ADMIN_KICK,"- say /thetime in chat") } // This is a stock function from my UAIO plugin (also in XS) // Mimics PHPs explode function stock UAIO_ExplodeString( p_szOutput[][], p_iMax, p_szInput[], p_iSize, p_szDelimiter ) {     new iIdx = 0, l = strlen(p_szInput)     new iLen = (1 + copyc( p_szOutput[iIdx], p_iSize, p_szInput, p_szDelimiter ))     while( (iLen < l) && (++iIdx < p_iMax) )         iLen += (1 + copyc( p_szOutput[iIdx], p_iSize, p_szInput[iLen], p_szDelimiter ))     return iIdx }


All times are GMT -4. The time now is 14:12.

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