Jump to content

[HELP] OutputChatBox for only one player


maffius

Recommended Posts

I'm doing anti combat log script and I don't know how to send these messages to only one player that got attacked

function outputChange(dataName,oldValue) 
    if getElementType(source) == "player" and dataName == "blood" then 
        local newValue = getElementData(source,dataName) 
        if newValue-oldValue < 0 then 
            local time = getRealTime() 
            setElementData ( source, "attacked", time.timestamp ) 
local timers = getTimers ( 999 ) 
-- Loop through the timer list 
for timerKey, timerValue in ipairs(timers) do 
    -- kill the timer 
      killTimer ( timerValue ) 
end 
            setTimer ( delay1, 50, 1, "" ) 
        end 
    end 
end 
addEventHandler("onElementDataChange",getRootElement(),outputChange) 
  
function antiQuitPlayer ( quitType ) 
    if quitType == "Quit" or quitType == "Timed out" then 
        local time = getRealTime() 
        local leavedTime = getElementData ( source, "attacked" ) 
        if leavedTime then 
            if time.timestamp-leavedTime < 15 then 
            --banPlayer ( source, false, false, true, nil, nil, 3600 ) 
            local playerAccount = getPlayerAccount(source) 
            if (playerAccount) then 
            setAccountData(playerAccount,'blood',-55) 
               end 
            end 
        end 
    end 
end 
addEventHandler ( "onPlayerQuit", getRootElement(), antiQuitPlayer ) 
  
function delay1 ( ) 
    outputChatBox ( "Antirelog: 15 seconds left",thePlayer,255,69,0) 
    setTimer ( delay2, 1000, 1, "" ) 
end 
  
function delay2 ( ) 
    outputChatBox ( "Antirelog: 14 seconds left",thePlayer,255,69,0) 
    setTimer ( delay3, 1000, 1, "" ) 
end 
  
function delay3 ( ) 
    outputChatBox ( "Antirelog: 13 seconds left",thePlayer,255,69,0) 
    setTimer ( delay4, 1000, 1, "" ) 
end 
  
function delay4 ( ) 
    outputChatBox ( "Antirelog: 12 seconds left",thePlayer,255,69,0) 
    setTimer ( delay5, 1000, 1, "" ) 
end 
  
function delay5 ( ) 
    outputChatBox ( "Antirelog: 11 seconds left",thePlayer,255,69,0) 
    setTimer ( delay6, 1000, 1, "" ) 
end 
  
function delay6 ( ) 
    outputChatBox ( "Antirelog: 10 seconds left",thePlayer,255,69,0) 
    setTimer ( delay7, 1000, 1, "" ) 
end 
  
function delay7 ( ) 
    outputChatBox ( "Antirelog: 9 seconds left",thePlayer,255,69,0) 
    setTimer ( delay8, 1000, 1, "" ) 
end 
  
function delay8 ( ) 
    outputChatBox ( "Antirelog: 8 seconds left",thePlayer,255,69,0) 
    setTimer ( delay9, 1000, 1, "" ) 
end 
  
function delay9 ( ) 
    outputChatBox ( "Antirelog: 7 seconds left",thePlayer,255,69,0) 
    setTimer ( delay10, 1000, 1, "" ) 
end 
  
function delay10 ( ) 
    outputChatBox ( "Antirelog: 6 seconds left",thePlayer,255,69,0) 
    setTimer ( delay11, 1000, 1, "" ) 
end 
  
function delay11 ( ) 
    outputChatBox ( "Antirelog: 5 seconds left",thePlayer,255,69,0) 
    setTimer ( delay12, 1000, 1, "" ) 
end 
  
function delay12 ( ) 
    outputChatBox ( "Antirelog: 4 seconds left",thePlayer,255,69,0) 
    setTimer ( delay13, 1000, 1, "" ) 
end 
  
function delay13 ( ) 
    outputChatBox ( "Antirelog: 3 seconds left",thePlayer,255,69,0) 
    setTimer ( delay14, 1000, 1, "" ) 
