Advertisement
cesar_google

Trabajo de Camionero [Guardar y Cargar Localidades]

Sep 4th, 2013
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.30 KB | None | 0 0
  1. /*
  2.     Trabajo de Camionero [Crear y Guardar Localidades]
  3.     By Parka
  4.     Fecha de Desarrollo 03:19 a.m. 19/07/2013
  5.     Version: 0.1a RC 1
  6.  
  7.                                Introduccion
  8.  
  9. El presente trabajo, es un sistema simple y completo para que usted pueda crear
  10. sus propias posiciones de cargamento y descarga automaticamente guardados en
  11. "scriptfiles/Trucking/Locations" para para cuando usted tenga la necesidad de
  12. reiniciar o cerrar el servidor no se pierdan las localidades, tambien dice hacia
  13. donde deves ir a llevar la carga.
  14.  
  15.                               Desarrollo
  16.  
  17. /Cargar
  18.  
  19. Sirve para iniciar a trabajar de camionero, respectivamente con un trailer y un
  20. camion.
  21.  
  22. /tutolc:
  23. este comando permite saber como usar el comando /crearlc.
  24.  
  25. /crearlc <Jugador> :
  26. Usar /crearlc para crear una localidad en la cual el jugador va a transportar el trailer.
  27. Su posicion es donde inicia la Carga.
  28. Posicion del Jugador: Es donde se descargara el trailer.
  29.  
  30. En este sistema los trailers son divididos en tres partes, el cual exigira nivel
  31. para poder cargar ese tipo de trailer.
  32.  
  33. 1-Facil
  34. 2-Medio     4-6
  35. 3-Dificil   7 >
  36.  
  37. Camionero:
  38. La restringcion esta basada en el skin del jugador por lo tanto para saber si es camionero
  39. debe poseer el skin de camionero que es la siguiente variable.
  40.  
  41. SkinTruckDriver[4]
  42. */
  43. #include    < a_samp  >// SAMP-TEAM
  44. #include    < sscanf2 >// Y_Less
  45. #include    < A_ZONES >// By ~Cueball~
  46. #include    < ZCMD    >// Zeex
  47. #include    < DINI    >// DracoBlue
  48.  
  49. #pragma unused ret_memcpy
  50. #pragma unused strtok
  51.  
  52. #define Locations_Save    "Trucking/Locations/%d.txt"
  53. #define Save_ID           "Trucking/Quantidade.txt"
  54.  
  55. #undef MAX_PLAYERS
  56. #define MAX_PLAYERS 100
  57.  
  58. new p_Get_Quantidade;
  59. new p_Quantidade;
  60. new p_ForID;
  61. new p_JopStatus[MAX_PLAYERS];
  62. new bool:p_Jop[MAX_PLAYERS];
  63.  
  64. new Float:p_OldPos[MAX_PLAYERS][3];
  65.  
  66. enum p_LAU
  67. {
  68. Float:Carregar_Posx,
  69. Float:Carregar_Posy,
  70. Float:Carregar_Posz,
  71. Float:Baixar_Posx,
  72. Float:Baixar_Posy,
  73. Float:Baixar_Posz
  74. }
  75. new LoadAndUnload[][p_LAU];
  76.  
  77. new SkinTruckDriver[4] =
  78. {
  79. 133,
  80. 202,
  81. 206,
  82. 261
  83. };
  84. //                  ========[Trucking Job By Parka]========                   //
  85. forward p_StopWork_LostTrailer( playerid );
  86. public p_StopWork_LostTrailer( playerid )
  87. {
  88.     DisablePlayerCheckpoint(playerid);
  89.     SendClientMessage(playerid, 0xFF0000AA, "Usted Perdio el Trailer,Se le descontara -$1000.");
  90.     SendClientMessage(playerid, 0xFF0000AA, "Usted esta despedido.");
  91.     GivePlayerMoney(playerid, -1000);
  92.     p_JopStatus[playerid] = 0;
  93.     p_Jop[ playerid ] = false;
  94.     return 1;
  95. }
  96. //                  ========[Trucking Job By Parka]========                   //
  97. forward p_StopWork( playerid );
  98. public p_StopWork( playerid )
  99. {
  100.     DisablePlayerCheckpoint(playerid);
  101.     SendClientMessage(playerid, 0xFF0000AA, "Usted escapo de su trabajo actual pierde -$1000");
  102.     GivePlayerMoney(playerid, -1000);
  103.     p_JopStatus[playerid] = 0;
  104.     p_Jop[ playerid ] = false;
  105.     return 1;
  106. }
  107. //                  ========[Trucking Job By Parka]========                   //
  108. forward p_LoadAndUnload( playerid );
  109. public p_LoadAndUnload( playerid )
  110. {
  111.     new v = GetPlayerVehicleID(playerid);
  112.     new p_All, p_Pay, Float:p_THealth, Float:p_CHealth, string[256];
  113.     GetVehicleHealth(v, p_CHealth);
  114.     GetVehicleHealth(GetVehicleTrailer(v),p_THealth);
  115.  
  116.     switch(p_JopStatus[ playerid ])
  117.     {
  118.         case 1:
  119.         {
  120.             DisablePlayerCheckpoint( playerid );
  121.             SetPlayerCheckpoint( playerid, p_OldPos[ playerid ][ 0 ], p_OldPos[ playerid ][ 1 ], p_OldPos[ playerid ][ 2 ], 7);
  122.             SendClientMessage( playerid, 0xFFFF00AA, "Camion Cargado dirijase al punto de descarga.!");
  123.             TogglePlayerControllable( playerid , true );
  124.             p_JopStatus[ playerid ] = 2;
  125.         }
  126.         case 2:
  127.         {
  128.             switch(GetVehicleModel(GetVehicleTrailer(v)))
  129.             {
  130.             case 450://Easy   Level 1 a 3
  131.             {
  132.             p_All = floatround(p_CHealth) + floatround(p_THealth);
  133.             p_Pay = p_All * 2;
  134.             format( string, sizeof string,
  135.             "{00ff00}[!]==========[Detalles de Paga]==========[!]\n\
  136.             {00ff00}Daños del Trailer: %d\n\
  137.             {00ff00}Daños del Camion: %d\n\
  138.             {00ff00}Total a pagar: %d", floatround(p_THealth), floatround(p_CHealth), p_Pay);
  139.             ShowPlayerDialog( playerid, 0x00100, DIALOG_STYLE_MSGBOX,"[Detalles de Paga]", string, "Aceptar", "");
  140.             GivePlayerMoney( playerid , p_Pay );
  141.             TogglePlayerControllable( playerid , true );
  142.             p_JopStatus[ playerid ] = 2;
  143.             p_Jop      [ playerid ] = true;
  144.             }
  145.             case 435,591://Medium Level 4 a 6
  146.             {
  147.             p_All = floatround(p_CHealth) + floatround(p_THealth);
  148.             p_Pay = p_All * 3;
  149.             format( string, sizeof string,
  150.             "{00ff00}[!]==========[Detalles de Paga]==========[!]\n\
  151.             {00ff00}Daños del Trailer: %d\n\
  152.             {00ff00}Daños del Camion: %d\n\
  153.             {00ff00}Total a pagar: %d", floatround(p_THealth), floatround(p_CHealth), p_Pay);
  154.             ShowPlayerDialog( playerid, 0x00100, DIALOG_STYLE_MSGBOX,"[Detalles de Paga]", string, "Aceptar", "");
  155.             GivePlayerMoney( playerid , p_Pay );
  156.             TogglePlayerControllable( playerid , true );
  157.             p_JopStatus[ playerid ] = 2;
  158.             p_Jop      [ playerid ] = true;
  159.             }
  160.             case 584://Hard   Level 7 a 9
  161.             {
  162.             p_All = floatround(p_CHealth) + floatround(p_THealth);
  163.             p_Pay = p_All * 4;
  164.             format( string, sizeof string,
  165.             "{00ff00}[!]==========[Detalles de Paga]==========[!]\n\
  166.             {00ff00}Daños del Trailer: %d\n\
  167.             {00ff00}Daños del Camion: %d\n\
  168.             {00ff00}Total a pagar: %d", floatround(p_THealth), floatround(p_CHealth), p_Pay);
  169.             ShowPlayerDialog( playerid, 0x00100, DIALOG_STYLE_MSGBOX,"[Detalles de Paga]", string, "Aceptar", "");
  170.             GivePlayerMoney( playerid , p_Pay );
  171.             TogglePlayerControllable( playerid , true );
  172.             p_JopStatus[ playerid ] = 2;
  173.             p_Jop      [ playerid ] = true;
  174.             }
  175.             }
  176.         }
  177.     }
  178.     return 1;
  179. }
  180. //                  ========[Trucking Job By Parka]========                   //
  181. forward GetTruckDriver( playerid );
  182. public GetTruckDriver( playerid )
  183. {
  184.     for(new i; i < sizeof SkinTruckDriver; i++)
  185.     {
  186.     if( GetPlayerSkin(playerid) == SkinTruckDriver[i])
  187.     {
  188.  
  189.     return 1;
  190.     }
  191.     }
  192.     return 0;
  193. }
  194. //                  ========[Trucking Job By Parka]========                   //
  195. forward PosForID();
  196. public PosForID()
  197. {
  198.     if( dini_Exists( Save_ID ) )
  199.     {
  200.     p_Quantidade = dini_Int( Save_ID , "Quantidade" ) + 1;
  201.     dini_IntSet( Save_ID , "Quantidade" , p_Quantidade );
  202.     }
  203.     return p_Quantidade;
  204. }
  205. //                  ========[Trucking Job By Parka]========                   //
  206. forward PlayerStartWork( playerid );
  207. public PlayerStartWork( playerid )
  208. {
  209.     new v = GetPlayerVehicleID(playerid);
  210.     if(GetVehicleModel(v)==403||GetVehicleModel(v)==515||GetVehicleModel(v)==514)
  211.     {
  212.         if(IsTrailerAttachedToVehicle(v))
  213.         {
  214.             switch(GetVehicleModel(GetVehicleTrailer(v)))
  215.             {
  216.             case 450://Easy   Level 1 a 3
  217.             {
  218.             SetPosDestination( playerid );
  219.             }
  220.             case 435,591://Medium Level 4 a 6
  221.             {
  222.             if(GetPlayerScore(playerid) <= 3) return SendClientMessage( playerid, 0xFF0000AA, "Usted debe ser nivel 4 para transportar carga media");
  223.             SetPosDestination( playerid );
  224.             }
  225.             case 584://Hard   Level 7 a 9
  226.             {
  227.             if(GetPlayerScore(playerid) <= 6) return SendClientMessage( playerid, 0xFF0000AA, "Usted debe ser nivel 7 para transportar carga pesada");
  228.             SetPosDestination( playerid );
  229.             }
  230.             }
  231.         }else return SendClientMessage( playerid, 0xFF0000AA, "Usted no tiene un trailer enganchado");
  232.     }
  233.     else return SendClientMessage( playerid, 0xFF0000AA, "Usted debe estar dentro de un camion");
  234.     return true;
  235. }
  236. //                  ========[Trucking Job By Parka]========                   //
  237. forward SetPosDestination( playerid );
  238. public SetPosDestination( playerid )
  239. {
  240.     if( dini_Exists( Save_ID ) )
  241.     {
  242.     p_Get_Quantidade = dini_Int( Save_ID , "Quantidade");
  243.     }
  244.  
  245.     new p_random = random(p_Get_Quantidade);
  246.     new Float:p_LastPos[MAX_PLAYERS][3];
  247.  
  248.     new string[32];
  249.     format( string, sizeof string, Locations_Save, p_random);
  250.  
  251.     if( !dini_Exists( string ) )
  252.         return SendClientMessage( playerid, 0xFF0000AA, "Contacta a un administrador si esto aparece.!");
  253.  
  254.     LoadAndUnload[ p_random ][ Carregar_Posx] = dini_Float  (   string, "Carregar_X");
  255.     LoadAndUnload[ p_random ][ Carregar_Posy] = dini_Float  (   string, "Carregar_Y");
  256.     LoadAndUnload[ p_random ][ Carregar_Posz] = dini_Float  (   string, "Carregar_Z");
  257.     LoadAndUnload[ p_random ][ Baixar_Posx] = dini_Float    (   string, "Baixar_X"  );
  258.     LoadAndUnload[ p_random ][ Baixar_Posy] = dini_Float    (   string, "Baixar_Y"  );
  259.     LoadAndUnload[ p_random ][ Baixar_Posz] = dini_Float    (   string, "Baixar_Z"  );
  260.  
  261.     p_LastPos[ playerid ][ 0 ] = LoadAndUnload[ p_random ][ Carregar_Posx ];
  262.     p_LastPos[ playerid ][ 1 ] = LoadAndUnload[ p_random ][ Carregar_Posy ];
  263.     p_LastPos[ playerid ][ 2 ] = LoadAndUnload[ p_random ][ Carregar_Posz ];
  264.  
  265.     p_OldPos[ playerid ][ 0 ] = LoadAndUnload[ p_random ][ Baixar_Posx ];
  266.     p_OldPos[ playerid ][ 1 ] = LoadAndUnload[ p_random ][ Baixar_Posy ];
  267.     p_OldPos[ playerid ][ 2 ] = LoadAndUnload[ p_random ][ Baixar_Posz ];
  268.  
  269.     SetPlayerCheckpoint(playerid, p_LastPos[ playerid ][ 0 ], p_LastPos[ playerid ][ 1 ], p_LastPos[ playerid ][ 2 ], 7);
  270.  
  271.     new StrIng_Text[256];
  272.     format( StrIng_Text, sizeof StrIng_Text, "%s", dini_Get( string, "Localidade"));
  273.     SendClientMessage( playerid, 0x00FF00AA, StrIng_Text);
  274.  
  275.     p_JopStatus[ playerid ] = 1;
  276.     p_Jop      [ playerid ] = true;
  277.  
  278.     return 1;
  279. }
  280. //                  ========[Trucking Job By Parka]========                   //
  281. forward SaveLocations( LocationName[], Float:Carregar_x, Float:Carregar_y, Float:Carregar_z, Float:Baixar_x, Float:Baixar_y, Float:Baixar_z );
  282. public SaveLocations( LocationName[], Float:Carregar_x, Float:Carregar_y, Float:Carregar_z, Float:Baixar_x, Float:Baixar_y, Float:Baixar_z )
  283. {
  284.     if(!dini_Exists(TKSave()))
  285.     {
  286.     dini_Create     (   TKSave());
  287.     dini_Set        (   TKSave(),   "Localidade",   LocationName);
  288.     dini_FloatSet   (   TKSave(),   "Carregar_X",   Carregar_x  );
  289.     dini_FloatSet   (   TKSave(),   "Carregar_Y",   Carregar_y  );
  290.     dini_FloatSet   (   TKSave(),   "Carregar_Z",   Carregar_z  );
  291.     dini_FloatSet   (   TKSave(),   "Baixar_X"  ,   Baixar_x    );
  292.     dini_FloatSet   (   TKSave(),   "Baixar_Y"  ,   Baixar_y    );
  293.     dini_FloatSet   (   TKSave(),   "Baixar_Z"  ,   Baixar_z    );
  294.     }
  295.     return 1;
  296. }
  297. //                  ========[Trucking Job By Parka]========                   //
  298. stock TKSave()
  299. {
  300.     new string[32];
  301.     format( string, sizeof string, Locations_Save, p_ForID);
  302.     return string;
  303. }
  304. //                  ========[Trucking Job By Parka]========                   //
  305. CMD:crearlc(playerid,params[])
  306. {
  307.     if( !IsPlayerAdmin( playerid ) ) return SendClientMessage( playerid, 0xFF0000AA, "Usted no es administrador /RCON");
  308.     new Target;
  309.     if( sscanf( params, "d", Target) ) return SendClientMessage( playerid, 0xFF0000AA, "Use: '/crearlc <Jugador>' Ayuda = (/tutolc)");
  310.  
  311.     if( !IsPlayerConnected(Target) || Target == INVALID_PLAYER_ID ) return SendClientMessage( playerid, 0xFF0000AA, "Jugador no esta conectado");
  312.     if( Target == playerid ) return SendClientMessage( playerid, 0xFF0000AA, "No puedes ser tu mismo.!");
  313.  
  314.     new Float:TargetPos[3];
  315.     new Float:PlayerPos[3];
  316.  
  317.     GetPlayerPos( playerid, PlayerPos[0], PlayerPos[1], PlayerPos[2]);
  318.     GetPlayerPos( Target,   TargetPos[0], TargetPos[1], TargetPos[2]);
  319.  
  320.     p_ForID = PosForID();
  321.  
  322.     new Zone_Target[32];
  323.     new Zone_Player[32];
  324.  
  325.     GetPlayer3DZone( Target,   Zone_Target, 32);
  326.     GetPlayer3DZone( playerid, Zone_Player, 32);
  327.  
  328.     new Str_Ing[256];
  329.     format( Str_Ing, sizeof Str_Ing, "Localidad: Cargar en %s y descargar en %s", Zone_Player, Zone_Target);
  330.     SaveLocations( Str_Ing, PlayerPos[0], PlayerPos[1], PlayerPos[2], TargetPos[0], TargetPos[1], TargetPos[2] );
  331.     SendClientMessage( playerid, 0x00FF00AA, "La localidad se creo automaticamnete.");
  332.     SendClientMessage( Target, 0x00FF00AA, "La localidad se creo automaticamnete.");
  333.     return 1;
  334. }
  335. //                  ========[Trucking Job By Parka]========                   //
  336. CMD:tutolc(playerid,params[])
  337. {
  338.     SendClientMessage( playerid, 0xFFFF00AA, "Usar /crearlc para crear una localidad en la cual el jugador va a transportar el trailer.");
  339.     SendClientMessage( playerid, 0xFFFF00AA, "Su posicion es donde inicia la Carga.");
  340.     SendClientMessage( playerid, 0xFFFF00AA, "Posicion del Jugador: Es donde se descargara el trailer.");
  341.     return 1;
  342. }
  343. //                  ========[Trucking Job By Parka]========                   //
  344. CMD:cargar(playerid,params[])
  345. {
  346.     if( IsPlayerConnected( playerid ) )
  347.     {
  348.         if( p_Jop[ playerid ] == false )
  349.         {
  350.             if(GetTruckDriver(playerid))
  351.             {
  352.                 PlayerStartWork( playerid );
  353.             }
  354.             else return SendClientMessage( playerid, 0xFF0000AA, "Usted no es Camionero.");
  355.         }
  356.         else return SendClientMessage( playerid, 0xFF0000AA, "Usted ya esta trabajando.");
  357.     }
  358.     return 1;
  359. }
  360. //                  ========[Trucking Job By Parka]========                   //
  361. public OnFilterScriptInit()
  362. {
  363.     if( !dini_Exists( Save_ID ) )
  364.     {
  365.     dini_Create( Save_ID );
  366.     dini_IntSet( Save_ID , "Quantidade" , -1);
  367.     }
  368.     return 1;
  369. }
  370. //                  ========[Trucking Job By Parka]========                   //
  371. public OnPlayerConnect(playerid)
  372. {
  373.     p_Jop      [ playerid ] = false;
  374.     p_JopStatus[ playerid ] = 0;
  375.  
  376.     return 1;
  377. }
  378. //                  ========[Trucking Job By Parka]========                   //
  379. public OnPlayerEnterCheckpoint(playerid)
  380. {
  381.     if( IsPlayerConnected( playerid ) )
  382.     {
  383.         switch(p_JopStatus[ playerid ])
  384.         {
  385.             case 1:
  386.             {
  387.                 GameTextForPlayer( playerid, "~y~~h~Cargando Productos~n~~p~Espere por favor..", 10000, 1);
  388.                 TogglePlayerControllable( playerid, false);
  389.                 SetTimerEx("p_LoadAndUnload", 10000, false, "d", playerid);
  390.             }
  391.             case 2:
  392.             {
  393.                 GameTextForPlayer( playerid, "~g~~h~Descargando Productos~n~~p~Espere por favor..", 10000, 1);
  394.                 TogglePlayerControllable( playerid, false);
  395.                 SetTimerEx("p_LoadAndUnload", 10000, false, "d", playerid);
  396.             }
  397.         }
  398.     }
  399.     return 1;
  400. }
  401. //                  ========[Trucking Job By Parka]========                   //
  402. public OnPlayerLeaveCheckpoint(playerid)
  403. {
  404.     if( IsPlayerConnected( playerid ) )
  405.     {
  406.     DisablePlayerCheckpoint(playerid);
  407.     }
  408.     return 1;
  409. }
  410. //                  ========[Trucking Job By Parka]========                   //
  411. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  412. {
  413.     new v = GetPlayerVehicleID(playerid);
  414.     if(!IsTrailerAttachedToVehicle(v) && p_JopStatus[ playerid ] >= 1)
  415.     {
  416.         p_StopWork_LostTrailer(playerid);
  417.     }
  418.     return 1;
  419. }
  420. /*
  421.         Trabajo de Camionero [Crear y Guardar Localidades]
  422.                             By Parka
  423.             Fecha de Desarrollo 03:19 a.m. 19/07/2013
  424.                         Version: 0.1a RC 1
  425. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement