Advertisement
TheBakkeseKing

RobsNPC

Sep 26th, 2024
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.83 KB | Gaming | 0 0
  1. function crearNPCsTiendas()
  2.     local x, y, z, rx, ry, rz, int, dim, blipx, blipy, blipz = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
  3.     local varNPC
  4.     local varColision
  5.     local varListaNPCs = exports["MR1_Inicio"]:query("SELECT * FROM NPCRobos")
  6.     if not varListaNPCs then return end
  7.  
  8.     -- Iterar sobre cada interior y crear los pickups de entrada y salida
  9.     for i, NPCs in ipairs(varListaNPCs) do
  10.         --outputChatBox("Creando NPC en: " .. x .. ", " .. y .. ", " .. z .. " | Interior: " .. int .. " | Dimensión: " .. dim)
  11.         varNPC = createPed(30, NPCs.posX, NPCs.posY, NPCs.posZ) -- ID del skin 30 (puedes cambiarlo)
  12.         setElementRotation(varNPC, NPCs.rotX, NPCs.rotY, NPCs.rotZ)
  13.         setElementInterior(varNPC, NPCs.Interior)
  14.         setElementDimension(varNPC, NPCs.Dimension)
  15.         setElementData(varNPC, "ID", i)
  16.  
  17.         -- Crear ColShape alrededor del NPC
  18.         varColision = createColSphere(NPCs.posX, NPCs.posY, NPCs.posZ, 3) -- Radio de 2 metros
  19.         setElementInterior(varColision, NPCs.Interior)
  20.         setElementDimension(varColision, NPCs.Dimension)
  21.  
  22.         npcCols[varNPC] = varColision;
  23.         npcData[varNPC] = {
  24.             x = NPCs.blipx,
  25.             y = NPCs.blipy,
  26.             z = NPCs.blipz,
  27.             int = NPCs.Interior,
  28.             dim = NPCs.Dimension,
  29.             col = varColision,
  30.             robo = false,
  31.             ladron = false,
  32.             cooldown = false,
  33.             maxRecompensa = 0,
  34.             acumulado = 0
  35.         }
  36.        
  37.         addEventHandler("onColShapeHit", varColision, function(source, Dimension)
  38.             if not (getElementType(source) == "player") or isPedInVehicle(source) then
  39.                 return
  40.             end
  41.             local playerDim = getElementDimension(source)
  42.             local colDim = getElementDimension(varColision)
  43.             if playerDim == colDim then
  44.                 outputChatBox("#9AA498[#FF7800NPC#9AA498] #53B440Presiona #FFFFFFH #53B440 para robar la tienda.", source, 255, 255, 255, true)
  45.                 bindKey(source, "H", "down", function()
  46.                     iniciarRobo(source, varNPC)
  47.                     --outputChatBox("Has presionado H frente al NPC con ID: " .. getElementData(varNPC, "ID"), source, 255, 255, 255)
  48.                 end)
  49.             end
  50.         end)
  51.         addEventHandler("onColShapeLeave", varColision, function(source)
  52.             if getElementType(source) == "player" then
  53.                 if (npcData[varNPC].robo == true) then
  54.                     if npcData[varNPC].ladron == source then
  55.                         outputChatBox("Has dejado la zona del robo, el robo ha sido cancelado.", source, 255, 0, 0)
  56.                         finalizarRobo(source, varNPC)
  57.                     end
  58.                 end
  59.                 unbindKey(source, "H")
  60.             end
  61.         end)
  62.     end
  63.  
  64. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement