Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.50 KB | None | 0 0
  1. cars = {
  2. --{id,név,ár},
  3. {400,"BMW X5",10000000},
  4. {401,"BMW X6",11000000},
  5. {402,"BMW X7",12000000},
  6. }
  7.  
  8. shopX,shopY,shopZ = 370.09644, -471.09140, 24.53954-1
  9. carX,carY,carZ = 396.42136, -401.18680, 26.02704
  10. minZ = -1
  11. maxZ = 2
  12.  
  13.  
  14. camRotX = 0
  15. camRotZ = 0
  16. startMarker = createMarker(shopX,shopY,shopZ,"cylinder",2,40,40,255)
  17.  
  18. function MarkerHit ( hitPlayer, matchingDimension )
  19.     if hitPlayer == localPlayer then
  20.         playerInShop = true
  21.         setElementFrozen(localPlayer,true)
  22.         selectedVeh = 1
  23.         if shopVeh then
  24.             destroyElement(shopVeh)
  25.         end
  26.         shopVeh = createVehicle(cars[selectedVeh][1],carX,carY,carZ)
  27.         startCameraAround(shopVeh,10)
  28.     end
  29. end
  30. addEventHandler ( "onClientMarkerHit", getRootElement(), MarkerHit )
  31.  
  32. bindKey("backspace","down",function()
  33.     if playerInShop then
  34.         playerInShop = false
  35.         setElementFrozen(localPlayer,false)
  36.         stopCameraAround()
  37.     end
  38. end)
  39.  
  40. bindKey("arrow_l","down",function()
  41.     selectedVeh = selectedVeh-1
  42.     if selectedVeh<1 then
  43.         selectedVeh = #cars
  44.     end
  45.     refreshModel()
  46. end)
  47. bindKey("arrow_r","down",function()
  48.     selectedVeh = selectedVeh+1
  49.     if selectedVeh>#cars then
  50.         selectedVeh = 1
  51.     end
  52.     refreshModel()
  53. end)
  54.  
  55. bindKey("enter","down",function()
  56.     if playerInShop then
  57.         --triggerserverevent!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  58.     end
  59. end)
  60.  
  61. panelSize={200,75}
  62.  
  63. function render()
  64.     if playerInShop then
  65.         if getKeyState("a") then
  66.             camRotX = camRotX+0.5
  67.         end
  68.         if getKeyState("d") then
  69.             camRotX = camRotX-0.5
  70.         end
  71.         if getKeyState("w") then
  72.             camRotZ = camRotZ+0.02
  73.             if camRotZ > maxZ then
  74.                 camRotZ = maxZ
  75.             end
  76.         end
  77.         if getKeyState("s") then
  78.             camRotZ = camRotZ-0.02
  79.             if camRotZ < minZ then
  80.                 camRotZ = minZ
  81.             end
  82.         end
  83.         camx,camy = getCirclePosition(camRotX,camDist)--vagy + ha fordítva forog a kamera
  84.         px,py,pz = getElementPosition(camAround)
  85.         setCameraMatrix(camx+px,camy+py,pz+camRotZ,px,py,pz)
  86.         cx,cy,cz = getElementPosition(shopVeh)
  87.         local coords = { getScreenFromWorldPosition ( cx+2,cy,cz ) }
  88.         if coords[1] and coords[2] then
  89.             dxDrawRectangle(coords[1]-panelSize[1]/2,coords[2]-panelSize[2]/2,panelSize[1],panelSize[2],tocolor(0,0,0,180))
  90.             dxDrawText(cars[selectedVeh][2].."\n"..convertNumber(cars[selectedVeh][3]).." forint ",coords[1],coords[2],coords[1],coords[2],tocolor(255,255,255,255),1.5,"sans","center","center")
  91.         end
  92.         local coords = { getScreenFromWorldPosition ( cx+2,cy,cz+1 ) }
  93.         if coords[1] and coords[2] then
  94.             dxDrawRectangle(coords[1]-panelSize[1]/2,coords[2]-panelSize[2]/2,panelSize[1],panelSize[2],tocolor(0,0,0,180))
  95.             dxDrawText("Forgatás: W,A,S,D\nVáltás: Nyilak\nMegvétel: Enter\nKilépés: Backspace",coords[1],coords[2],coords[1],coords[2],tocolor(255,255,255,255),1,"sans","center","center")
  96.         end
  97.     end
  98. end
  99. addEventHandler("onClientRender",root,render)
  100.  
  101.  
  102. function startCameraAround(element,distance)
  103.     camAround = element
  104.     camDist = distance
  105. end
  106.  
  107. function stopCameraAround()
  108.     camAround = false
  109.     setCameraTarget(localPlayer)
  110. end
  111.  
  112. function getCirclePosition(number,scale)
  113.     x = (math.cos(math.rad(number)))*scale
  114.     y = (math.sin(math.rad(number)))*scale
  115.     return x,y
  116. end
  117.  
  118. function convertNumber ( number )  
  119.     local formatted = number  
  120.     while true do      
  121.         formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')    
  122.         if ( k==0 ) then      
  123.             break  
  124.         end  
  125.     end  
  126.     return formatted
  127. end
  128.  
  129. function refreshModel()
  130.     setElementModel(shopVeh,cars[selectedVeh][1])
  131.     cx,cy,cz = getElementPosition(shopVeh)
  132.     setElementPosition(shopVeh,cx,cy,cz+0.5)
  133. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement