Jump to content

Problem with setPedAnimation


Gravestone

Recommended Posts

I had the animation code in freeroam file. This is the code:

--------------------------- 
--- Set animation window 
--------------------------- 
  
function applyAnimation(leaf) 
    if type(leaf) ~= 'table' then 
        leaf = getSelectedGridListLeaf(wndAnim, 'animlist') 
        if not leaf then 
            return 
        end 
    end 
    server.setPedAnimation(g_Me, leaf.parent.name, leaf.name, true, true) 
  
end 
  
function stopAnimation() 
    server.setPedAnimation(g_Me, false) 
end 
  
wndAnim = { 
    'wnd', 
    text = 'Set animation', 
    width = 250, 
    x = -20, 
    y = 0.3, 
    controls = { 
        { 
            'lst', 
            id='animlist', 
            width=230, 
            height=290, 
            columns={ 
                {text='Animation', attr='name'} 
            }, 
            rows={xml='animations.xml', attrs={'name'}}, 
            expandlastlevel=false, 
            onitemdoubleclick=applyAnimation 
        }, 
        {'btn', id='set', onclick=applyAnimation}, 
        {'btn', id='stop', onclick=stopAnimation}, 
        {'btn', id='close', closeswindow=true} 
    } 
} 
  
  
addCommandHandler('anim', 
    function(command, lib, name) 
        server.setPedAnimation(g_Me, lib, name, true, true) 
    end 
) 

The definition for this g_Me is "g_Me = getLocalPlayer()"

Link to comment

Can you explain, you don't want to set animation if player is in vehicle, right? If so, try this code (replace applyAnimation() function):

function applyAnimation(leaf) 
    if type(leaf) ~= 'table' then 
        leaf = getSelectedGridListLeaf(wndAnim, 'animlist') 
        if not leaf then 
            return 
        end 
    end 
     
    --if not isPedInVehicle(g_Me) then 
    if not getPedOccupiedVehicle(g_Me) then 
        server.setPedAnimation(g_Me, leaf.parent.name, leaf.name, true, true) 
    end 
end 

Edited by Guest
Link to comment

Thanks DakiLLa, it worked. But still there is a problem that anim binds are working when in a vehicle although the animation isn't working from F1 / Animation.

Tried this, but didn't work:

addCommandHandler('anim', 
    function(command, lib, name) 
                if not getPedOccupiedVehicle(g_Me) then 
        server.setPedAnimation(g_Me, lib, name, true, true) 
    end 
) 

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