end 
  
function delay14 ( ) 
    outputChatBox ( "Antirelog: 2 seconds left",thePlayer,255,69,0) 
    setTimer ( delay15, 1000, 1, "" ) 
end 
  
function delay15 ( ) 
    outputChatBox ( "Antirelog: 1 seconds left",thePlayer,255,69,0) 
    setTimer ( delay16, 1000, 1, "" ) 
end 
  
function delay16 ( ) 
    outputChatBox ( "Antirelog: You can disconnect now.",thePlayer,255,69,0) 
end 

Link to comment

Try this:

function outputChange(dataName,oldValue) 
    if getElementType(source) == "player" and dataName == "blood" then 
        local newValue = getElementData(source,dataName) 
        if newValue-oldValue < 0 then 
            local time = getRealTime() 
            setElementData ( source, "attacked", time.timestamp ) 
local timers = getTimers ( 999 ) 
-- Loop through the timer list 
for timerKey, timerValue in ipairs(timers) do 
    -- kill the timer 
      killTimer ( timerValue ) 
end 
            setTimer ( delay1, 50, 1, "" ) 
        end 
    end 
end 
addEventHandler("onElementDataChange",getRootElement(),outputChange) 
  
function antiQuitPlayer ( quitType ) 
    if quitType == "Quit" or quitType == "Timed out" then 
        local time = getRealTime() 
        local leavedTime = getElementData ( source, "attacked" ) 
        if leavedTime then 
            if time.timestamp-leavedTime < 15 then 
            --banPlayer ( source, false, false, true, nil, nil, 3600 ) 
            local playerAccount = getPlayerAccount(source) 
            if (playerAccount) then 
            setAccountData(playerAccount,'blood',-55) 
               end 
            end 
        end 
    end 
end 
addEventHandler ( "onPlayerQuit", getRootElement(), antiQuitPlayer ) 
  
function delay1 (source) 
    outputChatBox ( "Antirelog: 15 seconds left",source,255,69,0) 
    setTimer ( delay2, 1000, 1, "" ) 
end 
  
function delay2 (source) 
    outputChatBox ( "Antirelog: 14 seconds left",source,255,69,0) 
    setTimer ( delay3, 1000, 1, "" ) 
end 
  
function delay3 (source) 
    outputChatBox ( "Antirelog: 13 seconds left",source,255,69,0) 
    setTimer ( delay4, 1000, 1, "" ) 
end 
  
function delay4 (source) 
    outputChatBox ( "Antirelog: 12 seconds left",source,255,69,0) 
    setTimer ( delay5, 1000, 1, "" ) 
end 
  
function delay5 (source) 
    outputChatBox ( "Antirelog: 11 seconds left",source,255,69,0) 
    setTimer ( delay6, 1000, 1, "" ) 
end 
  
function delay6 (source) 
    outputChatBox ( "Antirelog: 10 seconds left",source,255,69,0) 
    setTimer ( delay7, 1000, 1, "" ) 
end 
  
function delay7 (source) 
    outputChatBox ( "Antirelog: 9 seconds left",source,255,69,0) 
    setTimer ( delay8, 1000, 1, "" ) 
end 
  
function delay8 (source) 
    outputChatBox ( "Antirelog: 8 seconds left",source,255,69,0) 
    setTimer ( delay9, 1000, 1, "" ) 
end 
  
function delay9 (source) 
    outputChatBox ( "Antirelog: 7 seconds left",source,255,69,0) 
    setTimer ( delay10, 1000, 1, "" ) 
end 
  
function delay10 (source) 
    outputChatBox ( "Antirelog: 6 seconds left",source,255,69,0) 
    setTimer ( delay11, 1000, 1, "" ) 
end 
  
function delay11 (source) 
    outputChatBox ( "Antirelog: 5 seconds left",source,255,69,0) 
    setTimer ( delay12, 1000, 1, "" ) 
end 
  
function delay12 (source) 
    outputChatBox ( "Antirelog: 4 seconds left",source,255,69,0) 
    setTimer ( delay13, 1000, 1, "" ) 
end 
  
function delay13 (source) 
    outputChatBox ( "Antirelog: 3 seconds left",source,255,69,0) 
    setTimer ( delay14, 1000, 1, "" ) 
end 
  
function delay14 (source) 
    outputChatBox ( "Antirelog: 2 seconds left",source,255,69,0) 
    setTimer ( delay15, 1000, 1, "" ) 
end 
  
function delay15 (source) 
    outputChatBox ( "Antirelog: 1 seconds left",source,255,69,0) 
    setTimer ( delay16, 1000, 1, "" ) 
end 
  
function delay16 (source) 
    outputChatBox ( "Antirelog: You can disconnect now.",source,255,69,0) 
end 

Link to comment
function outputChange(dataName,oldValue) 
    if getElementType(source) == "player" and dataName == "blood" then 
        local newValue = getElementData(source,dataName) 
        if newValue-oldValue < 0 then 
            local time = getRealTime() 
            setElementData ( source, "attacked", time.timestamp ) 
local timers = getTimers ( 999 ) 
-- Loop through the timer list 
for timerKey, timerValue in ipairs(timers) do 
    -- kill the timer 
      killTimer ( timerValue ) 
end 
            setTimer ( delay1, 50, 1, "" ) 
        end 
    end 
end 
addEventHandler("onElementDataChange",getRootElement(),outputChange) 
  
function antiQuitPlayer ( quitType ) 
    if quitType == "Quit" or quitType == "Timed out" then 
        local time = getRealTime() 
        local leavedTime = getElementData ( source, "attacked" ) 
        if leavedTime then 
            if time.timestamp-leavedTime < 15 then 
            --banPlayer ( source, false, false, true, nil, nil, 3600 ) 
            local playerAccount = getPlayerAccount(source) 
            if (playerAccount) then 
            setAccountData(playerAccount,'blood',-55) 
               end 
            end 
        end 
    end 
end 
addEventHandler ( "onPlayerQuit", getRootElement(), antiQuitPlayer ) 
  
function delay1 ( ) 
    outputChatBox ( "Antirelog: 15 seconds left",source,255,69,0) 
    setTimer ( delay2, 1000, 1, "" ) 
end 
  
function delay2 ( ) 
    outputChatBox ( "Antirelog: 14 seconds left",source,255,69,0) 
    setTimer ( delay3, 1000, 1, "" ) 
end 
  
function delay3 ( ) 
    outputChatBox ( "Antirelog: 13 seconds left",source,255,69,0) 
    setTimer ( delay4, 1000, 1, "" ) 
end 
  
function delay4 ( ) 
    outputChatBox ( "Antirelog: 12 seconds left",source,255,69,0) 
    setTimer ( delay5, 1000, 1, "" ) 
end 
  
function delay5 ( ) 
    outputChatBox ( "Antirelog: 11 seconds left",source,255,69,0) 
    setTimer ( delay6, 1000, 1, "" ) 
end 
  
function delay6 ( ) 
    outputChatBox ( "Antirelog: 10 seconds left",source,255,69,0) 
    setTimer ( delay7, 1000, 1, "" ) 
end 
  
function delay7 ( ) 
    outputChatBox ( "Antirelog: 9 seconds left",source,255,69,0) 
    setTimer ( delay8, 1000, 1, "" ) 
end 
  
function delay8 ( ) 
    outputChatBox ( "Antirelog: 8 seconds left",source,255,69,0) 
    setTimer ( delay9, 1000, 1, "" ) 
end 
  
function delay9 ( ) 
    outputChatBox ( "Antirelog: 7 seconds left",source,255,69,0) 
    setTimer ( delay10, 1000, 1, "" ) 
end 
  
function delay10 ( ) 
    outputChatBox ( "Antirelog: 6 seconds left",source,255,69,0) 
    setTimer ( delay11, 1000, 1, "" ) 
