Jump to content

annoying problem...


fmj02

Recommended Posts

I have script that stops anim when chat input is cancelled( I have talking animation when I press 't' ). It works, but the problem is it cancels animations executed by command for example /dance, /sit, I tried many ways to fix it one worked but I had to cancel input 2 times then animation was stopping... ;/ I don't know what should I do. Im angry, it's a little script and I have little problem hard to fix. Look at it please:

CLIENT:

  
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        triggerServerEvent("bindClientKey", localPlayer ) 
    end 
) 
  
local chatActive = false 
local chatActiveTimer 
addEventHandler( "onClientKey", root,  
    function(key,pressed) 
        if pressed and key == "t" or "y" and chatActive == false then 
                -- This timer checks if the chat input is active 50ms efter 't' has been pressed 
                        if isChatBoxInputActive() then 
                                chatActive = true 
                                -- Timer chat checks if the chat is still active every 250ms. The timer is destroyed when the chat becomes inactive. 
                                chatActiveTimer = setTimer( function() 
                                        if not isChatBoxInputActive() then 
                                                chatActive = false 
                                                --local animBlock, animName = getPedAnimation(localPlayer) 
                                                local animBlock, animName = getPedAnimation(localPlayer) 
                                                triggerServerEvent( "stopAnim", localPlayer, animBlock, animName ) 
                                                if chatActiveTimer then 
                                                    if isTimer(chatActiveTimer) then 
                                                        killTimer( chatActiveTimer ) 
                                                    end 
                                                end 
                                        end 
                                end, 250, 0 ) 
  
                        end 
               return true 
        end 
        return false 
    end 
  
) 

SERVER:

function stopAnim(animBlock, animName) 
    if animBlock == "gangs" and animName == "prtial_gngtlkg" then 
        setPedAnimation( source, false ) 
        return true 
    end 
end 
addEvent( "stopAnim", true ) 
addEventHandler( "stopAnim", root, stopAnim ) 
  
-- talking animation during IC chat 
function realisticIC(keyPresser, key, keyState) 
    if(keyState == "down") then 
        setPedAnimation(keyPresser, "gangs", "prtial_gngtlkg", -1, true, false, true) 
    end 
end 
  
addEvent("bindClientKey", true) 
function bindClientKey() 
    bindKey(source, "t", "down", realisticIC) 
end 
addEventHandler("bindClientKey", root, bindClientKey) 
  
  

Link to comment

CLIENT:

  
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        triggerServerEvent("bindClientKey", localPlayer ) 
    end 
) 
  
local chatActive = false 
  
addEventHandler( "onClientKey", root,  
    function(key,pressed) 
      setTimer( function() 
        if pressed and key == "t" or "y" and chatActive == false then 
                        if isChatBoxInputActive() then 
                                chatActive = true 
                        elseif not isChatBoxInputActive() then 
                            chatActive = false 
                            local animBlock, animName = getPedAnimation(localPlayer) 
                        end 
               return true 
        end 
        return false 
      end, 50, 0 ) 
    end 
) 

SERVER:

function realisticIC(keyPresser, key, keyState) 
    if(keyState == "down") then 
        setPedAnimation(keyPresser, "gangs", "prtial_gngtlkg", -1, true, false, true) 
    elseif animBlock == "gangs" and animName == "prtial_gngtlkg" then 
        setPedAnimation( source, false ) 
        return true 
    end 
end 
  
addEvent("bindClientKey", true) 
function bindClientKey_() 
if isKeyBound( source, "t" ) then 
unbindKey(source, "t", "down", realisticIC); 
bindKey(source, "t", "down", realisticIC) 
else 
    bindKey(source, "t", "down", realisticIC) 
end 
end 
addEventHandler("bindClientKey", root, bindClientKey_) 

I think that this should work :)

Edited by Guest
Link to comment
you have just changed stopAnim function name to stopAnimFunction, it doesn't matter what's the function name ...

Actually it does, because u created the same function name and an event

As midas said, functions aren't events. Functions must have different names because overwriting - unlike some languages that can differ functions by its parameters, any previous function declared with same name as the function being declared is overwritten.

Events aren't the same as functions. Functions are something from Lua language itself, event names are just a string to name events - event system is from MTA:SA, it's not something from Lua itself.

Hope you got it.

Link to comment
you have just changed stopAnim function name to stopAnimFunction, it doesn't matter what's the function name ...

Actually it does, because u created the same function name and an event

As midas said, functions aren't events. Functions must have different names because overwriting - unlike some languages that can differ functions by its parameters, any previous function declared with same name as the function being declared is overwritten.

Events aren't the same as functions. Functions are something from Lua language itself, event names are just a string to name events - event system is from MTA:SA, it's not something from Lua itself.

Hope you got it.

I meant something like this, but im terrible at english language as its not my national language

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