maffius Posted September 23, 2015 Share Posted September 23, 2015 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
1LoL1 Posted September 23, 2015 Share Posted September 23, 2015 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
maffius Posted September 24, 2015 Author Share Posted September 24, 2015 Bad argument @ 'outputChatBox' [Expected element at argument 2, got string] Link to comment
Fist Posted September 24, 2015 Share Posted September 24, 2015 local varPlayer = getPlayerFromName(source) try this Link to comment
maffius Posted September 24, 2015 Author Share Posted September 24, 2015 Still not working Link to comment
KariiiM Posted September 24, 2015 Share Posted September 24, 2015 Which line the error exist Link to comment
maffius Posted September 24, 2015 Author Share Posted September 24, 2015 Bad argument @ 'outputChatBox' [Expected element at argument 2, got string] In all delay function Link to comment
KariiiM Posted September 24, 2015 Share Posted September 24, 2015 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
maffius Posted September 24, 2015 Author Share Posted September 24, 2015 It now again display this messages to all players Link to comment
KariiiM Posted September 24, 2015 Share Posted September 24, 2015 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
maffius Posted September 24, 2015 Author Share Posted September 24, 2015 It works now, thank you very much. Can you tell me if I used killTimer to kill all timers below 999ms on serverside, it will kill timers only in this script or in another too? Link to comment
KariiiM Posted September 24, 2015 Share Posted September 24, 2015 It works now, thank you very much. Can you tell me if I used killTimer to kill all timers below 999ms on serverside, it will kill timers only in this script or in another too? Only in script and you're welcome Link to comment
t3wz Posted September 24, 2015 Share Posted September 24, 2015 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
maffius Posted September 24, 2015 Author Share Posted September 24, 2015 Thank you all, it works good now. Topic can be closed Link to comment
KariiiM Posted September 24, 2015 Share Posted September 24, 2015 It's also great way, i was going to tell him that, doing it in one function exept of 16 Functions..etc plus his code would be clear, anyway have fun scripting Link to comment
maffius Posted September 24, 2015 Author Share Posted September 24, 2015 One more question. It will not kill the timers for other players? Link to comment
KariiiM Posted September 24, 2015 Share Posted September 24, 2015 One more question. It will not kill the timers for other players? No it won't, what i gave you is killing the timer of the local player not all players Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now