AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Weird bug: script works for 1 person only [help plz] (https://forums.alliedmods.net/showthread.php?t=49796)

TiToTal 01-13-2007 03:13

Weird bug: script works for 1 person only [help plz]
 
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 01-13-2007 03:14

Re: Weird bug: script works for 1 person only [help plz]
 
I'm sorry, the code is quite translated to portuguese...

sawce 01-13-2007 03:15

Re: Weird bug: script works for 1 person only [help plz]
 
Moving to scripting help

Salepate 01-13-2007 06:14

Re: Weird bug: script works for 1 person only [help plz]
 
Code:
        if (preso[players[i]] == 0) return PLUGIN_HANDLED
it just stops the plugin.

TiToTal 01-13-2007 11:43

Re: Weird bug: script works for 1 person only [help plz]
 
But, it does works for one person... Why it is not working for the others?

Salepate 01-13-2007 16:58

Re: Weird bug: script works for 1 person only [help plz]
 
Perhaps the second person has it : Off and it just handle the rest of the plugin. Did you try without it ?

mysticssjgoku4 01-13-2007 17:23

Re: Weird bug: script works for 1 person only [help plz]
 
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 }

Emp` 01-13-2007 17:49

Re: Weird bug: script works for 1 person only [help plz]
 
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
}



All times are GMT -4. The time now is 22:27.

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