Jump to content

killmessages [ HELP ]


Dinossauro

Recommended Posts

Hello

I have a script, killmessages. I created a server and wanted the race killmessages appear in the upper right. See a picture here!

2uepv83.png

And also wanted nicks who died appeared with colors, when they appear like this: # FF0000Dinossauro.

Codes:

killmessages_client.lua

addEvent ("onClientPlayerKillMessage",true) 
function onClientPlayerKillMessage ( killer,weapon,wr,wg,wb,kr,kg,kb,width,resource ) 
    if wasEventCancelled() then return end 
    outputKillMessage ( source, wr,wg,wb,killer,kr,kg,kb,weapon,width,resource ) 
end 
addEventHandler ("onClientPlayerKillMessage",getRootElement(),onClientPlayerKillMessage) 
  
function outputKillMessage ( source, wr,wg,wb,killer,kr,kg,kb,weapon,width,resource ) 
    if not iconWidths[weapon] then  
        if type(weapon) ~= "string" then 
            weapon = 999  
        end 
    end 
    local killerName 
    local wastedName 
    if not tonumber(wr) then wr = 255 end 
    if not tonumber(wg) then wg = 255 end 
    if not tonumber(wb) then wb = 255 end 
    if not tonumber(kr) then kr = 255 end 
    if not tonumber(kg) then kg = 255 end 
    if not tonumber(kb) then kb = 255 end 
    if ( source ) then 
        if isElement ( source ) then 
            if getElementType ( source ) == "player" then  
                wastedName = getPlayerName ( source ) 
            else  
            outputDebugString ( "outputKillMessage - Invalid 'wasted' player specified",0,0,0,100) 
            return false end 
        elseif type(source) == "string" then 
            wastedName = source 
        end 
    else  
        outputDebugString ( "outputKillMessage - Invalid 'wasted' player specified",0,0,0,100) 
    return false end 
    if ( killer ) then 
        if isElement ( killer ) then 
            if getElementType ( killer ) == "player" then 
                killerName = getPlayerName ( killer ) 
            else  
                outputDebugString ( "outputKillMessage - Invalid 'killer' player specified",0,0,0,100) 
            return false end 
        elseif type(killer) == "string" then 
            killerName = killer 
        else 
            killerName = "" 
        end 
    else killerName = "" end 
    --create the new text 
    if not killerName then 
        killerName = "" 
    end 
    return outputMessage ( {killerName, {"padding",width=3}, {"icon",id=weapon}, 
        {"padding",width=3},{"color",r=wr,g=wg,b=wb}, wastedName}, 
        kr,kg,kb ) 
end 
  

killmessages_server.lua

local config = { 
["lines"] = 5, 
["startY"] = 0.35, 
["textHeight"] = 16, 
["iconHeight"] = 20, 
["iconSpacing"] = 4, 
["defaultWeapon"] = 255, 
["fadeTime"] = 5000, 
["startFade"] = 15000, 
["align"] = "right", 
["startX"] = -10 
} 
local default = { 
["lines"] = 5, 
["startY"] = 0.25, 
["textHeight"] = 16, 
["iconHeight"] = 20, 
["iconSpacing"] = 4, 
["defaultWeapon"] = 255, 
["fadeTime"] = 5000, 
["startFade"] = 15000, 
["align"] = "right", 
["startX"] = -10 
} 
  
