Sign in to follow this  
SkatCh

GetElementData problem

Recommended Posts

guys please i need some help here i create a mute system but i have some problems when the player reconnect i got some warnings:

function decreaseMutedTime ( player, time ) 
    if not ( isElement ( player ) ) then return; end 
     
    unmuteTimer[player] = setTimer ( function () 
             
            local timeLeft = tonumber ( getElementData ( player, "mt" ) );  ---- this line  
            if ( timeLeft == 0 ) then 
                killTimer(unmuteTimer[player]) 
                outputDebugString ( "0 sec left" ); 
                if ( getElementData ( player, "mute" ) ) then 
                    outputDebugString ( "is muted" ); 
                    setPlayerMuted ( player, false ); 
                    setElementData ( player, "mt", 0 ); 
                    setElementData ( player, "mute", false ); 
                    outputChatBox ( "Your time of being muted has expired.", player, 0, 255, 0 ); 
                    outputChatBox ( getPlayerName ( player ) .."'s mute has expired", root, 0, 255, 0 ); 
                    unmuteTimer[player] = nil; 
                end 
            else 
                if ( getElementData ( player, "mute" ) ) then -------------- and this line  
                    setElementData ( player, "mt", timeLeft - 1 ); 
                end 
            end 
        end, 1000, -1 
    ); 
end 

Bad Argument @ 'getElementData' Expected Element at agument one 1.

any help

Edited by Guest

Share this post


Link to post

inside the timer block should be a element check. (isElement(player))

If he isn't an element, the timer should be killed and the table should be cleared.

Share this post


Link to post

bro it happen just when the player reconnect i already create a save system to check the player mute time :

function checkMuteOnLogout(account) 
    if (not isPlayerMuted(source)) then return end 
    local mutedTime = getElementData(source, "mt") or 0 
    if (tonumber(mutedTime > 1)) then 
        setAccountData(account, "mt", tonumber(mutedTime)) 
    end 
end 
addEventHandler("onPlayerLogout", root, checkMuteOnLogout) 

Share this post


Link to post

It seems you aren't reading my post correctly. I am not talking about the mute time, I am hell talking about the player element it self, while leaving an invalid player element is still in the system.

onPlayerQuit would work better.

Players should not be able to logout if you want your system to work correct.

Share this post


Link to post
It seems you aren't reading my post correctly. I am not talking about the mute time, I am hell talking about the player element it self, while leaving an invalid player element is still in the system.

sorry bro i don't undrestand this can you help me to fix it i'm sorry if i aste ur time .

Share this post


Link to post
  
function decreaseMutedTime ( player, time ) 
    if isElement ( player ) == false  then return end 
    
    unmuteTimer[player] = setTimer ( function () 
            
            local timeLeft = tonumber ( getElementData ( player, "mt" ) );  ---- this line 
            if ( timeLeft == 0 ) then 
                killTimer(unmuteTimer[player]) 
                outputDebugString ( "0 sec left" ); 
                if ( getElementData ( player, "mute" ) ) then 
                    outputDebugString ( "is muted" ); 
                    setPlayerMuted ( player, false ); 
                    setElementData ( player, "mt", 0 ); 
                    setElementData ( player, "mute", false ); 
                    outputChatBox ( "Your time of being muted has expired.", player, 0, 255, 0 ); 
                    outputChatBox ( getPlayerName ( player ) .."'s mute has expired", root, 0, 255, 0 ); 
                    unmuteTimer[player] = nil; 
                end 
            else 
                if ( getElementData ( player, "mute" ) ) then -------------- and this line 
                    setElementData ( player, "mt", timeLeft - 1 ); 
                end 
            end 
        end, 1000, -1 
    ); 
end 
  

Share this post


Link to post
It seems you aren't reading my post correctly. I am not talking about the mute time, I am hell talking about the player element it self, while leaving an invalid player element is still in the system.

sorry bro i don't undrestand this can you help me to fix it i'm sorry if i aste ur time .

I have no time to write the whole thing bro.

But I will recommend you to use 1 timer and getTickCount().

With every timer execution you loop through the whole table and compare the time now with the future time.

unmuteTimer[player]=getTickCount()+10000 -- time now + 10 seconds. 

local timeNow = getTickCount() 
for player, futureTime in pairs(unmuteTimer) do 
  
    if isElemenr(player) then 
  
        if timeNow > futureTime then 
            unmuteTimer[player] = nil 
            setPlayerMuted ( player, false ) 
        end 
  
    else 
        unmuteTimer[player] = nil 
    end 
  
end 

Share this post


Link to post

If you don't finish it, of course it will not work...

Is this your code? Because you give me the feeling it isn't, since you don't try anything.

Share this post


Link to post

bro i try it also i create an other thing but didn't work i don't now why when the player quit the game this warning appear i can fix it by my self but i don't know what's the problem check this ;

function decreaseMutedTime(player, time) 
    if (not isElement(player) or not time) then return end 
    local function decreaseTime() 
        local o = tonumber(getElementData(player, "mt")) or 0 
        local time = o - 1 
        setElementData(player, "mt", getElementData(player, "mt") - 1) 
        if (time <= 1 and isPlayerMuted(player)) then 
            local time = nil 
            setElementData(player, "mt", false) 
            outputChatBox("You have been unmuted ", player, 255, 255, 0) 
            setPlayerMuted(player, false) 
            setElementData(player, "muteinfo", false) 
            if (isTimer(unmuteTimer[player])) then 
                killTimer(unmuteTimer[player]) 
            end 
        end 
    end 
    unmuteTimer[player] = setTimer(decreaseTime, 1000, tonumber(getElementData(player, "mt"))) 
end 

-- onPlayerLogout

function checkMuteOnLogout(account) 
    if (not isPlayerMuted(source)) then return end 
    local mutedTime = getElementData(source, "mt") or 0 
    if (tonumber(mutedTime > 1)) then 
        setAccountData(account, "mt", tonumber(mutedTime)) 
    end 
end 
addEventHandler("onPlayerLogout", root, checkMuteOnLogout) 

and i create this onPlayerLogin

function checkMuteOnLogin(account) 
    local mutedTime = getAccountData(account, "mt") or 0 
    if (tonumber(mutedTime > 1)) then 
        setPlayerMuted(source, true) 
        decreaseMutedTime(source, mutedTime) 
    end 
end 
addEventHandler("onPlayerLogin", root, checkMuteOnLogin) 

Share this post


Link to post

as I told you before, it is because you don't kill that timer when the player leaves.

Nor the table get cleaned.

Edited by Guest

Share this post


Link to post
  
function checkMuteOnLogout(account) 
    if (not isPlayerMuted(source)) then return end 
    local mutedTime = getElementData(source, "mt") or 0 
    if (tonumber(mutedTime > 1)) then 
        setAccountData(account, "mt", tonumber(mutedTime)) 
        if isTimer(unmuteTimer[source) then 
        killTimer(unmuteTimer[source]) 
end 
    end 
end 
addEventHandler("onPlayerLogout", root, checkMuteOnLogout) 
  

Share this post


Link to post
  
  
local quiter = function () 
 if isTimer(unmuteTimer[source) then 
        killTimer(unmuteTimer[source]) 
 unmuteTimer[source] = nil 
      end 
end 
  
addEventHandler("onPlayerQuit", root, quiter) 
  

Share this post


Link to post

every thing is working fine but when the muted player reconnect i got this warning

Bad Argument @ 'getElementData' Expected Element at agument 1.

function decreaseMutedTime ( player, time ) 
    if not ( isElement ( player ) ) then return; end 
    
    unmuteTimer[player] = setTimer ( function () 
            
            local timeLeft = tonumber ( getElementData ( player, "mt" ) );  ---- this line 
            if ( timeLeft == 0 ) then 
                killTimer(unmuteTimer[player]) 
                outputDebugString ( "0 sec left" ); 
                if ( getElementData ( player, "mute" ) ) then 
                    outputDebugString ( "is muted" ); 
                    setPlayerMuted ( player, false ); 
                    setElementData ( player, "mt", 0 ); 
                    setElementData ( player, "mute", false ); 
                    outputChatBox ( "Your time of being muted has expired.", player, 0, 255, 0 ); 
                    outputChatBox ( getPlayerName ( player ) .."'s mute has expired", root, 0, 255, 0 ); 
                    unmuteTimer[player] = nil; 
                end 
            else 
                if ( getElementData ( player, "mute" ) ) then -------------- and this line 
                    setElementData ( player, "mt", timeLeft - 1 ); 
                end 
            end 
        end, 1000, -1 
    ); 
end 

Share this post


Link to post
every thing is working fine but when the muted player reconnect i got this warning

Bad Argument @ 'getElementData' Expected Element at agument 1.

function decreaseMutedTime ( player, time ) 
    if not ( isElement ( player ) ) then return; end 
    
    unmuteTimer[player] = setTimer ( function () 
            
            local timeLeft = tonumber ( getElementData ( player, "mt" ) );  ---- this line 
            if ( timeLeft == 0 ) then 
                killTimer(unmuteTimer[player]) 
                outputDebugString ( "0 sec left" ); 
                if ( getElementData ( player, "mute" ) ) then 
                    outputDebugString ( "is muted" ); 
                    setPlayerMuted ( player, false ); 
                    setElementData ( player, "mt", 0 ); 
                    setElementData ( player, "mute", false ); 
                    outputChatBox ( "Your time of being muted has expired.", player, 0, 255, 0 ); 
                    outputChatBox ( getPlayerName ( player ) .."'s mute has expired", root, 0, 255, 0 ); 
                    unmuteTimer[player] = nil; 
                end 
            else 
                if ( getElementData ( player, "mute" ) ) then -------------- and this line 
                    setElementData ( player, "mt", timeLeft - 1 ); 
                end 
            end 
        end, 1000, -1 
    ); 
end 

I actually copied this code from Anubav and I just found a typo there. Try this.

  
  
local quiter = function () 
 if isTimer(unmuteTimer[source]) then 
        killTimer(unmuteTimer[source]) 
 unmuteTimer[source] = nil 
      end 
end 
  
addEventHandler("onPlayerQuit", root, quiter) 
  

Share this post


Link to post
didn't work :/
  
   
  
    unmuteTimer[player] = setTimer ( function (player) 
  
            
  
            local timeLeft = tonumber ( getElementData ( player, "mt" ) );  ---- this line 
  
            if ( timeLeft == 0 ) then 
  
                killTimer(unmuteTimer[player]) 
  
                outputDebugString ( "0 sec left" ); 
  
                if ( getElementData ( player, "mute" ) ) then 
  
                    outputDebugString ( "is muted" ); 
  
                    setPlayerMuted ( player, false ); 
  
                    setElementData ( player, "mt", 0 ); 
  
                    setElementData ( player, "mute", false ); 
  
                    outputChatBox ( "Your time of being muted has expired.", player, 0, 255, 0 ); 
  
                    outputChatBox ( getPlayerName ( player ) .."'s mute has expired", root, 0, 255, 0 ); 
  
                    unmuteTimer[player] = nil; 
  
                end 
  
            else 
  
                if ( getElementData ( player, "mute" ) ) then -------------- and this line 
  
                    setElementData ( player, "mt", timeLeft - 1 ); 
  
                end 
  
            end 
  
        end, 1000, -1, player 
    ); 

You must also add this:

local quiter = function () 
  
 if isTimer(unmuteTimer[source]) then 
  
        killTimer(unmuteTimer[source]) 
  
 unmuteTimer[source] = nil 
  
      end 
  
end 
  
  
  
addEventHandler("onPlayerQuit", root, quiter) 

Share this post


Link to post
Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.