Szerző Téma: Mit kellene beírnom a hud rendszerbe hogy fogyjon a stamina?  (Megtekintve 2872 alkalommal)

Mit kellene beírnom a hud rendszerbe hogy fogyjon a stamina?
« Dátum: 2020. március 21. - 20:28:51 »
0 Show voters
Sziasztok! Már a szerverünk nagy része megvan. Bugok vannak, rajta vagyunk a javításán. Most egy olyan dolog van hogy a hud rendszerben nincs beleírva hogy fogyjon a stamina. Szóval örök ideig lehet futni. De mivel egy RP szervert szeretnénk csinálni így fontos lenne ennek megoldása. Ha valaki tud segíteni azt nagyon szépen megköszönöm.
 
A script tartalma: -----<Scriptet Editelte>-----

local screenWidth, screenHeight = guiGetScreenSize()

local boxSize = 50
local hudW, hudH = 260, 150
local startX, startY = screenWidth - 5 - hudW, - 15

local hudHTML = createBrowser(hudW, hudH, true, true)
local create = true

addEventHandler("onClientBrowserCreated", hudHTML, function()
   loadBrowserURL(source, "http://mta/local/src/index.html")
end)

local font = dxCreateFont("src/gtaFont.ttf", 14)

local health = -1
local armor = -1
local food = -1
local stamina = -1
setPedAnimation(localPlayer)
toggleAllControls(true, true, true)

local money = 0

local framesPerSecond = 0
local framesDeltaTime = 0
local lastRenderTick = false

local moneyTick = 0

setElementData(localPlayer, "toggle-->Hud", true)
setElementData(localPlayer, "toggle-->All", true)
setElementData(localPlayer, "fps", 100)

function loadStats()
   setTimer(function()
      health = getElementHealth(localPlayer)
      executeBrowserJavascript(hudHTML, "changeHealth("..health..");")

      armor = getPedArmor(localPlayer)
      executeBrowserJavascript(hudHTML, "changeArmor("..armor..");")

      food = getElementData(localPlayer, "char:hunger")
      executeBrowserJavascript(hudHTML, "changeFood("..food..");")

      stamina = getElementData(localPlayer, "stamina")
      executeBrowserJavascript(hudHTML, "changeStamina("..stamina..");")
   end, 800, 1)
end
addEvent("loadStats", true)
addEventHandler("loadStats", root, loadStats)
addEventHandler("onClientResourceStart", resourceRoot, loadStats)

setPlayerHudComponentVisible("all", false)
setPlayerHudComponentVisible("crosshair", true)

addCommandHandler("togglehud", function()
   create = not create
end)

addEventHandler("onClientRender", root, function()
   if not getElementData(localPlayer, "loggedin") then return end
   if not getElementData(localPlayer, "toggle-->Hud") or not getElementData(localPlayer, "toggle-->All") then return end
   if not create then return end

   dxDrawImage(startX, startY, hudW, hudH, hudHTML)

   if getElementHealth(localPlayer) < 10 then
      dxDrawImage(0, 0, screenWidth, screenHeight, "src/damage.png")
   end

   dxDrawText("$ "..getMoney():gsub("#%x%x%x%x%x%x", ""), startX + 20 + 1, startY + 60 + 1, 0, 0, tocolor(0, 0, 0), 1, font, "left", "top", false, false, false, true)
   dxDrawText("$ "..getMoney():gsub("#%x%x%x%x%x%x", ""), startX + 20 + 1, startY + 60 - 1, 0, 0, tocolor(0, 0, 0), 1, font, "left", "top", false, false, false, true)
   dxDrawText("$ "..getMoney():gsub("#%x%x%x%x%x%x", ""), startX + 20 - 1, startY + 60 + 1, 0, 0, tocolor(0, 0, 0), 1, font, "left", "top", false, false, false, true)
   dxDrawText("$ "..getMoney():gsub("#%x%x%x%x%x%x", ""), startX + 20 - 1, startY + 60 - 1, 0, 0, tocolor(0, 0, 0), 1, font, "left", "top", false, false, false, true)
   dxDrawText("$ "..getMoney(), startX + 20, startY + 60, 0, 0, tocolor(255, 255, 255), 1, font, "left", "top", false, false, false, true)

   if moneyTick >= getTickCount() then
      dxDrawText("\n"..moneyChange:gsub("#%x%x%x%x%x%x", ""), startX + 20 + 1, startY + 60 + 1, 0, 0, tocolor(0, 0, 0), 1, font, "left", "top", false, false, false, true)
      dxDrawText("\n"..moneyChange:gsub("#%x%x%x%x%x%x", ""), startX + 20 + 1, startY + 60 - 1, 0, 0, tocolor(0, 0, 0), 1, font, "left", "top", false, false, false, true)
      dxDrawText("\n"..moneyChange:gsub("#%x%x%x%x%x%x", ""), startX + 20 - 1, startY + 60 + 1, 0, 0, tocolor(0, 0, 0), 1, font, "left", "top", false, false, false, true)
      dxDrawText("\n"..moneyChange:gsub("#%x%x%x%x%x%x", ""), startX + 20 - 1, startY + 60 - 1, 0, 0, tocolor(0, 0, 0), 1, font, "left", "top", false, false, false, true)
      dxDrawText("\n"..moneyChange, startX + 20, startY + 60, 0, 0, tocolor(255, 255, 255), 1, font, "left", "top", false, false, false, true)
   end

   renderFPS()
   if getElementData(localPlayer, "fps") <= 20 then
      hexCode = "#d24d57"         
   elseif getElementData(localPlayer, "fps") >= 21 and getElementData(localPlayer, "fps") <= 39 then
      hexCode = "#f89406"         
   elseif getElementData(localPlayer, "fps") >= 40 then
      hexCode = "#00aeef"
   end

   dxDrawText("FPS: "..getElementData(localPlayer, "fps"), startX + 1, startY + 60 + 1, startX + hudW - 10 + 1, startY + 1, tocolor(0, 0, 0), 1, font, "right", "top", false, false, false, true)
   dxDrawText("FPS: "..getElementData(localPlayer, "fps"), startX + 1, startY + 60 - 1, startX + hudW - 10 + 1, startY - 1, tocolor(0, 0, 0), 1, font, "right", "top", false, false, false, true)
   dxDrawText("FPS: "..getElementData(localPlayer, "fps"), startX - 1, startY + 60 + 1, startX + hudW - 10 - 1, startY + 1, tocolor(0, 0, 0), 1, font, "right", "top", false, false, false, true)
   dxDrawText("FPS: "..getElementData(localPlayer, "fps"), startX - 1, startY + 60 - 1, startX + hudW - 10 - 1, startY - 1, tocolor(0, 0, 0), 1, font, "right", "top", false, false, false, true)
   dxDrawText("FPS: "..hexCode..getElementData(localPlayer, "fps"), startX, startY + 60, startX + hudW - 10, startY, tocolor(255, 255, 255), 1, font, "right", "top", false, false, false, true)

   local hours = getRealTime().hour
   local minutes = getRealTime().minute

   if hours < 10 then
      hours = "0" .. hours
   end
   if minutes < 10 then
      minutes = "0" .. minutes
   end

   dxDrawText("\n" .. hours .. ":" .. minutes, startX + 1, startY + 60 + 1, startX + hudW - 10 + 1, startY + 1, tocolor(0, 0, 0), 1, font, "right", "top", false, false, false, false)
   dxDrawText("\n" .. hours .. ":" .. minutes, startX + 1, startY + 60 - 1, startX + hudW - 10 + 1, startY - 1, tocolor(0, 0, 0), 1, font, "right", "top", false, false, false, false)
   dxDrawText("\n" .. hours .. ":" .. minutes, startX - 1, startY + 60 + 1, startX + hudW - 10 - 1, startY + 1, tocolor(0, 0, 0), 1, font, "right", "top", false, false, false, false)
   dxDrawText("\n" .. hours .. ":" .. minutes, startX - 1, startY + 60 - 1, startX + hudW - 10 - 1, startY - 1, tocolor(0, 0, 0), 1, font, "right", "top", false, false, false, false)
   dxDrawText("\n" .. hours .. "#00aeef:#ffffff" .. minutes, startX, startY + 60, startX + hudW - 10, startY, tocolor(255, 255, 255), 1, font, "right", "top", false, false, false, true)

   if health ~= getElementHealth(localPlayer) then
      health = getElementHealth(localPlayer)
      executeBrowserJavascript(hudHTML, "changeHealth("..health..");")
   end

   if armor ~= getPedArmor(localPlayer) then
      armor = getPedArmor(localPlayer)
      executeBrowserJavascript(hudHTML, "changeArmor("..armor..");")
   end

   if food ~= getElementData(localPlayer, "char:hunger") then
      food = getElementData(localPlayer, "char:hunger")
      executeBrowserJavascript(hudHTML, "changeFood("..food..");")
   end

   if stamina ~= getElementData(localPlayer, "stamina") then
      stamina = getElementData(localPlayer, "stamina")
      executeBrowserJavascript(hudHTML, "changeStamina("..stamina..");")
   end
end)

