Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cars = {
- --{id,név,ár},
- {400,"BMW X5",10000000},
- {401,"BMW X6",11000000},
- {402,"BMW X7",12000000},
- }
- shopX,shopY,shopZ = 370.09644, -471.09140, 24.53954-1
- carX,carY,carZ = 396.42136, -401.18680, 26.02704
- minZ = -1
- maxZ = 2
- camRotX = 0
- camRotZ = 0
- startMarker = createMarker(shopX,shopY,shopZ,"cylinder",2,40,40,255)
- function MarkerHit ( hitPlayer, matchingDimension )
- if hitPlayer == localPlayer then
- playerInShop = true
- setElementFrozen(localPlayer,true)
- selectedVeh = 1
- if shopVeh then
- destroyElement(shopVeh)
- end
- shopVeh = createVehicle(cars[selectedVeh][1],carX,carY,carZ)
- startCameraAround(shopVeh,10)
- end
- end
- addEventHandler ( "onClientMarkerHit", getRootElement(), MarkerHit )
- bindKey("backspace","down",function()
- if playerInShop then
- playerInShop = false
- setElementFrozen(localPlayer,false)
- stopCameraAround()
- end
- end)
- bindKey("arrow_l","down",function()
- selectedVeh = selectedVeh-1
- if selectedVeh<1 then
- selectedVeh = #cars
- end
- refreshModel()
- end)
- bindKey("arrow_r","down",function()
- selectedVeh = selectedVeh+1
- if selectedVeh>#cars then
- selectedVeh = 1
- end
- refreshModel()
- end)
- bindKey("enter","down",function()
- if playerInShop then
- --triggerserverevent!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- end
- end)
- panelSize={200,75}
- function render()
- if playerInShop then
- if getKeyState("a") then
- camRotX = camRotX+0.5
- end
- if getKeyState("d") then
- camRotX = camRotX-0.5
- end
- if getKeyState("w") then
- camRotZ = camRotZ+0.02
- if camRotZ > maxZ then
- camRotZ = maxZ
- end
- end
- if getKeyState("s") then
- camRotZ = camRotZ-0.02
- if camRotZ < minZ then
- camRotZ = minZ
- end
- end
- camx,camy = getCirclePosition(camRotX,camDist)--vagy + ha fordítva forog a kamera
- px,py,pz = getElementPosition(camAround)
- setCameraMatrix(camx+px,camy+py,pz+camRotZ,px,py,pz)
- cx,cy,cz = getElementPosition(shopVeh)
- local coords = { getScreenFromWorldPosition ( cx+2,cy,cz ) }
- if coords[1] and coords[2] then
- dxDrawRectangle(coords[1]-panelSize[1]/2,coords[2]-panelSize[2]/2,panelSize[1],panelSize[2],tocolor(0,0,0,180))
- 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")
- end
- local coords = { getScreenFromWorldPosition ( cx+2,cy,cz+1 ) }
- if coords[1] and coords[2] then
- dxDrawRectangle(coords[1]-panelSize[1]/2,coords[2]-panelSize[2]/2,panelSize[1],panelSize[2],tocolor(0,0,0,180))
- 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")
- end
- end
- end
- addEventHandler("onClientRender",root,render)
- function startCameraAround(element,distance)
- camAround = element
- camDist = distance
- end
- function stopCameraAround()
- camAround = false
- setCameraTarget(localPlayer)
- end
- function getCirclePosition(number,scale)
- x = (math.cos(math.rad(number)))*scale
- y = (math.sin(math.rad(number)))*scale
- return x,y
- end
- function convertNumber ( number )
- local formatted = number
- while true do
- formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
- if ( k==0 ) then
- break
- end
- end
- return formatted
- end
- function refreshModel()
- setElementModel(shopVeh,cars[selectedVeh][1])
- cx,cy,cz = getElementPosition(shopVeh)
- setElementPosition(shopVeh,cx,cy,cz+0.5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement