Skip to content

Instantly share code, notes, and snippets.

@adamnejm
Last active March 11, 2022 10:11
Show Gist options
  • Save adamnejm/99c8b789e63a3aa6eb8a6ee426cbc039 to your computer and use it in GitHub Desktop.
Save adamnejm/99c8b789e63a3aa6eb8a6ee426cbc039 to your computer and use it in GitHub Desktop.
Starfall - Bodygroup and Bone Manipulation Example
--@name NPC bodygroup and bone manipulation example
--@author Name
--@shared
-- USAGE:
-- Place the chip on G-Man NPC (npc_gman)
local owner, client, chip, world = owner(), player(), chip(), entity(0)
if SERVER then
-- Grab the entity that's welded to the chip (entity on which the chip has been placed)
local ent = chip:isWeldedTo()
-- Disable G-Man's briefcase (it's the 2nd bodygroup, but they start from 0)
-- Value 1 for the briefcase bodygroup will disable it (use `printTable(ent:getBodygroups())` to learn more)
-- We could also disable it on clientside, but we would have to do it every time the NPC gets resent to our client by the engine (Source's PVS)
ent:setBodygroup(1, 1)
-- Wait for each client before starting and sending a network message
hook.add("ClientInitialized", "", function(ply)
net.start("npc")
net.writeEntity(ent) -- Attach our entity to the net message
net.send(ply) -- Send only to the player that has already initialized instead of broadcasting
end)
else
-- Catch the 'npc' message sent to the current client from the server
net.receive("npc", function()
net.readEntity(function(ent) -- Use one of Starfall's coolest features which is a callback that runs when the entity becomes valid on our client
if not ent then return end -- This can still obviously not return anything if the entity shat itself, but only requires this little check
local head_bone = ent:lookupBone("ValveBiped.Bip01_Head1") -- Grab the head bone, this can be useful: https://wiki.facepunch.com/gmod/ValveBiped_Bones
ent:manipulateBoneScale(head_bone, Vector(3)) -- Scale the head bone 3 times ( Vector(3) is short for Vector(3,3,3) )
-- Loop through all entity bones and make the jiggly, note that indices start from 0 for bones
for i = 0, ent:getBoneCount() - 1 do
ent:manipulateBoneJiggle(i, true) -- Make them wiggly jiggly
end
end)
end)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment