Jump to content

WhoAmI

Members
  • Posts

    1,248
  • Joined

  • Last visited

Posts posted by WhoAmI

  1. Biblioteka 'dx' wymaga renderowania co klatkę, więc dxDrawText musi być umieszczony w evencie onClientRender.

    function showPremium()
        local px,py,pz = getElementPosition(getLocalPlayer()) 
        local x,y,z = getElementPosition(getLocalPlayer()) 
        local distance = getDistanceBetweenPoints3D ( x,y,z,px,py,pz)
            if distance <= 10 then 
                local sx,sy = getScreenFromWorldPosition ( x, y, z+1.12, 0.05 ) 
                if not sx then return end 
                local scale = 0.01/(0.01 * (distance / 1))
    			dxDrawText ( "Premium", sx, sy, sx, sy + 25, tocolor(255,230,100,255), math.min ( 0.07    *(180/distance),1.8), "clear-normal", "center", "bottom", false, false, false ) 
        end 
    end
    
    function premiumhud()
    	addEventHandler("onClientRender", localPlayer, showPremium)
    end
    addCommandHandler("premium", premiumhud)

     

  2. Man, when player logs out he is no longer logged in. Look what argument onPlayerLogout event gives.

    account thePreviousAccount, account theCurrentAccount

    Do you see? So,

    addEventHandler("onPlayerLogout", getRootElement(),
    	function (acc, _)
    		local name = getPlayerName ( source )
        	if isObjectInACLGroup("user." .. getAccountName(acc), aclGetGroup("Admin")) then
    			exports[getResourceName(resource)]:addNotification(root, name.." kilépett a tulajdonos szolgálatból!", "success")
       	 	end
    	end
    )
    • Like 1
  3. If you want to collect how many kills did player get you have to make it s-side and store it in table.

    local kills = {} 
      
    addEventHandler("onPlayerWasted", root, function(_, killer) 
        if isElement(killer) and getElementType(killer) == "player" then 
            local killInt = kills[killer] 
            if not killInt then 
                killInt = 0 
            end 
             
            kills[killer] = killInt + 1 
        end 
    end) 
    

  4. This code works perfectly for me

    call ( getResourceFromName ( "scoreboard" ), "scoreboardAddColumn", "Play Time" ) ---Export of ScoreBoard 
      
    function getOnlineTime(player, acc) 
        if not isGuestAccount(acc) then 
            local playedTime = getAccountData(acc, "onlineTime"); 
            if not playedTime then 
                playedTime = 0; 
            end 
            
            setAccountData(acc, "onlineTime", playedTime); 
            setElementData(player, "onlineTime", playedTime); 
            
            local timer = setTimer(function() 
                setElementData(player, "onlineTime", getElementData(player, "onlineTime") + 1); 
                updateScoreboard(player); 
            end, 60000, 0); 
            updateScoreboard(player); 
            setElementData(player, "timer:onlineTime", timer); 
        end 
    end 
      
    addEventHandler("onResourceStart", resourceRoot, function() 
        for _, player in ipairs(getElementsByType("player")) do 
            getOnlineTime(player, getPlayerAccount(player)); 
        end 
    end); 
      
    addEventHandler("onPlayerLogin", root, function(_, acc) 
        getOnlineTime(source, acc); 
    end); 
      
    function updateScoreboard(player) 
        local playTime = getElementData(player, "onlineTime"); 
        if playTime then 
            if playTime >= 0 and playTime < 60 then 
                setElementData(player, "Play Time", playTime .. " minutes"); 
            elseif playTime >= 60 and playTime < 1440 then 
                playTime = math.floor(playTime / 60) 
                setElementData(player, "Play Time", playTime .. " hours"); 
            elseif playTime >= 1440 then 
                playTime = math.floor(playTime / 1440) 
                setElementData(player, "Play Time", playTime .. " days"); 
            end 
        end 
    end 
      
    function saveData(player, acc) 
        if acc and not isGuestAccount(acc) then 
            setAccountData(acc, "onlineTime", getElementData(player, "onlineTime")); 
            if isTimer(getElementData(player, "timer:onlineTime")) then 
               killTimer(getElementData(player, "timer:onlineTime")); 
            end 
        end 
    end 
      
    addEventHandler("onPlayerDisconnect", root, function() 
        saveData(source, getPlayerAccount(source)); 
    end); 
      
    addEventHandler("onPlayerLogout", root, function(acc) 
       saveData(source, acc); 
    end); 
    

    I have even created new account, just in case. Here are screens

    https://scr.hu/jPm0A1

    https://scr.hu/63rMWO

  5. Works for me now. Changed it a bit

    call ( getResourceFromName ( "scoreboard" ), "scoreboardAddColumn", "Play Time" ) ---Export of ScoreBoard 
      
    function getOnlineTime(player, acc) 
        if not isGuestAccount(acc) then 
            local playedTime = getAccountData(acc, "onlineTime"); 
            if not playedTime then 
                playedTime = 0; 
            end 
            
            setElementData(player, "onlineTime", playedTime); 
            
            local timer = setTimer(function() 
                setElementData(player, "onlineTime", getElementData(player, "onlineTime") + 1); 
                updateScoreboard(player); 
            end, 60000, 0); 
            updateScoreboard(player); 
            setElementData(player, "timer:onlineTime", timer); 
        end 
    end 
      
    addEventHandler("onResourceStart", resourceRoot, function() 
        for _, player in ipairs(getElementsByType("player")) do 
            getOnlineTime(player, getPlayerAccount(player)); 
        end 
    end); 
      
    addEventHandler("onPlayerLogin", root, function(_, acc) 
        getOnlineTime(source, acc); 
    end); 
      
    function updateScoreboard(player) 
        local playTime = getElementData(player, "onlineTime"); 
        if playTime then 
            if playTime >= 0 and playTime < 60 then 
                setElementData(player, "Play Time", playTime .. " minutes"); 
            elseif playTime >= 60 and playTime < 1440 then 
                playTime = math.floor(playTime / 60) 
                setElementData(player, "Play Time", playTime .. " hours"); 
            elseif playTime >= 1440 then 
                playTime = math.floor(playTime / 1440) 
                setElementData(player, "Play Time", playTime .. " days"); 
            end 
        end 
    end 
      
    function saveData(player, acc) 
        if acc and not isGuestAccount(acc) then 
            setAccountData(acc, "onlineTime", getElementData(player, "onlineTime")); 
            if isTimer(getElementData(player, "timer:onlineTime")) then 
               killTimer(getElementData(player, "timer:onlineTime")); 
            end 
        end 
    end 
      
    addEventHandler("onPlayerDisconnect", root, function() 
        saveData(source, getPlayerAccount(source)); 
    end); 
      
    addEventHandler("onPlayerLogout", root, function(acc) 
       saveData(source, acc); 
    end); 
    

  6. It stores playtime in seconds, but shows it in format you wanted.

    @EDIT: Found the error.

    Replace last lines to this

    function saveData(player, acc) 
        if acc and not isGuestAccount(acc) then 
            setAccountData(acc, "onlineTime", getElementData(player, "onlineTime")); 
            if isTimer(getElementData(player, "timer:onlineTime")) then 
               killTimer(getElementData(player, "timer:onlineTime")); 
            end 
        end 
    end 
      
    addEventHandler("onPlayerDisconnect", root, function() 
        saveData(source, getPlayerAccount(source)); 
    end); 
      
    addEventHandler("onPlayerLogout", root, function(acc) 
       saveData(source, acc); 
    end); 
    

×
×
  • Create New...