hello , I have a custom animation and I made a simple script by using it.
so when you start the resource in the server and type /outr22 in chat
the player will do the custom animation
client side :
addEvent( "otur", true )
addEventHandler( "otur", root,
function(enable)
if (enable) then setPedAnimation(source, "otur", "WEAPON_crouch", -1, true, false)
else setPedAnimation(source)
end
end
)
addEventHandler("onClientResourceStart", resourceRoot,
function()
triggerServerEvent("onClientSync", resourceRoot)
end
)
addEventHandler("onClientResourceStop", resourceRoot,
function()
if ifp then
for _,player in ipairs(getElementsByType("player")) do
local _, otur = getPedAnimation(player)
if (otur == "WEAPON_crouch") then
setPedAnimation(player)
end
end
destroyElement(ifp)
end
end
)
server side :
local animEnable = {}
local syncPlayers = {}
addCommandHandler("otur2",
function(player)
if (not animEnable[player]) then
animEnable[player] = true
triggerClientEvent(syncPlayers, "otur", player, true)
outputChatBox("[!]#FFFFFF animation enabled.", player, 0, 255, 0, true)
else
animEnable[player] = false
triggerClientEvent(syncPlayers, "otur", player, false)
outputChatBox("[!]#FFFFFF animation disabled.", player, 255, 0, 0, true)
end
end)
addEvent("onClientSync", true )
addEventHandler("onClientSync", resourceRoot,
function()
outputChatBox("done")
table.insert(syncPlayers, client)
for player, enable in ipairs(animEnable) do
if (enable) then
triggerClientEvent(client, "otur", player, true)
end
end
end
)
addEventHandler("onPlayerQuit", root,
function()
for i, player in ipairs(syncPlayers) do
if source == player then
table.remove(syncPlayers, i)
break
end
end
if (animEnable[source] == true or animEnable[source] == false) then animEnable[source] = nil end
end
)
Now I have decided to change the command you type in chat to do the animation(outr22)
from this
addCommandHandler("otur2",
function(player)
if (not animEnable[player]) then
animEnable[player] = true
triggerClientEvent(syncPlayers, "otur", player, true)
outputChatBox("[!]#FFFFFF animation enabled.", player, 0, 255, 0, true)
else
animEnable[player] = false
triggerClientEvent(syncPlayers, "otur", player, false)
outputChatBox("[!]#FFFFFF animation disabled.", player, 255, 0, 0, true)
end
end)
to this
addEvent("otur2",true)
addEventHandler("otur2",root,
function(player)
if (not animEnable[player]) then
animEnable[player] = true
triggerClientEvent(syncPlayers, "otur", player, true)
outputChatBox("[!]#FFFFFF animation enabled.", player, 0, 255, 0, true)
else
animEnable[player] = false
triggerClientEvent(syncPlayers, "otur", player, false)
outputChatBox("[!]#FFFFFF animation disabled.", player, 255, 0, 0, true)
end
end)
so what I did is I changed the way to do the animation from typing a command --> to press a button to do the custom animation
clarification : when I press a button , the client side will trigger the server event which called otur2 to do the custom animation
and here's the client side :
function mouse2()
if isMouseInPosition(1500, 240, 120, 120) and getKeyState("mouse1") then
playSound("SFX/click.mp3")
triggerServerEvent("otur2", localPlayer)
end
end
addEventHandler ( "onClientClick", root, mouse2)
and When I tested the script, a problem appeared to me
ERROR: AnimationsPanel\smain.lua:9: table index is nil
Knowing that the 9th line in server side is :
animEnable[player] = true
I didn't make any changes to the script As it is clear above, I just changed the command handler to event handler.
I can't figure out what's wrong or fix it, could you help me?
I hope my words are clear and I apologize if I took up too much of your time, thank you
Other information: The benefit of this script is to make custom animations with server side , not just client side .. it's working when I use the command way, but it's not working with event handler