Jump to content

Bad element pointer at setElementPosition


DarkLink

Recommended Posts

Hey guys, I keep getting this error on console and dont know why :S

can u guys please help me?

I have this code:

function teleportar1(hitElement) 
     
    if (getElementType(hitElement) == "player") then 
        setTimer(setElementPosition, 1000,1, hitElement, x2,y2,z2) 
    else 
  
        outputChatBox("hei") 
         
                local player = getVehicleController(hitElement) 
         
        setTimer(setElementPosition, 1000, 1, player, x2,y2,z2) 
         
    end 
     
     
end 
addEventHandler("onMarkerHit", passagem1, teleportar1 ) 
  

I am hitting the marker with a bike.. and I am on the bike.

and I get the "hei" on outputChatBox.

THANKS!

EDIT: fixed

Link to comment

This is not the first time I get errors like these, and dont know how to fix them.

Its about local variables.. that are not made, I guess..

look this code:

  
local entrada = getElementByID("entrada2") 
local prisao = getElementByID("prisao") 
local x,y,z = getElementPosition(prisao) 
  
  
  
  
function enviarParaPrisao(hitElement) 
     
  
    if (getElementType(hitElement) == "vehicle") then 
        local deliver = getVehicleOccupant(hitElement,1) --bad deliver? 
        setTimer(teleporte, 2000,1, deliver, hitElement) 
         
    end 
end 
addEventHandler("onMarkerHit", entrada, enviarParaPrisao ) 
  
function teleporte (deliver, hitElement) 
  
    if(isElementWithinMarker(hitElement, entrada)) then 
        removePedFromVehicle(deliver) 
        setElementInterior ( deliver, 6) 
        setTimer(setElementPosition, 1000, 1, deliver, x, y, z + 1) 
        toggleControl ( deliver, "enter_exit", true) 
    else 
        outputChatBox("car not in marker") 
    end 
end 
  

I keep getting errors on console, but function does what I want.. but I have this errors:

bad argument @ 'removePedFromVehicle'

bad argument @ 'setElementInterior'

bad argument @ 'toggleControl'

I hope u guys teach me this, commun errors..

Function does what is suppose to do, but always have errors like that on console!

WHY?

Thanks guys, I hope u know what is the problem.

Link to comment
dont assume that hitelement is a vehicle - check it, also i think you cant set the player position if he is in vehicle, so use:
removePedFromVehicle 

Thanks bro, I figure that today..

I was trying to teleport players that were in cars, but didnt was working..

and removing them from vehicles first solved the problem..

but now I have another kinds of problems, like those one I posted above..

do u know something about it ?

Thanks

Link to comment
local entrada = getElementByID("entrada2") 
local prisao = getElementByID("prisao") 
local x,y,z = getElementPosition(prisao) 
  
  
  
  
function enviarParaPrisao(hitElement) 
    
  
    if (getElementType(hitElement) == "vehicle") then 
        local vtab = getVehicleOccupants(hitElement) 
        if table.getn(vtab) < 1 than outputChatBox("no pasangers") end 
        for i , deliver in ipairs(vtab) do 
        setTimer(teleporte, 2000,1, deliver, hitElement) 
       end 
    end 
end 

dont know if it will work, but you may try...

Link to comment

the only logical explanation is that there is no player sitting in slot 1 (it may be slot 2 or 3)

bad argument means that the element don't exist or is invalid (you may check it using isElement() function)

If there is no player on slot 1, we can not use ipairs iterator (it is design only for tables indexed by integers starting from 1 with out skipping any number)

for other tables we use pairs iterator, that will browse trough any index (lua tables can be indexed by anything except nil)

Link to comment
the only logical explanation is that there is no player sitting in slot 1 (it may be slot 2 or 3)

bad argument means that the element don't exist or is invalid (you may check it using isElement() function)

If there is no player on slot 1, we can not use ipairs iterator (it is design only for tables indexed by integers starting from 1 with out skipping any number)

for other tables we use pairs iterator, that will browse trough any index (lua tables can be indexed by anything except nil)

Okay thanks, I will start using normal FORs, starting from index 0 to the length of the table/array.

It should fix always the problems, I guess :)

Thanks again!

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