end 
  
function delay11 ( ) 
    outputChatBox ( "Antirelog: 5 seconds left",source,255,69,0) 
    setTimer ( delay12, 1000, 1, "" ) 
end 
  
function delay12 ( ) 
    outputChatBox ( "Antirelog: 4 seconds left",source,255,69,0) 
    setTimer ( delay13, 1000, 1, "" ) 
end 
  
function delay13 ( ) 
    outputChatBox ( "Antirelog: 3 seconds left",source,255,69,0) 
    setTimer ( delay14, 1000, 1, "" ) 
end 
  
function delay14 ( ) 
    outputChatBox ( "Antirelog: 2 seconds left",source,255,69,0) 
    setTimer ( delay15, 1000, 1, "" ) 
end 
  
function delay15 ( ) 
    outputChatBox ( "Antirelog: 1 seconds left",source,255,69,0) 
    setTimer ( delay16, 1000, 1, "" ) 
end 
  
function delay16 ( ) 
    outputChatBox ( "Antirelog: You can disconnect now.",source,255,69,0) 
end 

Link to comment

Try it, not tested but should works and tell me the result

function outputChange(dataName,oldValue) 
    if getElementType(source) == "player" and dataName == "blood" then 
        local newValue = getElementData(source,dataName) 
        if newValue-oldValue < 0 then 
            local time = getRealTime() 
            setElementData ( source, "attacked", time.timestamp ) 
local timers = getTimers ( 999 ) 
-- Loop through the timer list 
for timerKey, timerValue in ipairs(timers) do 
    -- kill the timer 
      killTimer ( timerValue ) 
end 
            setTimer ( delay1, 50, 1, source) 
        end 
    end 
end 
addEventHandler("onElementDataChange",getRootElement(),outputChange) 
  
function antiQuitPlayer ( quitType ) 
    if quitType == "Quit" or quitType == "Timed out" then 
        local time = getRealTime() 
        local leavedTime = getElementData ( source, "attacked" ) 
        if leavedTime then 
            if time.timestamp-leavedTime < 15 then 
            --banPlayer ( source, false, false, true, nil, nil, 3600 ) 
            local playerAccount = getPlayerAccount(source) 
            if (playerAccount) then 
            setAccountData(playerAccount,'blood',-55) 
               end 
            end 
        end 
    end 
end 
addEventHandler ( "onPlayerQuit", getRootElement(), antiQuitPlayer ) 
  
function delay1 ( source) 
   if ( not isElement ( source ) ) then return end 
    outputChatBox ( "Antirelog: 15 seconds left",source,255,69,0) 
    setTimer ( delay2, 1000, 1, source ) 
end 
  
function delay2 ( source ) 
    if ( not isElement ( source ) ) then return end 
    outputChatBox ( "Antirelog: 14 seconds left",source,255,69,0) 
    setTimer ( delay3, 1000, 1, source ) 
end 
  
function delay3 ( source ) 
     if ( not isElement ( source ) ) then return end 
    outputChatBox ( "Antirelog: 13 seconds left",source,255,69,0) 
    setTimer ( delay4, 1000, 1, source ) 
end 
  
function delay4 ( source ) 
    if ( not isElement ( source ) ) then return end 
    outputChatBox ( "Antirelog: 12 seconds left",source,255,69,0) 
    setTimer ( delay5, 1000, 1, source ) 
end 
  
function delay5 ( source ) 
     if ( not isElement ( source ) ) then return end 
    outputChatBox ( "Antirelog: 11 seconds left",source,255,69,0) 
    setTimer ( delay6, 1000, 1, source ) 
end 
  
function delay6 ( source ) 
    if ( not isElement ( source ) ) then return end 
    outputChatBox ( "Antirelog: 10 seconds left",source,255,69,0) 
    setTimer ( delay7, 1000, 1, source ) 
end 
  
