fmj02 Posted November 16, 2012 Share Posted November 16, 2012 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
manve1 Posted November 16, 2012 Share Posted November 16, 2012 (edited) 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 November 16, 2012 by Guest Link to comment
fmj02 Posted November 16, 2012 Author Share Posted November 16, 2012 it doesn't work...... same and you forgot about trigger Link to comment
manve1 Posted November 16, 2012 Share Posted November 16, 2012 Copy code again, i think i found the problem. Link to comment
fmj02 Posted November 16, 2012 Author Share Posted November 16, 2012 ... and what did you change there? It's same. Link to comment
manve1 Posted November 16, 2012 Share Posted November 16, 2012 It isn't ... never call same function as an event. I mean the server script, i can't remember if i changed the client or not. Link to comment
fmj02 Posted November 16, 2012 Author Share Posted November 16, 2012 (edited) you have just changed stopAnim function name to stopAnimFunction, it doesn't matter what's the function name ... in this case Edited November 16, 2012 by Guest Link to comment
manve1 Posted November 16, 2012 Share Posted November 16, 2012 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 Link to comment
fmj02 Posted November 16, 2012 Author Share Posted November 16, 2012 event is not a function, it works worse than before ;/ it means it still doesn't work Link to comment
Castillo Posted November 16, 2012 Share Posted November 16, 2012 Correct me if I'm wrong, your problem is that the script is removing the animation even when is not the chat animation? Link to comment
Anderl Posted November 16, 2012 Share Posted November 16, 2012 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
manve1 Posted November 16, 2012 Share Posted November 16, 2012 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
fmj02 Posted November 16, 2012 Author Share Posted November 16, 2012 Correct me if I'm wrong, your problem is that the script is removing the animation even when is not the chat animation? yes, for example I have command that sets animation to some dance I use /dance but it stops Link to comment
Castillo Posted November 16, 2012 Share Posted November 16, 2012 I made a fast command ( "/dance" ) and used it, but it worked fine, I didn't lose the animation when finished writing it. Link to comment
fmj02 Posted November 16, 2012 Author Share Posted November 16, 2012 weird, try to make also command /dance2 and use first /dance and then /dance2 after few tryouts you will see. It works on beginning fine for me too 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