Skip to content

Instantly share code, notes, and snippets.

@silbinarywolf
Last active July 29, 2023 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save silbinarywolf/dc571b07d622c3ebe1ed2911e7e41fe7 to your computer and use it in GitHub Desktop.
Save silbinarywolf/dc571b07d622c3ebe1ed2911e7e41fe7 to your computer and use it in GitHub Desktop.
Force player to look like prop and strip weapons/cosmetics
// How to use
// - Place in tf\scripts\vscripts\mapspawn.nut
// References
// - https://developer.valvesoftware.com/wiki/Team_Fortress_2/Scripting/VScript_Examples/en#See_Also
// - https://wiki.alliedmods.net/Team_Fortress_2_Events#player_changeclass
function Precache() {
PrecacheModel("models/props_2fort/coffeepot.mdl");
PrecacheModel("models/player/pyro.mdl")
}
::PostPlayerSpawn <- function()
{
printl("-- Player Spawned --")
local player = self;
if (player == null) {
return;
}
player.SetForcedTauntCam(1); // enable third person
player.SetCustomModelVisibleToSelf(true); // show model of self
player.SetCustomModel("models/props_2fort/coffeepot.mdl"); // become prop
}
function OnGameEvent_player_spawn(params) {
if(!("userid" in params) || params.userid == 0) {
return;
}
local player = GetPlayerFromUserID(params.userid);
if (player == null) {
return;
}
// As per TF2 Vscript documentation, we need to defer our spawn logic to happen
// at the end of the frame by firing it with this.
//
// Otherwise properties/attributes/etc wont apply.
EntFireByHandle(player, "RunScriptCode", "PostPlayerSpawn()", 0.0, null, null);
}
function OnGameEvent_post_inventory_application(params) {
if(!("userid" in params) || params.userid == 0) {
return;
}
printl("-- Player Post Inventory --")
local player = GetPlayerFromUserID(params.userid);
// Strip weapons
for (local i = 0; i < 7; i++) {
local weapon = NetProps.GetPropEntityArray(player, "m_hMyWeapons", i);
if (weapon == null) {
continue;
}
weapon.Destroy();
}
// Strip wearables
for (local wearable = player.FirstMoveChild(); wearable != null;) {
if (wearable.GetClassname() != "tf_wearable") {
wearable = wearable.NextMovePeer();
continue;
}
local current_wearable = wearable;
wearable = wearable.NextMovePeer();
current_wearable.Destroy();
}
}
Precache();
__CollectGameEventCallbacks(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment