Advertisement
Nyft_

Motos & Destruction Timer ~Nyft

May 31st, 2021 (edited)
580
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include a_samp
  2. #include streamer
  3.  
  4. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
  5.  
  6. #define function%0(%1) \
  7.     forward%0(%1); public%0(%1)
  8.  
  9. #define PRESSED(%0) \
  10.     (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  11.  
  12. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
  13.  
  14. static const RENT_PRICE = 200;
  15. static const RENT_DESTROY = 120;
  16.  
  17. static gRentMotoID[MAX_PLAYERS] = {INVALID_VEHICLE_ID, ...};
  18. static gRentMotoTimer[MAX_PLAYERS] = {-1, ...};
  19. static gRentMotoCount[MAX_PLAYERS];
  20. static Text3D:gRentMotoLabel[MAX_PLAYERS];
  21.  
  22. static const Float:gRentMotoSpawns[][] =
  23. {
  24.     {1098.5000, -1755.0000, 12.8220, 90.0000},
  25.     {1098.5000, -1757.9000, 12.8220, 90.0000},
  26.     {1098.5000, -1760.8500, 12.8220, 90.0000},
  27.     {1098.5000, -1763.8500, 12.8220, 90.0000}
  28. };
  29.  
  30. main(){}
  31.  
  32. public OnGameModeInit()
  33. {
  34.     AddPlayerClass(0, 1144.3022, -1761.5577, 13.2000, 0.0000, 0, 0, 0, 0, 0, 0);
  35.  
  36.     CreateDynamicPickup(1318, 1, 1139.4188, -1761.8510, 13.5955, .streamdistance = 50.0);
  37.     CreateDynamic3DTextLabel("Motos\nPressione F ou Enter", -1, 1139.4188, -1761.8510, 13.5955+0.75, 25.0, .testlos = 1);
  38.     return 1;
  39. }
  40.  
  41. public OnPlayerSpawn(playerid)
  42.     return GivePlayerMoney(playerid, 10000);
  43.  
  44. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  45. {
  46.     if(PRESSED(KEY_SECONDARY_ATTACK))
  47.     {
  48.         if(IsPlayerInRangeOfPoint(playerid, 1.0, 1139.4188, -1761.8510, 13.5955))
  49.         {
  50.             if(IsPlayerInAnyVehicle(playerid))
  51.                 return SendClientMessage(playerid, -1, "* Você está conduzindo um veículo.");
  52.  
  53.             if(gRentMotoID[playerid] != INVALID_VEHICLE_ID)
  54.                 return SendClientMessage(playerid, -1, "* Você não pode pegar uma moto com outra criada.");
  55.  
  56.             if(GetPlayerMoney(playerid) < RENT_PRICE)
  57.                 return SendClientMessage(playerid, -1, "* Você não tem dinheiro suficiente.");
  58.  
  59.             new rand = random(sizeof(gRentMotoSpawns));
  60.             gRentMotoID[playerid] = CreateVehicle(581, gRentMotoSpawns[rand][0], gRentMotoSpawns[rand][1], gRentMotoSpawns[rand][2], gRentMotoSpawns[rand][3], -1, -1, -1);
  61.             PutPlayerInVehicle(playerid, gRentMotoID[playerid], 0);
  62.             GivePlayerMoney(playerid, -RENT_PRICE);
  63.         }
  64.     }
  65.     return 1;
  66. }
  67.  
  68. public OnPlayerStateChange(playerid, newstate, oldstate)
  69. {
  70.     switch(newstate)
  71.     {
  72.         case PLAYER_STATE_DRIVER:
  73.         {
  74.             if(gRentMotoID[playerid] != INVALID_VEHICLE_ID && gRentMotoCount[playerid] != 0 && gRentMotoTimer[playerid] != -1)
  75.             {
  76.                 DestroyDynamic3DTextLabel(gRentMotoLabel[playerid]);
  77.                 KillTimer(gRentMotoTimer[playerid]);
  78.                 gRentMotoTimer[playerid] = -1;
  79.                 gRentMotoCount[playerid] = 0;
  80.             }
  81.         }
  82.     }
  83.     switch(oldstate)
  84.     {
  85.         case PLAYER_STATE_DRIVER:
  86.         {
  87.             if(gRentMotoID[playerid] != INVALID_VEHICLE_ID && !gRentMotoCount[playerid] && gRentMotoTimer[playerid] == -1)
  88.             {
  89.                 if(IsValidDynamic3DTextLabel(gRentMotoLabel[playerid]))
  90.                     DestroyDynamic3DTextLabel(gRentMotoLabel[playerid]);
  91.  
  92.                 gRentMotoCount[playerid] = RENT_DESTROY;
  93.                 gRentMotoTimer[playerid] = SetTimerEx("OnDestroyRentMotoUpdate", 1000, true, "i", playerid);
  94.                 gRentMotoLabel[playerid] = CreateDynamic3DTextLabel("{FF0000}Moto destruída em:\n{FFFFFF}00:00", -1, 0.0, 0.0, 0.0, 50.0, .attachedvehicle = gRentMotoID[playerid]);
  95.             }
  96.         }
  97.     }
  98.     return 1;
  99. }
  100.  
  101. function OnDestroyRentMotoUpdate(playerid)
  102. {
  103.     if(gRentMotoTimer[playerid] != -1)
  104.     {
  105.         if((--gRentMotoCount[playerid]) < 0)
  106.         {
  107.             DestroyDynamic3DTextLabel(gRentMotoLabel[playerid]);
  108.             DestroyVehicle(gRentMotoID[playerid]);
  109.             KillTimer(gRentMotoTimer[playerid]);
  110.             gRentMotoTimer[playerid] = -1;
  111.             gRentMotoCount[playerid] = 0;
  112.             gRentMotoID[playerid] = INVALID_VEHICLE_ID;
  113.             SendClientMessage(playerid, -1, "* Você demorou muito para voltar à moto e ela foi destruída.");
  114.         }
  115.         else
  116.         {
  117.             new label[45];
  118.             format(label, sizeof(label), "{FF0000}Moto destruída em:\n{FFFFFF}%02d:%02d", gRentMotoCount[playerid] / 60, gRentMotoCount[playerid] % 60);
  119.             UpdateDynamic3DTextLabelText(gRentMotoLabel[playerid], -1, label);
  120.         }
  121.     }
  122.     return 1;
  123. }
Advertisement
RAW Paste Data Copied
Advertisement