Hello , I was making a swep and I encountered a little problem with drawing a model.Every time that my SecondaryAttack() function is called a model is supposed to draw (smod's kicking leg) , the problem is : it just won't draw. My model Draw function looks like this :
[lua]function SWEP:DrawLeg()
if CLIENT then
local model = ClientsideModel("models/weapons/v_kick.mdl")
model:SetPos(self.Owner:GetShootPos())
model:SetAngles(self.Owner:GetViewAngles())
model:SetParent(self.Owner)
model:DrawModel()
end
end
[/lua]
This function doesn't give any errors or something , the rest of my secondaryattack() function works perfectly.How can I make it draw everytime that I call SecondaryAttack() function?
Thanks.
Nevermind x2, it's a viewmodel. You aren't spawning it.
[QUOTE=PortalGod;29070953]How often are you calling that function?[/QUOTE]
Draw function? It is called every SecondaryAttack() func.
[editline]9th April 2011[/editline]
[editline]9th April 2011[/editline]
[QUOTE=PortalGod;29070953]Nevermind x2, it's a viewmodel. You aren't spawning it.[/QUOTE]
Well It's still not working ,
[lua]function SWEP:DrawLeg()
if CLIENT then
local model = ClientsideModel("models/weapons/v_kick.mdl")
model:Spawn()
model:SetPos(self.Owner:GetShootPos())
model:SetAngles(self.Owner:GetViewAngles())
model:SetParent(self.Owner)
model:DrawModel()
end
end
[/lua]
Any help?
DrawModel isn't being used correctly here - it draws the model once only, so it's something you'd put in an ENT:Draw(). Either way, it's not necessary for a ClientsideModel - you spawn it and the game will draw it for you, like any other entity. Try just creating the entity at the origin - on gm_construct this is above the ground in front of the spawn area.
[QUOTE=Azaz3l;29070967]Draw function? It is called every SecondaryAttack() func.[/QUOTE]
You shouldn't do that.
You can't just draw anywhere, only render stuff in hooks that are supposed to render stuff. In your situation, those would be SWEP:ViewModelDrawn or SWEP:DrawWorldModel, depends on what you want to do exactly.
Those hooks are called automatically, so don't try to call them from SecondaryAttack, instead you should let your code know what to render if you are using the secondary attack. Probably using a value that starts as false that you set to true when you start using the secondary attack, and back to false when you stop using it. Then all you'd need to do is check that value in your draw hook. Make sure the value exists, if you're setting it serverside, it will exist serverside only, if you're setting it clientside, it will exist clientside only.
If you add the fact that SWEPs behave differently in singleplayer and on a multiplayer server, you will get confused pretty quickly. For instance, PrimaryAttack and SecondaryAttack are never called clientside when playing singleplayer, even though they normally should. You can "fix" that by doing an "if SinglePlayer() then" and force the game to call the function clientside (for instance using [b][url=http://wiki.garrysmod.com/?title=Weapon.CallOnClient]Weapon.CallOnClient [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]).
Or if you want to make sure it works, just use networked variables or DT variables (but then you should make sure you only set them serverside, otherwise they might break).
Sorry, you need to Log In to post a reply to this thread.