Impossible to prevent bucket item use
#11
Use a cLineBlockTracer to find the block coords when the client doesn't give you any.
Reply
Thanks given by:
#12
Well that worked. I still find it weird though, even more so because when using a lighter it's only called once... Currently my method feels more like a hack but ooh well, it does the job.

What I ended up with:
Code:
function OnPlayerUsingItem(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, CursorY, CursorZ, BlockType, BlockMeta)
    local itemUsed = ItemToString(Player:GetEquippedItem());
    --Since this hook is always called twice when using buckets, we need the 2nd call which has BlockFace at -1 parameters
    if (BlockFace == -1) or (itemUsed == "lighter") then
        local CallBacks = {
            OnNextBlock = function(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta) --The actual check if the item is allowed or not
                local sql = "SELECT towns.town_id, towns.nation_id, towns.town_permissions, towns.town_fire_enabled FROM townChunks INNER JOIN towns ON townChunks.town_id = towns.town_id WHERE chunkX = ? AND chunkZ = ? AND world = ?";
                local parameters = {math.floor(a_BlockX / 16), math.floor(a_BlockZ / 16), Player:GetWorld():GetName()};
                local town = ExecuteStatement(sql, parameters)[1];
                if not (town) then --The item is used on a block that is not part of a town, so it's allowed
                    return false;
                else
                    if (town[1] == GetPlayerTown(Player:GetUUID())) then
                        allowed = CheckPermission(town[3], RESIDENTITEMUSE);
                    else
                        if (town[2] == GetPlayerNation(Player:GetUUID())) then
                            allowed = CheckPermission(town[3], ALLYITEMUSE);
                        else
                            allowed = CheckPermission(town[3], OUTSIDERITEMUSE);
                        end
                    end

                    if (allowed == true) then
                        if (itemUsed == "lighter") then
                            if (town[4] == 0) then --If fire is disabled in this town, prevent the player from starting a fire
                                return false; --Prevent item use
                            else
                                return true; --Allow item use
                            end
                        else
                            return true; --Allow item use
                        end
                    else
                        return false; --Prevent item use
                    end
                end
            end
        };
        local EyePos = Player:GetEyePosition();
        local LookVector = Player:GetLookVector();
        LookVector:Normalize(); --Make the vector 1m long
        local Start = EyePos + LookVector;
        local End = EyePos + LookVector * 50;
        return cLineBlockTracer.Trace(Player:GetWorld(), CallBacks, Start.x, Start.y, Start.z, End.x, End.y, End.z);
    end
end
Reply
Thanks given by:
#13
@xoft didn't you do some work on the OnPlayerPlacingBlock and OnPlayerBreakingBlock hooks I thought it detected water and lava placements now.
Reply
Thanks given by:
#14
I honestly don't remember.
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)