.:HyPeX:. Posted March 15, 2014 Posted March 15, 2014 Well, its outputing the dance name correctly, but it wont dance. local DanceTable = {} table.insert(DanceTable, 1, "bd_clap") table.insert(DanceTable, 2, "bd_clap1") table.insert(DanceTable, 3, "dance_loop") table.insert(DanceTable, 4, "DAN_Down_A") table.insert(DanceTable, 5, "DAN_Left_A") table.insert(DanceTable, 6, "DAN_Loop_A") table.insert(DanceTable, 7, "DAN_Right_A") table.insert(DanceTable, 8, "DAN_Up_A") table.insert(DanceTable, 9, "dnce_M_a") table.insert(DanceTable, 10, "dnce_M_b") table.insert(DanceTable, 11, "dnce_M_c") table.insert(DanceTable, 12, "dnce_M_d") table.insert(DanceTable, 13, "dnce_M_e") function Dance() if not dance then i = nil countedTable = 0 for i,v in ipairs(DanceTable) do countedTable = countedTable + 1 end dance = true valRandom = math.random(1,countedTable) outputChatBox("#0046C8[bF3]: Random Dance: "..tostring(DanceTable[valRandom]), 255,255,255,true) setPedAnimation(getLocalPlayer(), tostring(DanceTable[valRandom]), 5000,true,true, false) dance = false setPedAnimation(getLocalPlayer()) end end addCommandHandler("Dance", Dance)
Mr_Moose Posted March 15, 2014 Posted March 15, 2014 Correct syntax for setPedAnimation is: setPedAnimation ( ped thePed [, string block=nil, string anim=nil, int time=-1, bool loop=true, bool updatePosition=true, bool interruptable=true, bool freezeLastFrame = true] ) You forgot to specify the animation block for your animations, take a look here to see which blocks you should use according to your animations, I guess they are in the same block named dance or something You may also use a # to get the length of your table instead of that loop local randomDanceAnimID = math.random(#DanceTable) And last detail, setting this on the client will result in that only you will see the animation, other players won't see you dance so either user triggerServerEvent or convert the entire script to the server.
Saml1er Posted March 15, 2014 Posted March 15, 2014 I think this is how you get something random from table. local valRandom = DanceTable[ math.random( 1,#DanceTable ) ] setPedAnimation( localPlayer,"DANCING", valRandom ) -- optional ( timers etc )
.:HyPeX:. Posted March 15, 2014 Author Posted March 15, 2014 Correct syntax for setPedAnimation is: setPedAnimation ( ped thePed [, string block=nil, string anim=nil, int time=-1, bool loop=true, bool updatePosition=true, bool interruptable=true, bool freezeLastFrame = true] ) You forgot to specify the animation block for your animations, take a look here to see which blocks you should use according to your animations, I guess they are in the same block named dance or something You may also use a # to get the length of your table instead of that loop local randomDanceAnimID = math.random(#DanceTable) And last detail, setting this on the client will result in that only you will see the animation, other players won't see you dance so either user triggerServerEvent or convert the entire script to the server. Kinda forgot that detail of the server/client, and block of animation, the rest i already know it.
Moderators Citizen Posted March 15, 2014 Moderators Posted March 15, 2014 Why did you do that ? setPedAnimation(getLocalPlayer()) Not specifying the type of animation will automatically cancel the current one So you are making him dance and then cancelling it immediatly ... Here is the server-side version of your script: local DanceTable = {} table.insert(DanceTable, "bd_clap") --no need to specify the index (auto incrementing and starting at 1) table.insert(DanceTable, "bd_clap1") table.insert(DanceTable, "dance_loop") table.insert(DanceTable, "DAN_Down_A") table.insert(DanceTable, "DAN_Left_A") table.insert(DanceTable, "DAN_Loop_A") table.insert(DanceTable, "DAN_Right_A") table.insert(DanceTable, "DAN_Up_A") table.insert(DanceTable, "dnce_M_a") table.insert(DanceTable, "dnce_M_b") table.insert(DanceTable, "dnce_M_c") table.insert(DanceTable, "dnce_M_d") table.insert(DanceTable, "dnce_M_e") function Dance( player ) if not getElementData(player, "dancing") then local valRandom = math.random(#DanceTable) --#myTable returns the size of myTable outputChatBox("#0046C8[bF3]: Random Dance: "..tostring(DanceTable[valRandom]), 255,255,255,true) setPedAnimation(player, tostring(DanceTable[valRandom]), 5000, true, true, false) setElementData(player, "dancing", true) --used for the if statement end end addCommandHandler("Dance", Dance) To stop the animation: setPedAnimation(player) --cancelling the animation removeElementData(player, "dancing") --let the player to use /Dance again
manawydan Posted March 15, 2014 Posted March 15, 2014 one edit in citizen code: local DanceTable = {} table.insert(DanceTable, "bd_clap") --no need to specify the index (auto incrementing and starting at 1) table.insert(DanceTable, "bd_clap1") table.insert(DanceTable, "dance_loop") table.insert(DanceTable, "DAN_Down_A") table.insert(DanceTable, "DAN_Left_A") table.insert(DanceTable, "DAN_Loop_A") table.insert(DanceTable, "DAN_Right_A") table.insert(DanceTable, "DAN_Up_A") table.insert(DanceTable, "dnce_M_a") table.insert(DanceTable, "dnce_M_b") table.insert(DanceTable, "dnce_M_c") table.insert(DanceTable, "dnce_M_d") table.insert(DanceTable, "dnce_M_e") function Dance( player ) if not getElementData(player, "dancing") then local valRandom = math.random(#DanceTable) --#myTable returns the size of myTable outputChatBox("#0046C8[bF3]: Random Dance: "..tostring(DanceTable[valRandom]), 255,255,255,true) setPedAnimation(player, tostring(DanceTable[valRandom]), 5000, true, true, false) setElementData(player, "dancing", true) --used for the if statement else setPedAnimation(player) --cancelling the animation removeElementData(player, "dancing") --let the player to use /Dance again end end addCommandHandler("Dance", Dance)
manawydan Posted March 15, 2014 Posted March 15, 2014 (edited) edit: local DanceTable = {} table.insert(DanceTable, "bd_clap") --no need to specify the index (auto incrementing and starting at 1) table.insert(DanceTable, "bd_clap1") table.insert(DanceTable, "dance_loop") table.insert(DanceTable, "DAN_Down_A") table.insert(DanceTable, "DAN_Left_A") table.insert(DanceTable, "DAN_Loop_A") table.insert(DanceTable, "DAN_Right_A") table.insert(DanceTable, "DAN_Up_A") table.insert(DanceTable, "dnce_M_a") table.insert(DanceTable, "dnce_M_b") table.insert(DanceTable, "dnce_M_c") table.insert(DanceTable, "dnce_M_d") table.insert(DanceTable, "dnce_M_e") local DanceP = {} function Dance( player ) if not DanceP[player] then DanceP[player] = 1 else if DanceP[player] >13 then DanceP[player] = DanceP[player] +1 else DanceP[player] = DanceP[player] -1 end end setPedAnimation(player,"DANCING",DanceTable[DanceP[player]], 5000, true, true, false) end addCommandHandler("Dance", Dance) sorry for missing comma Edited March 16, 2014 by Guest
DNL291 Posted March 16, 2014 Posted March 16, 2014 Is missing a comma in the manawydan's code after DanceTable[DanceP[player]] (line 28).
.:HyPeX:. Posted March 16, 2014 Author Posted March 16, 2014 Is missing a comma in the manawydan's code after DanceTable[DanceP[player]] (line 28). Im not using it anyways, i've fixed this since the 3rd post and it works perfectly like that
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