Jump to content

[HELP] onPickupHit event


..:D&G:..

Recommended Posts

Posted

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

76561198066470453.png

SP37Ecj.jpg?2MTA:Rust Pre-Alpha Build v.0.3:SP37Ecj.jpg?2

https://forum.mtasa.com/viewtopic.php?f=114&t=97848

2Pac: ''Only God can judge me!''

Posted

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> 
  

76561198066470453.png

SP37Ecj.jpg?2MTA:Rust Pre-Alpha Build v.0.3:SP37Ecj.jpg?2

https://forum.mtasa.com/viewtopic.php?f=114&t=97848

2Pac: ''Only God can judge me!''

Posted

It is.

function pickupShowGarageGUI(thePlayer) 
    if ( source ~= pickup ) then return end 
    showGarageGUI() 
end 
addEventHandler ( "onPickupHit", resourceRoot, pickupShowGarageGUI ) 

Posted
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 ) 

76561198066470453.png

SP37Ecj.jpg?2MTA:Rust Pre-Alpha Build v.0.3:SP37Ecj.jpg?2

https://forum.mtasa.com/viewtopic.php?f=114&t=97848

2Pac: ''Only God can judge me!''

Posted

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) 
  
  

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted

[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 

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted

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

76561198066470453.png

SP37Ecj.jpg?2MTA:Rust Pre-Alpha Build v.0.3:SP37Ecj.jpg?2

https://forum.mtasa.com/viewtopic.php?f=114&t=97848

2Pac: ''Only God can judge me!''

Posted

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

more than that garage it's not defined here :

setElementData(garage, "pickup", pickup) 

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

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

76561198066470453.png

SP37Ecj.jpg?2MTA:Rust Pre-Alpha Build v.0.3:SP37Ecj.jpg?2

https://forum.mtasa.com/viewtopic.php?f=114&t=97848

2Pac: ''Only God can judge me!''

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