local vehicleIDs = { [50]=true,[49]=true,[31]=true,[38]=true,[52]=true } 
function KillMessages_onPlayerWasted ( totalammo, killer, killerweapon, bodypart ) 
    ---These are special checks for certain kill types 
    local usedVehicle 
    if killerweapon == 19 and isElement(killer) then --rockets 
        killerweapon = killer and getElementType ( killer ) == "player" and getPedWeapon(killer) 
        if not killerweapon then 
            killerweapon = 51 
        end 
    elseif vehicleIDs[killerweapon] then --heliblades/rammed 
        if ( isElement(killer) and getElementType ( killer ) == "vehicle" ) then 
            usedVehicle = getElementModel ( killer ) 
            killer = getVehicleOccupant ( killer, 0 ) 
        end 
    elseif ( killerweapon == 59 and isElement(killer) ) then 
        if ( getElementType ( killer ) == "player" ) then 
            local vehicle = getPedOccupiedVehicle(killer) 
            if ( vehicle ) then 
                usedVehicle = getElementModel ( vehicle ) 
            end 
        end 
    end 
    --finish this 
    -- Got a killer? Print the normal "* X died" if not 
    if ( killer and isElement(killer) and getElementType ( killer ) == "player" ) then 
        local kr,kg,kb = getPlayerNametagColor  ( killer ) 
        if getPlayerTeam ( killer ) then 
            kr,kg,kb = getTeamColor ( getPlayerTeam ( killer ) ) 
        end 
        -- Suicide? 
        if (source == killer) then 
            if not killerweapon then killerweapon = 255 end 
            local triggered = triggerEvent ( "onPlayerKillMessage", source,false,killerweapon,bodypart ) 
            --outputDebugString ( "Cancelled: "..tostring(triggered) ) 
            if ( triggered ) then 
                eventTriggered ( source,false,killerweapon,bodypart,true,usedVehicle) 
                return 
            end 
        end 
        local triggered = triggerEvent ( "onPlayerKillMessage", source,killer,killerweapon,bodypart ) 
                --outputDebugString ( "Cancelled: "..tostring(triggered) ) 
        if ( triggered ) then 
            eventTriggered ( source,killer,killerweapon,bodypart,false,usedVehicle) 
        end 
    else 
        local triggered = triggerEvent ( "onPlayerKillMessage", source,false,killerweapon,bodypart ) 
        --outputDebugString ( "Cancelled: "..tostring(triggered) ) 
        if ( triggered ) then 
            eventTriggered ( source,false,killerweapon,bodypart,false,usedVehicle) 
        end 
    end 
end 
addEventHandler ( "onPlayerWasted", getRootElement(), KillMessages_onPlayerWasted ) 
  
addEvent ( "onPlayerKillMessage" ) 
function eventTriggered ( source,killer,weapon,bodypart,suicide,usedVehicle ) 
    local wr,wg,wb = getPlayerNametagColor  ( source ) 
    if getPlayerTeam ( source ) then 
        wr,wg,wb = getTeamColor ( getPlayerTeam ( source ) ) 
    end 
    local kr,kg,kb = false,false,false 
    if ( killer ) then 
        kr,kg,kb = getPlayerNametagColor    ( killer ) 
        if getPlayerTeam ( killer ) then 
            kr,kg,kb = getTeamColor ( getPlayerTeam ( killer ) ) 
        end 
    end 
    if ( usedVehicle ) then 
        weapon = usedVehicle 
    end 
    outputKillMessage ( source, wr,wg,wb,killer,kr,kg,kb,weapon ) 
    -- 
    local extra = "" 
    if ( usedVehicle ) then 
    extra = " (Vehicle)" 
    end 
    if ( killer ) then 
        if suicide then 
            local weaponName = getWeaponNameFromID ( weapon ) 
            if weaponName then 
                outputConsoleKillMessage ( "* "..getPlayerName(source).." killed himself. ("..weaponName..")" ) 
            else 
                outputConsoleKillMessage ( "* "..getPlayerName(source).." killed himself."..extra ) 
            end 
        else 
            local weaponName = getWeaponNameFromID ( weapon ) 
            if weaponName then 
                outputConsoleKillMessage ( "* "..getPlayerName(killer).." killed "..getPlayerName(source)..". ("..weaponName..")" ) 
            else 
                outputConsoleKillMessage ( "* "..getPlayerName(killer).." killed "..getPlayerName(source).."."..extra ) 
            end 
        end 
    else 
        outputConsoleKillMessage ( "* "..getPlayerName(source).." died."..extra ) 
    end 
    -- 
end 
  
function outputConsoleKillMessage ( text ) 
    outputConsole ( text ) 
end 
  
function outputKillMessage ( killed, wr,wg,wb,killer,kr,kg,kb,weapon,width,resource ) 
    if ( resource ) then resource = getResourceName(resource) end 
    if not isElement(killed) then 
        outputDebugString ( "outputKillMessage - Invalid 'wasted' player specified",0,0,0,100) 
        return false 
    end 
    if not getElementType(killed) == "player" then 
        outputDebugString ( "outputKillMessage - Invalid 'wasted' player specified",0,0,0,100) 
        return false 
    end 
    return triggerClientEvent(getRootElement(),"onClientPlayerKillMessage",killed,killer,weapon,wr,wg,wb,kr,kg,kb,width,resource ) 
end 
  
function outputMessage ( message, visibleTo, r, g, b, font ) 
    if type(message) ~= "string" and type(message) ~= "table" then 
        outputDebugString ( "outputMessage - Bad 'message' argument", 0, 112, 112, 112 )  
        return false  
    end 
    if not isElement(visibleTo) then  
        outputDebugString ( "outputMessage - Bad argument", 0, 112, 112, 112 )  
        return false  
    end 
    --Turn any resources into resource names 
    if type(message) == "table" then 
        for i,part in ipairs(message) do 
            if type(part) == "table" and part[1] == "image" then 
                if part.resource then 
                    message[i].resourceName = getResourceName(part.resource) 
                else 
                    part.resourceName = getResourceName(sourceResource) 
                end 
            end 
        end 
    end 
    return triggerClientEvent ( visibleTo, "doOutputMessage", visibleTo, message, r, g, b, font ) 
end 
  
function setKillMessageStyle ( startX,startY,align,lines,fadeStart,fadeAnimTime ) 
    if ( not startX ) then startX = default.startX end 
    if ( not startY ) then startY = default.startY end 
    if ( not align ) then startY = align.startY end 
    if ( not lines ) then lines = default.lines end 
    if ( not fadeStart ) then fadeStart = default.startFade end 
    if ( not fadeAnimTime ) then fadeAnimTime = default.fadeTime end 
    config.startX = startX 
    config.startY = startY 
    config.align = align 
    config.lines = lines 
    config.startFade = fadeStart 
    config.fadeTime = fadeAnimTime 
    for k,v in ipairs(getElementsByType"player") do 
        triggerClientEvent(v,"doSetKillMessageStyle",v,config.startX,config.startY,config.alignX,config.lines,config.startFade,config.fadeTime) 
    end 
    return true 
end 
  
addEvent ("onClientKillmessagesLoaded",true) 
addEventHandler ( "onClientKillmessagesLoaded", getRootElement(), 
function() 
    triggerClientEvent(source,"doSetKillMessageStyle",source,config.startX,config.startY,config.alignX,config.lines,config.startFade,config.fadeTime) 
end ) 
  

gui.lua

local customKills = {} 
local config = {
["lines"] = 5,
["startY"] = 0.35,
["textHeight"] = 16,
["iconPosOffY"] = -10,
["iconHeight"] = 20,
["iconSpacing"] = 4,
["defaultWeapon"] = 255,
["fadeTime"] = 5000,
["startFade"] = 15000,
["align"] = "right",
["startX"] = -10
}
local default = {
["lines"] = 5,
["startY"] = 0.25,
["textHeight"] = 16,
["iconPosOffY"] = -10,
["iconHeight"] = 20,
["iconSpacing"] = 4,
["defaultWeapon"] = 255,
["fadeTime"] = 5000,
["startFade"] = 15000,
["align"] = "right",
["startX"] = -10
}
local endTime
local screenX,screenY = guiGetScreenSize ()
local contentMessages = {}
local fadingLines = {}
---
local iconOrder = {}
 
 
function setupTextOnStart ( resource )
    if resource ~= getThisResource() then return end
    triggerServerEvent ( "onClientKillmessagesLoaded", getLocalPlayer() )
end
addEventHandler ( "onClientResourceStart", getRootElement(), setupTextOnStart )
 
addEvent ("doSetKillMessageStyle",true)
function setKillMessageStyle ( startX,startY,align,lines,fadeStart,fadeAnimTime )
    if ( not startX ) then startX = default.startX end
    if ( not startY ) then startY = default.startY end
    if ( not align ) then align = default.align end
    if ( not lines ) then lines = default.lines end
    if ( not fadeStart ) then fadeStart = default.startFade end
    if ( not fadeAnimTime ) then fadeAnimTime = default.fadeTime end
    config.startX = startX
    config.startY = startY
    config.align = align
    config.lines = lines
    config.startFade = fadeStart
    config.fadeTime = fadeAnimTime
    if #contentMessages ~= 0 then
        for i=1,config.lines do
            if contentMessages[i] then
                destroyLine ( i )
            end
        end
    end
    fadingLines = {}
    killMessages = {}
    if ( config.startY < 0 ) then
        config.startY = screenY - math.abs(config.startY*screenY) - (config.iconHeight*config.lines)
        config.startY = config.startY/screenY
    end
    createKillMessageGUI()
    return true
end
addEventHandler ( "doSetKillMessageStyle",getRootElement(),setKillMessageStyle)
 
function createKillMessageGUI()
    local gap = config.iconHeight - config.textHeight
    gap = gap/2
    for i=1,config.lines do
        local y = config.startY*screenY + (config.iconHeight*(i-1))
        y = y + gap
        contentMessages[i] = { dxText:create("",0,y) }
    end
    endTime = config.fadeTime + config.startFade
end
 
function shiftUpGUI()
    local i = 1
    for i=config.lines,2,-1 do
        local y = config.startY*screenY + (config.iconHeight*(i-1)) + (config.iconHeight - config.textHeight)/2
        local targetY = config.startY*screenY + (config.iconHeight*(i-2)) + (config.iconHeight - config.textHeight)/2
        if contentMessages[i] then
            for k,part in ipairs(contentMessages[i]) do
                local x,realY = getWidgetPosition(part)
 
                local diffY = realY - y
                setWidgetPosition(part,x,targetY + diffY)
            end
        end
    end 
    for i=1,config.lines-1 do
        ---shift up the alpha too
        local tick = fadingLines[i+1]
        fadingLines[i] = tick
        fadingLines[i+1] = nil
    end 
end
 
addEvent ( "doOutputMessage", true )
function outputMessage ( message, r, g, b, font )
    if type(message) ~= "string" and type(message) ~= "table" then
        outputDebugString ( "outputMessage - Bad 'message' argument", 0, 112, 112, 112 )
        return false
    end
    if type(font) ~= "string" then
        font = "default"
    end
    r = tonumber(r) or 255
    g = tonumber(g) or 255
    b = tonumber(b) or 255
    ---shift everything up
    shiftUpGUI()
    --Delete the first line
    destroyLine (1)
    table.remove ( contentMessages, 1 )
    if type(message) == "string" then
        message = {message}
    end
    local y = config.startY*screenY + (config.iconHeight*(config.lines-1)) + (config.iconHeight - config.textHeight)/2
    local startX = config.startX
    if startX < 1 and startX > -1 then --auto calculate whether its relative or absolute
        startX = screenX/startX --make it relative
    end
    if startX < 0 then
        startX = screenX + startX
    end
   
    for i,part in ipairs(message) do
        if type(part) == "table" and part[1] == "image" then
            if not part.resource and not part.resourceName then
                part.resource = sourceResource
            end
        end
    end
   
    drawLine ( message, startX, y, config.align, config.lines, r, g, b, font, 1 )
    fadeLine ( config.lines )   
end
addEventHandler ( "doOutputMessage", getRootElement(), outputMessage )
 
function drawLine ( message, x,y, align, line, r, g, b, font, scale )
    --First draw it and work out the width
    local width = 0
    contentMessages[line] = {}
    for i,part in ipairs(message) do
        if type(part) == "string" then
            local text = dxText:create ( part, width, y, false )
            text:font ( font )
            text:scale ( scale )
            text:type("shadow",1)
            text:align"left"
            text:color ( r,g,b )
            table.insert ( contentMessages[line], text )
            width = width + text:extent()
        elseif part[1] == "icon" then
            local iconWidth = part.width or iconWidths[part.id or -1] or iconWidths[255]
            local iconHeight = part.height or config.iconHeight
            local image = dxImage:create ( icons[part.id or 0] or icons[255], width, y + (part.posOffY or config.iconPosOffY), iconWidth, iconHeight, false )
            image:color ( part.r or 255, part.g or 255, part.b or 255 )
            image:rotation ( part.rot or 0, part.rotOffX or 0, part.rotOffY or 0 )
            width = width + iconWidth
            table.insert ( contentMessages[line], image )
        elseif part[1] == "image" then
            if part.width and part.path then
                if part.resourceName then
                    part.resource = getResourceFromName(tostring(part.resourceName)) or part.resource
                end
                local image = dxImage:create ( ":"..getResourceName(part.resource).."/"..part.path, width, y + (part.posOffY or config.iconPosOffY), part.width, part.height or config.iconHeight, false )
                image:color ( part.r or 255, part.g or 255, part.b or 255 )
                image:rotation ( part.rot or 0, part.rotOffX or 0, part.rotOffY or 0 )             
                width = width + part.width
                table.insert ( contentMessages[line], image )
            end 
        elseif part[1] == "color" or part[1] == "colour" then
            r = part.r or r
            g = part.g or g
            b = part.b or b
        elseif part[1] == "padding" then
            width = width + part.width or 0
        end
        contentMessages[line].scale = scale
    end
    --Now reposition everything properly
    if align == "center" or align == "centre" then
        x = x - width/2
    elseif align == "right" then
        x = x - width
    end
    for i,widget in ipairs(contentMessages[line]) do
        local wx,wy = getWidgetPosition ( widget )
        setWidgetPosition ( widget, x + wx, wy )
    end
    return true
