Our Scripts Vault contains many game scripts that you can use to create your own game!
again game logic different people have different ideas on making something logical and to implement "real life" feeling instead of just "math" feeling...so that player think that he is driving and not only IF 3>2 then you win style.I would do it like that:engine -> max speedtransmission & chip tuning -> accelerationspoilers and all -> better tractionso then you think of some road I dont know 3 curves and lines between there. so you can use your math/physics knowledge to calculate how fast does he gain top speed and then in curves max speed is limited (coz of traction), but if he has spoilers n shit then he can drive faster ... this system would need much more thinking and all but it would give players feeling that something means something (coz in description of parts u tell impact on driving of each part).now to give you idea:v = a*ts = 1/2 * a * t^2v = speeda = accelerationt = times = lengthso lets say your a = 3m/s^2, and max speed of your car is 24m/s ... t = v/a = 24/3 = 8sso this car will need 8 seconds to reach this speed and in that time it will drive s = 1/2 * 3 * 8^2 = 96mso if you 1st section is 200m he will need to drive another 104m with constant speed 24m/s meaning 104/24 = 4.333sso total time for 1st section is 12.333secondsthen lets say you dont use braking (althrough that can be great too so he must brake to speed in that curve which is max 15m/s)so curve is 100m and his speed is 15m/s which comes to 6.667secondsso alltogether that is 19seconds driving timeand other player have some good spoiler or tires or something and he can drive max 16m/s in that corner so that is 6.25secondsall together that is 10.583s for 2nd car and he wins!so you can make such system that outputs (print,echo) those times:A---------B \ \ \ CA-B is lineB-C is curve with limited speed so you output that times A = 0 and B and C so user see where is his car lacking or what can he improvehope you get basic idea
So let's say I have a car max speed 35 m/sa = 2 m/sSo if the track is 200 meters long, how do I calculate how long it takes him to get from the start to finish?
$getcar = $db->execute("SELECT c.car_name, c.max_speed, c.acceleration, c.max_corner_speed, co.driving_skills, co.car_id FROM Cars c INNER JOIN cars_owned co ON co.car_id=c.car_id WHERE co.id=?", array(13));$getcar1 = $getcar->fetchrow();//track sections$section1=200;$section2=100;$section3=400;if($getcar->recordcount() == 0){ echo "no results";}else{ $getaddons = $db->execute("SELECT u.acceleration_increase, u.corner_speed_increase, u.top_speed_increase FROM car_upgrades u LEFT JOIN cars_upgradesinstalled cui ON cui.addon_id=u.id WHERE cui.car_id=?", array(13)); if($getaddons->recordcount() == 0) { echo "no getaddon results"; } else { while ($getaddons1 = $getaddons->fetchrow()) { $supbonus += $getaddons1['corner_speed_increase']/100; $speedbonus += $getaddons1['top_speed_increase']/100; $accbonus += $getaddons1['acceleration_increase']/100; } //add bonus equipment $acceleration = $getcar1['acceleration']+($getcar1['acceleration']*$accbonus); $speed = $getcar1['max_speed']+($getcar1['max_speed']*$speedbonus); $suspension = $getcar1['max_corner_speed']+($getcar1['max_corner_speed']*$accbonus); //get final speed of car for section 1 $v1 = sqrt(2*$acceleration*$section1); echo "<br>v1\n" . $v1; //time for section 1 $time = $v1/$acceleration; echo "<br>time1\n" . ($time); //get speed of car for section 2 this is a curve section. $time2 = $section2/$suspension; echo "<br>Time2\n" . $time2; //get final speed and time for section 3 $v3 = sqrt(2*$acceleration*$section3); echo "<br>v1\n" . $v3; $time3 = $v3/$acceleration; echo "<br>time1\n" . ($time3); $totaltime = $time + $time2 + $time3; $totalpercent = $totaltime * .5; $totaltimemax = $totaltime + $totalpercent; function random_float ($totaltime,$totaltimemax) { return ($totaltime+lcg_value()*(abs($totaltimemax-$totaltime))); } echo "randomfloat" . round(random_float($totaltime,$totaltimemax), 2);
You could sort it into an array but then you would need to pull some sort of pre-canned sorting algorithm for sorting multi-dimensional arrays. Not very hard to do and there are some great functions on the net for this.Or you can go with another option.Player creates race with and says 5 player's can join. You will need to store this in a table which would have something like raceidplayeridtimerankWhen the script for the race runs it'll calculate time and update it for the player, you could then pull that from the database with time in descending order giving you your ranking, then loop though and update the rank. It does creates a couple more queries and updates but it is another option.
why cron? just check how many players signed and when last signed up first calculate his time & write it to table, then sort that table by time desc and you have winner using that you can also send message to every contestant...while (6 players from sql->array) {$i+=1;//send message to player where $i is his final position }