Jump to content

[HELP] onPickupHit event


..:D&G:..

Recommended Posts

Hi, I am trying to make a function that opens a client side window when the player hits a pickup

function pickupShowGarageGUI(thePlayer) 
    showGarageGUI() 
end 
addEventHandler ( "onPickupHit", pickup, pickupShowGarageGUI ) 

There is the function, and the pickup is in another function but same file (server side):

pickup = createPickup ( x+4.40, y+4, z-1, 3, 1277, 0, 0 ) 

I keep getting that error, which says that an element is expected at argument 2 ("pickup") and got nil, but the pickup exists...

Link to comment

Um... ok..

<meta> 
    <script src="garage_server.lua" type="server" /> 
    <script src="garage_client.lua" type="client" /> 
     
    <file src="pickup.txd"/> 
    <file src="pickup.dff"/> 
     
    <file src="icon.png"/> 
  
    <export function="openGarageGate" type="server" /> 
</meta> 
  

Link to comment
function spawnGaragesOnStart( res ) 
     
    local result = mysqli:query("SELECT x, y, z, interior, dimension FROM garages") 
    while true do 
        local row = mysqli:fetch_assoc(result) 
        if not (row) then break end 
         
        local x = row['x'] 
        local y = row['y'] 
        local z = row['z'] 
        local int = row['interior'] 
        local dim = row['dimension'] 
         
        pickup = createPickup ( x+4.40, y+4, z-1, 3, 1277, 0, 0 ) 
        setElementData(garage, "pickup", pickup) 
         
        setElementInterior(pickup, tonumber(int)) 
        setElementDimension(pickup, tonumber(dim)) 
    end 
  
    mysqli:free_result(result)   
end 
addEventHandler("onResourceStart", resourceRoot, spawnGaragesOnStart) 
  
function pickupShowGarageGUI(thePlayer) 
  if ( source ~= pickup ) then return end 
    triggerClientEvent ( thePlayer, "showGarageUI", thePlayer ) 
end 
addEventHandler ( "onPickupHit", resourceRoot, pickupShowGarageGUI ) 

Link to comment

Try this :

function pickupShowGarageGUI(thePlayer) 
  if ( source ~= pickup ) then return end 
    triggerClientEvent ( thePlayer, "showGarageUI", thePlayer ) 
end 
  
  
function spawnGaragesOnStart( res ) 
    
    local result = mysqli:query("SELECT x, y, z, interior, dimension FROM garages") 
    while true do 
        local row = mysqli:fetch_assoc(result) 
        if not (row) then break end 
        
        local x = row['x'] 
        local y = row['y'] 
        local z = row['z'] 
        local int = row['interior'] 
        local dim = row['dimension'] 
        
        pickup = createPickup ( x+4.40, y+4, z-1, 3, 1277, 0, 0 ) 
        setElementData(garage, "pickup", pickup) 
        
        setElementInterior(pickup, tonumber(int)) 
        setElementDimension(pickup, tonumber(dim)) 
        addEventHandler ( "onPickupHit", pickup, pickupShowGarageGUI ) 
    end 
  
    mysqli:free_result(result)  
end 
addEventHandler("onResourceStart", resourceRoot, spawnGaragesOnStart) 
  
  

Link to comment

[quote name=..:D&G:..]Still nothing..

-- add ouputChatBox to this part and tell me if you can see the msg or not  
  
function pickupShowGarageGUI(thePlayer) 
    outputChatBox("Working fine",thePlayer) 
    triggerClientEvent ( thePlayer, "showGarageUI", thePlayer ) 
end 

Link to comment

Nope, it still says that an element is expected at argument 2 for the event onPickupHit. I tried creating a separate pickup on top of that function (outside any functions) and it works. For some reasons it doesn't get the pickup from the first function

I even tried this:

function pickupShowGarageGUI(thePlayer) 
    for i, v in ipairs (getElementsByType("object")) do 
        if (getElementModel(v) == 17950) then 
            pickup = getElementData(v, "pickup") 
            outputChatBox("Working fine",thePlayer) 
            triggerClientEvent ( thePlayer, "showGarageUI", thePlayer ) 
        end 
    end 
end 
addEventHandler ( "onPickupHit", pickup, pickupShowGarageGUI ) 

The pickup is attached to a garage, but it still says that there is no element at argument 2

Link to comment
Try to attach ' ColSphere' createColSphere() to the pickup then use onColShipHit.

more than that garage it's not defined here :

setElementData(garage, "pickup", pickup) 

It still outputs the same error.

Garage is defined, but I deleted half the function, to only leave the things that relate to my problem..

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