AryanV

TRL Driving Test System - By TheRageLord

Jul 14th, 2015
1,019
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 11.89 KB | None | 0 0
  1. #include <a_samp>
  2. #include <zcmd>
  3. #include <YSI\y_ini>
  4. #define UserPath "License/%s.ini"
  5. #define COLOR_RED 0xC00000FF //Red Color
  6. #define COLOR_GREEN 0x009647FF //Green Color
  7. #define COLOR_BLUE 0x0093BBFF //Blue Color
  8. #define VEHICLE_ID 426 //Current Vehicle is Premier
  9. #define VEH_DAMAGE 900 //Here 900 means that If Vehicle health is less than 900 and test would fail
  10. #define MINI_SPEED 40 //maximum speed at which player should drive car
  11. #define MAX_SPEEDING 4 //number of warnings
  12.  
  13. new ncar[MAX_PLAYERS];
  14. enum pinfo{
  15.    license,
  16.    CP,
  17.    speeding,
  18. };
  19. new gPlayer[MAX_PLAYERS][pinfo];
  20.  
  21.  
  22.  
  23. public OnFilterScriptInit()
  24. {
  25.     print("\n======================================");
  26.     print(" TRL Driving Test By Rage Loaded!!");
  27.     print("======================================\n");
  28.    
  29. CreateObject(1412, 1279.60181, -1561.81287, 13.47932,   0.00000, 0.00000, 359.76001);
  30. CreateObject(1412, 1284.81030, -1561.81824, 13.42387,   0.00000, 0.00000, -0.12000);
  31. CreateObject(1412, 1287.57068, -1559.17639, 13.49489,   0.00000, 0.00000, 86.09998);
  32. CreateObject(1412, 1287.96887, -1553.98267, 13.51316,   0.00000, 0.00000, 85.31999);
  33. CreateObject(1412, 1288.39575, -1548.77991, 13.50460,   0.00000, 0.00000, 83.82001);
  34. CreateObject(1412, 1289.05505, -1543.61560, 13.51273,   0.00000, 0.00000, 81.42001);
  35. CreateObject(1412, 1290.06531, -1538.52112, 13.56483,   0.00000, 0.00000, 74.52000);
  36. CreateObject(1412, 1291.64819, -1533.51697, 13.57772,   0.00000, 0.00000, 70.38003);
  37. CreateObject(1412, 1293.41418, -1528.64636, 13.55346,   0.00000, 0.00000, 69.71999);
  38. CreateObject(1412, 1295.25208, -1523.78308, 13.56062,   0.00000, 0.00000, 68.04002);
  39. CreateObject(1412, 1293.60803, -1521.35400, 13.59054,   0.00000, 0.00000, 0.00000);
  40. CreateObject(1412, 1288.37805, -1521.36536, 13.63041,   0.00000, 0.00000, 0.00000);
  41. CreateObject(1412, 1283.14111, -1521.43250, 13.66456,   0.00000, 0.00000, 0.00000);
  42. CreateObject(1412, 1277.96399, -1521.42505, 13.68231,   0.00000, 0.00000, -0.36000);
  43. CreateObject(1412, 1272.79675, -1521.42407, 13.67245,   0.00000, 0.00000, -0.06000);
  44. CreateObject(1412, 1267.70337, -1521.48181, 13.71738,   0.00000, 0.00000, 0.00000);
  45. CreateObject(1412, 1265.17786, -1524.05994, 13.84590,   0.00000, 0.00000, 91.91999);
  46. CreateObject(1412, 1265.39380, -1529.26270, 13.83466,   0.00000, 0.00000, 92.64003);
  47. CreateObject(1412, 1267.21936, -1562.06421, 13.60090,   0.00000, 0.00000, 0.00000);
  48. CreateObject(1412, 1264.60339, -1559.48193, 13.60165,   0.00000, 0.00000, 88.32004);
  49.  
  50.     return 1;
  51. }
  52.  
  53. public OnFilterScriptExit()
  54. {
  55.     print("\n======================================");
  56.     print(" TRL Driving Test By Rage UNLoaded!!");
  57.     print("======================================\n");
  58.     return 1;
  59. }
  60.  
  61. public OnPlayerConnect(playerid)
  62. {
  63.     new name[MAX_PLAYER_NAME];
  64.     GetPlayerName(playerid,name,sizeof(name));
  65.     if(fexist(Path(playerid)))
  66.     {
  67.         INI_ParseFile(Path(playerid),"loadaccount_%s", .bExtra = true, .extra = playerid);
  68.     }
  69.     else
  70.     {
  71.            new INI:file = INI_Open(Path(playerid));
  72.             INI_SetTag(file,"User's License");
  73.             INI_WriteInt(file,"License",0);
  74.             INI_Close(file);
  75.            
  76.        return 1;
  77.     }
  78.     RemoveBuildingForPlayer(playerid, 638, 1266.5469, -1557.6172, 13.2656, 0.25);
  79. RemoveBuildingForPlayer(playerid, 792, 1279.7344, -1552.9453, 12.2188, 0.25);
  80. RemoveBuildingForPlayer(playerid, 1231, 1273.6094, -1542.3750, 15.2344, 0.25);
  81. RemoveBuildingForPlayer(playerid, 638, 1266.5469, -1544.0000, 13.2656, 0.25);
  82. RemoveBuildingForPlayer(playerid, 638, 1266.5469, -1550.8828, 13.2656, 0.25);
  83. RemoveBuildingForPlayer(playerid, 638, 1266.5469, -1537.2969, 13.2656, 0.25);
  84. RemoveBuildingForPlayer(playerid, 792, 1280.0313, -1531.1406, 12.0703, 0.25);
  85. RemoveBuildingForPlayer(playerid, 638, 1266.5469, -1530.5859, 13.2656, 0.25);
  86. RemoveBuildingForPlayer(playerid, 1231, 1289.8906, -1520.1484, 15.1953, 0.25);
  87.     return 1;
  88. }
  89.  
  90. public OnPlayerDisconnect(playerid, reason)
  91. {
  92.    
  93.         new INI:file = INI_Open(Path(playerid));
  94.         INI_SetTag(file,"User's License");
  95.         INI_WriteInt(file,"License",gPlayer[playerid][license]);
  96.             return 1;
  97. }
  98. CMD:drivingtest(playerid,params[]){ //Making the command
  99.    new money;
  100.    money=GetPlayerMoney(playerid);
  101.    if(gPlayer[playerid][license]==1) return SendClientMessage(playerid, COLOR_RED,"You already have a driving license");
  102.    if(money<2000) return SendClientMessage(playerid, COLOR_RED,"You must have $2000 to begin driving test");
  103.    gPlayer[playerid][CP]=1;
  104.    SendClientMessage(playerid, COLOR_GREEN,"Instruction: Destination Saved. Make your way to the red marker to begin driving test.");
  105.    SetPlayerCheckpoint(playerid,1271.5436,-1545.9067,13.5648,4.0);
  106.  
  107.   return 1;
  108. }
  109.  
  110.  
  111. public OnVehicleDeath(vehicleid, killerid)
  112. {
  113.     return 1;
  114. }
  115.  
  116.  
  117. public OnPlayerStateChange(playerid, newstate, oldstate)
  118. {
  119.     return 1;
  120. }
  121.  
  122. public OnPlayerEnterCheckpoint(playerid)
  123. {
  124.   if(gPlayer[playerid][CP]==1){
  125.    DisablePlayerCheckpoint(playerid);
  126.   ShowPlayerDialog(playerid, 1, DIALOG_STYLE_MSGBOX, "Driving Test Approval","Are you sure you want to begin your driving test?","Yes","No");
  127.  
  128.   }
  129.   else if(gPlayer[playerid][CP]==2){
  130.   DisablePlayerCheckpoint(playerid);
  131.   gPlayer[playerid][CP]=3;
  132.   SetPlayerCheckpoint(playerid,1295.2511,-1602.4054,13.3828,4.0);
  133.   IsSpeeding(playerid);
  134.   }
  135.  
  136.   else if(gPlayer[playerid][CP]==3){
  137.   DisablePlayerCheckpoint(playerid);
  138.   gPlayer[playerid][CP]=4;
  139.   SetPlayerCheckpoint(playerid,1295.0060,-1654.1892,13.3828,4.0);
  140.  
  141.   }
  142.   else if(gPlayer[playerid][CP]==4){
  143.   DisablePlayerCheckpoint(playerid);
  144.   gPlayer[playerid][CP]=5;
  145.   SetPlayerCheckpoint(playerid,1295.4152,-1708.8987,13.3828,4.0);
  146.   IsSpeeding(playerid);
  147.  
  148.   }
  149.   else if(gPlayer[playerid][CP]==5){
  150.   DisablePlayerCheckpoint(playerid);
  151.   gPlayer[playerid][CP]=6;
  152.   SetPlayerCheckpoint(playerid,1256.7621,-1709.6104,13.3828,4.0);
  153.   }
  154.   else if(gPlayer[playerid][CP]==6){
  155.   DisablePlayerCheckpoint(playerid);
  156.   gPlayer[playerid][CP]=7;
  157.   SetPlayerCheckpoint(playerid,1201.9366,-1709.9708,13.3828,4.0);
  158.   IsSpeeding(playerid);
  159.   }
  160.   else if(gPlayer[playerid][CP]==7){
  161.   DisablePlayerCheckpoint(playerid);
  162.   gPlayer[playerid][CP]=8;
  163.   SetPlayerCheckpoint(playerid,1156.5132,-1709.4323,13.7813,4.0);
  164.  
  165.   }
  166.   else if(gPlayer[playerid][CP]==8){
  167.   DisablePlayerCheckpoint(playerid);
  168.   gPlayer[playerid][CP]=9;
  169.   SetPlayerCheckpoint(playerid,1109.7393,-1709.3726,13.3828,4.0);
  170.   IsSpeeding(playerid);
  171.   }
  172.   else if(gPlayer[playerid][CP]==9){
  173.   DisablePlayerCheckpoint(playerid);
  174.   gPlayer[playerid][CP]=10;
  175.   SetPlayerCheckpoint(playerid,1040.7274,-1709.6338,13.3828,4.0);
  176.   }
  177.   else if(gPlayer[playerid][CP]==10){
  178.   DisablePlayerCheckpoint(playerid);
  179.   gPlayer[playerid][CP]=11;
  180.   SetPlayerCheckpoint(playerid,1040.4951,-1673.3054,13.3828,4.0);
  181.   IsSpeeding(playerid);
  182.   }
  183.   else if(gPlayer[playerid][CP]==11){
  184.   DisablePlayerCheckpoint(playerid);
  185.   gPlayer[playerid][CP]=12;
  186.   SetPlayerCheckpoint(playerid,1039.7523,-1614.5819,13.3828,4.0);
  187.   }
  188.   else if(gPlayer[playerid][CP]==12){
  189.   DisablePlayerCheckpoint(playerid);
  190.   gPlayer[playerid][CP]=13;
  191.   SetPlayerCheckpoint(playerid,1050.4260,-1574.9825,13.3892,4.0);
  192.   IsSpeeding(playerid);
  193.   }
  194.   else if(gPlayer[playerid][CP]==13){
  195.   DisablePlayerCheckpoint(playerid);
  196.   gPlayer[playerid][CP]=14;
  197.   SetPlayerCheckpoint(playerid,1118.1987,-1574.7905,13.3966,4.0);
  198.   }
  199.   else if(gPlayer[playerid][CP]==14){
  200.  
  201.   DisablePlayerCheckpoint(playerid);
  202.   gPlayer[playerid][CP]=15;
  203.   SetPlayerCheckpoint(playerid,1147.7310,-1584.6283,13.3395,4.0);
  204.   IsSpeeding(playerid);
  205.   }
  206.   else if(gPlayer[playerid][CP]==15){
  207.   DisablePlayerCheckpoint(playerid);
  208.   gPlayer[playerid][CP]=16;
  209.   SetPlayerCheckpoint(playerid,1147.5430,-1629.2367,13.7813,4.0);
  210.   }
  211.   else if(gPlayer[playerid][CP]==16){
  212.   DisablePlayerCheckpoint(playerid);
  213.   gPlayer[playerid][CP]=17;
  214.   SetPlayerCheckpoint(playerid,1147.7458,-1704.4374,13.7813,4.0);
  215.   IsSpeeding(playerid);
  216.   }
  217.   else if(gPlayer[playerid][CP]==17){
  218.   DisablePlayerCheckpoint(playerid);
  219.   gPlayer[playerid][CP]=18;
  220.   SetPlayerCheckpoint(playerid,1181.2891,-1714.7313,13.5279,4.0);
  221.   IsSpeeding(playerid);
  222.   }
  223.   else if(gPlayer[playerid][CP]==18){
  224.   DisablePlayerCheckpoint(playerid);
  225.   gPlayer[playerid][CP]=19;
  226.   SetPlayerCheckpoint(playerid,1239.9648,-1715.3239,13.3828,4.0);
  227.   }
  228.   else if(gPlayer[playerid][CP]==19){
  229.   DisablePlayerCheckpoint(playerid);
  230.   gPlayer[playerid][CP]=20;
  231.   SetPlayerCheckpoint(playerid,1286.8646,-1714.1796,13.3828,4.0);
  232.   IsSpeeding(playerid);
  233.   }
  234.   else if(gPlayer[playerid][CP]==20){
  235.   DisablePlayerCheckpoint(playerid);
  236.   gPlayer[playerid][CP]=21;
  237.   SetPlayerCheckpoint(playerid,1300.1241,-1670.1123,13.3828,4.0);
  238.   IsSpeeding(playerid);
  239.  
  240.   }
  241.   else if(gPlayer[playerid][CP]==21){
  242.   DisablePlayerCheckpoint(playerid);
  243.   gPlayer[playerid][CP]=22;
  244.   SetPlayerCheckpoint(playerid,1300.7595,-1625.7065,13.3828,4.0);
  245.   IsSpeeding(playerid);
  246.   }
  247.   else if(gPlayer[playerid][CP]==22){
  248.   DisablePlayerCheckpoint(playerid);
  249.   gPlayer[playerid][CP]=23;
  250.   SetPlayerCheckpoint(playerid,1300.3802,-1570.8374,13.3828,4.0);
  251.  
  252.   }
  253.   else if(gPlayer[playerid][CP]==23){
  254.   DisablePlayerCheckpoint(playerid);
  255.   gPlayer[playerid][CP]=24;
  256.   SetPlayerCheckpoint(playerid,1271.1886,-1570.4200,13.3828,4.0);
  257.   IsSpeeding(playerid);
  258.   }
  259.   else if(gPlayer[playerid][CP]==24){  
  260.   DisablePlayerCheckpoint(playerid);
  261.   gPlayer[playerid][CP]=25;
  262.   SetPlayerCheckpoint(playerid,1271.5436,-1545.9067,13.5648,4.0);
  263.   }
  264.  else if(gPlayer[playerid][CP]==25){
  265.   DisablePlayerCheckpoint(playerid);
  266.   new Float:health;
  267.   new vehid = GetPlayerVehicleID(playerid);
  268.     GetVehicleHealth(vehid, health);
  269.   if(health>VEH_DAMAGE && gPlayer[playerid][speeding]<MAX_SPEEDING){
  270.   SendClientMessage(playerid, COLOR_BLUE,"Congratulations! You have successfully acquired your driving license");
  271.   gPlayer[playerid][license] = 1;
  272.   new vehicleid = GetPlayerVehicleID(playerid);
  273.   DestroyVehicle(vehicleid);
  274.   }
  275.   else{
  276.   SendClientMessage(playerid, COLOR_RED,"Sorry! But you failed driving test, Try again to get your driving license");
  277.   new vehicleid = GetPlayerVehicleID(playerid);
  278.   DestroyVehicle(vehicleid);
  279.   }
  280.     return 1;
  281. }
  282. return 1;
  283. }
  284.  
  285.  
  286. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  287. {
  288.   if(dialogid==1){
  289.     if(response){
  290.     gPlayer[playerid][CP]=2;
  291.     SetPlayerCheckpoint(playerid,1282.1848,-1574.9357,13.3828,4.0);
  292.      ncar[playerid]=AddStaticVehicle(VEHICLE_ID,1271.5435,-1545.9233,13.1358,177.9724,0,0);
  293.      PutPlayerInVehicle(playerid, ncar[playerid], 0);
  294.      SendClientMessage(playerid, COLOR_GREEN,"Instruction: Your driving test has started. Drive carefully on the right lane(Make your way through Checkpoints)");
  295.      }
  296.      else{
  297.      SendClientMessage(playerid,COLOR_RED,"Rejected: It seems you don't want to have driving test");
  298.      }
  299.   }
  300.     return 1;
  301. }
  302.  
  303. GetVehicleSpeed(vehicleid)
  304. {
  305.     new Float:Vx, Float:Vy, Float:Vz;
  306.     GetVehicleVelocity(vehicleid, Vx, Vy, Vz);
  307.     new Float:rtn;
  308.     rtn = floatsqroot(floatpower(Vx*100,2) + floatpower(Vy*100,2));
  309.     rtn = floatsqroot(floatpower(rtn,2) + floatpower(Vz*100,2));
  310.     return floatround(rtn);
  311. }
  312.  
  313. stock IsSpeeding(playerid)
  314. {
  315. if(GetVehicleSpeed(ncar[playerid])>MINI_SPEED)
  316. {
  317. gPlayer[playerid][speeding]++;
  318. SendClientMessage(playerid, COLOR_RED, "Slow down! Or You will Fail your driving test!");
  319. }
  320. }
  321.  
  322. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  323. {
  324. if(gPlayer[playerid][license]==0){
  325.  ClearAnimations(playerid);
  326.  SendClientMessage(playerid, COLOR_RED,"Driving License: You need a Driving license to drive vehicles. Type /drivingtest to get your driver's license");
  327. }
  328.  
  329. return 1;
  330. }
  331.  
  332. stock Path(playerid)
  333. {
  334.     new str[128],name[MAX_PLAYER_NAME];
  335.     GetPlayerName(playerid,name,sizeof(name));
  336.     format(str,sizeof(str),UserPath,name);
  337.     return str;
  338. }
  339.  
  340. forward loadaccount_user(playerid, name[], value[]);
  341. public loadaccount_user(playerid, name[], value[])
  342. {
  343.  
  344.     INI_Int("License",gPlayer[playerid][license]);
  345.     return 1;
  346. }
Add Comment
Please, Sign In to add comment