end
 
function fadeLine ( line )
    setLineAlpha ( line, 1 )
    fadingLines[line] = getTickCount()
end
-----
addEventHandler ( "onClientRender",getRootElement(),
function()
    for line,originalTick in pairs(fadingLines) do
        local tickDifference = getTickCount() - originalTick
        if tickDifference > endTime then
            destroyLine ( line )
            setLineAlpha ( line, 1 )
            fadingLines[line] = nil
        elseif tickDifference >  config.startFade then
            local fadeTimeDifference = tickDifference - config.startFade
            --calculate the alpha
            local newAlpha = 1 - fadeTimeDifference/config.fadeTime
            --Set all the alphas
            setLineAlpha ( line, newAlpha )
        end
    end
end )
 
function setLineAlpha ( line, alpha )
    for i,part in ipairs(contentMessages[line]) do
        setWidgetAlpha ( part, alpha )
    end
end
 
function destroyLine ( line )
    for k,part in ipairs(contentMessages[line]) do
        destroyWidget(part)
    end
    contentMessages[line] = {}
end
 
function destroyWidget ( widget )
    if isElement(widget) then
        destroyElement ( widget )
    elseif type(widget) == "table" and widget.destroy then
        widget:destroy()
    end
end
 
function getWidgetPosition ( widget )
    if isElement(widget) then
        return guiGetPosition ( widget, false )
    elseif
Link to comment

It is in utils folder.

I edited it for you:

  
dxText = {}
dxText_mt = { __index = dxText }
local idAssign,idPrefix = 0,"c"
local g_screenX,g_screenY = guiGetScreenSize()
local visibleText = {}
------
local defaults = {
    fX                          = 0.5,
    fY                          = 0.5,
    bRelativePosition           = true,
    strText                     = "",
    bVerticalAlign              = "center",
    bHorizontalAlign            = "center",
    tColor                      = {255,255,255,255},
    fScale                      = 1,
    strFont                     = "default",
    strType                     = "normal",
    tAttributes                 = {},
    bPostGUI                    = false,
    bClip                       = false,
    bWordWrap                   = true,
    bVisible                    = true,
    tBoundingBox                = false, --If a bounding box is not set, it will not be used.
    bRelativeBoundingBox        = true,
}
 
local validFonts = {
    default                     = true,
    ["default-bold"]            = true,
    clear                       = true,
    arial                       = true,
    pricedown                   = true,
    bankgothic                  = true,
    diploma                     = true,
    beckett                     = true,
}
 
local validTypes = {
    normal                      = true,
    shadow                      = true,
    border                      = true,
    stroke                      = true, --Clone of border
}
 
local validAlignTypes = {
    center                      = true,
    left                        = true,
    right                       = true,
}
 
function dxText:create( text, x, y, relative )
    assert(not self.fX, "attempt to call method 'create' (a nil value)")
    if ( type(text) ~= "string" ) or ( not tonumber(x) ) or ( not tonumber(y) ) then
        outputDebugString ( "dxText:create - Bad argument", 0, 112, 112, 112 )
        return false
    end
    local new = {}
    setmetatable( new, dxText_mt )
    --Add default settings
    for i,v in pairs(defaults) do
        new[i] = v
    end
    idAssign = idAssign + 1
    new.id = idPrefix..idAssign
    new.strText = text or new.strText
    new.fX = x or new.fX
    new.fY = y or new.fY
    if type(relative) == "boolean" then
        new.bRelativePosition = relative
    end
    visibleText[new] = true
    return new
end
 
function dxText:text(text)
    if type(text) ~= "string" then return self.strText end
    self.strText = text
    return true
end
 
function dxText:position(x,y,relative)
    if not tonumber(x) then return self.fX, self.fY end
    self.fX = x
    self.fY = y
    if type(relative) == "boolean" then
        self.bRelativePosition = relative
    else
        self.bRelativePosition = true
    end
    return true
end
 
