Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.67 KB | None | 0 0
  1. function giveColumnName(collection, valueId)
  2.     local res = nil
  3.         local id = tonumber(valueId)
  4.         if (collection == "component") then
  5.             if (id == 0) then
  6.                 res = "face"
  7.             end
  8.             if (id == 1) then
  9.                 res = "mask"
  10.             end
  11.             if (id == 2) then
  12.                 res = "hair"
  13.             end
  14.             if (id == 3) then
  15.                 res = "gloves"
  16.             end
  17.             if (id == 4) then
  18.                 res = "pants"
  19.             end
  20.             if (id == 5) then
  21.                 res = "bag"
  22.             end
  23.             if (id == 6) then
  24.                 res = "shoes"
  25.             end
  26.             if (id == 8) then
  27.                 res = "shirt"
  28.             end
  29.             if (id == 9) then
  30.                 res = "vest"
  31.             end
  32.             if (id == 11) then
  33.                 res = "jacket"
  34.             end
  35.         else
  36.             if (collection == "prop") then
  37.                 if (id == 0) then
  38.                     res = "hat"
  39.                 end
  40.                 if (id == 1) then
  41.                     res = "glasses"
  42.                 end
  43.                 if (id == 2) then
  44.                     res = "ears"
  45.                 end
  46.             end
  47.         end
  48.         return res
  49. end
  50.  
  51. RegisterServerEvent("clothing_shop:SpawnPlayer_server")
  52. AddEventHandler("clothing_shop:SpawnPlayer_server", function()
  53. local source = source
  54.     TriggerEvent('es:getPlayerFromId', source, function(user)
  55.         TriggerEvent('weaponshop:GiveWeaponsToPlayer', source)
  56.         local player = user.getIdentifier()
  57.         MySQL.Async.fetchAll("SELECT isFirstConnection FROM users WHERE identifier = @username", {['@username'] = player}, function(result)
  58.         if(result)then
  59.          if (result[1].isFirstConnection == 1) then
  60.             MySQL.Async.execute("INSERT INTO user_clothes(identifier) VALUES ('@identifier')",{['@identifier']=player})
  61.             MySQL.Async.execute("UPDATE users SET isFirstConnection = 0 WHERE identifier = '@username'", {['@username'] = player})
  62.             MySQL.Async.fetchAll("SELECT * FROM user_clothes WHERE identifier = @username", {['@username'] = player}, function(result1)
  63.             if(result1) then
  64.             TriggerClientEvent("clothing_shop:loadItems_client", source, {result[1].face,result[1].face_texture,result[1].hair,result[1].hair_texture,result[1].shirt,result[1].shirt_texture,result[1].pants,result[1].pants_texture,result[1].shoes,result[1].shoes_texture,result[1].vest,result[1].vest_texture,result[1].bag,result[1].bag_texture,result[1].hat,result[1].hat_texture,result[1].mask,result[1].mask_texture,result[1].glasses,result[1].glasses_texture,result[1].gloves,result[1].gloves_texture,result[1].jacket,result[1].jacket_texture,result[1].ears,result[1].ears_texture})
  65.         end
  66.         end)
  67.         end
  68.         end
  69.         end)
  70.             MySQL.Async.fetchAll("SELECT * FROM user_clothes WHERE identifier = @username", {['@username'] = player}, function(result2)
  71.             if(result2) then
  72.             TriggerClientEvent("clothing_shop:loadItems_client", source, {result[1].face,result[1].face_texture,result[1].hair,result[1].hair_texture,result[1].shirt,result[1].shirt_texture,result[1].pants,result[1].pants_texture,result[1].shoes,result[1].shoes_texture,result[1].vest,result[1].vest_texture,result[1].bag,result[1].bag_texture,result[1].hat,result[1].hat_texture,result[1].mask,result[1].mask_texture,result[1].glasses,result[1].glasses_texture,result[1].gloves,result[1].gloves_texture,result[1].jacket,result[1].jacket_texture,result[1].ears,result[1].ears_texture})
  73.         end
  74.     end)
  75. end)
  76. end)
  77.  
  78. RegisterServerEvent("clothing_shop:SetItems_server")
  79.     AddEventHandler("clothing_shop:SetItems_servers",function()
  80.     local source = source
  81.     TriggerEvent('es:getPlayerFromId', source, function(user)
  82.         local player = user.getIdentifier()
  83.         MySQL.Async.fetchAll("SELECT * FROM user_clothes WHERE identifier = @username", {['@username'] = player}, function(result)
  84.         if(result) then
  85.         TriggerClientEvent("clothing_shop:loadItems_client", source, {result[1].face,result[1].face_texture,result[1].hair,result[1].hair_texture,result[1].shirt,result[1].shirt_texture,result[1].pants,result[1].pants_texture,result[1].shoes,result[1].shoes_texture,result[1].vest,result[1].vest_texture,result[1].bag,result[1].bag_texture,result[1].hat,result[1].hat_texture,result[1].mask,result[1].mask_texture,result[1].glasses,result[1].glasses_texture,result[1].gloves,result[1].gloves_texture,result[1].jacket,result[1].jacket_texture,result[1].ears,result[1].ears_texture})
  86.         end
  87.         end)
  88.     end)
  89. end)
  90.  
  91. RegisterServerEvent("clothing_shop:SaveItem_server")
  92. AddEventHandler("clothing_shop:SaveItem_server", function(item, values)
  93. local source = source
  94.     TriggerEvent('es:getPlayerFromId', source, function(user)
  95.         local name = giveColumnName(item.collection, item.id)
  96.         if (name == "skin") then
  97.             MySQL.Async.execute("UPDATE user_clothes SET skin = '@value' WHERE identifier = '@identifier'",{
  98.                    ['@value'] = values.value,
  99.                    ['@identifier'] = user.getIdentifier()
  100.                 }
  101.             )
  102.         else
  103.             MySQL.Async.execute("UPDATE user_clothes SET ".. name .." = '@value', ".. name..'_texture' .." = '@texture_value' WHERE identifier = '@identifier'",{
  104.                    ['@value'] = values.value,
  105.                    ['@texture_value'] = values.texture_value,
  106.                    ['@identifier'] = user.getIdentifier()
  107.                 }
  108.             )
  109.         end
  110.         TriggerClientEvent("es_freeroam:notify", source, "CHAR_SOCIAL_CLUB", 1, "Binco Shop", false, "You bought a new item!")
  111.        
  112.     end)
  113. end)
  114.  
  115.  
  116. RegisterServerEvent("clothing_shop:WithDraw_server")
  117. AddEventHandler("clothing_shop:WithDraw_server",function(item, values)
  118. local source = source
  119. TriggerEvent('es:getPlayerFromId', source, function(user)
  120.         MySQL.Async.fetchAll("SELECT money FROM users WHERE identifier = '@identifier'", {['@identifier'] = user.getIdentifier()}, function(money)
  121.         if money[1] then
  122.         TriggerClientEvent("clothing_shop:buyItem_client", source, {item=item, values=values, money=money})
  123.         end
  124.         end)
  125.     end)
  126. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement