Advertisement
brauf

[FS] Taxi Job

Aug 15th, 2018
1,992
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 10.57 KB | None | 0 0
  1. /* MADE BY BRAUF OF SA-MP FORUMS */
  2.  
  3. #include <a_samp>
  4. #include <pawn.cmd> // replace this with #include <izcmd>
  5.  
  6. #define MAX_FARE_ACTORS 999
  7.  
  8. new Text3D:PassengerLabel[MAX_VEHICLES];
  9.  
  10. new bool:DestinationCheckpointCheck[MAX_PLAYERS];
  11.  
  12. new Float:gFareCollection[][3] =
  13. {
  14.     {1958.3783,1343.1572,15.3746},
  15.     {2199.6531,1393.3678,10.8203},
  16.     {2483.5977,1222.0825,10.8203},
  17.     {2637.2712,1129.2743,11.1797},
  18.     {2000.0106,1521.1111,17.0625},
  19.     {2024.8190,1917.9425,12.3386},
  20.     {2261.9048,2035.9547,10.8203},
  21.     {2262.0986,2398.6572,10.8203},
  22.     {2244.2566,2523.7280,10.8203},
  23.     {2335.3228,2786.4478,10.8203},
  24.     {2150.0186,2734.2297,11.1763},
  25.     {2158.0811,2797.5488,10.8203},
  26.     {1969.8301,2722.8564,10.8203},
  27.     {1652.0555,2709.4072,10.8265},
  28.     {1564.0052,2756.9463,10.8203},
  29.     {1271.5452,2554.0227,10.8203},
  30.     {1441.5894,2567.9099,10.8203},
  31.     {1480.6473,2213.5718,11.0234},
  32.     {1400.5906,2225.6960,11.0234},
  33.     {1598.8419,2221.5676,11.0625},
  34.     {1318.7759,1251.3580,10.8203},
  35.     {1558.0731,1007.8292,10.8125},
  36.     {1705.2347,1025.6808,10.8203}
  37. };
  38.  
  39. new Float:gFareDestination[][3] =
  40. {
  41.     {-857.0551,1536.6832,22.5870},
  42.     {817.3494,856.5039,12.7891},
  43.     {116.9315,1110.1823,13.6094},
  44.     {-18.8529,1176.0159,19.5634},
  45.     {-315.0575,1774.0636,43.6406}
  46. };
  47.  
  48.  
  49. new fare_actor[MAX_FARE_ACTORS];
  50.  
  51. public OnFilterScriptInit()
  52. {
  53.  
  54.     for(new id; id < MAX_FARE_ACTORS; id++)
  55.     {
  56.         fare_actor[id] = CreateActor(id, 0.0, 0.0, 0.0, 1.0);
  57.         ApplyActorAnimation(fare_actor[id], "CAR", "Sit_relaxed", 0, 0, 0, 0, 0, 0);
  58.         printf("Created actor %i", fare_actor[id]);
  59.     }
  60.  
  61.     return 1;
  62. }
  63.  
  64. public OnFilterScriptExit()
  65. {
  66.     for(new id; id < MAX_FARE_ACTORS; id++)
  67.     {
  68.         DestroyActor(fare_actor[id]);
  69.     }  
  70.  
  71.     return 1;
  72. }
  73.  
  74.  
  75.  
  76. #define HOLDING(%0) \
  77.     ((newkeys & (%0)) == (%0))
  78.  
  79.  
  80. #define PRESSED(%0) \
  81.     (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  82.  
  83.  
  84. #define PRESSING(%0,%1) \
  85.     (%0 & (%1))
  86.  
  87. //new ActorFollowDriverTimer[MAX_PLAYERS];
  88.  
  89. new IsPlayerTaxiDriver[MAX_PLAYERS] = false;
  90.  
  91. new IsPlayerDoingAFare[MAX_PLAYERS] = false;
  92.  
  93. new TotalFaresEarnedInSession[MAX_PLAYERS] = 0;
  94.  
  95. new TotalFaresDoneInSession[MAX_PLAYERS] = 0;
  96.  
  97. new TotalAngryClientsInSession[MAX_PLAYERS] = 0;
  98.  
  99. new MoneyEarntInThisFare[MAX_PLAYERS] = 0;
  100.  
  101. new HasClientBeenAlerted[MAX_PLAYERS] = false;
  102.  
  103.  
  104. CMD:taxi(playerid, params[])
  105. {
  106.     if(IsPlayerInTaxi(playerid))
  107.     {
  108.         if(IsPlayerTaxiDriver[playerid])
  109.         {
  110.             new TaxiSessionMessage[364];
  111.  
  112.             IsPlayerTaxiDriver[playerid] = false; // player is no longer a taxi driver
  113.  
  114.             format(TaxiSessionMessage, sizeof(TaxiSessionMessage), "{98FF98} [TAXI]:{FFFFFF} Your current taxi session has ended and you have earnt a total amount of %i with %i unhappy customers out of %i customers.", TotalFaresEarnedInSession[playerid], TotalAngryClientsInSession[playerid], TotalFaresDoneInSession[playerid]);
  115.             SendClientMessage(playerid, -1, TaxiSessionMessage);
  116.  
  117.             return 1;
  118.         }
  119.  
  120.         if(!IsPlayerTaxiDriver[playerid])
  121.         {
  122.             HasClientBeenAlerted[playerid] = false;
  123.  
  124.             IsPlayerTaxiDriver[playerid] = true; // player is a taxi driver
  125.  
  126.             TotalFaresEarnedInSession[playerid] = 0; // reset the money earnt from the last session
  127.  
  128.             MoneyEarntInThisFare[playerid] = 0;
  129.  
  130.             TotalFaresDoneInSession[playerid] = 0;
  131.  
  132.             TotalAngryClientsInSession[playerid] = 0;
  133.  
  134.             IsPlayerDoingAFare[playerid] = false;
  135.  
  136.             SendClientMessage(playerid, -1, "{98FF98} [TAXI]:{FFFFFF} You are now a taxi driver.");
  137.             SendClientMessage(playerid, -1, "{98FF98} [TAXI]:{FFFFFF} Press Y to pick-up a fare. After you complete your fare, press Y again.");
  138.        
  139.             return 1;
  140.         }
  141.     }
  142.  
  143.     SendClientMessage(playerid, -1, "{98FF98} [TAXI]:{FFFFFF} You are not in a taxi.");
  144.  
  145.     return 1;
  146.  
  147. }
  148.  
  149.  
  150. CMD:taxistats(playerid, params[])
  151. {
  152.     new TaxiSessionMessage[364];
  153.     format(TaxiSessionMessage, sizeof(TaxiSessionMessage), "{98FF98} [TAXI]:{FFFFFF} You have earnt a total amount of %i with %i unhappy customers out of %i customers.", TotalFaresEarnedInSession[playerid], TotalAngryClientsInSession[playerid], TotalFaresDoneInSession[playerid]);
  154.     SendClientMessage(playerid, -1, TaxiSessionMessage);
  155.  
  156.  
  157. }
  158.  
  159.  
  160. public OnPlayerStateChange(playerid, newstate, oldstate)
  161. {
  162.     if(oldstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_ONFOOT) // player gets out of car
  163.     {
  164.         if(IsPlayerTaxiDriver[playerid])
  165.         {
  166.             SetActorPos(fare_actor[playerid], 0, 0, 0);
  167.  
  168.             HasClientBeenAlerted[playerid] = false;
  169.             IsPlayerTaxiDriver[playerid] = false;
  170.             IsPlayerDoingAFare[playerid] = false;
  171.             DestinationCheckpointCheck[playerid] = false;
  172.  
  173.             DisablePlayerCheckpoint(playerid);
  174.             new v_id = GetPlayerVehicleID(playerid);
  175.             Delete3DTextLabel(PassengerLabel[v_id]);
  176.  
  177.             SendClientMessage(playerid, -1, "{98FF98} [TAXI]:{FFFFFF} You are no longer a taxi driver since you have left the vehicle.");
  178.             return 1;
  179.         }
  180.  
  181.         new v_id = GetPlayerVehicleID(playerid);
  182.         Delete3DTextLabel(PassengerLabel[v_id]);
  183.  
  184.         return 1;
  185.     }
  186.     return 1;
  187. }
  188.  
  189. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  190. {
  191.     if(PRESSED(KEY_YES))
  192.     {
  193.         if(IsPlayerTaxiDriver[playerid] && !IsPlayerDoingAFare[playerid])
  194.         {
  195.             SendClientMessage(playerid, -1, "{98FF98} [TAXI]:{FFFFFF} We have found you a fare, pelase collect the client.");
  196.             IsPlayerDoingAFare[playerid] = true;
  197.             printf("actor_fare for id: %i is actor_fare[%i]", playerid, playerid);
  198.  
  199.  
  200.             new rand_actor_spawn = random(sizeof(gFareCollection));
  201.             SetActorPos(fare_actor[playerid], gFareCollection[rand_actor_spawn][0], gFareCollection[rand_actor_spawn][1], gFareCollection[rand_actor_spawn][2]);
  202.            
  203.             ApplyActorAnimation(fare_actor[playerid], "CAR", "Sit_relaxed", 4.1, 0, 0, 0, 0, 0);
  204.            
  205.             new Float:actor_x, Float:actor_y, Float:actor_z;
  206.             GetActorPos(fare_actor[playerid], Float:actor_x, Float:actor_y, Float:actor_z);
  207.             SetPlayerCheckpoint(playerid, Float:actor_x, Float:actor_y, Float:actor_z, 2);
  208.  
  209.             SendClientMessage(playerid, -1, "{98FF98} [TAXI]:{FFFFFF} When you are near your client, press H [horn] to alert them you are here.");
  210.             return 1;
  211.         }
  212.         return 1;
  213.     }
  214.  
  215.     if(IsPlayerTaxiDriver[playerid] && IsPlayerDoingAFare[playerid] && !HasClientBeenAlerted[playerid])
  216.     {
  217.         if((newkeys & (KEY_CROUCH)) == (KEY_CROUCH))
  218.         {
  219.             new Float:actor_x, Float:actor_y, Float:actor_z;
  220.             GetActorPos(fare_actor[playerid], Float:actor_x, Float:actor_y, Float:actor_z);
  221.  
  222.             new Float:player_x, Float:player_y, Float:player_z;
  223.             GetPlayerPos(playerid, Float:player_x, Float:player_y, Float:player_z);
  224.             if(IsPlayerInRangeOfPoint(playerid, Float:5.0, Float:actor_x, Float:actor_y, Float:actor_z))
  225.             {
  226.                 HasClientBeenAlerted[playerid] = true;
  227.                 SendClientMessage(playerid, -1, "{98FF98} [TAXI]:{FFFFFF} The client has been alerted, please wait for them to enter your vehicle.");
  228.                 ApplyActorAnimation(fare_actor[playerid], "CAR", "Sit_relaxed", 2.3, 0, 0, 0, 1, 5000000);
  229.                 SetActorPos(fare_actor[playerid], Float:player_x, Float:player_y-0.7, Float:player_z);
  230.  
  231.                 //ActorFollowDriverTimer[playerid] = SetTimerEx("ActorInPlayersCar", 250, true, "i", playerid);
  232.  
  233.                 SendClientMessage(playerid, -1, "");
  234.                
  235.  
  236.                 new rand_actor_destination = random(sizeof(gFareDestination));
  237.                 SetPlayerCheckpoint(playerid, gFareDestination[rand_actor_destination][0], gFareDestination[rand_actor_destination][1], gFareDestination[rand_actor_destination][2], 3);
  238.                 DestinationCheckpointCheck[playerid] = true;
  239.                 SetActorPos(fare_actor[playerid], 0, 0, 0);
  240.                 new v_id = GetPlayerVehicleID(playerid);
  241.                 PassengerLabel[v_id] = Create3DTextLabel("Passenger", 0xFFFFF0,  0.0, 0.0, 0.0, 50.0, 0, 1);
  242.                 Attach3DTextLabelToVehicle(PassengerLabel[v_id], v_id, 0.0, -0.7, 1);
  243.                 return 1;
  244.             }
  245.             print("horn");
  246.             return 1;
  247.         }
  248.     }
  249.     return 1;
  250. }
  251.  
  252.  
  253. public OnPlayerEnterCheckpoint(playerid)
  254. {
  255.     if(DestinationCheckpointCheck[playerid])
  256.     {
  257.         new Float:vhealth;
  258.         new veh = GetPlayerVehicleID(playerid);
  259.         GetVehicleHealth(veh, vhealth);
  260.  
  261.         if(veh > 999)
  262.         {
  263.             TotalFaresDoneInSession[playerid] += 1;
  264.             MoneyEarntInThisFare[playerid] = randomEx(250, 650);
  265.             GivePlayerMoney(playerid, MoneyEarntInThisFare[playerid]);
  266.         }
  267.  
  268.         if(veh > 640 && veh < 999)
  269.         {
  270.             TotalFaresDoneInSession[playerid] += 1;
  271.             MoneyEarntInThisFare[playerid] = randomEx(244, 540);
  272.             GivePlayerMoney(playerid, MoneyEarntInThisFare[playerid]);
  273.         }
  274.  
  275.         if(veh > 350 && veh < 640)
  276.         {
  277.             TotalFaresDoneInSession[playerid] += 1;
  278.             MoneyEarntInThisFare[playerid] = randomEx(125, 366);
  279.             GivePlayerMoney(playerid, MoneyEarntInThisFare[playerid]);
  280.  
  281.             TotalAngryClientsInSession[playerid] += 1;
  282.         }
  283.  
  284.         if(veh > 0 && veh < 350)
  285.         {
  286.             TotalFaresDoneInSession[playerid] += 1;
  287.             MoneyEarntInThisFare[playerid] = randomEx(99, 233);
  288.             GivePlayerMoney(playerid, MoneyEarntInThisFare[playerid]);
  289.  
  290.             TotalAngryClientsInSession[playerid] += 1;
  291.         }
  292.  
  293.         else
  294.         {
  295.             MoneyEarntInThisFare[playerid] = randomEx(150, 600);
  296.             GivePlayerMoney(playerid, MoneyEarntInThisFare[playerid]);
  297.         }
  298.  
  299.         IsPlayerDoingAFare[playerid] = false;
  300.  
  301.         DestinationCheckpointCheck[playerid] = false;
  302.  
  303.         HasClientBeenAlerted[playerid] = false;
  304.  
  305.         TotalFaresEarnedInSession[playerid] = TotalFaresEarnedInSession[playerid] + MoneyEarntInThisFare[playerid];
  306.  
  307.         TotalFaresDoneInSession[playerid] += 1;
  308.  
  309.         DisablePlayerCheckpoint(playerid);
  310.  
  311.         new v_id = GetPlayerVehicleID(playerid);
  312.         Delete3DTextLabel(PassengerLabel[v_id]);
  313.  
  314.        
  315.         new TaxiDoneMessage[144];
  316.         format(TaxiDoneMessage, sizeof(TaxiDoneMessage), "{98FF98} [TAXI]:{FFFFFF} You have earnt a amount of $%i for this fare.", MoneyEarntInThisFare[playerid]);
  317.         SendClientMessage(playerid, -1, TaxiDoneMessage);
  318.  
  319.         return 1;
  320.     }
  321.  
  322.     return 1;
  323. }
  324. /*forward ActorInPlayersCar(playerid);
  325. public ActorInPlayersCar(playerid)
  326. {
  327.     if(IsPlayerDoingAFare[playerid] && HasClientBeenAlerted[playerid])
  328.     {
  329.         new Float:player_x, Float:player_y, Float:player_z;
  330.         GetPlayerPos(playerid, Float:player_x, Float:player_y, Float:player_z);
  331.         //SetActorPos(fare_actor[playerid], Float:player_x, Float:player_y-0.7, Float:player_z);
  332.         return 1;
  333.     }
  334.     else
  335.     {
  336.         SetActorPos(fare_actor[playerid], 0, 0, 0);
  337.         KillTimer(ActorFollowDriverTimer[playerid]);
  338.     }
  339.  
  340.     return 1;
  341. }*/
  342.  
  343.  
  344. IsPlayerInTaxi(playerid)
  345. {
  346.     if(!IsPlayerInAnyVehicle(playerid)) return false;
  347.     if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT) return false;
  348.     if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 420 || 438 && GetPlayerVehicleSeat(playerid) == 0) return true;
  349.     return true;
  350. }
  351.  
  352. randomEx(min, max)
  353. {    
  354.     //Credits to y_less    
  355.     new rand = random(max-min)+min;    
  356.     return rand;
  357. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement