Jump to content

isConsoleActive or isChatboxInputActive problem


-Doc-

Recommended Posts

these are client sided functions and don't need a player in them. If you're using isChatboxInputActive then it automatically only works for that client. If you want to get it from another player, you'll have to trigger an event under their name to the client, execute the function and send a trigger back to the source with the answer.

Link to comment

client

function isPlayerConsoleActive ( thePlayer, callback ) 
    if ( thePlayer == getLocalPlayer() ) then 
        triggerServerEvent ( callback, source, thePlayer, isConsoleActive() ); 
    end 
end 
addEvent ( "isPlayerConsoleActive", true ); 
addEventHandler ( "isPlayerConsoleActive", getRootElement(), isPlayerConsoleActive ); 

server

addEvent ( "receiveActiveState", true ); 
addEventHandler ( "receiveActiveState", root, 
    function ( thePlayer, state ) 
        outputChatBox ( getPlayerName ( thePlayer ) .." his console is ".. ( state and "not" or "" ) .. " active.", source ); 
    end 
); 
  
addCommandHandler ( "isActive", 
    function ( thePlayer, _, playername ) 
        if ( playername ) then 
            local player = getPlayerFromName ( playername ); 
            if ( player ) then 
                triggerClientEvent ( "isPlayerConsoleActive", thePlayer, player, "receiveActiveState" ); 
            else 
                outputChatBox ( "player not found.", thePlayer ); 
            end 
        end 
    end 
); 

by using the command: isActive the script will send a trigger towards the client from the player and return the answer to the callback. (not tested though, might be wrong)

Link to comment

That is a bit complicated if you want to see if someone writes without need to check.

You have to use bindKey "t" to know when someone is writing. Then use isChatBoxInputActive to set him element data if hr is writing or not. You can use this elementdata to show you if someone is writing. Same with F8.

Please just dont do it with a timer.

Edited by Guest
Link to comment

Server side

addEvent ( "receiveActiveState", true ); 
addEventHandler ( "receiveActiveState", root, 
    function ( thePlayer, state ) 
        outputChatBox ( getPlayerName ( thePlayer ) .." his console is ".. ( state and "not" or "" ) .. " active.", source ); 
    end 
); 
  
setTimer(check,50,0) 
    function check ( thePlayer, _, playername ) 
        if ( playername ) then 
            local player = getPlayerFromName ( playername ); 
            if ( player ) then 
                triggerClientEvent ( "isPlayerConsoleActive", thePlayer, player, "receiveActiveState" ); 
            else 
                outputChatBox ( "player not found.", thePlayer ); 
            end 
        end 
    end 
  

Link to comment
That is a bit complicated if you want to see if someone writes without need to check.

You have to use bindKey "t" to know when someone is writing. Then use isChatBoxInputActive to set him element data if hr is writing or not. You can use this elementdata to show you if someone is writing. Same with F8.

Please just dont do it with a timer.

That's the more appropriate way and best way to go with, haven't thought about that. :lol:

Link to comment

Player can bind chat input to another key, so bindKey isn't an option.

Put setTimer below triggered function.

  
    function check ( thePlayer, _, playername ) 
        if ( playername ) then 
            local player = getPlayerFromName ( playername ); 
            if ( player ) then 
                triggerClientEvent ( "isPlayerConsoleActive", thePlayer, player, "receiveActiveState" ); 
            else 
                outputChatBox ( "player not found.", thePlayer ); 
            end 
        end 
    end 
setTimer(check,50,0) 

(By the way, setTimer - not a good idea imo)

Edited by Guest
Link to comment

Try this:

local chatison = false 
  
addEventHandler ( "onClientKey", root, function ( ) 
     local chatboxactive = isChatBoxInputActive() 
     if not chatison and chatboxactive then 
          chatison = true 
          setElementData ( localPlayer, "chatIsOn", true ) 
     elseif chatison and not chatboxactive then 
          chatison = false 
          setElementData ( localPlayer, "chatIsOn", false ) 
     end 
end ) 

Edited by Guest
Link to comment

Oh, you don't talk about fadeCamera, you talk about the sound getting lower until its stopped.

You can do it that way:

local sound = nil 
local startvolume = 0 
local actualvolume = 0 
local steptostop = 0 
  
local function fadeTheSoundAway ( ) 
     actualvolume = actualvolume - startvolume/steptostop  
     if actualvolume == 0 then 
          stopSound ( sound ) 
     else 
          setSoundVolume ( sound , actualvolume ) 
     end 
end 
  
function stopSoundWithFade ( sound, step ) 
     if isElement ( sound ) and getElementType ( sound ) == "sound" and tonumber ( step ) then 
          startvolume = getSoundVolume ( sound ) 
          actualvolume = startvolume 
          steptostop = tonumber ( step ) 
          addEventHandler ( "onClientRender", root, fadeTheSoundAway ) 
          return true 
     end 
     return false 
end ) 

With this code you should be able to use the function:

stopSoundWithFade ( thesound, step )

thesound := sound element, which you want to stop

step := float, sets the speed how fast the sound will stop

For step you should use a higher number like 180.

Then the sound will be stopped after 180 Frames (in 3 seconds with 60 FPS).

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