Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.44 KB | None | 0 0
  1. ITEMS = {}
  2.  
  3. local inventory_table = {}
  4. AddEventHandler("playerSpawned", function()
  5.     RegisterNetEvent("item:getItems")
  6.     TriggerServerEvent("item:getItems")
  7. end)
  8.  
  9. RegisterNetEvent("gui:getItems")
  10. AddEventHandler("gui:getItems", function(THEITEMS)
  11.     ITEMS = {}
  12.     ITEMS = THEITEMS
  13.     InventoryMenu()
  14. end)
  15.  
  16. AddEventHandler("player:receiveItem", function(item, quantity)
  17.     item = tonumber(item)
  18.     if (ITEMS[item] == nil) then
  19.         new(item, quantity)
  20.     else
  21.         add({ item, quantity })
  22.     end
  23. end)
  24.  
  25. AddEventHandler("player:looseItem", function(item, quantity)
  26.     item = tonumber(item)
  27.     if (ITEMS[item].quantity >= quantity) then
  28.         delete({ item, quantity })
  29.     else
  30.         Chat("Vous n'avez pas assez de ressources")
  31.     end
  32. end)
  33.  
  34. function new(item, quantity)
  35.     RegisterNetEvent("item:setItem")
  36.     TriggerServerEvent("item:setItem", item, quantity)
  37.     TriggerServerEvent("item:getItems")
  38. end
  39.  
  40. function dump(o)
  41.    if type(o) == 'table' then
  42.       local s = '{ '
  43.       for k,v in pairs(o) do
  44.          if type(k) ~= 'number' then k = '"'..k..'"' end
  45.          s = s .. '['..k..'] = ' .. dump(v) .. ','
  46.       end
  47.       return s .. '} '
  48.    else
  49.       return tostring(o)
  50.    end
  51. end
  52.  
  53. function delete(arg)
  54.     local itemId = tonumber(arg[1])
  55.     local qty = arg[2]
  56.     local item = ITEMS[itemId]
  57.     item.quantity = item.quantity - qty
  58.     RegisterNetEvent("item:updateQuantity")
  59.     TriggerServerEvent("item:updateQuantity", item.quantity, itemId)
  60.     TriggerEvent("farm:updateQuantity", item.quantity, itemId)
  61.     InventoryMenu()
  62. end
  63.  
  64. function add(arg)
  65.     local itemId = tonumber(arg[1])
  66.     local qty = arg[2]
  67.     local item = ITEMS[itemId]
  68.     item.quantity = item.quantity + qty
  69.     RegisterNetEvent("item:updateQuantity")
  70.     TriggerServerEvent("item:updateQuantity", item.quantity, itemId)
  71.     TriggerEvent("farm:updateQuantity", item.quantity, itemId)
  72.     InventoryMenu()
  73. end
  74.  
  75.  
  76. function InventoryMenu()
  77.     for k,v in pairs(inventory_table) do
  78.         inventory_table[k] = nil
  79.     end
  80.     for k, v in pairs(ITEMS) do
  81.         if (v.quantity > 0) then
  82.             table.insert(inventory_table, {title = v.quantity .. " " .. tostring(v.libelle), name = tostring(v.libelle)})
  83.         end
  84.     end
  85. end
  86.  
  87. RegisterNetEvent("farm:updateQuantity")
  88. AddEventHandler("farm:updateQuantity", function(qty, id)
  89.     TriggerEvent('chatMessage', "", {255, 0, 0}, ITEMS[id].quantity)
  90.     ITEMS[id].quantity = qty
  91.     TriggerEvent('chatMessage', "", {255, 0, 0}, ITEMS[id].quantity)
  92. end)
  93.  
  94. local pmenu = {
  95.     opened = false,
  96.     title = "Menu Personnel",
  97.     currentmenu = "main",
  98.     lastmenu = nil,
  99.     currentpos = nil,
  100.     selectedbutton = 0,
  101.     marker = { r = 0, g = 155, b = 255, a = 200, type = 1 },
  102.     menu = {
  103.         x = 0.1,
  104.         y = 0.26,
  105.         width = 0.2,
  106.         height = 0.04,
  107.         buttons = 10,
  108.         from = 1,
  109.         to = 10,
  110.         scale = 0.4,
  111.         font = 0,
  112.         ["main"] = {
  113.             title = "CATEGORIES",
  114.             name = "main",
  115.             buttons = {
  116.                 {title = "Inventaire", name = "Inventaire", description = ""},
  117.                 {title = "Animations", name = "Animations", description = ""},
  118.                 {title = "Objets", name = "Objets", description = ""},
  119.                 {title = "Téléphone (WIP)", name = "TelephoneWIP", description = ""},
  120.                 {title = "Carté d'identité (WIP)", name = "CarteidentiteWIP", description = ""},
  121.                 {title = "Donner de l'argent (WIP)", name = "DonnerdelargentWIP", description = ""},
  122.             }
  123.         },
  124.         ["Inventaire"] = {
  125.             title = "Inventaire",
  126.             name = "Inventaire",
  127.             buttons = inventory_table
  128.                 -- {title = "Couteau", name = "Knife", costs = 400, description = {}, model = "WEAPON_Knife"},
  129.             -- }
  130.         },
  131.         ["InventaireSelect"] = {
  132.             title = "INVENTAIRE",
  133.             name = "InventaireSelect",
  134.             buttons = {
  135.                 {title = "Jeter (WIP)", name = "drop"},
  136.             }
  137.         },
  138.         ["Animations"] = {
  139.             title = "ANIMATIONS",
  140.             name = "Animations",
  141.             buttons = {
  142.                 {title = "Annuler Animation", emote = "STOP EMOTE"},
  143.                 {title = "Applaudire", emote = "WORLD_HUMAN_CHEERING"},
  144.                 {title = "Allongé par terre", emote = "WORLD_HUMAN_BUM_SLUMPED"},
  145.                 {title = "Regarder sa carte", emote = "WORLD_HUMAN_TOURIST_MAP"},
  146.                 {title = "Faire du Yoga", emote = "WORLD_HUMAN_YOGA"},
  147.                 {title = "Faire des pompes", emote = "WORLD_HUMAN_PUSH_UPS"},
  148.                 {title = "Montrer ses muscles", emote = "WORLD_HUMAN_MUSCLE_FLEX"},
  149.                 {title = "Lever des haltères", emote = "WORLD_HUMAN_MUSCLE_FREE_WEIGHTS"},
  150.                 {title = "Faire des abdo", emote = "WORLD_HUMAN_SIT_UPS"},
  151.                 {title = "Faire des tractions", emote = "PROP_HUMAN_MUSCLE_CHIN_UPS"},
  152.                 {title = "Fumer une cigarette", emote = "WORLD_HUMAN_SMOKING"},
  153.                 {title = "Fumer un buzz1", emote = "WORLD_HUMAN_SMOCKING_POT"},
  154.                 {title = "Fumer un buzz2", emote = "WORLD_HUMAN_DRUG_DEALER"},
  155.                 {title = "Café", emote = "WORLD_HUMAN_AA_COFFEE"},
  156.                 {title = "Café2", emote = "WORLD_HUMAN_DRINKING"},
  157.                 {title = "Clipboard", emote = "WORLD_HUMAN_CLIPBOARD"},
  158.                 {title = "Photo", emote = "WORLD_HUMAN_PAPARAZZI"},
  159.                 {title = "Jumelle", emote = "WORLD_HUMAN_BINOCULARS"},
  160.                 {title = "Jouer de la musique", emote = "WORLD_HUMAN_MUSICIAN"},
  161.                 {title = "Se laver comme un clochard", emote = "WORLD_HUMAN_BUM_WASH"},
  162.                 {title = "Pancarte de clochard", emote = "WORLD_HUMAN_BUM_FREEWAY"},
  163.                 {title = "Fouiler", emote = "PROP_HUMAN_BUM_BIN"},
  164.                 {title = "Faire la circulation", emote = "WORLD_HUMAN_CAR_PARK_ATTENDANT"},
  165.                 {title = "jardiner", emote = "WORLD_HUMAN_GARDENER_PLANT"},
  166.                 {title = "utiliser un marteau", emote = "WORLD_HUMAN_HAMMERING"},
  167.                 {title = "posture de garde", emote = "WORLD_HUMAN_GUARD_STAND"},
  168.                 {title = "Chill", emote = "WORLD_HUMAN_LEANING"},
  169.                 {title = "Faire la teuf", emote = "WORLD_HUMAN_PARTYING"},
  170.                 {title = "S'assoir par terre", emote = "WORLD_HUMAN_PICNIC"},
  171.                 {title = "Nettoyer", emote = "WORLD_HUMAN_MAID_CLEAN"},
  172.                 {title = "Faire le tapin luxe", emote = "WORLD_HUMAN_PROSTITUTE_HIGH_CLASS"},
  173.                 {title = "Faire le tapin pauvre", emote = "WORLD_HUMAN_PROSTITUTE_LOW_CLASS"},
  174.                 {title = "Se rechauffer les mains", emote = "WORLD_HUMAN_STAND_FIRE"},
  175.                 {title = "Pécher", emote = "WORLD_HUMAN_STAND_FISHING"},
  176.                 {title = "Utiliser sont portable", emote = "WORLD_HUMAN_STAND_MOBILE"},
  177.                 {title = "Prendre un selfie", emote = "WORLD_HUMAN_TOURIST_MOBILE"},
  178.                 {title = "Dur Dur l'alcool", emote = "WORLD_HUMAN_STUPOR"},
  179.                 {title = "Allongé sur le ventre", emote = "WORLD_HUMAN_SUNBATHE"},
  180.                 {title = "Allongé sur le dos", emote = "WORLD_HUMAN_SUNBATHE_BACK"},
  181.                 {title = "Faire de la mecanique", emote = "WORLD_HUMAN_VEHICULE_MECHANIC"},
  182.                 {title = "Souder", emote = "WORLD_HUMAN_WELDING"},
  183.                 {title = "Faire un BBQ", emote = "PROP_HUMAN_BBQ"},
  184.                 {title = "S'appuyer contre un mur", emote = "PROP_HUMAN_BUM_SHOPPING_CART"},
  185.                 {title = "Prendre des notes", emote = "CODE_HUMAN_MEDIC_TIME_OF_DEATH"},
  186.             }
  187.         },
  188.         ["Objets"] = {
  189.             title = "Objets",
  190.             name = "Objets",
  191.             buttons = {
  192.                 {title = "Prendre Mallette 1", hash = "WEAPON_BRIEFCASE"},
  193.                 {title = "Prendre Mallette 2", hash = "WEAPON_BRIEFCASE_02"},
  194.                 {title = "Prendre digiscanner 1", hash = "WEAPON_DIGISCANNER"},
  195.             }
  196.         },
  197.         ["Telephone"] = {
  198.             title = "TELEPHONE",
  199.             name = "Telephone",
  200.             buttons = {
  201.                 {title = "Répertoire", name = "Pistol", model = "WEAPON_Pistol"},
  202.                 {title = "Police", name = "CombatPistol", model = "WEAPON_CombatPistol"},
  203.                 {title = "Médecin", name = "Pistol50", model = "WEAPON_PISTOL50"},
  204.                 {title = "Taxi", name = "HeavyPistol", model = "WEAPON_HeavyPistol"},
  205.                 {title = "Dépanneur", name = "VintagePistol", model = "WEAPON_VintagePistol"},
  206.                 {title = "Journaliste", name = "APPistol", model = "WEAPON_APPistol"},
  207.             }
  208.         },
  209.         ["Carteidentite"] = {
  210.             title = "CARTE DIDENTITE",
  211.             name = "Carteidentite",
  212.             buttons = {
  213.                 {title = "TEST", name = "MicroSMG", model = "WEAPON_MicroSMG"},
  214.                 {title = "TEST", name = "MachinePistol", model = "WEAPON_MachinePistol"},
  215.                 {title = "TEST", name = "SMG", model = "WEAPON_SMG"},
  216.                 {title = "TEST", name = "AssaultSMG", model = "WEAPON_AssaultSMG"},
  217.                 {title = "TEST", name = "CombatPDW", model = "WEAPON_CombatPDW"},
  218.                 {title = "TEST", name = "Gusenberg", model = "WEAPON_Gusenberg"},
  219.             }
  220.         },
  221.         ["Donnerdelargent"] = {
  222.             title = "DONNER DE LARGENT",
  223.             name = "Donnerdelargent",
  224.             buttons = {
  225.                 {title = "TEST", name = "PumpShotgun", description = {}, model = "WEAPON_PumpShotgun"},
  226.                 {title = "TEST", name = "SawnoffShotgun", description = {}, model = "WEAPON_SawnoffShotgun"},
  227.             }
  228.         },
  229.     }
  230. }
  231.  
  232. local function LocalPed()
  233. return GetPlayerPed(-1)
  234. end
  235.  
  236. function drawTxt(text,font,centre,x,y,scale,r,g,b,a)
  237.     SetTextFont(font)
  238.     SetTextProportional(0)
  239.     SetTextScale(scale, scale)
  240.     SetTextColour(r, g, b, a)
  241.     SetTextDropShadow(0, 0, 0, 0,255)
  242.     SetTextEdge(1, 0, 0, 0, 255)
  243.     SetTextDropShadow()
  244.     SetTextOutline()
  245.     SetTextCentre(centre)
  246.     SetTextEntry("STRING")
  247.     AddTextComponentString(text)
  248.     DrawText(x , y)
  249. end
  250.  
  251. function f(n)
  252.     return n + 0.0001
  253. end
  254.  
  255. function LocalPed()
  256.     return GetPlayerPed(-1)
  257. end
  258.  
  259. function try(f, catch_f)
  260.     local status, exception = pcall(f)
  261.     if not status then
  262.         catch_f(exception)
  263.     end
  264. end
  265.  
  266. function firstToUpper(str)
  267.     return (str:gsub("^%l", string.upper))
  268. end
  269.  
  270. --local veh = nil
  271. function OpenCreator()
  272.     boughtWeapon = false
  273.     local ped = GetPlayerPed(-1)
  274.     pmenu.currentmenu = "main"
  275.     pmenu.opened = true
  276.     pmenu.selectedbutton = 0
  277. end
  278.  
  279. function CloseCreator()
  280.     Citizen.CreateThread(function()
  281.         local ped = GetPlayerPed(-1)
  282.         pmenu.opened = false
  283.         pmenu.menu.from = 1
  284.         pmenu.menu.to = 10
  285.     end)
  286. end
  287.  
  288. function drawMenuButton(button,x,y,selected)
  289.     local menu = pmenu.menu
  290.     SetTextFont(menu.font)
  291.     SetTextProportional(0)
  292.     SetTextScale(menu.scale, menu.scale)
  293.     if selected then
  294.         SetTextColour(0, 0, 0, 255)
  295.     else
  296.         SetTextColour(255, 255, 255, 255)
  297.     end
  298.     SetTextCentre(0)
  299.     SetTextEntry("STRING")
  300.     AddTextComponentString(button.title)
  301.     if selected then
  302.         DrawRect(x,y,menu.width,menu.height,255,255,255,255)
  303.     else
  304.         DrawRect(x,y,menu.width,menu.height,0,0,0,150)
  305.     end
  306.     DrawText(x - menu.width/2 + 0.005, y - menu.height/2 + 0.0028)
  307. end
  308.  
  309. function drawMenuTitle(txt,x,y)
  310. local menu = pmenu.menu
  311.     SetTextFont(2)
  312.     SetTextProportional(0)
  313.     SetTextScale(0.5, 0.5)
  314.     SetTextColour(255, 255, 255, 255)
  315.     SetTextEntry("STRING")
  316.     AddTextComponentString(txt)
  317.     DrawRect(x,y,menu.width,menu.height,0,0,0,150)
  318.     DrawText(x - menu.width/2 + 0.005, y - menu.height/2 + 0.0028)
  319. end
  320.  
  321. function tablelength(T)
  322.   local count = 0
  323.   for _ in pairs(T) do count = count + 1 end
  324.   return count
  325. end
  326.  
  327. local backlock = false
  328. Citizen.CreateThread(function()
  329.     while true do
  330.         Citizen.Wait(0)
  331.         -- drawTxt(dump(pmenu.menu["Animations"].buttons),0,1,0.5,0.75,0.2,255,255,255,255)
  332.         -- drawTxt(dump(pmenu.menu["Inventaire"].buttons),0,1,0.5,0.80,0.2,255,255,255,255)
  333.         -- drawTxt(dump(inventory_table),0,1,0.5,0.85,0.2,255,255,255,255)
  334.         -- drawTxt(dump(ITEMS),0,1,0.5,0.9,0.4,255,255,255,255)
  335.         -- drawTxt(pmenu.menu["Inventaire"].title),0,1,0.5,0.95,0.4,255,255,255,255)
  336.         if IsControlJustPressed(1,246) then
  337.             if pmenu.opened then
  338.                 CloseCreator()
  339.             else
  340.                 OpenCreator()
  341.             end
  342.         end
  343.         if pmenu.opened then
  344.             local ped = LocalPed()
  345.             local menu = pmenu.menu[pmenu.currentmenu]
  346.             drawTxt(pmenu.title,1,1,pmenu.menu.x,pmenu.menu.y,1.0, 255,255,255,255)
  347.             drawMenuTitle(menu.title, pmenu.menu.x,pmenu.menu.y + 0.08)
  348.             drawTxt(pmenu.selectedbutton.."/"..tablelength(menu.buttons),0,0,pmenu.menu.x + pmenu.menu.width/2 - 0.0385,pmenu.menu.y + 0.067,0.4, 255,255,255,255)
  349.             local y = pmenu.menu.y + 0.12
  350.             buttoncount = tablelength(menu.buttons)
  351.             local selected = false
  352.  
  353.             for i,button in pairs(menu.buttons) do
  354.                 if i >= pmenu.menu.from and i <= pmenu.menu.to then
  355.  
  356.                     if i == pmenu.selectedbutton then
  357.                         selected = true
  358.                     else
  359.                         selected = false
  360.                     end
  361.                     drawMenuButton(button,pmenu.menu.x,y,selected)
  362.                     y = y + 0.04
  363.                     if selected and IsControlJustPressed(1,201) then
  364.                         ButtonSelected(button)
  365.                     end
  366.                 end
  367.             end
  368.         end
  369.         if pmenu.opened then
  370.             if IsControlJustPressed(1,202) then
  371.                 Back()
  372.             end
  373.             if IsControlJustReleased(1,202) then
  374.                 backlock = false
  375.             end
  376.             if IsControlJustPressed(1,188) then
  377.                 if pmenu.selectedbutton > 1 then
  378.                     pmenu.selectedbutton = pmenu.selectedbutton -1
  379.                     if buttoncount > 10 and pmenu.selectedbutton < pmenu.menu.from then
  380.                         pmenu.menu.from = pmenu.menu.from -1
  381.                         pmenu.menu.to = pmenu.menu.to - 1
  382.                     end
  383.                 end
  384.             end
  385.             if IsControlJustPressed(1,187)then
  386.                 if pmenu.selectedbutton < buttoncount then
  387.                     pmenu.selectedbutton = pmenu.selectedbutton +1
  388.                     if buttoncount > 10 and pmenu.selectedbutton > pmenu.menu.to then
  389.                         pmenu.menu.to = pmenu.menu.to + 1
  390.                         pmenu.menu.from = pmenu.menu.from + 1
  391.                     end
  392.                 end
  393.             end
  394.         end
  395.  
  396.     end
  397. end)
  398.  
  399. function round(num, idp)
  400.   if idp and idp>0 then
  401.     local mult = 10^idp
  402.     return math.floor(num * mult + 0.5) / mult
  403.   end
  404.   return math.floor(num + 0.5)
  405. end
  406.  
  407. function ButtonSelected(button)
  408.     local ped = GetPlayerPed(-1)
  409.     local this = pmenu.currentmenu
  410.     local btn = button.name
  411.     if this == "main" then
  412.         if btn == "Inventaire" then
  413.             OpenMenu('Inventaire')
  414.         elseif btn == "Animations" then
  415.             OpenMenu('Animations')
  416.         elseif btn == "Objets" then
  417.             OpenMenu('Objets')
  418.         elseif btn == "Telephone" then
  419.             OpenMenu('Telephone')
  420.         elseif btn == "Carteidentite" then
  421.             OpenMenu('Carteidentite')
  422.         elseif btn == "Donnerdelargent" then
  423.             OpenMenu('Donnerdelargent')
  424.         end
  425.     elseif this == "Inventaire" then
  426.         OpenMenu('InventaireSelect')
  427.     elseif this == "Animations" then
  428.         if ped and button.emote == "STOP EMOTE" then
  429.             ClearPedTasks(ped)
  430.         elseif ped then
  431.             ClearPedTasks(ped)
  432.             TaskStartScenarioInPlace(ped, button.emote, 0, true)
  433.         end
  434.     elseif this == "Objets" then
  435.         if ped then
  436.             GiveDelayedWeaponToPed(PlayerPedId(), GetHashKey(button.hash), 1000, true)
  437.         end
  438.     end
  439. end
  440.  
  441. function OpenMenu(menu)
  442.     pmenu.lastmenu = pmenu.currentmenu
  443.     pmenu.menu.from = 1
  444.     pmenu.menu.to = 10
  445.     pmenu.selectedbutton = 0
  446.     pmenu.currentmenu = menu
  447. end
  448.  
  449. function Back()
  450.     if backlock then
  451.         return
  452.     end
  453.     backlock = true
  454.     if pmenu.currentmenu == "main" then
  455.         boughtWeapon = false
  456.         CloseCreator()
  457.     elseif pmenu.currentmenu == "Inventaire" then
  458.         OpenMenu("main")
  459.     else
  460.         OpenMenu(pmenu.lastmenu)
  461.     end
  462.  
  463. end
  464.  
  465. function stringstarts(String,Start)
  466.    return string.sub(String,1,string.len(Start))==Start
  467. end
  468.  
  469. function Chat(debugg)
  470.     TriggerEvent("chatMessage", '', { 0, 0x99, 255 }, tostring(debugg))
  471. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement