• Print

Author Topic: TTT Setting ulx usergroups to custom player models.  (Read 7711 times)

0 Members and 1 Guest are viewing this topic.

Offline PeddleMe

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
TTT Setting ulx usergroups to custom player models.
« on: March 02, 2017, 07:34:06 pm »
Hi, I'm not entirely sure if I'm posting in the correction section, sorry if I am. :/

I've been trying to set ulx groups to have custom player models on spawn for TTT. So far this is all I've got:

Quote
   if ply:IsUserGroup("owner") then
      return "models/player/superheroes/superman.mdl"
   end
I placed this into lua/autorun/server

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: TTT Setting ulx usergroups to custom player models.
« Reply #1 on: March 02, 2017, 08:07:49 pm »
Is that the _only_ code you have?
Is that code in a function?
Does TTT call whatever function you have, and set the model of the player depending on if it's returned.
The way you have it set is literally returning "/model/.../path/etc" to whatever is calling it.
If that code is just in a file, it's likely erroring out on server start.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline PeddleMe

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Re: TTT Setting ulx usergroups to custom player models.
« Reply #2 on: March 02, 2017, 08:19:04 pm »
Is that the _only_ code you have?
Is that code in a function?
Does TTT call whatever function you have, and set the model of the player depending on if it's returned.
The way you have it set is literally returning "/model/.../path/etc" to whatever is calling it.
If that code is just in a file, it's likely erroring out on server start.
Yes this is the only code I have.
It's not in a function.
The only model related stuff I have are;
shared.lua
Quote
-- Everyone's model
local ttt_playermodels = {
   
   Model("models/player/gman_high.mdl")
   
};

function GetRandomPlayerModel()
   return table.Random(ttt_playermodels)
end


local ttt_playercolors = {
   all = {
      COLOR_GREEN
   },

   serious = {
      COLOR_DGREEN
   }
};

player.lua
Quote
hook.Call("PlayerSetModel", GAMEMODE, ply)

player_ext.lua
Quote
function plymeta:SpawnForRound(dead_only)
   hook.Call("PlayerSetModel", GAMEMODE, self)

Those last three quotes are from the original TTT files with only the first one being slightly edited. I'm posting these because when I tried to add functions (a couple of hours ago, I get kept getting errors from these lines; forgot what functions I was adding because I gave up at some point :/ ).




Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: TTT Setting ulx usergroups to custom player models.
« Reply #3 on: March 04, 2017, 09:39:26 pm »
I think this function might help you:

Code: Lua
  1. function GM:PlayerSetModel(ply)
  2.    local mdl = GAMEMODE.playermodel or "models/player/phoenix.mdl"
  3.    util.PrecacheModel(mdl)
  4.    ply:SetModel(mdl)
  5.  
  6.    -- Always clear color state, may later be changed in TTTPlayerSetColor
  7.    ply:SetColor(COLOR_WHITE)
  8. end

Taken from "player.lua". However, this is called from the PlayerSpawn hook:
Code: Lua
  1. function GM:PlayerSpawn(ply)
  2.    -- Some spawns may be tilted
  3.    ply:ResetViewRoll()
  4.  
  5.  
  6.    -- Clear out stuff like whether we ordered guns or what bomb code we used
  7.    ply:ResetRoundFlags()
  8.  
  9.  
  10.    -- latejoiner, send him some info
  11.    if GetRoundState() == ROUND_ACTIVE then
  12.       SendRoundState(GetRoundState(), ply)
  13.    end
  14.  
  15.  
  16.    ply.spawn_nick = ply:Nick()
  17.    ply.has_spawned = true
  18.  
  19.  
  20.    -- let the client do things on spawn
  21.    net.Start("TTT_PlayerSpawned")
  22.       net.WriteBit(ply:IsSpec())
  23.    net.Send(ply)
  24.  
  25.  
  26.    if ply:IsSpec() then
  27.       ply:StripAll()
  28.       ply:Spectate(OBS_MODE_ROAMING)
  29.       return
  30.    end
  31.  
  32.  
  33.    ply:UnSpectate()
  34.  
  35.  
  36.    -- ye olde hooks
  37.    hook.Call("PlayerLoadout", GAMEMODE, ply)
  38.    hook.Call("PlayerSetModel", GAMEMODE, ply)
  39.    hook.Call("TTTPlayerSetColor", GAMEMODE, ply)
  40.  
  41.  
  42.    ply:SetupHands()
  43.  
  44.  
  45.    SCORE:HandleSpawn(ply)
  46. end


 It's best to NOT edit this as it is a core terrortown file, but by adding a PlayerSpawn hook, something like

Code: Lua
  1. hook.Add( "PlayerSpawn", "Give Admins Specific Models", function( ply )
  2.     if ply:IsUserGroup( "owner" ) then
  3.         ply:SetModel( "models/player/superheroes/superman.mdl" )
  4.     --[[ elseif ply:IsUserGroup( "your_other_group" )
  5.         ply:SetModel( "some/other/model.mdl" ) ]]
  6.     end
  7. end
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

  • Print