How to make random?
#7

Quote:
Originally Posted by Larceny
Посмотреть сообщение
Yes, it was just an example. To do this, could be used variables.
Example:

Код:
new totalplayers;

public OnPlayerConnect(playerid)
{
    if(totalplayers < GetMaxPlayers()) totalplayers++;
    return 1;
}

public OnPlayerDisconnect(playerid)
{
    if(totalplayers > 0) totalplayers--;
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_CROUCH)
    {
	SendClientMessage(playerid,0xFFFFFFFF, "WORKING");
	new randomid = random(totalplayers);
	TogglePlayerControllable(randomid, false);
	SendClientMessage(randomid,0xFFFFFFFF, "You've been freezed by someone.");
    }
    return 1;
}
This will ALSO have bugs. If there are 2 players, and one has ID 3, it will exclude him, and it might pick 2 which is not connected. Best way is using foreach.
pawn Код:
#include < foreach >
public OnPlayerKeyStateChange( playerid, newkeys, oldkeys )
{
    if( newkeys & KEY_CROUCH )
    {
        SendClientMessage( playerid,0xFFFFFFFF, "WORKING" );
        new randomid = Iter_Random( Player );
        TogglePlayerControllable( randomid, false );
        SendClientMessage( randomid,0xFFFFFFFF, "You've been frozen by someone." ); // It's frozen not freezed :P
    }
    return 1;
}
Reply


Messages In This Thread
How to make random? - by Ben7544 - 13.04.2011, 23:50
Re: How to make random? - by DarrenReeder - 14.04.2011, 00:06
Re: How to make random? - by Shelby - 14.04.2011, 00:07
Re: How to make random? - by DarrenReeder - 14.04.2011, 00:12
Re: How to make random? - by Shelby - 14.04.2011, 00:23
Re: How to make random? - by Ben7544 - 14.04.2011, 09:33
Re: How to make random? - by Mean - 14.04.2011, 09:55
Re: How to make random? - by Shelby - 14.04.2011, 10:33

Forum Jump:


Users browsing this thread: 1 Guest(s)