Jump to content

I have a problem with cancelEvent() in this code.


Recommended Posts

Hi to all friends I have a problem is that if the character is not in the fraction, it will still enter the car and cancelEvent() does not work

Quote

Hi to all friends I have a problem is that if the character is not in the fraction, it will still enter the car and cancelEvent() does not work


function enterpdVehicle ( player, seat, jacked ) 

    local username = getPlayerName(player)
    if seat == 0 then

        if jacked then

            local theVehicle = getPedOccupiedVehicle (jacked)
            if theVehicle then

                local vehid = getElementID ( theVehicle )
                dbQuery(function(qh)
                    local result = dbPoll(qh,0);
                    if #result > 0 then 
                        for k,v in pairs(result) do 
                            if (v.isactive == 0) then
                                local pelak = getVehiclePlateText(theVehicle):gsub("-fac","")
                                dbQuery(function(qhs)
                                    local res = dbPoll(qhs,0);
                                        if #res > 0 then 
                                            for k,x in pairs(res) do         
                                                dbQuery(function(qhss)
                                                    local rese = dbPoll(qhss,0);
                                                        if #rese > 0 then 
                                                            for k,n in pairs(rese) do   
                                                                if (n.factionid == x.factionid) then
                                                                else
                                                                    cancelEvent()
               
                                                                end
                                                            end
                                                        end
                                    
                                                     end,db,"SELECT * FROM users WHERE username=?",username)
                                            end
                                        end
                    
                                     end,db,"SELECT * FROM factioncars WHERE vfid=?",pelak)
                            end
                        end
                    end
                
                end,db,"SELECT * FROM factioncars WHERE isactive=?",0)
            end
        else

            local theVehicle = getPedOccupiedVehicle (player)
            if theVehicle then

                local vehid = getElementID ( theVehicle )
                dbQuery(function(qh)

                    local result = dbPoll(qh,0);
                    if #result > 0 then 
                        for k,v in pairs(result) do 
                            if (v.isactive == 0) then
                                local pelak = getVehiclePlateText(theVehicle):gsub("-fac","")
                                dbQuery(function(qhs)
                                    local res = dbPoll(qhs,0);
                                        if #res > 0 then 
                                            for k,x in pairs(res) do         
                                                dbQuery(function(qhss)
                                                    local rese = dbPoll(qhss,0);
                                                        if #rese > 0 then 
                                                            for k,n in pairs(rese) do   
                                                                if (n.factionid == x.factionid) then
                                                                else
                                                                    cancelEvent()
                                                                end
                                                            end
                                                        end
                                    
                                                     end,db,"SELECT * FROM users WHERE username=?",username)
                                            end
                                        end
                    
                                     end,db,"SELECT * FROM factioncars WHERE vfid=?",pelak)
                            end
                        end
                    end
                
                end,db,"SELECT * FROM factioncars WHERE isactive=?",0)
            end
        end
    end
    

end
addEventHandler ( "onVehicleStartEnter", getRootElement(), enterpdVehicle ) 

 

I know it's written very badly.

 

For bad English, if there's a problem, I'm sorry.

Link to post
Quote

I know it's written very badly.

Yes, this is terribly bad.

But you can't cancel the event inside dbQuery's callback because it is a different function, you can cancel in the original enterpdVehicle function only.

Edited by Patrick
Link to post
Posted (edited)
4 hours ago, Patrick said:

Yes, this is terribly bad.

But you can't cancel the event inside dbQuery's callback because it is a different function, you can cancel in the original enterpdVehicle function only.

can you give me a healthy code . Code performance is like my code.

Edited by nimzahed
Link to post
13 hours ago, nimzahed said:

can you give me a healthy code . Code performance is like my code.

Thanks for saying you can not cancelvent it, but I did not know there was another way to select and I looked for it and realized how wrong I was and rebuilt all my code
Link to post

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