Skip to content

Instantly share code, notes, and snippets.

@AgentLoneStar007
Last active June 12, 2023 16:01
Show Gist options
  • Save AgentLoneStar007/180f75157327ee62812601a076f58fc3 to your computer and use it in GitHub Desktop.
Save AgentLoneStar007/180f75157327ee62812601a076f58fc3 to your computer and use it in GitHub Desktop.
GMod Model Lock: A simple bit of code to insert into a GMod playermodel addon that allows the model to be locked to one username.
--[[
Model-Lock v1.0 by AgentLoneStar007
A simple bit of Lua code that will allow only you to use your model. If someone is using
your model, but doesn't have your username, the game will crash every time the player:
- Takes damage,
- Gets in or out of a vehicle,
- Types in chat, or
- Dies.
Support for multiple models is planned.
PLEASE NOTE that this addon is designed to crash the game of anyone who uses the model
that doesn't have the correct username. If you want a different outcome, modify the code
inside the If statement in the playerInfo_TEMP function.
FOR EVERY OCCURRENCE OF THE WORD "TEMP" IN THIS FILE, REPLACE IT WITH A UNIQUE WORD!
FAILURE TO DO SO MIGHT CLASH WITH OTHER MODELS USING THIS LOCK TEMPLATE, MAKING THIS
LOCK NON-FUNCTIONING! You can use Ctrl+H in most text editors to mass-replace a word.
Look up a guide on Lua function naming and variable naming for valid characters that
can be used. I'd recommend using a word that coincides with the name of your model
and/or addon.
And as a side note, I'd recommend obfuscating the code of this file. Otherwise removal
of the lock is as simple as decompiling the .gma file. I'd recommend LuaObfuscator: https://luaobfuscator.com/
Make sure you set the obfuscate setting to chaotic evil.
]]
-- Model code here
-- Data
local usernameToLock_TEMP = 'MyUsername'
local playerModelToLock_TEMP = 'models/your/model.mdl'
local addonName_TEMP = 'Name of the Addon'
-- Player model lock enforce function
local playerInfo_TEMP = function(username, model)
if (username ~= usernameToLock_TEMP and model == playerModelToLock_TEMP)
then
local i = 0
while true do
i = i + 65536
print('YOUR FAULT! ' .. math.max(i))
end
end
end
-- Event triggers
-- Hurt
hook.Add("EntityTakeDamage", addonName_TEMP, function(target)
if target:IsPlayer() then
local playerName = target:Name()
local playerModel = target:GetModel()
playerInfo_TEMP(playerName, playerModel)
end
end )
-- Speak
hook.Add("PlayerSay", addonName_TEMP, function(player)
local playerName = player:Nick()
local playerModel = player:GetModel()
playerInfo_TEMP(playerName, playerModel)
end)
-- Die
hook.Add("PlayerDeath", addonName_TEMP, function(player)
local playerName = player:Nick()
local playerModel = player:GetModel()
playerInfo_TEMP(playerName, playerModel)
end)
-- Get in vehicle
hook.Add("PlayerEnteredVehicle", addonName_TEMP, function(player)
local playerName = player:Nick()
local playerModel = player:GetModel()
playerInfo_TEMP(playerName, playerModel)
end)
-- Get out of vehicle
hook.Add("PlayerLeaveVehicle", addonName_TEMP, function(player)
local playerName = player:Nick()
local playerModel = player:GetModel()
playerInfo_TEMP(playerName, playerModel)
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment