Welcome, Guest. Please login or register.
Did you miss your activation email?
September 20, 2024, 04:14:24 AM
Home Help Login Register
News: Trouble in Terrorist Town? Site here, forum here.

Zombie Master  |  Other  |  Trouble in Terrorist Town  |  Topic: Advice with this code:
Pages: [1]
Author Topic: Advice with this code:  (Read 4391 times)
Mr. Wepz.
Poster

Posts: 65


« on: March 14, 2011, 11:11:18 PM »

Hey guys, so yesterday i was browsing the Wiki and was looking into some standard TTT functions and hooks etc. and i founded this one "ply:IsActiveTraitor()" at the disguiser code.

My question is does this work for Detective too?

Because i made this code but it doesnt seem to work:


local function Detectivemodel(ply)
  if IsValid(ply) and ply:IsActiveDetective() then
  ply:SetModel ( "models/player/gman_high.mdl" )
  end
  end
  hook.Add( "TTTBeginRound", "Detectivemodel", "Detectivemodel" )  

I tried put them into lua/autorun  - lua/autorun/server and autorun/client all 3 dint seem to work?

Thanks ^^
« Last Edit: March 14, 2011, 11:12:24 PM by Mr. Wepz. »
Manmax75
Poster

Posts: 254


Programming Guy


« Reply #1 on: March 15, 2011, 09:19:30 PM »

the hook "TTTBeginRound" does not return any player object values, thus ply will be nill and your script wont work.

You can probably try overriding the default ttt model set function.

Try the following code:


function GM:PlayerSetModel(ply)
  if ply:IsActiveDetective() then
       ply:SetModel ( "models/player/gman_high.mdl" )
  else
       local mdl = GAMEMODE.playermodel or "models/player/phoenix.mdl"
       util.PrecacheModel(mdl)
       ply:SetModel(mdl)
   end
end


I am not sure if this will fully work, worth a shot tho.

Ride Forward and Thrust Your Pelvis In The Dark Void. The One Induced By Pleasure Yet Cast By The Bigger Picture.
Bad King Urgrain
Administrator
*****
Posts: 12276



« Reply #2 on: March 15, 2011, 09:28:56 PM »

Instead of overriding, you can use the default gmod PlayerSetModel hook. TTT calls it just like gmod calls it. TTT's GM:PlayerSetModel function only runs if there is no hook that returns true for that player.

local function DetectiveModel(ply)
  if IsValid(ply) and ply:IsActiveDetective() then
     ply:SetModel ( "models/player/gman_high.mdl" )

     -- Important: if you do not return true, TTT will set a model for the player, overriding yours
     return true
  end
end
hook.Add( "PlayerSetModel", "Detectivemodel", DetectiveModel )


This won't work in this case, however: PlayerSetModel is called when players spawn. At that point, traitors and detectives have not been selected yet. You have to hook TTTBeginRound and loop over all players, check if they're detective, and change their model.
« Last Edit: March 15, 2011, 09:30:55 PM by Bad King Urgrain »
Mr. Wepz.
Poster

Posts: 65


« Reply #3 on: March 15, 2011, 10:14:25 PM »

Excuse me if im wrong Bad King but then it would be:


local function DetectiveModel()
   for k,v in pairs( player.GetAll() ) do
       if v:GetDetective() then
           v:SetModel ( "models/player/gman_high.mdl" )
return true
end
end
end
hook.Add( "TTTBeginRound", "Detectivemodel", Detectivemodel )
« Last Edit: March 15, 2011, 10:16:54 PM by Mr. Wepz. »
Mr. Wepz.
Poster

Posts: 65


« Reply #4 on: March 16, 2011, 04:32:39 PM »

The code dont work, placed into lua/autorun, any advices?
Bad King Urgrain
Administrator
*****
Posts: 12276



« Reply #5 on: March 16, 2011, 05:12:13 PM »

Last help you're getting from me.


local function DetectiveModel()
    for k,v in pairs( player.GetAll() ) do
        if v:GetDetective() then
            v:SetModel ( "models/player/gman_high.mdl" )
        end
    end
end
hook.Add( "TTTBeginRound", "DetectiveModel", DetectiveModel )
Mr. Wepz.
Poster

Posts: 65


« Reply #6 on: March 16, 2011, 06:32:26 PM »

Thanks got it working now :D
Pages: [1]
Zombie Master  |  Other  |  Trouble in Terrorist Town  |  Topic: Advice with this code: « previous next »
Jump to:  


Login with username, password and session length

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines
Page created in 0.008 seconds with 17 queries.