Speed Reaction Test - 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: Speed Reaction Test (
/showthread.php?tid=436617)
Speed Reaction Test -
Xicor - 12.05.2013
Hello, How can i make a Speed Reaction Test Like :
Reaction Test:The first Player to Drive Faster than 140 KM/H wins!
Then the first player to go faster than 140 KM/H wins the money?
Please Help, Thanks.
Re: Speed Reaction Test -
Kwarde - 12.05.2013
Well, use timers to give these random messages. Then set a var to 'true' (for example) to check in OnPlayerUpdate who goes 140KM/H. If someone goes faster then 140KM/H while that var is true, immediately set the var to false and that player will win. Small examle:
pawn Код:
//Somewhere in the script
#define MAX_WAIT_TIME 1200000 //20 minutes (to calculate minutes: 1000 * 60 * minutes)
new bool:speedReactionTest = false; //The var to check for those tests
forward randomSpeedReactionTest(); //Forward for the callback (for the timer)
public OnGameModeInit()
{
//Standard stuff
SetTimer("randomSpeedReactionTest", random(MAX_WAIT_TIME), false); //Set first timer, DONt repeat, random timer-time with a max of MAX_WAIT_TIME (so it can also take 1 second when it starts!)
return 1;
}
public OnPlayerUpdate(playerid)
{
if (speedReactionTest) //If the speed reaction test is opened...
{
if (GetPlayerSpeed(playerid) > 140) //Improvised function 'GetPlayerSpeed()'! Replace this with an actual workin speed checker
{
SendClientMessageToAll(COLOR_WHITE, "I won!"); //Don't forget formatting and such.. too lazy for it
GivePlayerMoney(playerid, 10000); //Player won 10,000 for it
speedReactionTest = false; //Test is over
SetTimer("randomSpeedReactionTest", random(MAX_WAIT_TIME), false); //Set timer again
}
}
return 1;
}
public randomSpeedReactionTest()
{
speedReactionTest = true; //Test started
SendClientMessageToAll(COLOR_GREEN, "[Speed reaction test] The first one who goes faster then 140KM/H will win $10,000!");
return 1;
}
Something like that (it's just an example !!)
Re: Speed Reaction Test -
Xicor - 12.05.2013
Do i have to change "GetPlayerSpeed" Function to working speed checker like "GetPlayerVelocity" ?
Re: Speed Reaction Test -
Tanush123 - 12.05.2013
pawn Код:
stock GetVehicleSpeed(vehicleid)
{
if(vehicleid != INVALID_VEHICLE_ID)
{
new Float:Pos[3],Float:VS ;
GetVehicleVelocity(vehicleid, Pos[0], Pos[1], Pos[2]);
VS = floatsqroot(Pos[0]*Pos[0] + Pos[1]*Pos[1] + Pos[2]*Pos[2])*200;
return floatround(VS,floatround_round);
}
return INVALID_VEHICLE_ID;
}
stock GetPlayerSpeed(playerid)
{
if(playerid != INVALID_PLAYER_ID)
{
new Float:Pos[3],Float:PS;
GetPlayerVelocity(playerid, Pos[0], Pos[1], Pos[2]);
PS = floatsqroot(Pos[0]*Pos[0] + Pos[1]*Pos[1] + Pos[2]*Pos[2])*200;
return floatround(PS,floatround_round);
}
return INVALID_PLAYER_ID;
}
Change if (GetPlayerSpeed(playerid) > 140) to
pawn Код:
if (GetVehicleSpeed(GetPlayerVehicleID(playerid)) > 140)