..:D&G:.. Posted April 25, 2015 Posted April 25, 2015 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...
..:D&G:.. Posted April 25, 2015 Author Posted April 25, 2015 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>
WhoAmI Posted April 25, 2015 Posted April 25, 2015 Maybe you are creating pickup after attaching event to function? I mean pickup's function is created earlier than pickup.
..:D&G:.. Posted April 25, 2015 Author Posted April 25, 2015 Yes it is. The pickup's function is on top of the onPickupHit function.
WhoAmI Posted April 25, 2015 Posted April 25, 2015 Pickup has to be created before you attach it to onPickupHit event.
..:D&G:.. Posted April 25, 2015 Author Posted April 25, 2015 It is, as I said, the function that creates the pickup is ON TOP of that function with onPickupHit. Also I have not local'ed it. The function that creates the pickup has the onResourceStart event, maybe that interferes with the other function/event?
WhoAmI Posted April 25, 2015 Posted April 25, 2015 Move pickup creation from onResourceStart. Make it without any event - put it on top of code.
..:D&G:.. Posted April 25, 2015 Author Posted April 25, 2015 I can't really put the line on top of the code, cuz it's getting the coordinates from a MySQL table: pickup = createPickup ( x+4.40, y+4, z-1, 3, 1277, 0, 0 ) Is there other way of doing it?
WhoAmI Posted April 25, 2015 Posted April 25, 2015 It is. function pickupShowGarageGUI(thePlayer) if ( source ~= pickup ) then return end showGarageGUI() end addEventHandler ( "onPickupHit", resourceRoot, pickupShowGarageGUI )
..:D&G:.. Posted April 25, 2015 Author Posted April 25, 2015 That doesn't work at all. It is like the event is not even there
Mr.unpredictable. Posted April 26, 2015 Posted April 26, 2015 [quote name=..&G:..]That doesn't work at all. It is like the event is not even there can you post your full code?
..:D&G:.. Posted April 26, 2015 Author Posted April 26, 2015 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 )
Walid Posted April 26, 2015 Posted April 26, 2015 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)
Walid Posted April 26, 2015 Posted April 26, 2015 [quote name=..&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
..:D&G:.. Posted April 26, 2015 Author Posted April 26, 2015 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
Walid Posted April 26, 2015 Posted April 26, 2015 Try to attach ' ColSphere' createColSphere() to the pickup then use onColShipHit. more than that garage it's not defined here : setElementData(garage, "pickup", pickup)
..:D&G:.. Posted April 26, 2015 Author Posted April 26, 2015 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..
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now