Jump to content

Help finding element from ID


glowdemon1

Recommended Posts

function getPedById ( id ) 
    if ( id ) then 
        local peds = getElementsByType ( "ped" ) 
        for _, v in pairs ( peds ) do 
            local d = getElementData ( v, "ped_id__" ) 
            if ( d == tonumber ( id ) ) then 
                return v 
            end 
        end 
    end 
end 

Try that one.

Link to comment
function getPedById ( id ) 
    if ( id ) then 
        local peds = getElementsByType ( "ped" ) 
        for _, v in pairs ( peds ) do 
            local d = getElementData ( v, "ped_id__" ) 
            if ( d == tonumber ( id ) ) then 
                return v 
            end 
        end 
    end 
end 

Try that one.

This one seemed to work,thanks.

Link to comment
The problem was that you were comparing a string with a number, since 'pedid' in your command is a string, not a number.

Ah, that explains it. Since I'm here now, I've got another problem. I can successfully set a ped's anim and it gets saved into my mysql db. But after restarting the script it doesn't load the anims. No errors at all. Here's the code http://paste.ofcode.org/yyyyHeYzb4aYBQQatmL3SW and here's the mysql layout incase you need it. http://puu.sh/6I0X0.png and http://puu.sh/6I0VN.png

I've tried without checking if v.animblock exists etc. I also tried tostring() but none helped.

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