SHARE
TWEET

Untitled

a guest Jun 17th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* www.cityofangels-roleplay.com - Pilot System - by Salesman */
  2.  
  3. #include <YSI\y_hooks>
  4. //=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ (define)
  5. #define MAX_ROUTES  (10) // Maximalna mogučnost kreiranja ruta.
  6. #define JOB_PILOT   (17) // Job_ID
  7. //=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ (enums)
  8. enum ENUM_ROUTE {
  9.     rID,
  10.     rName[MAX_PLAYER_NAME],
  11.     Float:rPosX,
  12.     Float:rPosY,
  13.     Float:rPosZ,
  14.     rPay
  15. }
  16. new rInfo[MAX_ROUTES][ENUM_ROUTE];
  17.  
  18. /*enum{ -> prebačeno u coarp.pwn
  19.     DIALOG_JOB_START,
  20.     DIALOG_CREATE_ROUTE,
  21.     DIALOG_ROUTE_NAME,
  22.     DIALOG_ROUTES
  23. }*/
  24.  
  25. enum {
  26.         load_passangers     = 997,
  27.         take_pay            = 998,
  28.         INVALID_PILOT_CP    = 999
  29. }
  30. //=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ (vars & iters & rBits)
  31. new
  32.     plane[1],
  33.     cpstatus[MAX_PLAYERS]       = INVALID_PILOT_CP,
  34.     proggres[MAX_PLAYERS]       = 0,
  35.     exit_timer[MAX_PLAYERS]     = 0,
  36.     Route_number[MAX_PLAYERS]   = 0,
  37.     route[MAX_PLAYERS]          = -1,
  38.     route_edit[MAX_PLAYERS]     = -1,
  39.    
  40.     Iterator:PILOT<MAX_ROUTES>;
  41.  
  42. new
  43.     Bit1: JobStarted <MAX_PLAYERS>  = Bit1: false;
  44.    
  45. //=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ (functions)
  46. ControlPlayerJob(job_id = JOB_PILOT, route_id = -1, playerid, bool: work) {
  47.     if(PlayerInfo[playerid][pJob] != job_id)
  48.         return (true);
  49.  
  50.     if(work == false) {
  51.         Bit1_Set(JobStarted, playerid, false);
  52.         proggres[playerid]      = (0);
  53.         route[playerid]         = (-1);
  54.         cpstatus[playerid]      = INVALID_PILOT_CP;
  55.        
  56.         DeletePreciseTimer(exit_timer[playerid]);
  57.        
  58.         SetVehicleToRespawn(plane[0]);
  59.         SetVehicleVirtualWorld(plane[0], 0);
  60.         SetPlayerVirtualWorld(playerid, 0);
  61.         DisablePlayerCheckpoint(playerid);
  62.     }
  63.     else if(work == true) {
  64.         SetPlayerCheckpoint(playerid, rInfo[route_id][rPosX], rInfo[route_id][rPosY],rInfo[route_id][rPosZ], 20.0 );
  65.         SendClientMessage(playerid, -1,"Ruta je oznacena crveno na mapi.");
  66.     }
  67.     return (true);
  68. }
  69.  
  70. CheckPilotRoutes() {
  71.     new winfo[256],
  72.         motd[64];
  73.        
  74.     format(motd, sizeof(motd), "\n");
  75.     strcat(winfo, motd, sizeof(winfo));
  76.    
  77.     foreach(new i : PILOT) {
  78.         if( rInfo[ i ][ rPay ] != 0 ) {
  79.             format(motd, sizeof(motd), "{3C95C2}[RUTA %d]:{FFFFFF} %s.\n", rInfo[i][rID], rInfo[ i ][ rName ]);
  80.             strcat(winfo, motd, sizeof(winfo));
  81.         }
  82.     }
  83.     return winfo;
  84. }
  85. //=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ (hooks)
  86. hook OnGameModeInit(){
  87.     msyql_loadroutes();
  88.     CreatePilotVehicles();
  89.     return (true);
  90. }
  91.  
  92. hook OnPlayerStateChange(playerid, newstate, oldstate) {
  93.     if(newstate == PLAYER_STATE_DRIVER) {
  94.         if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 519) {
  95.             if(PlayerInfo[playerid][pJob] != JOB_PILOT)
  96.                 return SendErrorMessage(playerid, "Niste zaposleni kao Pilot."), RemovePlayerFromVehicle(playerid);
  97.            
  98.             if(Bit1_Get(JobStarted, playerid))
  99.                 return DeletePreciseTimer(exit_timer[playerid]), SendClientMessage(playerid, COLOR_GREEN,"[INFO]: Dobrodosli nazad u vase vozilo.");       
  100.                
  101.             ShowPlayerDialog(playerid, DIALOG_JOB_START, DIALOG_STYLE_MSGBOX, "Starting job", "Usli ste u poslovno vozilo (pilot)\nDa li zelite da pokrenete posao?\nKo-pilot sjedi do vas cekajuci na znak.", "Prihvati", "Odustani");
  102.         }
  103.     }
  104.     return (true);
  105. }
  106.  
  107. hook OnPlayerExitVehicle(playerid, vehicleid){
  108.     if(vehicleid == plane[0] && Bit1_Get(JobStarted, playerid)) {
  109.         SendClientMessage(playerid, -1, "Napustili ste vozilo. Imate 30 sekundi da se vratite u njega ili ce te prekinuti posao.");
  110.         exit_timer[playerid] = SetPreciseTimer("VehTimer", 30000, false, "d", playerid);
  111.     }
  112.     return (true);
  113. }
  114.  
  115. hook OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]){
  116.     switch(dialogid){
  117.         case DIALOG_JOB_START:
  118.         {
  119.             if(!response)
  120.                 return SendClientMessage(playerid, -1,"Odustali ste od posla."), RemovePlayerFromVehicle(playerid);
  121.             if(response) {
  122.                 if(Iter_Count(PILOT) == 0)
  123.                     return SendErrorMessage(playerid, "Trenutno nema kreiranih ruta."), RemovePlayerFromVehicle(playerid);
  124.            
  125.                 new virtualworld = random(random(999));
  126.                 TogglePlayerControllable(playerid, 0);
  127.                 SetVehicleVirtualWorld(plane[0], virtualworld);
  128.                 SetPlayerVirtualWorld(playerid, virtualworld);
  129.                
  130.                 Bit1_Set(JobStarted, playerid, true);
  131.                
  132.                 SetPreciseTimer("PaljenjeAviona", 5000, false, "i", playerid);
  133.                 GameTextForPlayer(playerid, "Avion se pali", 5000, 5);
  134.             }
  135.         }
  136.         case DIALOG_CREATE_ROUTE:
  137.         {
  138.             if(!response) return (true);
  139.             if(response){
  140.                 new Float:x, Float:y, Float:z, pay,
  141.                     free_id = Iter_Free(PILOT), DB_Query[256];
  142.                    
  143.                 GetPlayerPos(playerid, x, y, z);
  144.                 if(sscanf(inputtext, "i", pay)) return ShowPlayerDialog(playerid, DIALOG_CREATE_ROUTE, DIALOG_STYLE_INPUT, "Route pay", "Koliko para zelite da bude plata na ruti?", "Unesi", "Odustani");
  145.                 if(pay < 1) return ShowPlayerDialog(playerid, DIALOG_CREATE_ROUTE, DIALOG_STYLE_INPUT, "Route pay", "Koliko para zelite da bude plata na ruti?", "Unesi", "Odustani");
  146.                
  147.                 // Create Route
  148.                 route_edit[playerid] = free_id;
  149.                 rInfo[free_id][rID] = free_id;
  150.                
  151.                 rInfo[free_id][rPosX] = x;
  152.                 rInfo[free_id][rPosY] = y;
  153.                 rInfo[free_id][rPosZ] = z;
  154.                 rInfo[free_id][rPay] = pay;
  155.                
  156.                 mysql_format(g_SQL, DB_Query, sizeof DB_Query, "INSERT INTO `ROUTES` (`NAME`, `POSX`, `POSY`, `POSZ`, `PAY`) VALUES ('N/A','%f','%f','%f','%d')", x,y,z, pay);
  157.                 mysql_tquery(g_SQL, DB_Query, "OnRouteCreated", "ii", playerid, free_id);
  158.                
  159.                 // continue...
  160.                 ShowPlayerDialog(playerid, DIALOG_ROUTE_NAME, DIALOG_STYLE_INPUT, "Route name", "Ime rute: ", "Unesi", "Odustani");
  161.                
  162.             }
  163.         }
  164.         case DIALOG_ROUTE_NAME:
  165.         {
  166.             if(!response) return ShowPlayerDialog(playerid, DIALOG_ROUTE_NAME, DIALOG_STYLE_INPUT, "Route name", "Ime rute: ", "Unesi", "Odustani");
  167.             if(response){
  168.                 new name[24], DB_Query[128],
  169.                     get_id = route_edit[playerid];
  170.                 if(sscanf(inputtext, "s[24]", name)) return ShowPlayerDialog(playerid, DIALOG_ROUTE_NAME, DIALOG_STYLE_INPUT, "Route name", "Ime rute: ", "Unesi", "Odustani");
  171.                
  172.                 SetString(rInfo[get_id][rName], name);
  173.                
  174.                 format(DB_Query, sizeof(DB_Query), "UPDATE `ROUTES` SET `NAME` = '%s' WHERE `rID` = '%d'", rInfo[get_id][rName], rInfo[get_id][rID]);
  175.                 mysql_tquery(g_SQL, DB_Query);
  176.                
  177.                 // Return
  178.                 va_SendClientMessage(playerid, COLOR_YELLOW, "[INFO]: Uspjesno ste kreirali rutu '%s', plata: %s.", rInfo[get_id][rName], FormatNumber(rInfo[get_id][rPay]));
  179.                
  180.                 route_edit[playerid] = INVALID_PLAYER_ID;
  181.             }
  182.         }
  183.         case DIALOG_ROUTES: {
  184.             if(response){
  185.                 new number = listitem += 1;
  186.                 for( new route_id; route_id < MAX_ROUTES; route_id ++ ) {
  187.                     if( rInfo[ route_id ][ rPay ] != 0 )
  188.                     {
  189.                         if( Route_number[ route_id ] == number )
  190.                         {
  191.                             ControlPlayerJob(JOB_PILOT, route_id, playerid, true);
  192.                             break;
  193.                         }
  194.                     }
  195.                 }
  196.             }
  197.         }
  198.     }
  199.     return (true);
  200. }
  201.  
  202. hook OnPlayerDeath(playerid) {
  203.     if(Bit1_Get(JobStarted, playerid))
  204.         ControlPlayerJob(JOB_PILOT, -1, playerid, false);
  205.    
  206.     return (true);
  207. }
  208.  
  209. hook OnPlayerDisconnect(playerid, reason){
  210.     if(Bit1_Get(JobStarted, playerid))
  211.         ControlPlayerJob(JOB_PILOT, -1, playerid, false);
  212.     return (true);
  213. }
  214.  
  215. hook OnPlayerConnect(playerid)
  216.     return ControlPlayerJob(JOB_PILOT, -1, playerid, false);
  217.  
  218.  
  219. hook OnPlayerEnterCheckpoint(playerid){
  220.     if(cpstatus[playerid] == load_passangers){
  221.         TogglePlayerControllable(playerid, 0);
  222.         SetPreciseTimer("UtovarPutnika", 15000, false, "d", playerid);
  223.         GameTextForPlayer(playerid, "Utovar putnika", 15000, 5);
  224.         DisablePlayerCheckpoint(playerid);
  225.     }
  226.     else if(cpstatus[playerid] == take_pay){
  227.         AC_GivePlayerMoney(playerid, rInfo[route[playerid]][rPay]);
  228.         SendClientMessage(playerid, -1, "Zavrsili ste rutu i uzeli odredjenu svotu novca.");
  229.        
  230.         // reset
  231.         ControlPlayerJob(JOB_PILOT, -1, playerid, false);
  232.     }
  233.     if(route[playerid] != -1){
  234.         TogglePlayerControllable(playerid, 0);
  235.         SetPreciseTimer("IstovarPutnika", 15000, false, "d", playerid);
  236.         GameTextForPlayer(playerid, "Istovar putnika", 15000, 5);
  237.         DisablePlayerCheckpoint(playerid);
  238.     }
  239.     return (true);
  240. }
  241.  
  242. CreatePilotVehicles() { // in-game kreirati ostala vozila (L3o)
  243.     plane[0] = CreateVehicle(519, 1794.8909, -2426.1665, 14.6257, -127.0000, -1, -1, 100);
  244.     VehicleInfo[plane[0]][vHealth] = 1000.0;
  245.     VehicleInfo[plane[0]][vFuel] = 100;
  246.     VehicleInfo[plane[0]][vCanStart] = 1;
  247.     VehicleInfo[plane[0]][vUsage] = VEHICLE_USAGE_NORMAL;
  248.     return (true);
  249. }
  250. //=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ (timers)
  251. Function: PaljenjeAviona(playerid){
  252.     SetPlayerCheckpoint(playerid, 1543.6648, -2448.0859, 14.6257, 3.0); // utovar
  253.     TogglePlayerControllable(playerid, 1); // dajemo kontrolu
  254.     SendClientMessage(playerid, -1, "Idite na oznaceno mjesto na vasem GPS-u, pokupite putnike.");
  255.     cpstatus[playerid] = load_passangers;
  256.     return (true);
  257. }
  258.  
  259. Function: VehTimer(playerid) {
  260.     if(GetPlayerVehicleID(playerid) == INVALID_VEHICLE_ID){
  261.         SendClientMessage(playerid,-1, "Prekinuli ste posao jer se niste vratili u vozilo.");
  262.         ControlPlayerJob(JOB_PILOT, -1, playerid, false);
  263.     }
  264.     return (true);
  265. }
  266.  
  267. Function: UtovarPutnika(playerid) {
  268.     TogglePlayerControllable(playerid, 1);
  269.     proggres[playerid] = 1;
  270.    
  271.     SendClientMessage(playerid, -1,"Sada koristite komandu /plane takecoords");
  272.     return (true);
  273. }
  274.  
  275. Function: IstovarPutnika(playerid) {
  276.     TogglePlayerControllable(playerid, 1);
  277.     proggres[playerid] = 0;
  278.     SendClientMessage(playerid, -1,"Sada se vratite nazad za platu.");
  279.     SetPlayerCheckpoint( playerid, 1644.0344, -2489.8647, 13.6025, 4.0 );
  280.     cpstatus[playerid] = take_pay;
  281.     route[playerid] = -1;
  282.     return (true);
  283. }
  284.  
  285. //=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ (mysql)
  286. Function: OnRouteCreated(playerid, free_iter) {
  287.     rInfo[free_iter][rID] = cache_insert_id();
  288.     Iter_Add(PILOT, free_iter);
  289.     return (true);
  290. }
  291.  
  292. msyql_loadroutes() {   
  293.     mysql_tquery(g_SQL, "SELECT * FROM `ROUTES`", "OnRouteLoaded", "");
  294.     return (true);
  295. }
  296.  
  297. Function: OnRouteLoaded() {
  298.     new
  299.         rows = cache_num_rows();
  300.     if(rows == 0) return (true);
  301.     for (new i = 0; i < rows; i++) {   
  302.         cache_get_value_name_int(i,     "rID",      rInfo[i][rID]);
  303.         cache_get_value_name_int(i,     "NAME",     rInfo[i][rName]);
  304.         cache_get_value_name_int(i,     "PAY",      rInfo[i][rPay]);
  305.        
  306.         cache_get_value_name_float(i,   "POSX",     rInfo[i][rPosX]);
  307.         cache_get_value_name_float(i,   "POSY",     rInfo[i][rPosY]);
  308.         cache_get_value_name_float(i,   "POSZ",     rInfo[i][rPosZ]);
  309.        
  310.         Iter_Add(PILOT, i);
  311.     }
  312.     printf("(debug report): Created %d/%d pilot routes.", Iter_Count(PILOT), MAX_ROUTES);
  313.     return (true);
  314. }
  315. //=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ (commands)
  316. CMD:plane(playerid, params[])
  317. {
  318.     new action[25];
  319.            
  320.     if(sscanf(params, "s[25] ", action))
  321.     {
  322.         SendClientMessage(playerid, -1, "[INFO]: /plane [option].");
  323.         SendClientMessage(playerid, 0xAFAFAFAA, "(options): takeroute, info, quit.");
  324.         if(PlayerInfo[playerid][pAdmin] != 0)
  325.             SendClientMessage(playerid, 0xAFAFAFAA, "(options): createroute.");
  326.         return (true);
  327.     }
  328.    
  329.     if(strcmp(action,"takeroute", true) == 0) {
  330.         if(Iter_Count(PILOT) == 0)
  331.             return SendErrorMessage(playerid, "Trenutno nema kreiranih ruta.");
  332.         if(proggres[playerid] != 1)
  333.             return SendClientMessage(playerid, -1, "Niste u mogucnosti da koristite komandu.");
  334.        
  335.         ShowPlayerDialog( playerid, DIALOG_ROUTES, DIALOG_STYLE_LIST, "Routes", CheckPilotRoutes(), "Odaberi", "(x)" );
  336.     }
  337.    
  338.     if(strcmp(action,"info", true) == 0) {
  339.         if(proggres[playerid] != 1) return SendClientMessage(playerid, -1, "Niste u mogucnosti da koristite komandu.");
  340.         new Float:x,Float:z,Float:y;
  341.         GetVehiclePos(plane[0], x, y, z);
  342.         va_SendClientMessage(playerid, -1, "Nalazite se %.2f metara u zraku.", z);
  343.     }
  344.    
  345.     if(strcmp(action,"quit", true) == 0) {
  346.         if(!Bit1_Get(JobStarted, playerid))
  347.             return SendClientMessage(playerid, -1, "Niste zapoceli sa poslom.");
  348.            
  349.         SendClientMessage(playerid, -1, "Prekinuli ste posao.");   
  350.         ControlPlayerJob(JOB_PILOT, -1, playerid, false);
  351.     }
  352.    
  353.     if(strcmp(action,"createroute", true) == 0) {
  354.         if(PlayerInfo[playerid][pAdmin] < 1337)
  355.             return SendClientMessage(playerid, COLOR_RED, "[GRESKA]: Niste ovlasteni za koristenje ove komande (admin lvl 1337+).");
  356.         ShowPlayerDialog(playerid, DIALOG_CREATE_ROUTE, DIALOG_STYLE_INPUT, "Route pay", "Koliko para zelite da bude plata na ruti?", "Unesi", "(x)");
  357.     }
  358.     return (true);
  359. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top