function delay7 ( source ) 
    if ( not isElement ( source ) ) then return end 
    outputChatBox ( "Antirelog: 9 seconds left",source,255,69,0) 
    setTimer ( delay8, 1000, 1,  source) 
end 
  
function delay8 ( source ) 
     if ( not isElement ( source ) ) then return end 
    outputChatBox ( "Antirelog: 8 seconds left",source,255,69,0) 
    setTimer ( delay9, 1000, 1, source ) 
end 
  
function delay9 ( source ) 
    if ( not isElement ( source ) ) then return end 
    outputChatBox ( "Antirelog: 7 seconds left",source,255,69,0) 
    setTimer ( delay10, 1000, 1, source ) 
end 
  
function delay10 ( source ) 
    if ( not isElement ( source ) ) then return end 
    outputChatBox ( "Antirelog: 6 seconds left",source,255,69,0) 
    setTimer ( delay11, 1000, 1, source ) 
end 
  
function delay11 ( source ) 
    if ( not isElement ( source ) ) then return end 
    outputChatBox ( "Antirelog: 5 seconds left",source,255,69,0) 
    setTimer ( delay12, 1000, 1, source ) 
end 
  
function delay12 ( source ) 
    if ( not isElement ( source ) ) then return end 
    outputChatBox ( "Antirelog: 4 seconds left",source,255,69,0) 
    setTimer ( delay13, 1000, 1, source ) 
end 
  
function delay13 ( source ) 
    if ( not isElement ( source ) ) then return end 
    outputChatBox ( "Antirelog: 3 seconds left",source,255,69,0) 
    setTimer ( delay14, 1000, 1, source ) 
end 
  
function delay14 ( source ) 
    if ( not isElement ( source ) ) then return end 
    outputChatBox ( "Antirelog: 2 seconds left",source,255,69,0) 
    setTimer ( delay15, 1000, 1, source ) 
end 
  
function delay15 ( source ) 
    if ( not isElement ( source ) ) then return end 
    outputChatBox ( "Antirelog: 1 seconds left",source,255,69,0) 
    setTimer ( delay16, 1000, 1, source ) 
end 
  
function delay16 ( source ) 
    if ( not isElement ( source ) ) then return end 
    outputChatBox ( "Antirelog: You can disconnect now.",source,255,69,0) 
end 

Link to comment

This code can be simplified, define thousand functions for the timers isn't needed.

relog = {} 
  
function outputChange(dataName,oldValue) 
    if getElementType(source) == "player" and dataName == "blood" then 
        local newValue = getElementData(source,dataName) 
        if ( newValue - oldValue ) < 0 then 
            local time = getRealTime() 
  
            if relog[source] and relog[source] and isTimer ( relog[source] ) then 
                killTimer ( relog[source] ) 
            end 
  
            relog[source] = 
            setTimer ( 
                function(player) 
                    local _, seconds    =   getTimerDetails ( sourceTimer ) 
                    local seconds       =   seconds -1 
  
                    if seconds ~= 0 then 
                        outputChatBox ( "Antirelog: "..seconds.." seconds left",player,255,69,0) 
                    else 
                        outputChatBox ( "Antirelog: You can disconnect now", player, 255, 69, 0 ) 
                        relog[player] = nil 
                    end 
                end 
            , 1000, 16, source ) 
        end 
    end 
end 
addEventHandler("onElementDataChange",getRootElement(),outputChange) 
  
function antiQuitPlayer ( quitType ) 
    if quitType == "Quit" or quitType == "Timed out" then 
        if relog[source] and isTimer ( relog[source] ) then 
            killTimer ( relog[source] ) 
            relog[source] = nil 
             
            --banPlayer ( source, false, false, true, nil, nil, 3600 ) 
            local playerAccount = getPlayerAccount(source) 
            if ( playerAccount ) then 
                setAccountData(playerAccount,'blood',-55) 
            end 
        end 
    end 
end 
addEventHandler ( "onPlayerQuit", getRootElement(), antiQuitPlayer ) 

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...