Skip to content

Player Collector Badge #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions lua/metaworks/metabadges/server/modules/sitters.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
if not MetaBadges then return end

local Tag = "MetaBadges"
local id = "sitters"

local levels = {
default = {
title = "Player Collector",
description = "Total number of players who have sat on your head."
}
}

MetaBadges.RegisterBadge(id, {
basetitle = "Player Collector",
levels = levels,
level_interpolation = MetaBadges.INTERPOLATION_FLOOR
})

local function IsCustomSeat(seat)
-- seat.IsSitVehicle: aowl/commands/easy_sit_on_player.lua:81
-- seat.playerdynseat: sitanywhere/server/sit.lua:76
return seat:GetClass() == "prop_vehicle_prisoner_pod" and (seat.IsSitVehicle or seat.playerdynseat)
end

local function FindRootPlayer(seat, depth)
depth = (depth or 0) + 1

local parent = seat:GetParent()
if IsValid(seat) and IsCustomSeat(seat) and depth <= 64 and IsValid(parent) then
return FindRootPlayer(parent, depth)
end
if seat and seat:IsPlayer() and not IsValid(parent) then
return seat
end
end

hook.Add("PlayerEnteredVehicle", Tag .. "_" .. id, function(_, veh)
if not IsValid(veh) then return end
if not IsCustomSeat(veh) then return end

local root_player = FindRootPlayer(veh)
-- Player sit on world or prop
if not IsValid(root_player) then return end
-- sitanywhere/helpers.lua:116
local sitters = root_player:GetSitters()
local sits_count = table.Count(sitters)
local cur_level = MetaBadges.GetBadgeLevel(root_player, id) or 0

if cur_level >= sits_count then return end
MetaBadges.UpgradeBadge(root_player, id, sits_count, MetaBadges.VARIANT_SILENT)
end)