function dxText:color(r,g,b,a)
    if not tonumber(r) then return unpack(self.tColor) end
    g = g or self.tColor[2]
    b = b or self.tColor[3]
    a = a or self.tColor[4]
    self.tColor = { r,g,b,a }
    return true
end
 
function dxText:scale(scale)
    if not tonumber(scale) then return self.fScale end
    self.fScale = scale
    return true
end
 
function dxText:visible(bool)
    if type(bool) ~= "boolean" then return self.bVisible end
    self.bVisible = bool
    if bool then
        visibleText[self] = true
    else
        visibleText[self] = nil
    end
    return true
end
 
function dxText:destroy()
    self.bDestroyed = true
    setmetatable( self, self )
    return true
end
 
function dxText:extent()
    local extent = dxGetTextWidth ( self.strText, self.fScale, self.strFont )
    if self.strType == "stroke" or self.strType == "border" then
        extent = extent + self.tAttributes[1]
    end
    return extent
end
 
function dxText:height()
    local height = dxGetFontHeight ( self.fScale, self.strFont )
    if self.strType == "stroke" or self.strType == "border" then
        height = height + self.tAttributes[1]
    end
    return height
end
 
function dxText:font(font)
    if not validFonts[font] then return self.strFont end
    self.strFont = font
    return true
end
 
function dxText:postGUI(bool)
    if type(bool) ~= "boolean" then return self.bPostGUI end
    self.bPostGUI = bool
    return true
end
 
function dxText:clip(bool)
    if type(bool) ~= "boolean" then return self.bClip end
    self.bClip = bool
    return true
end
 
function dxText:wordWrap(bool)
    if type(bool) ~= "boolean" then return self.bWordWrap end
    self.bWordWrap = bool
    return true
end
 
function dxText:type(type,...)
    if not validTypes[type] then return self.strType, unpack(self.tAttributes) end
    self.strType = type
    self.tAttributes = {...}
    return true
end
 
function dxText:align(horzA, vertA)
    if not validAlignTypes[horzA] then return self.bHorizontalAlign, self.bVerticalAlign end
    vertA = vertA or self.bVerticalAlign
    self.bHorizontalAlign, self.bVerticalAlign = horzA, vertA
    return true
end
 
function dxText:boundingBox(left,top,right,bottom,relative)
    if left == nil then
        if self.tBoundingBox then
            return unpack(boundingBox)
        else
            return false
        end
    elseif tonumber(left) and tonumber(right) and tonumber(top) and tonumber(bottom) then
        self.tBoundingBox = {left,top,right,bottom}
        if type(relative) == "boolean" then
            self.bRelativeBoundingBox = relative
        else
            self.bRelativeBoundingBox = true
        end
    else
        self.tBoundingBox = false
    end
    return true
end
 
