SA-MP Forums Archive
Why won't this randomise? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Why won't this randomise? (/showthread.php?tid=311684)



Why won't this randomise? - Dokins - 17.01.2012

It doesnt actually select Hospital 2 At all! I can't figure it out.

pawn Код:
stock dohospital(playerid)
{
    if(Hospitalized[playerid] == 1 && random(1) == 0)
    {
                ResetPlayerWeapons(playerid);
                SetSpawnInfo(playerid, -1, PlayerSkin[playerid], -216.0915,972.2845,19.3201 -10, 180.0, 0,0,0,0,0,0);
                SpawnPlayer(playerid);
                SetPlayerHealth(playerid, 20.0);
                SetPlayerVirtualWorld(playerid, 3);
                TogglePlayerControllable(playerid, 0);
                SetPlayerInterior(playerid, 0);
                SetPlayerCameraPos(playerid, -315.1983, 1064.2436, 19.5937);
                SetPlayerCameraLookAt(playerid, -319.19,1050.22,20.3403);
                SendClientMessage(playerid, COLOUR_WHITE, "You are recovering in hospital.");
                SendClientMessage(playerid, COLOUR_WHITE, "You will be released shortly. ((Revenge killing is against the server rules)).");
                HospitalUsed = 1;
    }
    if(Hospitalized[playerid] == 1 && random(1) == 1)
    {
                ResetPlayerWeapons(playerid);
                SetSpawnInfo(playerid, -1, PlayerSkin[playerid], -216.0915,972.2845,19.3201 -10, 180.0, 0,0,0,0,0,0);
                SpawnPlayer(playerid);
                SetPlayerHealth(playerid, 20.0);
                SetPlayerVirtualWorld(playerid, 3);
                TogglePlayerControllable(playerid, 0);
                SetPlayerInterior(playerid, 0);
                SetPlayerCameraPos(playerid, 1606.5913,1840.1801,10.8203);
                SetPlayerCameraLookAt(playerid, 1605.9766,1822.4442,15.8125);
                SendClientMessage(playerid, COLOUR_WHITE, "You are recovering in hospital.");
                SendClientMessage(playerid, COLOUR_WHITE, "You will be released shortly. ((Revenge killing is against the server rules)).");
                HospitalUsed = 2;
            }
    return 1;
}



Re: Why won't this randomise? - 2KY - 17.01.2012

pawn Код:
stock dohospital(playerid)
{
    new
        RandomHospital = random(1);

    if(Hospitalized[playerid] == 1 && RandomHospital == 0)
    {
                ResetPlayerWeapons(playerid);
                SetSpawnInfo(playerid, -1, PlayerSkin[playerid], -216.0915,972.2845,19.3201 -10, 180.0, 0,0,0,0,0,0);
                SpawnPlayer(playerid);
                SetPlayerHealth(playerid, 20.0);
                SetPlayerVirtualWorld(playerid, 3);
                TogglePlayerControllable(playerid, 0);
                SetPlayerInterior(playerid, 0);
                SetPlayerCameraPos(playerid, -315.1983, 1064.2436, 19.5937);
                SetPlayerCameraLookAt(playerid, -319.19,1050.22,20.3403);
                SendClientMessage(playerid, COLOUR_WHITE, "You are recovering in hospital.");
                SendClientMessage(playerid, COLOUR_WHITE, "You will be released shortly. ((Revenge killing is against the server rules)).");
                HospitalUsed = 1;
    }
    if(Hospitalized[playerid] == 1 && RandomHospital == 1)
    {
                ResetPlayerWeapons(playerid);
                SetSpawnInfo(playerid, -1, PlayerSkin[playerid], -216.0915,972.2845,19.3201 -10, 180.0, 0,0,0,0,0,0);
                SpawnPlayer(playerid);
                SetPlayerHealth(playerid, 20.0);
                SetPlayerVirtualWorld(playerid, 3);
                TogglePlayerControllable(playerid, 0);
                SetPlayerInterior(playerid, 0);
                SetPlayerCameraPos(playerid, 1606.5913,1840.1801,10.8203);
                SetPlayerCameraLookAt(playerid, 1605.9766,1822.4442,15.8125);
                SendClientMessage(playerid, COLOUR_WHITE, "You are recovering in hospital.");
                SendClientMessage(playerid, COLOUR_WHITE, "You will be released shortly. ((Revenge killing is against the server rules)).");
                HospitalUsed = 2;
            }
    return 1;
}
Try that and see if that makes a difference.


Re: Why won't this randomise? - Dokins - 17.01.2012

That made no difference at all, it confuses me as to why it won't work.


Re: Why won't this randomise? - Tannz0rz - 17.01.2012

random(1) will always return 0.

Код:
stock dohospital(playerid)
{
	if(Hospitalized[playerid] == 1)
	{
		ResetPlayerWeapons(playerid);
		SetSpawnInfo(playerid, -1, PlayerSkin[playerid], -216.0915,972.2845,19.3201 -10, 180.0, 0,0,0,0,0,0);
		SpawnPlayer(playerid);
		SetPlayerHealth(playerid, 20.0);
		SetPlayerVirtualWorld(playerid, 3);
		TogglePlayerControllable(playerid, 0);
		SetPlayerInterior(playerid, 0);

		SendClientMessage(playerid, COLOUR_WHITE, "You are recovering in hospital.");
		SendClientMessage(playerid, COLOUR_WHITE, "You will be released shortly. ((Revenge killing is against the server rules)).");
			
		if(random(2) == 0)
		{
			SetPlayerCameraPos(playerid, -315.1983, 1064.2436, 19.5937);
			SetPlayerCameraLookAt(playerid, -319.19,1050.22,20.3403);
			HospitalUsed = 1;
		}
		else
		{
			SetPlayerCameraPos(playerid, 1606.5913,1840.1801,10.8203);
			SetPlayerCameraLookAt(playerid, 1605.9766,1822.4442,15.8125);
			HospitalUsed = 2;
		}
	}
}



Re: Why won't this randomise? - jamesbond007 - 17.01.2012

ye.. duhhh

random (2 ) for two numbers and random ( 1) will return only one number...