Hello,
I'm trying to make a system where when a donator picks up a supported weapon the weapon turns gold. I figured the best way to implement this would be to modify weapon_tttbase so that
[code]
function SWEP:Deploy()
self:SetIronsights(false)
return true
end
[/code]
becomes
[code]
function SWEP:Deploy()
self:SetIronsights(false)
if CLIENT then
if self.GoldDonationAmount and self.Owner:GetDonationAmount()>=self.GoldDonationAmount then
self.Owner:GetViewModel():SetMaterial(self.GoldViewMaterial)
else
self.Owner:GetViewModel():SetMaterial("")
end
return true
end
end
[/code]
(there's also some code for world models, but that seems to be working fine so don't worry about that)
Right, so here's the issue. SWEP:Deploy is never called clientside. It is, however, called serverside. I tried placing the code in SWEP:Think instead, and this worked to an extent but A) it's messy/laggy, B) the weapon only starts thinking AFTER the deploy animation is finished, resulting in a texture pop and C) some weapons override SWEP:Think because by default it's empty in weapon_tttbase.
So my question is, basically, is there either a way to fix SWEP:Deploy not being called clientside (it says it should be shared on the wiki) and if not, is there some other hook I can use to achieve my goal? I'm thinking I might try hooking gamemode:Think() next, but ideally I'd like to not have to.
(I know that GetViewModel() and SetMaterial() are also shared, but they don't do anything if I call them on the server so idk what the purpose of that is)
Thanks,
YM
Try running the set material in SWEP:Initialize?
[QUOTE=wranders;42354564]Try running the set material in SWEP:Initialize?[/QUOTE]
SWEP:Initialize won't work because at that point the SWEP doesn't have an owner.
SWEP:Equip won't work either because I need to change the view material every time the weapon is deployed though, otherwise when switching weapons the view material is carried between them. (View material is per player not per weapon for some stupid reason)
[code]
function SWEP:Think( )
self.BaseClass:Think( self )
self.LastOwner = self.LastOwner or NULL
if CLIENT and self.Owner ~= self.LastOwner then
self.Owner = self.LastOwner
self:Deploy( )
end
end[/code]
Something like that is what you will need to do - you could also use SWEP:CallOnClient if you don't want to wrangle it yourself.
[QUOTE=Kogitsune;42354713][code]
function SWEP:Think( )
self.BaseClass:Think( self )
self.LastOwner = self.LastOwner or NULL
if CLIENT and self.Owner ~= self.LastOwner then
self.Owner = self.LastOwner
self:Deploy( )
end
end[/code]
Something like that is what you will need to do - you could also use SWEP:CallOnClient if you don't want to wrangle it yourself.[/QUOTE]
What's the latency like with CallOnClient?
EDIT: I couldn't get CallOnClient working so I bit the bullet and used gamemode think. It works perfectly now, shame it has to run code every frame but it's fairly lightweight so I doubt it'll be an issue.
[QUOTE=YoshieMaster;42354785]What's the latency like with CallOnClient?
EDIT: I couldn't get CallOnClient working so I bit the bullet and used gamemode think. It works perfectly now, shame it has to run code every frame but it's fairly lightweight so I doubt it'll be an issue.[/QUOTE]
You do call on client like this:
[lua]
function SWEP:Deploy()
self:CallOnClient("Deploy", "")
-- stuff
end[/lua]
Sorry, you need to Log In to post a reply to this thread.