Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.25 KB | None | 0 0
  1. local skinCost = math.random(150, 200)
  2. local s = {guiGetScreenSize()}
  3. local box = {200,50}
  4. local pos = {s[1]/2 - box[1]/2,s[2]/1.9 - box[2]/2}
  5. local font = dxCreateFont("assets/fonts/font.ttf", 14)
  6.  
  7. addEventHandler("onClientResourceStart", resourceRoot,
  8. function()
  9. for k,v in pairs(markers) do
  10. local x,y,z,int,dim,type = unpack(v)
  11. local marker = createMarker(x,y,z, "cylinder", 1, 255,153,51)
  12. setElementDimension(marker, dim)
  13. setElementInterior(marker, int)
  14. setElementData(marker, "skinshop >> marker", true)
  15. setElementData(marker, "skinshop >> type", type)
  16. end
  17.  
  18. for k,v in pairs(getElementsByType("marker", root, true)) do
  19. if getElementType(v) == "marker" and getElementData(v, "skinshop >> marker") then
  20. cache[v] = true
  21. end
  22. end
  23. end
  24. )
  25.  
  26. addEventHandler("onClientElementStreamIn", root,
  27. function()
  28. if getElementType(source) == "marker" and getElementData(source, "skinshop >> marker") then
  29. cache[source] = true
  30. end
  31.  
  32. local id = 0
  33. for k,v in pairs(cache) do
  34. id = id + 1
  35. if id > 2 then
  36. return
  37. end
  38. end
  39.  
  40. if id == 1 and not state then
  41. addEventHandler("onClientRender", root, drawnIcons, false, "low")
  42. state = true
  43. --setElementData(localPlayer, "hudVisible", false)
  44. end
  45. end
  46. )
  47.  
  48. local ped
  49. local pedPos = {359.244140625, 6.6425838470459, 842.69158935547}
  50. local cameraMatrix = {359.25869750977, 12.592300415039, 844.83660888672, pedPos[1], pedPos[2], pedPos[3]}
  51.  
  52.  
  53. addEventHandler("onClientElementStreamOut", root,
  54. function()
  55. if getElementType(source) == "marker" and getElementData(source, "skinshop >> marker") then
  56. cache[source] = nil
  57. end
  58.  
  59. local id = 0
  60. for k,v in pairs(cache) do
  61. id = id + 1
  62. if id > 0 then
  63. return
  64. end
  65. end
  66.  
  67. if id == 0 and state then
  68. removeEventHandler("onClientRender", root, drawnIcons)
  69. state = false
  70. --setElementData(localPlayer, "hudVisible", true)
  71. end
  72. end
  73. )
  74.  
  75. function drawnIcons()
  76. for k,v in pairs(cache) do
  77. local x,y,z = getElementPosition(k)
  78. z = z + 1
  79. local sx, sy = getScreenFromWorldPosition(x,y,z)
  80.  
  81. if sx and sy then
  82. local xx, yy, zz = getElementPosition(localPlayer)
  83. local dist = getDistanceBetweenPoints3D(x, y, z, xx, yy, zz)
  84. if dist < maxDist then
  85. local fontsize = 1 - (dist / maxDist)
  86. local alpha = 255 * fontsize
  87. dxDrawImage(sx-25, sy-60, 60, 60, getElementData(k, "skinshop >> type"),0,0,0, tocolor(255,255,255,255))
  88.  
  89. end
  90. end
  91. end
  92. end
  93.  
  94. addEventHandler("onClientMarkerHit", root,
  95. function(hitPlayer, matchingDimension)
  96.  
  97. if hitPlayer ~= localPlayer then return end
  98. if getElementDimension(source) == getElementDimension(localPlayer) and getElementData(source, "skinshop >> marker") then
  99. addEventHandler("onClientRender", root, shopRender, false, "low")
  100. startTime = getTickCount()
  101. endTime = startTime + 2000
  102. setElementFrozen(localPlayer, true)
  103. nowSkin = 1
  104. setCameraMatrix(unpack(cameraMatrix))
  105. bindKeys()
  106. setElementData(localPlayer, "hudVisible", false)
  107. showChat(false)
  108. executeCommandHandler("togbar")
  109. markerDim = getElementDimension(source)
  110. markerType = getElementData(source, "skinshop >> type")
  111. if markerType == "assets/icons/male.png" then
  112. ped = createPed(maleSkins[1], unpack(pedPos))
  113. setElementInterior(ped, getElementInterior(localPlayer))
  114. setElementDimension(ped, getElementDimension(localPlayer))
  115. skin = maleSkins[1]
  116. elseif markerType == "assets/icons/female.png" then
  117. ped = createPed(femaleSkins[1], unpack(pedPos))
  118. setElementInterior(ped, getElementInterior(localPlayer))
  119. setElementDimension(ped, getElementDimension(localPlayer))
  120. skin = femaleSkins[1]
  121. end
  122. end
  123. end
  124. )
  125.  
  126. function bindKeys()
  127. bindKey("backspace", "down", closePanel)
  128. bindKey("enter", "down", buyClothes)
  129. bindKey("arrow_r", "down", rightSwitch)
  130. bindKey("arrow_l", "down", leftSwitch)
  131. end
  132.  
  133. function closePanel()
  134. unbindKeys()
  135. if isElement(ped) then
  136. destroyElement(ped)
  137. ped = nil
  138. end
  139. setCameraTarget(localPlayer, localPlayer)
  140. setElementFrozen(localPlayer, false)
  141. removeEventHandler("onClientRender", root, shopRender)
  142. setElementDimension(localPlayer, markerDim)
  143. setElementData(localPlayer, "hudVisible", true)
  144. showChat(true)
  145. executeCommandHandler("togbar")
  146. end
  147.  
  148. function unbindKeys()
  149. unbindKey("backspace", "down", closePanel)
  150. unbindKey("enter", "down", buyClothes)
  151. unbindKey("arrow_r", "down", rightSwitch)
  152. unbindKey("arrow_l", "down", leftSwitch)
  153. end
  154.  
  155. function buyClothes()
  156. local money = tonumber(getElementData(localPlayer, "money"))
  157. if money >= skinCost then
  158. setElementData(localPlayer, "money", money - skinCost)
  159. setElementData(localPlayer, "newSkin", skin)
  160. outputChatBox("#ff9933[Replay]:#FFFFFF Sikeresen megvásároltad a kiválasztott kinézetet, ez #ff9933"..skinCost.."#FFFFFF $-ba került!",255,255,255,true)
  161. closePanel()
  162. else
  163. exports['dm_infobox']:addNotification("Nincs elég pénzed!", "error")
  164. end
  165. end
  166.  
  167. function rightSwitch(element)
  168. if markerType == "assets/icons/male.png" then
  169. if maleSkins[nowSkin + 1] then
  170. nowSkin = nowSkin + 1
  171. skin = maleSkins[nowSkin]
  172. setElementModel(ped, skin)
  173. skinCost = math.random(150, 200)
  174. end
  175. elseif markerType == "assets/icons/female.png" then
  176. if femaleSkins[nowSkin + 1] then
  177. nowSkin = nowSkin + 1
  178. skin = femaleSkins[nowSkin]
  179. setElementModel(ped, skin)
  180. skinCost = math.random(150, 200)
  181. end
  182. end
  183. end
  184.  
  185. function leftSwitch(element)
  186. if markerType == "assets/icons/male.png" then
  187. if maleSkins[nowSkin - 1] then
  188. nowSkin = nowSkin - 1
  189. skin = maleSkins[nowSkin]
  190. setElementModel(ped, skin)
  191. skinCost = math.random(150, 200)
  192. end
  193. elseif markerType == "assets/icons/female.png" then
  194. if femaleSkins[nowSkin - 1] then
  195. nowSkin = nowSkin - 1
  196. skin = femaleSkins[nowSkin]
  197. setElementModel(ped, skin)
  198. skinCost = math.random(150, 200)
  199. end
  200. end
  201. end
  202.  
  203. local x1, y1 = 140, 80
  204.  
  205. function shopRender()
  206.  
  207. rot = rot + 2
  208.  
  209. if rot >= 360 then
  210. rot = -360
  211. elseif rot <= -360 then
  212. rot = -360
  213. end
  214.  
  215. setElementRotation(ped, 0, 0, rot + 10)
  216.  
  217. --[[local now = getTickCount()
  218. local elapsedTime = now - startTime
  219. local duration = endTime - startTime
  220. local progress = elapsedTime / duration
  221.  
  222. local x = interpolateBetween(scy, 0, 0, scy - x1 - 30, 0, 0, progress, "OutInQuad")
  223.  
  224. dxDrawRectangle(x, scy / 2 - y1/2-100, x1, y1, tocolor(0,0,0,220))
  225. dxDrawLine(x, scy / 2 + y1/2, x + x1, scy / 2 + y1/2, tocolor(87,87,255), 2)
  226. dxDrawText("Karakter kinézet:" .. skin, x + x1/2, scy / 2 - y1/2 + 20, x + x1/2, scy / 2 - y1/2 + 20, tocolor(255,255,255,255), 1, "sans", "center", "center")
  227. dxDrawText("Ár: " .. skinCost .. "Ft", x + x1/2, scy / 2 + y1/2 - 20, x + x1/2, scy / 2 + y1/2 - 20, tocolor(255,255,255,255), 1, "sans", "center", "center")]]
  228.  
  229. dxDrawRectangle(pos[1], pos[2]+300, box[1], box[2], tocolor(22,22,22, 240))
  230. dxDrawBorder(pos[1], pos[2]+300, box[1], box[2],2, tocolor(0,0,0, 140))
  231. -- Ára
  232. dxDrawText("Kinézet ára:", pos[1]+49, pos[2]+301, 0,0, tocolor(0,0,0,255),1, font)
  233. dxDrawText("Kinézet ára:", pos[1]+50, pos[2]+300, 0,0, tocolor(255,255,255,255),1, font)
  234. dxDrawText("#ff9933" ..skinCost.. " #ffffff$", pos[1]+75, pos[2]+325, 0,0, tocolor(255,255,255,255),1, font, "left", "top", true, true, true, true)
  235. dxDrawText("" ..skinCost.. " $", pos[1]+76, pos[2]+326, 0,0, tocolor(0,0,0,255),1, font)
  236. if nowSkin > 1 then
  237. dxDrawImage(pos[1]-39, pos[2]+311, 30, 30, "assets/icons/left.png", 0,0,0, tocolor(0,0,0,255))
  238. dxDrawImage(pos[1]-40, pos[2]+310, 30, 30, "assets/icons/left.png", 0,0,0, tocolor(255,255,255,255))
  239. end
  240. dxDrawImage(pos[1]+209, pos[2]+311, 30, 30, "assets/icons/right.png", 0,0,0, tocolor(0,0,0,255))
  241. dxDrawImage(pos[1]+210, pos[2]+310, 30, 30, "assets/icons/right.png", 0,0,0, tocolor(255,255,255,255))
  242. end
  243.  
  244. function clientClick(btn, state)
  245. if state == "down" then
  246. if isInSlot(pos[1]+210, pos[2]+310, 30, 30) then
  247. rightSwitch()
  248. elseif isInSlot(pos[1]-39, pos[2]+311, 30, 30) and nowSkin > 1 then
  249. leftSwitch()
  250. end
  251. end
  252. end
  253. addEventHandler("onClientClick", root, clientClick)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement