Xabi Posted February 5, 2015 Share Posted February 5, 2015 Hi all, I've got a problem with this callback, as it's executed twice sometimes in my house system. When I create a house with the command (/crearcasa) it just gets called once, but if I load all houses from the database and step into the pickup, the callback gets called twice. function loadAllHouses() local query = dbQuery(connectionHandle, "SELECT * FROM houses") local result = dbPoll(query, -1) for _, row in ipairs(result) do local housePickup = createPickup(row["posX"], row["posY"], row["posZ"], 3, 1273, 0, 0) setElementData(housePickup, "houses.hId", row["id"]) ... Set all data in database here addEventHandler("onPickupHit", housePickup, showHouseInfo) end dbFree(query) end function createHouseCommand(playerSource, commandName) if playerSource then local posX, posY, posZ = getElementPosition(playerSource) ... Create all needed variables local housePickup = createPickup(posX, posY, posZ, 3, 1273, 0, 0) setElementData(housePickup, "houses.hPosX", posX) ... Setting again all data local query = dbQuery(connectionHandle, "INSERT INTO houses (posX, posY, posZ, interior, dimension, houseType) VALUES (?, ?, ?, ?, ?, ?)", posX, posY, posZ, interior, dimension, houseType) local result, num_affected_rows, last_insert_id = dbPoll(query, -1) setElementData(housePickup, "houses.hId", last_insert_id) addEventHandler("onPickupHit", housePickup, showHouseInfo) end end function showHouseInfo(thePlayer) triggerClientEvent(thePlayer, "onShowHouseInfo", thePlayer, source) end addEventHandler("onResourceStart", getRootElement(), loadAllHouses) addCommandHandler("crearcasa", createHouseCommand) What can be wrong with this code? Thanks in advance Link to comment
Xabi Posted February 6, 2015 Author Share Posted February 6, 2015 Anybody knows what can it be, please? Link to comment
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