Raised This Month: $12 Target: $400
 3% 

Spectate time


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 08-02-2007 , 16:28   Spectate time
Reply With Quote #1

Hi.Is there a way to get a user spectate time with "systime" or "gametime" or other ways...?

Thanks.
__________________
Still...lovin' . Connor noob! Hello

Last edited by Alka; 08-02-2007 at 16:45.
Alka is offline
Drak
Veteran Member
Join Date: Jul 2005
Old 08-02-2007 , 23:24   Re: Spectate time
Reply With Quote #2

I'm sure there's a very easy way, but I was bored. So you can try this.
I made two versions, one for dynamic natives, so you can use it in any plugin.
And, just the normal 'local' functions.

Dynamic Native:
Code:
#include <amxmodx> #define PLUGIN "Spectator Time" #define VERSION "1.0" #define AUTHOR "Drak" #define TASK_ID 8699 new counter[33] public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)         register_event("TeamInfo","teamInfo", "a"); } public plugin_natives() {     register_library("SpecTime");     register_native("get_user_spectime","_get_user_spectime"); } public teamInfo() {     new id = read_data(1);             new team[12];     read_data(2,team,sizeof team - 1);         switch(team[0])     {           case 'S': {             // They re-joined spectators, let's reset the timer.             if(counter[id] >= 1) {                 counter[id] = 0;             }             set_task(1.0,"counterTask",id+TASK_ID,"",0,"b"); // Begin counting.         }         default: {             // We aren't on spectators anymore.. Stop the timer.             if(counter[id] >=1) {                 remove_task(id+TASK_ID);                 counter[id] = 0; // Reset it.             }         }                                     } } public counterTask(id) {     counter[id]++ } // This returns how many seconds they have been in spectator. public _get_user_spectime(Plugin,Params) {     if(Params != 1)     {         server_print("[%s] Parameters do not match. Expected: 1, Found: %d",PLUGIN,Params)         return 0;     }     new id = get_param(1);     if(is_user_connected(id))         return counter[id];             return PLUGIN_HANDLED } public client_disconnect(id) {     if(task_exists(id+TASK_ID)) {         remove_task(id+TASK_ID);     }       counter[id] = 0 } public client_putinserver(id) counter[id] = 0
The include file, if you use the dynamic version:
Code:
#pragma library "SpecTime" // Returns how many seconds the user has been in spectator native get_user_spectime(id)


Normal Version:
Code:
#include <amxmodx> #define PLUGIN "Spectator Time" #define VERSION "1.0" #define AUTHOR "Drak" #define TASK_ID 8699 new counter[33] public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_event("TeamInfo","teamInfo", "a"); } public teamInfo() {     new id = read_data(1);             new team[12];     read_data(2,team,sizeof team - 1);         switch(team[0])     {           case 'S': {             // They re-joined spectators, let's reset the timer.             if(counter[id] >= 1) {                 counter[id] = 0;             }             set_task(1.0,"counterTask",id+TASK_ID,"",0,"b"); // Begin counting.         }         default: {             // We aren't on spectators anymore.. Stop the timer.             if(counter[id] >=1) {                 remove_task(id+TASK_ID);                 counter[id] = 0; // Reset it.             }         }                                     } } public counterTask(id) {     counter[id]++ } public get_user_spectime(id) {     if(is_user_connected(id))         return counter[id]; } public client_disconnect(id) {     if(task_exists(id+TASK_ID)) {         remove_task(id+TASK_ID);     }       counter[id] = 0 } public client_putinserver(id) counter[id] = 0

Like i said, this is probably way over-done, but i don't see why it wont work.

The function "get_user_spectime" will return the amount of seconds the user has been in the spectator team. If the user switches out of spectator, the counter is reset. (You can obviously change that)
__________________
Oh yeah
Drak is offline
Send a message via MSN to Drak
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 08-03-2007 , 04:21   Re: Spectate time
Reply With Quote #3

Huh...thanks! I've maded a version too ;)....
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
Wilson [29th ID]
Veteran Member
Join Date: Nov 2005
Location: London
Old 08-03-2007 , 10:50   Re: Spectate time
Reply With Quote #4

No! No! No! No! No!
Read this to see why!

You're using a set task to up the counter every second, taking up valuable memory.

Instead, make the global variable a Float, in which you will store the gametime that the user went to the spectators team.

When you want to retrieve how long the user has been in spectate, get the current gametime and subtract the global variable's game time.

This way you're not straining the memory every second.
__________________

Day of Defeat AMXX Community

FakeMeta Research . Voice Proximity . Advanced Deploy . Technician
Wilson [29th ID] is offline
Send a message via ICQ to Wilson [29th ID] Send a message via AIM to Wilson [29th ID] Send a message via MSN to Wilson [29th ID] Send a message via Yahoo to Wilson [29th ID]
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 20:10.


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