Is there a way I can have a weapon check to see if a player is the traitor?
7 replies, posted
I'd like to change stats on the gun depending on the player being the traitor or not. 'if client.IsTraitor' or something like that.
Thanks for any help.
Regards,
Me
yeah it's almost exactly that, but a function. to :IsTraitor() instead of .IsTraitor
I tried
if client:IsTraitor()
but it says
attempt to index global 'client' (a nil value)
Oh see I was calling a global variable which traitor or innocent or detective can't be because then it would apply to everyone. But everyone has their own variable. I had to put it in a legitimate function that the game uses. So I found drawhud in weapon_tttbase. That is something that will get called everytime a weapon gets equipped. So now I can identify if a player is indeed a traitor or not and changes stats accordingly. I set to print to console to see if it was working and my name came up in the console when I Was the traitor so looks good. When I'm finished I would not have it print to the console, just change weapon stats.
function SWEP:DrawHUD()
local client = LocalPlayer()
if client.IsTraitor and client:IsTraitor() then
print(client)
//weapon stat changes go here
else
print("not traitor")
end
end
Oh well balls. Sweps are loaded when the level loads. So changing the weapon's stats from within the lua file after the game has already loaded doesn't work. I suppose I could have a different version of the weapon be given to the traitor via some code to delete one weapon and go off a modified different .lua file for the weapon being picked up. So there'd be two lua files for the same weapon, one for traitors and one for everyone else. Anyhoo - that's another deal.
pseudocode
local stronkTs = {["weapon_m16"] = 1.25, ["weapon_deagle"] = 0.8} --means m16 will deal 125% dmg for T's and deagle will deal only 80% dmg for T's
hook.Add("ScalePlayerDamage", "ScaleTDamage", function(ply, hg, dmg)
local atk = dmg:GetAttacker()
if not IsPlayer(atk) or not atk:IsTraitor() then return end --attacker is not a player or not a traitor; bail
local wep = atk:GetActiveWeapon():GetClass() -- there's probably a better way; if the attacker deals 100 prop damage
-- and holds an m16 during that time, the damage will be 125.
if stronkTs[wep] then -- if there's an entry for the weapon the attacker was holding
dmg:SetDamage(dmg:GetDamage()*stronkTs[wep]) -- apply damage multiplier
end
end)
ok I'll test this out
While what you wrote most recently should work, changing the stats should work. Can you post your code from this attempt?
Sorry, you need to Log In to post a reply to this thread.