Raised This Month: $ Target: $400
 0% 

Little help:


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
|2eM!x
Member
Join Date: Mar 2005
Old 03-20-2005 , 17:50   Little help:
Reply With Quote #1

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

|2eM!x is offline
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 03-20-2005 , 17:58   Re: Little help:
Reply With Quote #2

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..
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
xeroblood
BANNED
Join Date: Mar 2004
Location: Toronto, Canada
Old 03-20-2005 , 18:02  
Reply With Quote #3

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 )
xeroblood is offline
Send a message via MSN to xeroblood
|2eM!x
Member
Join Date: Mar 2005
Old 03-20-2005 , 18:16  
Reply With Quote #4

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!
|2eM!x is offline
xeroblood
BANNED
Join Date: Mar 2004
Location: Toronto, Canada
Old 03-20-2005 , 20:49  
Reply With Quote #5

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..
xeroblood is offline
Send a message via MSN to xeroblood
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 03-20-2005 , 21:01  
Reply With Quote #6

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


I'll leave it to xeroblood to answer your questions.
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
|2eM!x
Member
Join Date: Mar 2005
Old 03-20-2005 , 22:44  
Reply With Quote #7

cool!thanks for the great response!
|2eM!x is offline
|2eM!x
Member
Join Date: Mar 2005
Old 03-21-2005 , 20:54  
Reply With Quote #8

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?
|2eM!x is offline
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 03-21-2005 , 21:05  
Reply With Quote #9

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 :)
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
xeroblood
BANNED
Join Date: Mar 2004
Location: Toronto, Canada
Old 03-21-2005 , 21:06  
Reply With Quote #10

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 }
xeroblood is offline
Send a message via MSN to xeroblood
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:12.


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