Little problem with random.. - 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: Little problem with random.. (
/showthread.php?tid=474343)
Little problem with random.. -
Lajko1 - 07.11.2013
Hey, I have little problem with switch random thing..
I want to make if car have more than 500hp there are 100% chances to turn engine on (this is working perfect)
But if car is under 500HP I want to make random thing.. but it's working somehow but the problem is.. time to time this random thing don't even choose the given options "case 1" or "case 2" there isn't any effect / SendClientMessage or anything...
here is the code
pawn Код:
public EngStart(playerid)
{
new Float:vehHP, vehicle = GetPlayerVehicleID(playerid);
GetVehicleHealth(vehicle, vehHP);
if(vehHP >= 500)
{
Eng[playerid] = 1;
SendClientMessage(playerid, COLOR_YELLOW,"Engine is succesfully started");
TogglePlayerControllable(playerid, 1);
}
if(vehHP <= 500)
{
switch(random(3))
{
case 1:
{
Eng[playerid] = 1;
SendClientMessage(playerid, COLOR_YELLOW,"Engine is succesfully started");
TogglePlayerControllable(playerid, 1);
}
case 2:
{
Eng[playerid] = 0;
SendClientMessage(playerid, COLOR_YELLOW,"Engine failed to start, please try again");
TogglePlayerControllable(playerid, 0);
}
}
}
return 1;
}
What is wrong ?
Re: Little problem with random.. -
Konstantinos - 07.11.2013
What if the number was 0? It does nothing.
Change to:
pawn Код:
public EngStart(playerid)
{
new Float:vehHP, vehicle = GetPlayerVehicleID(playerid);
GetVehicleHealth(vehicle, vehHP);
if(vehHP >= 500)
{
Eng[playerid] = 1;
SendClientMessage(playerid, COLOR_YELLOW,"Engine is succesfully started");
TogglePlayerControllable(playerid, 1);
}
else
{
switch(random(2))
{
case 0:
{
Eng[playerid] = 1;
SendClientMessage(playerid, COLOR_YELLOW,"Engine is succesfully started");
TogglePlayerControllable(playerid, 1);
}
case 1:
{
Eng[playerid] = 0;
SendClientMessage(playerid, COLOR_YELLOW,"Engine failed to start, please try again");
TogglePlayerControllable(playerid, 0);
}
}
}
return 1;
}
Re: Little problem with random.. -
Lajko1 - 07.11.2013
Oh true everything here starts with 0

Umm you helped me as always

REP for you
Thank you
Re: Little problem with random.. -
Lajko1 - 07.11.2013
Okay 1 more problem.. When I enter the vehicle I added if player state is Driver it will start the timer but it won't..
Code:
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
SetTimerEx("EngStartup", 1000, false, "d", playerid);
return 1;
}
return 1;
}
Where is the problem?
Re: Little problem with random.. -
TouR - 07.11.2013
You should use OnPlayerStateChange instead. You are going to detect the driver's new state there.
Re: Little problem with random.. -
Lajko1 - 07.11.2013
Thanks