Advertisement
Guest User

Simple MotorEngine + Light Control mit TASTATUR

a guest
Jul 15th, 2012
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 9.10 KB | None | 0 0
  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2. *                                                                              *
  3. *     ##    ##  ########  ##    ##  ########  ##    ##  ########  ########     *
  4. *     ##    ##  ##        ##    ##     ##     ##    ##  ##    ##  ##           *
  5. *     ########  ####      ##    ##     ##     ##    ##  ########  ######       *
  6. *           ##  ##        ##    ##     ##     ##    ##  ##  ##    ##           *
  7. *           ##  ##        ########     ##     ########  ##    ##  ########     *
  8. *                                                                              *
  9. *     --------------------------------------------------------------------     *
  10. *                                                                              *
  11. *        P     R     O     D     U     C     T     I     O     N     S         *
  12. *                                                                              *
  13. *     --------------------------------------------------------------------     *
  14. *                                                                              *
  15. *        Scripter:  Fake (Philip)                  Release:  15.07.2012        *
  16. *                                                                              *
  17. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  18.  
  19.  
  20. /*
  21. *   Includes
  22. */
  23.  
  24. #include <a_samp>
  25.  
  26.  
  27. /*
  28. *   Deklarationen
  29. */
  30.  
  31. #define HOLDING(%0) \
  32.         ((newkeys & (%0)) == (%0))
  33. #define PRESSED(%0) \
  34.         (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  35. #define RELEASED(%0) \
  36.         (((newkeys & (%0)) != (%0)) && ((oldkeys & (%0)) == (%0)))
  37.  
  38. #define WEIS    0xFFFFFFFF
  39. #define GRAU    0x9F9F9FFF
  40. #define LILA    0xC2A2DAAA
  41.  
  42. new vEngineState[MAX_VEHICLES];
  43.  
  44. new playerName[MAX_PLAYER_NAME];
  45.  
  46. forward vStartMotor(playerid);
  47. forward ProxDetector(Float:radi, playerid, string[], col1, col2, col3, col4, col5);
  48.  
  49.  
  50. /*
  51. *   Initialisierung
  52. */
  53.  
  54. public OnFilterScriptInit()
  55. {
  56.     //
  57.     //  Fahrzeuge
  58.     //
  59.    
  60.     for(new c = 0; c < MAX_VEHICLES; c++)
  61.     {
  62.         vEngineState[c] = 0;
  63.     }
  64.    
  65.     return 1;
  66. }
  67.  
  68. public OnFilterScriptExit()
  69. {
  70.     return 1;
  71. }
  72.  
  73.  
  74. /*
  75. *   Funktionen
  76. */
  77.  
  78. strtok(const string[], &index)
  79. {
  80.     new length = strlen(string);
  81.     while ((index < length) && (string[index] <= ' '))
  82.     {
  83.         index++;
  84.     }
  85.     new offset = index;
  86.     new result[20];
  87.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  88.     {
  89.         result[index - offset] = string[index];
  90.         index++;
  91.     }
  92.     result[index - offset] = EOS;
  93.     return result;
  94. }
  95.  
  96. //
  97.  
  98. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  99. {
  100.     new engine, lights, alarm, doors, bonnet, boot, objective;
  101.     GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
  102.    
  103.     if(!vEngineState[vehicleid])
  104.     {
  105.         SetVehicleParamsEx(vehicleid, false, lights, alarm, doors, bonnet, boot, objective);
  106.     }
  107.    
  108.     return 1;
  109. }
  110.  
  111. public OnPlayerExitVehicle(playerid, vehicleid)
  112. {
  113.     new engine, lights, alarm, doors, bonnet, boot, objective;
  114.     GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
  115.    
  116.     if(vEngineState[vehicleid])
  117.     {
  118.         SetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
  119.     }
  120.     else
  121.     {
  122.         SetVehicleParamsEx(vehicleid, false, false, alarm, doors, bonnet, boot, objective);
  123.     }
  124.    
  125.     return 1;
  126. }
  127.  
  128. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  129. {
  130.     if(PRESSED(KEY_FIRE))
  131.     {
  132.         if(IsPlayerInAnyVehicle(playerid))
  133.         {
  134.             if(GetPlayerState(playerid) == 2)
  135.             {
  136.                 GetPlayerName(playerid, playerName, sizeof(playerName));
  137.                 new string[255], engine, lights, alarm, doors, bonnet, boot, objective;
  138.                 new vehicle = GetPlayerVehicleID(playerid);
  139.                
  140.                 if(vEngineState[vehicle])
  141.                 {
  142.                     GetVehicleParamsEx(vehicle, engine, lights, alarm, doors, bonnet, boot, objective);
  143.  
  144.                     SetVehicleParamsEx(vehicle, false, false, alarm, doors, bonnet, boot, objective);
  145.                     vEngineState[vehicle] = 0;
  146.  
  147.                     format(string, sizeof(string), "* %s schaltet sein Fahrzeug ab.", playerName);
  148.                     ProxDetector(30.0, playerid, string, LILA, LILA, LILA, LILA, LILA);
  149.                     GameTextForPlayer(playerid,"~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~r~Der Motor ist nun aus.", 3000, 3);
  150.                 }
  151.                 else
  152.                 {
  153.                     format(string, sizeof(string), "* %s versucht sein Fahrzeug zu starten.", playerName);
  154.                     ProxDetector(30.0, playerid, string, LILA, LILA, LILA, LILA, LILA);
  155.                     GameTextForPlayer(playerid,"~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~y~Motor wird gestartet...", 3000, 3);
  156.                    
  157.                     SetTimerEx("vStartMotor", 3500, 0, "i", playerid);
  158.                 }
  159.             }
  160.         }
  161.     }
  162.    
  163.     if(PRESSED(KEY_ACTION))
  164.     {
  165.         if(IsPlayerInAnyVehicle(playerid))
  166.         {
  167.             if(GetPlayerState(playerid) == 2)
  168.             {
  169.                 new engine, lights, alarm, doors, bonnet, boot, objective;
  170.                 new vehicle = GetPlayerVehicleID(playerid);
  171.  
  172.                 GetVehicleParamsEx(vehicle, engine, lights, alarm, doors, bonnet, boot, objective);
  173.                
  174.                 if(lights)
  175.                 {
  176.                     SetVehicleParamsEx(vehicle, engine, false, alarm, doors, bonnet, boot, objective);
  177.                 }
  178.                 else
  179.                 {
  180.                     SetVehicleParamsEx(vehicle, engine, true, alarm, doors, bonnet, boot, objective);
  181.                 }
  182.             }
  183.         }
  184.     }
  185.    
  186.     return 1;
  187. }
  188.  
  189. public vStartMotor(playerid)
  190. {
  191.     new StartChance = random(5);
  192.     new string[255], engine, lights, alarm, doors, bonnet, boot, objective;
  193.     new vehicle = GetPlayerVehicleID(playerid);
  194.    
  195.     if(IsPlayerConnected(playerid))
  196.     {
  197.         if(IsPlayerInAnyVehicle(playerid))
  198.         {
  199.             if(GetPlayerState(playerid) == 2)
  200.             {
  201.                 switch(StartChance)
  202.                 {
  203.                     case 0,1,2,3:
  204.                     {
  205.                         GetPlayerName(playerid, playerName, sizeof(playerName));
  206.                         GetVehicleParamsEx(vehicle, engine, lights, alarm, doors, bonnet, boot, objective);
  207.  
  208.                         SetVehicleParamsEx(vehicle, true, true, alarm, doors, bonnet, boot, objective);
  209.                         vEngineState[vehicle] = 1;
  210.                        
  211.                         format(string, sizeof(string), "* %s hat den Motor gestartet.", playerName);
  212.                         ProxDetector(30.0, playerid, string, LILA, LILA, LILA, LILA, LILA);
  213.                         GameTextForPlayer(playerid,"~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~g~Der Motor ist nun an.", 3000, 3);
  214.                        
  215.  
  216.                     }
  217.                     case 4:
  218.                     {
  219.                         GetPlayerName(playerid, playerName, sizeof(playerName));
  220.                         GetVehicleParamsEx(vehicle, engine, lights, alarm, doors, bonnet, boot, objective);
  221.  
  222.                         SetVehicleParamsEx(vehicle, false, lights, alarm, doors, bonnet, boot, objective);
  223.                         vEngineState[vehicle] = 0;
  224.  
  225.                         format(string, sizeof(string), "* %s hat den Motor verrecken lassen.", playerName);
  226.                         ProxDetector(30.0, playerid, string, LILA, LILA, LILA, LILA, LILA);
  227.                         GameTextForPlayer(playerid,"~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~r~Der Motor ist verreckt!", 3000, 3);
  228.                     }
  229.                 }
  230.             }
  231.         }
  232.     }
  233.     return 1;
  234. }
  235.                        
  236.  
  237. public ProxDetector(Float:radi, playerid, string[], col1, col2, col3, col4, col5)
  238. {
  239.     if(IsPlayerConnected(playerid))
  240.     {
  241.         new Float:posx, Float:posy, Float:posz;
  242.         new Float:oldposx, Float:oldposy, Float:oldposz;
  243.         new Float:tempposx, Float:tempposy, Float:tempposz;
  244.         GetPlayerPos(playerid, oldposx, oldposy, oldposz);
  245.         for(new i = 0; i < MAX_PLAYERS; i++)
  246.         {
  247.             if(IsPlayerConnected(i))
  248.             {
  249.                 GetPlayerPos(i, posx, posy, posz);
  250.                 tempposx = (oldposx -posx);
  251.                 tempposy = (oldposy -posy);
  252.                 tempposz = (oldposz -posz);
  253.                 if (((tempposx < radi/16) && (tempposx > -radi/16)) && ((tempposy < radi/16) && (tempposy > -radi/16)) && ((tempposz < radi/16) && (tempposz > -radi/16)))
  254.                 {
  255.                     SendClientMessage(i, col1, string);
  256.                 }
  257.                 else if (((tempposx < radi/8) && (tempposx > -radi/8)) && ((tempposy < radi/8) && (tempposy > -radi/8)) && ((tempposz < radi/8) && (tempposz > -radi/8)))
  258.                 {
  259.                     SendClientMessage(i, col2, string);
  260.                 }
  261.                 else if (((tempposx < radi/4) && (tempposx > -radi/4)) && ((tempposy < radi/4) && (tempposy > -radi/4)) && ((tempposz < radi/4) && (tempposz > -radi/4)))
  262.                 {
  263.                     SendClientMessage(i, col3, string);
  264.                 }
  265.                 else if (((tempposx < radi/2) && (tempposx > -radi/2)) && ((tempposy < radi/2) && (tempposy > -radi/2)) && ((tempposz < radi/2) && (tempposz > -radi/2)))
  266.                 {
  267.                     SendClientMessage(i, col4, string);
  268.                 }
  269.                 else if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
  270.                 {
  271.                     SendClientMessage(i, col5, string);
  272.                 }
  273.             }
  274.         }
  275.     }
  276.     return 1;
  277. }
  278.  
  279.  
  280. /*
  281. *   Kommandos
  282. */
  283.  
  284. public OnPlayerCommandText(playerid, cmdtext[])
  285. {
  286.     new cmd[255];
  287.     new idx = 0;
  288.     cmd = strtok(cmdtext, idx);
  289.  
  290.     if(strcmp(cmd, "/fsinfo", true) == 0)
  291.     {
  292.         for(new i = 0; i < MAX_PLAYERS; i++)
  293.         {
  294.             if(IsPlayerConnected(i))
  295.             {
  296.                 SendClientMessage(playerid, GRAU, "------------------------------------------");
  297.                 SendClientMessage(playerid, WEIS, "--   4#Future Productions präsentiert   --");
  298.                 SendClientMessage(playerid, WEIS, "--          # MotorEngine FS #          --");
  299.                 SendClientMessage(playerid, GRAU, "------------------------------------------");
  300.                 return 1;
  301.             }
  302.         }
  303.         return 1;
  304.     }
  305.  
  306.     return SendClientMessage(playerid, GRAU, "Der eingegebene Befehl ist nicht bekannt.");
  307. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement