Raised This Month: $ Target: $400
 0% 

Problem with tasks & players


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xEhsaan
Member
Join Date: Mar 2015
Location: Isfahan, Iran
Old 03-26-2015 , 11:59   Problem with tasks & players
Reply With Quote #1

I have a problem with tasks. I created a server and activated my plugin, tasks works fine for me, but for my another client, they don't work.

Here is my code, what am I doing wrong?
Code:
public plugin_init() {
...
	set_task( 1.0, "Check_Prizes",0,"", 0, "b" )
}
public Check_Prizes() {
	new players[32], playersnum
	get_players(players, playersnum)
	// First, check glows
	new i
	
	for (i = 0; i < playersnum; i++) {
		if ( ! glows[i] )
			continue;
			
		if ( is_user_alive( i ) )
			glows[i] = glows[i] - 1
		
		if ( glows[i] > 1 ) {
			set_hudmessage(255, 0, 255, 0.05, 0.5, 0, 6.0, 1.0, 0.1, 0.1, 3)
			show_hudmessage(i, "Zamane Baghi Mande Glow Shoma: %d", glows[i] )
			if (is_user_alive(i))
				set_user_rendering( i, kRenderFxGlowShell, glowr[i], glowg[i], glowb[i], kRenderTransAlpha, 0.5 )
		} else {
			set_hudmessage(255, 0, 0, 0.05, 0.5, 0, 6.0, 1.0, 0.1, 0.1, 3)
			show_hudmessage(i, "Glow Shoma Tamam Shod!" )
			set_user_rendering( i, kRenderFxNone )
			client_print_color( i, print_chat, "!g* Glow Shoma Tamom Shod!" )
		}
	}
	
	// Check the hook
	for (i = 0; i < playersnum; i++) {
		if ( ! hookers[i] )
			continue;
			
		if ( is_user_alive( i ) )
			hookers[i] = hookers[i] - 1
			
		new hookername[32]
		get_user_name(i, hookername, 32)
			
		if ( hookers[i] > 1 ) {
			set_hudmessage(255, 255, 0, 0.05, 0.75, 0, 6.0, 1.0, 0.1, 0.1, 2)
			show_hudmessage(i, "Zamane Baghi Mande Hook Shoma: %d", hookers[i] )
			if (is_user_alive(i))
				server_cmd( "amx_givehook %s", hookername )
		} else {
			set_hudmessage(255, 0, 0, 0.05, 0.75, 0, 6.0, 1.0, 0.1, 0.1, 2)
			show_hudmessage(i, "Hook Shoma Tamam Shod!" )
			server_cmd( "amx_takehook %s", hookername )
		}
	}
}
Thanks. :X
__________________
* Wait for something awesome...
* AMX Mod X Plugin Translation Repository [Paused Temporarily]
* Knife Deathmatch Shop
* Knife CFG Detector
* Looking for an idea...

Last edited by xEhsaan; 03-26-2015 at 12:01.
xEhsaan is offline
Send a message via Skype™ to xEhsaan
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-26-2015 , 21:20   Re: Problem with tasks & players
Reply With Quote #2

When you use get_players(), i in your for loop is not a reference to a player. You have to use players[i] to get the player index.

You should cache the players[i] value into a variable at the beginning of your loop and then use that variable anywhere you need the player index.
__________________

Last edited by fysiks; 03-26-2015 at 21:21.
fysiks 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 23:38.


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