Raised This Month: $ Target: $400
 0% 

Weird bug: script works for 1 person only [help plz]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
TiToTal
Member
Join Date: Feb 2006
Old 01-13-2007 , 03:13   Weird bug: script works for 1 person only [help plz]
Reply With Quote #1

The following code is working only for one person, I think it only works for the first who joins the server, or the first to get the piece of code activated.

take a look...

it is for The Specialists mod...

Code:
new preso[33]
new timer_seconds[33] = 0
new timer_minutes[33] = 0


Code:
		if(get_distance(origin,jailone) <= 100.0 || get_distance(origin,jailtwo) <= 100.0 || get_distance(origin,jailthree) <= 100.0 || get_distance(origin,jailfour) <= 100.0)
		{
			set_hudmessage(175,0,0,-1.5,0.95,2,0.0,99.9,0.0,0.0,2)
			show_hudmessage(players[i],"Voce esta na prisao. Seu Salario foi suspendido enquanto estiver aqui")
			if (preso[players[i]] == 1) return PLUGIN_HANDLED
			if (preso[players[i]] == 0) 
			{
				preso[players[i]] = 1
				client_print(players[i],print_chat,"[Brasileiros RolePlay] Para saber a quanto tempo voce esta preso use say /tempopreso!^n")
			}
		}


And I think the truly problem is here:

Code:
public jail_timer(id)
{
	new num, players[32]
	get_players(players,num,"ac")
	for( new i = 0;  i < num; i++ )
	{
		if (preso[players[i]] == 0) return PLUGIN_HANDLED
		else if (preso[players[i]] == 1)
		{
			if ( timer_seconds[players[i]] < 60) timer_seconds[players[i]] += 1
			else if (timer_seconds[players[i]] >= 60)
			{
				timer_seconds[players[i]] = 0
				timer_minutes[players[i]] += 1
			}
		}
	}
	return PLUGIN_CONTINUE
}
TiToTal is offline
TiToTal
Member
Join Date: Feb 2006
Old 01-13-2007 , 03:14   Re: Weird bug: script works for 1 person only [help plz]
Reply With Quote #2

I'm sorry, the code is quite translated to portuguese...
TiToTal is offline
sawce
The null pointer exception error and virtual machine bug
Join Date: Oct 2004
Old 01-13-2007 , 03:15   Re: Weird bug: script works for 1 person only [help plz]
Reply With Quote #3

Moving to scripting help
__________________
fyren sucks
sawce is offline
Salepate
Junior Member
Join Date: Jan 2007
Old 01-13-2007 , 06:14   Re: Weird bug: script works for 1 person only [help plz]
Reply With Quote #4

Code:
        if (preso[players[i]] == 0) return PLUGIN_HANDLED
it just stops the plugin.
Salepate is offline
TiToTal
Member
Join Date: Feb 2006
Old 01-13-2007 , 11:43   Re: Weird bug: script works for 1 person only [help plz]
Reply With Quote #5

But, it does works for one person... Why it is not working for the others?
TiToTal is offline
Salepate
Junior Member
Join Date: Jan 2007
Old 01-13-2007 , 16:58   Re: Weird bug: script works for 1 person only [help plz]
Reply With Quote #6

Perhaps the second person has it : Off and it just handle the rest of the plugin. Did you try without it ?
Salepate is offline
mysticssjgoku4
Veteran Member
Join Date: Jan 2005
Location: Chicago Heights, IL
Old 01-13-2007 , 17:23   Re: Weird bug: script works for 1 person only [help plz]
Reply With Quote #7

Code:
new num, players[32]     get_players(players,num,"ac")     for( new i = 0;  i < num; i++ )     {

I'm not sure why, but PAWN likes to screw things up in these for loops with lots of commands inside them for each player.
The way to fix this would be to code it like this:
Code:
public jail_timer(id) {     new num, players[32]     get_players(players,num,"ac")     for( new i = 0;  i < num; i++ )     {         jail2(players[i])     }     return PLUGIN_CONTINUE } public jail2(id) {     if (preso[id] == 0) return PLUGIN_HANDLED     else if (preso[id] == 1)     {         if ( timer_seconds[id] < 60) timer_seconds[id] += 1         else if (timer_seconds[id] >= 60)         {             timer_seconds[id] = 0             timer_minutes[id] += 1         }     }     return PLUGIN_CONTINUE }
__________________

mysticssjgoku4 is offline
Send a message via AIM to mysticssjgoku4 Send a message via MSN to mysticssjgoku4
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 01-13-2007 , 17:49   Re: Weird bug: script works for 1 person only [help plz]
Reply With Quote #8

no point in making 2 functions...

Code:
public jail_timer(id)
{
	new num, players[32], temp_id
	get_players(players,num,"ac")
	for( new i = 0;  i < num; i++ )
	{
		temp_id = players[i]
		if (preso[temp_id] == 0) continue
		else if (preso[temp_id] == 1)
		{
			if ( timer_seconds[temp_id] < 60) timer_seconds[temp_id] += 1
			else if (timer_seconds[temp_id] >= 60)
			{
				timer_seconds[temp_id] = 0
				timer_minutes[temp_id] += 1
			}
		}
	}
	return PLUGIN_CONTINUE
}
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Reply


Thread Tools
Display Modes

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 22:27.


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