addEventHandler ( "onClientRender", getRootElement(),
    function()
        for self,_ in pairs(visibleText) do
            while true do
                if self.bDestroyed then
                    visibleText[self] = nil
                    break
                end
                local l,t,r,b
                --If we arent using a bounding box
                if not self.tBoundingBox then
                    --Decide if we use relative or absolute
                    local p_screenX,p_screenY = 1,1
                    if self.bRelativePosition then
                        p_screenX,p_screenY = g_screenX,g_screenY
                    end
                    local fX,fY = (self.fX)*p_screenX,(self.fY)*p_screenY
                    if self.bHorizontalAlign == "left" then
                        l = fX
                        r = fX + g_screenX
                    elseif self.bHorizontalAlign == "right" then
                        l = fX - g_screenX
                        r = fX
                    else
                        l = fX - g_screenX
                        r = fX + g_screenX
                    end
                    if self.bVerticalAlign == "top" then
                        t = fY
                        b = fY + g_screenY
                    elseif self.bVerticalAlign == "bottom" then
                        t = fY - g_screenY
                        b = fY
                    else
                        t = fY - g_screenY
                        b = fY + g_screenY
                    end
                elseif type(self.tBoundingBox) == "table" then
                    local b_screenX,b_screenY = 1,1
                    if self.bRelativeBoundingBox then
                        b_screenX,b_screenY = g_screenX,g_screenY
                    end
                    l,t,r,b = self.tBoundingBox[1],self.tBoundingBox[2],self.tBoundingBox[3],self.tBoundingBox[4]
                    l = l*b_screenX
                    t = t*b_screenY
                    r = r*b_screenX
                    b = b*b_screenY
                end
                local type,att1,att2,att3,att4,att5 = self:type()
                if type == "border" or type == "stroke" then
                    att2 = att2 or 0
                    att3 = att3 or 0
                    att4 = att4
Link to comment
  
local customKills = {}
local config = {
["lines"] = 5,
["startY"] = 0.35,
["textHeight"] = 566,
["iconPosOffY"] = -10,
["iconHeight"] = 20,
["iconSpacing"] = 4,
["defaultWeapon"] = 255,
["fadeTime"] = 5000,
["startFade"] = 15000,
["align"] = "right",
["startX"] = -10
}
local default = {
["lines"] = 5,
["startY"] = 0.25,
["textHeight"] = 16,
["iconPosOffY"] = -10,
["iconHeight"] = 20,
["iconSpacing"] = 4,
["defaultWeapon"] = 255,
["fadeTime"] = 5000,
["startFade"] = 15000,
["align"] = "right",
["startX"] = -10
}
local endTime
local screenX,screenY = guiGetScreenSize ()
local contentMessages = {}
local fadingLines = {}
---
local iconOrder = {}
 
 
function setupTextOnStart ( resource )
    if resource ~= getThisResource() then return end
    triggerServerEvent ( "onClientKillmessagesLoaded", getLocalPlayer() )
end
addEventHandler ( "onClientResourceStart", getRootElement(), setupTextOnStart )
 
addEvent ("doSetKillMessageStyle",true)
function setKillMessageStyle ( startX,startY,align,lines,fadeStart,fadeAnimTime )
    if ( not startX ) then startX = default.startX end
    if ( not startY ) then startY = default.startY end
    if ( not align ) then align = default.align end
    if ( not lines ) then lines = default.lines end
    if ( not fadeStart ) then fadeStart = default.startFade end
    if ( not fadeAnimTime ) then fadeAnimTime = default.fadeTime end
    config.startX = startX
    config.startY = startY
    config.align = align
    config.lines = lines
    config.startFade = fadeStart
    config.fadeTime = fadeAnimTime
    if #contentMessages ~= 0 then
        for i=1,config.lines do
            if contentMessages[i] then
                destroyLine ( i )
            end
        end
    end
    fadingLines = {}
    killMessages = {}
    if ( config.startY < 0 ) then
        config.startY = screenY - math.abs(config.startY*screenY) - (config.iconHeight*config.lines)
        config.startY = config.startY/screenY
    end
    createKillMessageGUI()
    return true
end
addEventHandler ( "doSetKillMessageStyle",getRootElement(),setKillMessageStyle)
 
function createKillMessageGUI()
    local gap = config.iconHeight - config.textHeight
    gap = gap/2
    for i=1,config.lines do
        local y = config.startY*screenY + (config.iconHeight*(i-1))
        y = y + gap
        contentMessages[i] = { dxText:create("",0,y) }
    end
    endTime = config.fadeTime + config.startFade
end
 
function shiftUpGUI()
    local i = 1
    for i=config.lines,2,-1 do
        local y = config.startY*screenY + (config.iconHeight*(i-1)) + (config.iconHeight - config.textHeight)/2
        local targetY = config.startY*screenY + (config.iconHeight*(i-2)) + (config.iconHeight - config.textHeight)/2
        if contentMessages[i] then
            for k,part in ipairs(contentMessages[i]) do
                local x,realY = getWidgetPosition(part)
 
                local diffY = realY - y
                setWidgetPosition(part,x,targetY + diffY)
            end
        end
    end
    for i=1,config.lines-1 do
        ---shift up the alpha too
        local tick = fadingLines[i+1]
        fadingLines[i] = tick
        fadingLines[i+1] = nil
    end
end
 
addEvent ( "doOutputMessage", true )
function outputMessage ( message, r, g, b, font )
    if type(message) ~= "string" and type(message) ~= "table" then
        outputDebugString ( "outputMessage - Bad 'message' argument", 0, 112, 112, 112 )
        return false
    end
    if type(font) ~= "string" then
        font = "default"
    end
    r = tonumber(r) or 255
    g = tonumber(g) or 255
    b = tonumber(b) or 255
    ---shift everything up
    shiftUpGUI()
    --Delete the first line
    destroyLine (1)
    table.remove ( contentMessages, 1 )
    if type(message) == "string" then
        message = {message}
    end
    local y = config.startY*screenY + (config.iconHeight*(config.lines-1)) + (config.iconHeight - config.textHeight)/2
    local startX = config.startX
    if startX < 1 and startX > -1 then --auto calculate whether its relative or absolute
        startX = screenX/startX --make it relative
    end
    if startX < 0 then
        startX = screenX + startX
    end
   
    for i,part in ipairs(message) do
        if type(part) == "table" and part[1] == "image" then
            if not part.resource and not part.resourceName then
                part.resource = sourceResource
            end
        end
    end
   
    drawLine ( message, startX, y, config.align, config.lines, r, g, b, font, 1 )
    fadeLine ( config.lines )  
end
addEventHandler ( "doOutputMessage", getRootElement(), outputMessage )
 
function drawLine ( message, x,y, align, line, r, g, b, font, scale )
    --First draw it and work out the width
    local width = 0
    contentMessages[line] = {}
    for i,part in ipairs(message) do
        if type(part) == "string" then
            local text = dxText:create ( part, width, y, false )
            text:font ( font )
            text:scale ( scale )
            text:type("shadow",1)
            text:align"left"
            text:color ( r,g,b )
            table.insert ( contentMessages[line], text )
            width = width + text:extent()
        elseif part[1] == "icon" then
            local iconWidth = part.width or iconWidths[part.id or -1] or iconWidths[255]
            local iconHeight = part.height or config.iconHeight
            local image = dxImage:create ( icons[part.id or 0] or icons[255], width, y + (part.posOffY or config.iconPosOffY), iconWidth, iconHeight, false )
            image:color ( part.r or 255, part.g or 255, part.b or 255 )
            image:rotation ( part.rot or 0, part.rotOffX or 0, part.rotOffY or 0 )
            width = width + iconWidth
            table.insert ( contentMessages[line], image )
        elseif part[1] == "image" then
            if part.width and part.path then
                if part.resourceName then
                    part.resource = getResourceFromName(tostring(part.resourceName)) or part.resource
                end
                local image = dxImage:create ( ":"..getResourceName(part.resource).."/"..part.path, width, y + (part.posOffY or config.iconPosOffY), part.width, part.height or config.iconHeight, false )
                image:color ( part.r or 255, part.g or 255, part.b or 255 )
                image:rotation ( part.rot or 0, part.rotOffX or 0, part.rotOffY or 0 )            
                width = width + part.width
                table.insert ( contentMessages[line], image )
            end
        elseif part[1] == "color" or part[1] == "colour" then
            r = part.r or r
            g = part.g or g
            b = part.b or b
        elseif part[1] == "padding" then
            width = width + part.width or 0
        end
        contentMessages[line].scale = scale
    end
    --Now reposition everything properly
    if align == "center" or align == "centre" then
        x = x - width/2
    elseif align == "right" then
        x = x - width
    end
    for i,widget in ipairs(contentMessages[line]) do
        local wx,wy = getWidgetPosition ( widget )
        setWidgetPosition ( widget, x + wx, wy )
    end
    return true
end
 
function fadeLine ( line )
    setLineAlpha ( line, 1 )
    fadingLines[line] = getTickCount()
end
-----
addEventHandler ( "onClientRender",getRootElement(),
function()
    for line,originalTick in pairs(fadingLines) do
        local tickDifference = getTickCount() - originalTick
        if tickDifference > endTime then
            destroyLine ( line )
            setLineAlpha ( line, 1 )
            fadingLines[line] = nil
        elseif tickDifference >  config.startFade then
            local fadeTimeDifference = tickDifference - config.startFade
            --calculate the alpha
            local newAlpha = 1 - fadeTimeDifference/config.fadeTime
            --Set all the alphas
            setLineAlpha ( line, newAlpha )
        end
    end
end )
 
function setLineAlpha ( line, alpha )
    for i,part in ipairs(contentMessages[line]) do
        setWidgetAlpha ( part, alpha )
    end
end
 
function destroyLine ( line )
    for k,part in ipairs(contentMessages[line]) do
        destroyWidget(part)
    end
    contentMessages[line] = {}
end
 
function destroyWidget ( widget )
    if isElement(widget) then
        destroyElement ( widget )
    elseif type(widget) == "table" and widget.destroy then
        widget:destroy()
    end
end
 
function getWidgetPosition ( widget )
    if isElement(widget) then
        return
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...