Raised This Month: $ Target: $400
 0% 

set_task & userid


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
breaddawson
Senior Member
Join Date: Jul 2004
Location: Beijing,China
Old 11-12-2004 , 05:00   set_task & userid
Reply With Quote #1

i have prolem using set_task to call a function and use userid in that

for example,i wrote like this
Code:
set_task(1.0,"abc",906912,"",0,b)
then the function abc will be called every second
then i worte abc like this
Code:
public abc() {    client_print(0,print_chat,"haha"); }
then all players will see this message "haha"
but it' not enough
now i don't want everyone to see this message
instead,i add an array like this
Code:
new  g_iShow[33]
er...yes,i want to set flag for every player
when g_iShow[userid] is 0
then the player won't see any message
but i just have trouble with this
how could i get the user's id in this function abc()??
like this?
Code:
public abc(id) { if (g_iShow(id)==0) ..... }

but it won't work,"id "here will be set to the task's id,not user's id
or maybe this is impossible and i should try another way?
__________________
i'm bread dawson ,a chinese boy
wish u be happy~
breaddawson is offline
Send a message via ICQ to breaddawson Send a message via MSN to breaddawson
Johnny got his gun
Veteran Member
Join Date: Jan 2004
Location: Tokyo
Old 11-12-2004 , 05:10  
Reply With Quote #2

Well, easy...

Code:
somefunction() { new parameters[1] parameters[0] = ourData set_task(5.0, "anotherfunction", 0, parameters, 1) // last parameter here tells how many values we send in parameters. } public anotherfunction(theparameters[1]) { new theData = theparameters[0] }
Johnny got his gun is offline
breaddawson
Senior Member
Join Date: Jul 2004
Location: Beijing,China
Old 11-12-2004 , 05:18  
Reply With Quote #3

yes,if in "somefunction" i set ourdata as a parameter of another function
i can do that
but,how could i get "ourdata"??
it must be user's id

as what i did,i pug "set_task" in plugin_init
here u put it in somefunction
then how will somefunction be called?
can i call it in plugin_init?
__________________
i'm bread dawson ,a chinese boy
wish u be happy~
breaddawson is offline
Send a message via ICQ to breaddawson Send a message via MSN to breaddawson
DS
SourceMod Developer
Join Date: Sep 2004
Location: WI, USA
Old 11-12-2004 , 05:30  
Reply With Quote #4

Since you said you are using set_task in plugin_init, I think the only way you can do what you want is to loop through all the players...

Code:
new g_iShow[33] public plugin_init() {     set_task(1.0, "abc", 906912, "", 0, b) } public abc() {     for (new i = 1; i <= get_maxplayers(); i++) {         if (is_user_connected(id) && g_iShow[id])             client_print(id, print_chat, "haha")     } }

But doing that would run the loop every second. You might want to reconsider how you want to do this.

As for your question about how "somefunction" would be called with JGHG's code... I'm thinking you could register a command in plugin_init which would use "somefunction". Maybe that command would set a task to do client_print every second for the player that you specified in the command?
__________________
エル・プサイ・コングルゥ
DS is offline
breaddawson
Senior Member
Join Date: Jul 2004
Location: Beijing,China
Old 11-12-2004 , 05:49  
Reply With Quote #5

er...maybe what i said is not clear
i just want to make a time_display plugin
so i want to call the function every second
and i must check every player's flag in the function
by doing this,i could know if display messages on their screen

@Damaged Soul
thank u,it works
er...will this,i mean what i want to do,cause the server lag?

i can't register a command in the plugin_init to call "somefunction"
er...as i said before,i want to make a time_display plugin
so i must use set_task to do it
but if i use set_task to call "somefunction"
how should i pass the user id to "somefunction"??
__________________
i'm bread dawson ,a chinese boy
wish u be happy~
breaddawson is offline
Send a message via ICQ to breaddawson Send a message via MSN to breaddawson
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 00:29.


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