Cronoss Posted March 7, 2022 Share Posted March 7, 2022 I don't know what's wrong with this, I'm trying to cancel an animation with a timer: (server-side) function changeWeapon(player) setPedAnimation(player, "colt45", "colt45_reload", 0, false, false, true, true) ------- this part works setTimer( function () setPedAnimation(player) ---------got nil / doesn't exist end, 1000, 1) end addEvent("animCw", true) addEventHandler("animCw", root, changeWeapon) And the console keeps sending me the message "expected element, got nil", I tried this way: function changeWeapon(player) setPedAnimation(player, "colt45", "colt45_reload", 0, false, false, true, true) ------- this part works setTimer( function (player) -------* setPedAnimation(player) ----------still don't work end, 1000, 1) end addEvent("animCw", true) addEventHandler("animCw", root, changeWeapon) Link to comment
Moderators Citizen Posted March 7, 2022 Moderators Share Posted March 7, 2022 The variable doesn't exist when the inner function is executed later (different scope). You have to send the player to the inner function (after the 3rd argument of setTimer): function changeWeapon(player) setPedAnimation(player, "colt45", "colt45_reload", 0, false, false, true, true) setTimer( function (timerPlayer) setPedAnimation(timerPlayer) end, 1000, 1, player) end addEvent("animCw", true) addEventHandler("animCw", root, changeWeapon) And since the argument you send through the setTimer call is exactly the one you send in setPedAnimation, you can make it shorter like so: function changeWeapon(player) setPedAnimation(player, "colt45", "colt45_reload", 0, false, false, true, true) setTimer(setPedAnimation, 1000, 1, player) end addEvent("animCw", true) addEventHandler("animCw", root, changeWeapon) 1 Link to comment
#\_oskar_/# Posted March 7, 2022 Share Posted March 7, 2022 function changeWeapon(player) setPedAnimation(player, "colt45", "colt45_reload", -1, false, false, true, true) ------- this part works setTimer( function (player) setPedAnimation(player) ---------got nil / doesn't exist end, 1000, 1,player) end addEvent("animCw", true) addEventHandler("animCw", root, changeWeapon) 1 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