Advertisement
Ner0x

[FS] Sistema de motor (básico)

Nov 6th, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.70 KB | None | 0 0
  1. //=== FileScript Sencillo del comando /motor.
  2. //=== - Creditos: Ner0x (Creación en el FS).
  3.  
  4. #include <a_samp>
  5.  
  6. #define COLOR 0xC2A2DAAA
  7. #define COLOR_GRAD2 0xBFC0C2FF
  8.  
  9. new PrendiendoM[MAX_PLAYERS];
  10.  
  11. public OnFilterScriptInit()
  12. {
  13.     print("\n-----------------------------------------");
  14.     print("Cargado correctamente");
  15.     print("-------------------------------------------\n");
  16.    
  17.     ManualVehicleEngineAndLights();
  18.     return 1;
  19. }
  20.  
  21. public OnFilterScriptExit()
  22. {
  23.     print("\n-----------------------------------------");
  24.     print("Cerrado Correctamente");
  25.     print("-------------------------------------------\n");
  26.     return 1;
  27. }
  28.  
  29. public OnPlayerCommandText(playerid, cmdtext[])
  30. {
  31.     new string[256];
  32.     new cmd[256];
  33.     new idx;
  34.     cmd = strtok(cmdtext, idx);
  35.    
  36.     if(strcmp(cmd, "/engine", true) == 0 || strcmp(cmd, "/motor", true) == 0)
  37.     {
  38.         if(GetPlayerState(playerid) == 2)
  39.         {
  40.             new enginem, lights, alarm, doors, bonnet, boot, objective;
  41.             GetVehicleParamsEx(GetPlayerVehicleID(playerid),enginem, lights, alarm, doors, bonnet, boot, objective);
  42.             if(enginem == VEHICLE_PARAMS_ON)
  43.             {
  44.                 SetVehicleParamsEx(GetPlayerVehicleID(playerid),VEHICLE_PARAMS_OFF, lights, alarm, doors, bonnet, boot, objective);
  45.  
  46.                 format(string,sizeof(string),"* %s apaga el motor del vehiculo.",NombreEx(playerid));
  47.                 MensajeCercaDe(10.0, playerid, string, COLOR,COLOR,COLOR,COLOR,COLOR);
  48.                 SendClientMessage(playerid, 0xFFFFFFFF, "* Motor {FF0000}Apagado.");
  49.                 return 1;
  50.             }
  51.             if(enginem == VEHICLE_PARAMS_OFF)
  52.             {
  53.                 if(PrendiendoM[playerid] == 1) return 1;
  54.                 SetVehicleParamsEx(GetPlayerVehicleID(playerid),VEHICLE_PARAMS_OFF, lights, alarm, doors, bonnet, boot, objective);
  55.  
  56.  
  57.                 format(string,sizeof(string),"* %s intenta encender el motor del vehiculo.",NombreEx(playerid));
  58.                 MensajeCercaDe(10.0, playerid, string, COLOR,COLOR,COLOR,COLOR,COLOR);
  59.                 SendClientMessage(playerid, 0x00B000FF, "* Encendiendo{FF0000}...");
  60.                 PrendiendoM[playerid] = 1;
  61.                 SetTimerEx("PMotor",2000,0,"d",playerid);
  62.                 return 1;
  63.             }
  64.             if(enginem == VEHICLE_PARAMS_UNSET)
  65.             {
  66.                 if(PrendiendoM[playerid] == 1) return 1;
  67.                 SetVehicleParamsEx(GetPlayerVehicleID(playerid),VEHICLE_PARAMS_OFF, lights, alarm, doors, bonnet, boot, objective);
  68.  
  69.                 format(string,sizeof(string),"* %s intenta encender el motor del vehiculo.",NombreEx(playerid));
  70.                 MensajeCercaDe(10.0, playerid, string, COLOR,COLOR,COLOR,COLOR,COLOR);
  71.                 SendClientMessage(playerid, 0x00B000FF, "* Encendiendo{FF0000}...");
  72.  
  73.                 PrendiendoM[playerid] = 1;
  74.                 SetTimerEx("PMotor",2000,0,"d",playerid);
  75.                 return 1;
  76.             }
  77.         } return SendClientMessage(playerid, COLOR_GRAD2, "Debes estar en un vehiculo.");
  78.     }
  79.     return 0;
  80. }
  81.  
  82. public OnPlayerStateChange(playerid,newstate,oldstate)
  83. {
  84.     if(newstate == PLAYER_STATE_DRIVER)
  85.     {
  86.         new vehicleid = GetPlayerVehicleID(playerid);
  87.         new enginem, lights, alarm, doors, bonnet, boot, objective;
  88.         GetVehicleParamsEx(vehicleid,enginem, lights, alarm, doors, bonnet, boot, objective);
  89.         if(enginem == VEHICLE_PARAMS_OFF || enginem == VEHICLE_PARAMS_UNSET)
  90.         {
  91.              SendClientMessage(playerid,COLOR,"*MOTOR: El motor del vehiculo se encuentra apagado. Para encender use /motor");
  92.         }
  93.         if(enginem == VEHICLE_PARAMS_ON)
  94.         {
  95.              SendClientMessage(playerid,COLOR,"*MOTOR: El motor del vehiculo se encuentra encendido. Para apagar use /motor");
  96.         }
  97.     }
  98.     return 1;
  99. }
  100.  
  101.  
  102. forward MensajeCercaDe(Float:radi, playerid, string[],col1,col2,col3,col4,col5);
  103. public MensajeCercaDe(Float:radi, playerid, string[],col1,col2,col3,col4,col5)
  104. {
  105.     if(IsPlayerConnected(playerid))
  106.     {
  107.         new Float:posx, Float:posy, Float:posz;
  108.         new Float:oldposx, Float:oldposy, Float:oldposz;
  109.         new Float:tempposx, Float:tempposy, Float:tempposz;
  110.         GetPlayerPos(playerid, oldposx, oldposy, oldposz);
  111.         for(new i = 0; i < MAX_PLAYERS; i++)
  112.         {
  113.             if(IsPlayerConnected(i) && (GetPlayerVirtualWorld(playerid) == GetPlayerVirtualWorld(i)))
  114.             {
  115.                 GetPlayerPos(i, posx, posy, posz);
  116.                 tempposx = (oldposx -posx);
  117.                 tempposy = (oldposy -posy);
  118.                 tempposz = (oldposz -posz);
  119.                 if (((tempposx < radi/16) && (tempposx > -radi/16)) && ((tempposy < radi/16) && (tempposy > -radi/16)) && ((tempposz < radi/16) && (tempposz > -radi/16)))
  120.                 {
  121.                     SendClientMessage(i, col1, string);
  122.                 }
  123.                 else if (((tempposx < radi/8) && (tempposx > -radi/8)) && ((tempposy < radi/8) && (tempposy > -radi/8)) && ((tempposz < radi/8) && (tempposz > -radi/8)))
  124.                 {
  125.                     SendClientMessage(i, col2, string);
  126.                 }
  127.                 else if (((tempposx < radi/4) && (tempposx > -radi/4)) && ((tempposy < radi/4) && (tempposy > -radi/4)) && ((tempposz < radi/4) && (tempposz > -radi/4)))
  128.                 {
  129.                     SendClientMessage(i, col3, string);
  130.                 }
  131.                 else if (((tempposx < radi/2) && (tempposx > -radi/2)) && ((tempposy < radi/2) && (tempposy > -radi/2)) && ((tempposz < radi/2) && (tempposz > -radi/2)))
  132.                 {
  133.                     SendClientMessage(i, col4, string);
  134.                 }
  135.                 else if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
  136.                 {
  137.                     SendClientMessage(i, col5, string);
  138.                 }
  139.             }
  140.         }
  141.     }
  142.     return 1;
  143. }
  144.  
  145. stock NombreEx(playerid)
  146. {
  147.     new string[24];
  148.     GetPlayerName(playerid,string,24);
  149.     new str[24];
  150.     strmid(str,string,0,strlen(string),24);
  151.     for(new i = 0; i < MAX_PLAYER_NAME; i++)
  152.     {
  153.         if (str[i] == '_') str[i] = ' ';
  154.     }
  155.     return str;
  156. }
  157.  
  158. strtok(const string[], &index)
  159. {
  160.     new length = strlen(string);
  161.     while ((index < length) && (string[index] <= ' '))
  162.     {
  163.         index++;
  164.     }
  165.  
  166.     new offset = index;
  167.     new result[20];
  168.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  169.     {
  170.         result[index - offset] = string[index];
  171.         index++;
  172.     }
  173.     result[index - offset] = EOS;
  174.     return result;
  175. }
  176.  
  177. forward PMotor(playerid);
  178. public PMotor(playerid)
  179. {
  180.     if(GetPlayerState(playerid) == 2)
  181.     {
  182.         new enginem, lights, alarm, doors, bonnet, boot, objective;
  183.         GetVehicleParamsEx(GetPlayerVehicleID(playerid),enginem, lights, alarm, doors, bonnet, boot, objective);
  184.         PrendiendoM[playerid] = 0;
  185.         new REnce = random(2);
  186.         if(REnce == 0)
  187.         {
  188.             SetVehicleParamsEx(GetPlayerVehicleID(playerid),VEHICLE_PARAMS_ON, lights, alarm, doors, bonnet, boot, objective);
  189.             SendClientMessage(playerid, 0x00C900FF, "* Motor Encendido!");
  190.             return 1;
  191.         }
  192.         else if(REnce == 1)
  193.         {
  194.             SendClientMessage(playerid, COLOR_ROJO, "* El motor se atasca y no enciende...");
  195.         }
  196.         return 1;
  197.     }
  198.     PrendiendoM[playerid] = 0;
  199.     return 1;
  200. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement