Jump to content

GetElementData problem


SkatCh

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
Link to comment

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) 

Link to comment
  • Moderators

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.

Link to comment
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 .

Link to comment
  
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 
  

Link to comment
  • Moderators
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 

Link to comment

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) 

Link to comment
  
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) 
  

Link to comment

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 

Link to comment
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) 
  

Link to comment
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) 

Link to comment
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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