Hello,
the last few days a friend and I were trying to create a traitor item for ttt.
The item is a gun and with its shot the target gets a random ‘new role’,
either detecitve, traitor or innocent. Now we’re experiencing some minor bugs.
Sometimes the target changes its role, but can’t see any change in the bottom left nor the scoreboard.
He is only visible as the new role for the one who shot him, but still counts as its previous role. Also in some cases when the target gets shot,
the shown role changes between the possible ones(T/D) for half a second or less until it settles down on the final role.
Here’s the part of the code where our mistakes were probably made.
Thanks in advance for any help we’ll receive.
function SWEP:PrimaryAttack()
local tr = self.Owner:GetEyeTrace();
local tracedata = {};
self:TakePrimaryAmmo(1);
self:EmitSound( self.Primary.Sound, self.Primary.SoundLevel );
tracedata.pos = tr.HitPos + Vector(0,0,2);
ply = tr.Entity;
math.randomseed(os.time());
h = math.random( 1, 9 );
--local message = "Es wurde " .. h .. " gerollt.";
--ply:PrintMessage(HUD_PRINTTALK, message );
if h > 6 then
ply:SetRole(ROLE_TRAITOR);
SendFullStateUpdate();
ply:AddCredits ( 1 );
elseif h > 3 then
ply:SetRole(ROLE_DETECTIVE);
SendFullStateUpdate();
ply:AddCredits ( 1 );
else
ply:SetRole(ROLE_INNOCENT);
ply:SetTeam(TEAM_TERROR);
SendFullStateUpdate();
end
if self.Owner:GetAmmoCount(self.Primary.Ammo) < 1 then
self.Owner:DropWeapon( self );
self:Remove();
return false
end
end