addEventHandler("onClientElementDataChange", root, function(dataName, oldValue)
   if source == localPlayer and dataName == "char:money" and getElementData(localPlayer, "loggedin") then
        local newValue = getElementData(source, "char:money") or 0
        if newValue then
            moneyTick = getTickCount() + 5000

            moneyChange = math.abs(newValue - oldValue)
            if newValue < oldValue then
               moneyChange = "#d24d57$#ffffff-"..moneyChange
            else
               moneyChange = "#00aeef$#ffffff+"..moneyChange
            end

         playSound("src/money.mp3", false)
        end
    elseif source == localPlayer and dataName == "loggedin" then
       loadStats()
   end
end)

function getMoney()
   local maxDrawNull = 8
   local actualCharMoney = maxDrawNull - string.len(tostring(getElementData(localPlayer,"char:money")))
   finalConvert = ""
         
   for i = 0, actualCharMoney, 1 do
      finalConvert = finalConvert .. "0"
   end

   if getElementData(localPlayer, "char:money") >= 0 then
      finalConvert = finalConvert .. "#00aeef" .. thousandsStepper(getElementData(localPlayer, "char:money"))
   else
      finalConvert = "-" .. finalConvert .. "#d24d57" .. thousandsStepper(math.abs(getElementData(localPlayer, "char:money")))
   end

   return finalConvert
end

function thousandsStepper(amount)
   local formatted = amount
   
   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 renderFPS()
   local currentTick = getTickCount()
   lastRenderTick = lastRenderTick or currentTick
   framesDeltaTime = framesDeltaTime + (currentTick - lastRenderTick)
   lastRenderTick = currentTick
   framesPerSecond = framesPerSecond + 1
   
   if framesDeltaTime >= 1000 then
      setElementData(localPlayer, "fps", framesPerSecond)
      framesDeltaTime = framesDeltaTime - 1000
      framesPerSecond = 0
   end
end

warning = 0
setTimer(function()
    if getElementData(localPlayer, "loggedin") and getElementData(localPlayer, "char:adminduty") == 0 then
        local hunger = getElementData(localPlayer, "char:hunger")
        if getElementData(localPlayer, "adminjail") == 1 then
         return
      end
      
      if hunger > 7 then
            random = math.random(4, 7)
            setElementData(localPlayer, "char:hunger", hunger - random)
        elseif hunger ~= 0 and hunger <= 7 then
            setElementData(localPlayer, "char:hunger", 0)
        else
            if warning ~= 3 then
                outputChatBox("#00aeef[EvolutionGaming] #ffffffKezdesz éhes lenni! Egyél valamit!",255, 255, 255, true)
                warning = warning + 1
            else
                setElementHealth(localPlayer, getElementHealth(localPlayer) - 3)
            end
        end
    end
end, 1000 * 60 * 6, 0)

Nem elérhető KrisT

  • 106
    • Profil megtekintése
Re:Mit kellene beírnom a hud rendszerbe hogy fogyjon a stamina?
« Válasz #1 Dátum: 2020. augusztus 16. - 12:29:53 »
0 Show voters
Szia!
Renderen vizsgáljátok a játékos mozgását, valamitnt sebességét (getElementVelocity). Ha éppen nincs járműben és a sebessége bizonyos tartományban van, akkor csökkentse X-szel a staminát. A lényege igazából ennyi.

 

SimplePortal 2.3.7 © 2008-2024, SimplePortal