Jump to content

news Ticker


abu5lf

Recommended Posts

I did not find the solution?

News of the resource script, but does not support the Arabic language when I write seems to me just point!

And also when I added the news directly from the server using the button u activated users can talk to me!

Is there a solution?

newsTicker_client.lua

local w_newsTickerAnim = false 
local s_tickerMsg = {" أهلا بك", 
  
  
} 
local currentItem = 1 
  
addEventHandler ( "onClientResourceStart", getResourceRootElement(getThisResource()), function(name) 
    --Create the ticker GUI 
    local screenWidth, screenHeight = guiGetScreenSize () 
    w_newsTickerWidth = 500 
    w_newsTickerHeight = 50 
    w_newsTickerLeft = (( screenWidth / 4 ) - ( w_newsTickerWidth / 4 )) 
    w_newsTickerTop = -50 
  w_newsTickerMinWidth = 200 
    w_newsTicker = guiCreateWindow( w_newsTickerLeft, w_newsTickerTop, w_newsTickerWidth, w_newsTickerHeight, "News Ticker /hidenews /shownews", false ) 
  --w_newsTicker = guiCreateWindow( 0.5, 0, 0.35, 0.1, "News Ticker /hidenews /shownews", true ) 
  w, h = guiGetSize ( w_newsTicker, false ) 
  if ( w < w_newsTickerMinWidth ) then 
    w = w_newsTickerMinWidth 
  end 
  guiSetSize ( w_newsTicker, w, 20, false ) 
  guiSetPosition ( w_newsTicker, ( screenWidth / 2 ) - ( w / 2 ), -20, false ) 
  
    w_newsTickerName = guiCreateLabel ( w + 100, 25, w, 18, "News is loading... Please wait", false, w_newsTicker ) 
  
    guiSetAlpha ( w_newsTicker, 0.50 ) 
    guiWindowSetSizable ( w_newsTicker, false ) 
    local guiLength = guiLabelGetTextExtent ( w_newsTickerName ) 
     
    guiSetFont ( w_newsTickerName, "clear-normal" ) 
    guiLabelSetColor ( w_newsTickerName, 0, 255, 0 ) 
  
    guiSetSize ( w_newsTickerName, guiLength, 20, false ) 
    setTimer ( function() 
        if ( ( w_newsTickerAnim ) and ( w_newsTickerAnim:isPlaying() ) ) then 
            return 
        else 
            guiSetPosition ( w_newsTickerName, w, 25, false ) 
            guiSetText ( w_newsTickerName, s_tickerMsg[currentItem] ) 
            guiLength = guiLabelGetTextExtent ( w_newsTickerName ) 
            guiSetSize ( w_newsTickerName, guiLength, 18, false ) 
           --w_newsTickerAnim = Animation.createAndPlay(w_newsTickerName, Animation.presets.guiMoveResize(guiLength - guiLength - guiLength - 100, 25, guiLength, 18, 10000 + (tonumber(guiLength)*50.45))) 
              w_newsTickerAnim = Animation.createAndPlay(w_newsTickerName, Animation.presets.guiMoveResize( -guiLength , 25, guiLength, 18, 8000 + (tonumber(guiLength)*50.45))) 
            currentItem = currentItem + 1 
            if ( currentItem > #s_tickerMsg ) then 
                currentItem = 1 
            end 
        end 
    end, 1000, 0 ) 
end) 
  
function getPlayerCount() 
    return #getElementsByType("player") 
end 
  
function hideNews() 
    guiSetVisible ( w_newsTicker, false ) 
    outputChatBox ( "News Ticker hidden, you can show it again by typing /shownews", 50, 255, 50 ) 
end 
  
function showNews() 
    guiSetVisible ( w_newsTicker, true ) 
    outputChatBox ( "News Ticker shown, you can hide it again by typing /hidenews", 50, 255, 50 ) 
end 
  
addCommandHandler ( "hidenews", hideNews ) 
addCommandHandler ( "HIDENEWS", hideNews ) 
addCommandHandler ( "shownews", showNews ) 
addCommandHandler ( "SHOWNEWS", showNews ) 
  
  
  
  
addEvent("new", true ) 
addEventHandler("new", getRootElement(), start) 
function yana(getPlayerName,s_tickerMsg) 
    outputChatBox(getPlayerName,s_tickerMsg,getRootElement(),255,0,0,true) 
end 
addEvent("yanas", true ) 
addEventHandler("yanas", getRootElement(), yana) 
bindKey("u", "down", "chatbox","AM") 

client_anim_util.lua

function table.find(t, ...) 
    local args = { ... } 
    if #args == 0 then 
        for k,v in pairs(t) do 
            if v then 
                return k 
            end 
        end 
        return false 
    end 
     
    local value = table.remove(args) 
    if value == '[nil]' then 
        value = nil 
    end 
    for k,v in pairs(t) do 
        for i,index in ipairs(args) do 
            if type(index) == 'function' then 
                v = index(v) 
            else 
                if index == '[last]' then 
                    index = #v 
                end 
                v = v[index] 
            end 
        end 
        if v == value then 
            return k 
        end 
    end 
    return false 
end 
  
function table.removevalue(t, val) 
    for i,v in ipairs(t) do 
        if v == val then 
            table.remove(t, i) 
            return i 
        end 
    end 
    return false 
end 

client_anim.lua

Animation = {} 
Animation.__index = Animation 
  
Animation.collection = {} 
  
function Animation.create(elem, ...) 
    local anim = setmetatable({ type = 'anim', elem = elem, phases = {...} }, Animation) 
    for i,phase in ipairs(anim.phases) do 
        if type(phase) == 'table' then 
            phase.from = phase.from or 0 
            phase.to = phase.to or 1 
            phase.time = phase.time or 0 
            phase.value = phase.from 
            phase.speed = phase.time > 0 and ((phase.to - phase.from) / phase.time) or 0 
        end 
    end 
    return anim 
end 
  
function Animation.createAndPlay(elem, ...) 
    local anim = Animation.create(elem, ...) 
    anim:play() 
    return anim 
end 
  
function Animation.createQueue(...) 
    local queue = setmetatable({ type = 'queue' }, Animation) 
    local args = { ... } 
    if type(args[1]) == 'string' then 
        queue.name = table.remove(args, 1) 
    end 
    for i,obj in ipairs(args) do 
        queue:add(obj) 
    end 
    return queue 
end 
  
function Animation.createQueueAndPlay(...) 
    local queue = Animation.createQueue(...) 
    queue:play() 
    return queue 
end 
  
function Animation.getQueue(name) 
    for i,obj in ipairs(Animation.collection) do 
        if obj:isQueue() and obj.name == name then 
            return obj 
        end 
    end 
    return false 
end 
  
function Animation.getOrCreateQueue(name) 
    local queue = Animation.getQueue(name) 
    if not queue then 
        queue = Animation.createQueue(name) 
    end 
    return queue 
end 
  
function Animation:isPlaying() 
    return self.playing or false 
end 
  
function Animation.playingAnimationsExist() 
    return table.find(Animation.collection, 'playing', true) and true 
end 
  
function Animation:add(anim) 
    if self:isQueue() then 
        if type(anim) == 'function' then 
            anim = setmetatable({ type = 'function', fn = anim }, Animation) 
        end 
        anim.queue = self 
        anim.playing = self.playing 
        table.insert(self, anim) 
    end 
end 
  
function Animation:remove() 
    if self.queue then 
        table.removevalue(self.queue, self) 
        if #self.queue == 0 then 
            self.queue:remove() 
        end 
    else 
        table.removevalue(Animation.collection, self) 
        if not Animation.playingAnimationsExist() then 
            removeEventHandler('onClientRender', getRootElement(), updateAnim) 
            Animation.prevTick = nil 
        end 
    end 
    self.playing = false 
end 
  
function Animation:isAnimation() 
    return self.type == 'anim' 
end 
  
function Animation:isQueue() 
    return self.type == 'queue' 
end 
  
function Animation:play() 
    if self:isPlaying() then 
        return 
    end 
    if self:isQueue() then 
        for i,anim in ipairs(self) do 
            anim.playing = true 
        end 
    end 
    if not table.find(Animation.collection, self) then 
        table.insert(Animation.collection, self) 
    end 
    if not Animation.playingAnimationsExist() then 
        Animation.prevTick = getTickCount() 
        addEventHandler('onClientRender', getRootElement(), updateAnim) 
    end 
    self.playing = true 
end 
  
function Animation:pause() 
    self.playing = false 
    if not Animation.playingAnimationsExist() then 
        removeEventHandler('onClientRender', getRootElement(), updateAnim) 
        Animation.prevTick = nil 
    end 
end 
  
function updateAnim() 
    local phase 
    local curTick = getTickCount() 
    local doRemove 
     
    for i,obj in ipairs(Animation.collection) do 
        if obj.playing then 
            if obj:isQueue() then 
                obj = obj[1] 
            end 
            if not isElement(obj.elem) then 
                obj:remove() 
            end 
        end 
        if obj.playing then 
            phase = obj.phases[1] 
            doRemove = false 
            if type(phase) == 'function' then 
                phase(obj.elem) 
                doRemove = true 
            else 
                if not phase.starttick then 
                    phase.starttick = curTick 
                end 
                phase.prevpassed = phase.passed 
                phase.passed = (curTick - phase.starttick) % phase.time 
                if phase.prevpassed and phase.passed < phase.prevpassed then 
                    if phase.repeats and phase.repeats > 0 then 
                        phase.repeats = phase.repeats - 1 
                        doRemove = phase.repeats == 0 
                    elseif not phase.repeats then 
                        doRemove = true 
                    end 
                end 
            end 
            if doRemove then 
                table.remove(obj.phases, 1) 
                phase = false 
                if #obj.phases == 0 then 
                    obj:remove() 
                    obj = false 
                end 
            end 
            if obj and phase then 
                phase.value = phase.from + phase.speed*phase.passed 
                if phase.fn then 
                    phase.fn(obj.elem, phase.transform and phase.transform(phase.value) or phase.value, phase) 
                end 
            end 
        end 
    end 
end 
  
Animation.presets = {} 
  
function Animation.presets.pulse(time, value, phase) 
    if not value then 
        return { from = 0, to = 2*math.pi, transform = math.sin, time = time, repeats = 0, fn = Animation.presets.pulse } 
    else 
        local elem = time 
        if not phase.width then 
            phase.width, phase.height = guiGetSize(elem, false) 
            phase.centerX, phase.centerY = guiGetPosition(elem, false) 
            phase.centerX = phase.centerX + math.floor(phase.width/2) 
            phase.centerY = phase.centerY + math.floor(phase.height/2) 
        end 
        local pct = 1 - (value+1)*0.1 
        local width = pct*phase.width 
        local height = pct*phase.height 
        local x = phase.centerX - math.floor(width/2) 
        local y = phase.centerY - math.floor(height/2) 
        guiSetPosition(elem, x, y, false) 
        guiSetSize(elem, width, height, false) 
    end 
end 
  
function Animation.presets.guiMoveResize(x, y, width, height, time) 
    if height then 
        return { from = -math.pi/2, to = math.pi/2, time = time or 1000, transform = math.sin, 
                 endX = x, endY = y, endWidth = width, endHeight = height, 
                 fn = Animation.presets.guiMoveResize } 
    else 
        local elem, value, phase = x, (y + 1)/2, width 
        if not phase.startX then 
            phase.startX, phase.startY = guiGetPosition(elem, false) 
            phase.startWidth, phase.startHeight = guiGetSize(elem, false) 
        end 
        guiSetPosition(elem, math.floor(phase.startX + value*(phase.endX - phase.startX)), math.floor(phase.startY + value*(phase.endY - phase.startY)), false) 
        guiSetSize(elem, math.floor(phase.startWidth + value*(phase.endWidth - phase.startWidth)), math.floor(phase.startHeight + value*(phase.endHeight - phase.startHeight)), false) 
    end 
end 
  

Edited by Guest
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...