• Thermal Detonator or grenade for starwars is shooting insted of throwing grenade
    5 replies, posted
Ok so Iv recently been configuring/developing for this server and someone suggested that we have grenades. Me being the Star Wars savvy guy I knew exactly what to do. So I used a base from this guy and the model is showing in the view-model but the world-model is showing a pistol hold type. Which inst how I coded it. Also it shoots like a pistol/shotgun which is weird and it inst showing any errors. Iv been looking through the code and changed it multiple time in the 3-4 hours spent on it and just said ok I need sleep. So I need help if someone would be kind enough. UPDATE/EDIT Ok got it working! Now I get an error when I try to spawn it with a tool gun. Here is the error also I update the new code below [CODE][ERROR] addons/thermalgernade/lua/weapons/sstw_weapon_thermaldetonator/shared.lua:109: attempt to call method 'DrawViewModel' (a nil value) 1. Holster - addons/thermalgernade/lua/weapons/sstw_weapon_thermaldetonator/shared.lua:109 2. unknown - addons/thermalgernade/lua/weapons/sstw_weapon_thermaldetonator/shared.lua:323 [ERROR] addons/thermalgernade/lua/weapons/sstw_weapon_thermaldetonator/shared.lua:109: attempt to call method 'DrawViewModel' (a nil value) 1. Holster - addons/thermalgernade/lua/weapons/sstw_weapon_thermaldetonator/shared.lua:109 2. unknown - addons/thermalgernade/lua/weapons/sstw_weapon_thermaldetonator/shared.lua:323 [/CODE] [CODE]if (SERVER) then AddCSLuaFile ("shared.lua") SWEP.Weight = 5 SWEP.AutoSwitchTo = true SWEP.AutoSwitchFrom = false end SWEP.VElements = { ["grenda"] = { type = "Model", model = "models/starwarsbf2/compiled 0.34/thermal_detonator.mdl", bone = "ValveBiped.Grenade_body", rel = "", pos = Vector(0.518, -0.519, -4.676), angle = Angle(0, 0, 0), size = Vector(0.755, 0.755, 0.755), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} } } SWEP.WElements = { ["succ"] = { type = "Model", model = "models/starwarsbf2/compiled 0.34/thermal_detonator.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(2.596, 2.596, -4.676), angle = Angle(-5.844, -1.17, 0), size = Vector(0.95, 0.95, 0.95), color = Color(255, 255, 255, 255), surpresslightning = true, material = "", skin = 0, bodygroup = {} } } SWEP.PrintName = "Thermal Detonator " SWEP.Slot = 4 SWEP.SlotPos = 1 SWEP.DrawAmmo = true SWEP.DrawCrosshair = false SWEP.Category = "Star Wars: Thermal Detonator" SWEP.UseHands = false SWEP.ViewModel = "models/weapons/v_grenade.mdl" SWEP.WorldModel = "models/weapons/w_grenade.mdl" SWEP.HoldType = "grenade" SWEP.ViewModelFOV = 63.718592964824 SWEP.ViewModelFlip = false function SWEP:Reload() return false end SWEP.ShowViewModel = true SWEP.ShowWorldModel = false SWEP.ViewModelBoneMods = { ["ValveBiped.Grenade_body"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) } } SWEP.Spawnable = true SWEP.AdminSpawnable = true SWEP.ViewModelFlip = false SWEP.ViewModelFOV = 60 SWEP.Primary.ClipSize = 1 SWEP.Primary.DefaultClip = 30 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "grenade" SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" SWEP.Primed = 0 SWEP.Throw = CurTime() SWEP.PrimaryThrow = true function SWEP:Initialize() self:SetWeaponHoldType( self.HoldType ) if CLIENT then self.VElements = table.FullCopy( self.VElements ) self.WElements = table.FullCopy( self.WElements ) self.ViewModelBoneMods = table.FullCopy( self.ViewModelBoneMods ) self:CreateModels(self.VElements) // create viewmodels self:CreateModels(self.WElements) // create worldmodels // init view model bone build function if IsValid(self.Owner) then local vm = self.Owner:GetViewModel() if IsValid(vm) then self:ResetBonePositions(vm) // Init viewmodel visibility if (self.ShowViewModel == nil or self.ShowViewModel) then vm:SetColor(Color(255,255,255,255)) else // we set the alpha to 1 instead of 0 because else ViewModelDrawn stops being called vm:SetColor(Color(255,255,255,1)) // ^ stopped working in GMod 13 because you have to do Entity:SetRenderMode(1) for translucency to kick in // however for some reason the view model resets to render mode 0 every frame so we just apply a debug material to prevent it from drawing vm:SetMaterial("Debug/hsv") end end end end end /*--------------------------------------------------------- Holster ---------------------------------------------------------*/ function SWEP:Holster() self.Primed = 0 self.Throw = CurTime() self.Owner:DrawViewModel(true) return true end /*--------------------------------------------------------- Holster ---------------------------------------------------------*/ function SWEP:Reload() self.Owner:DrawViewModel(true) self.Weapon:DefaultReload(ACT_VM_DRAW) end ------------------------THINK-------------------------- function SWEP:Think() if ((self:Clip1() > 0)) then self.Owner:DrawViewModel(true) else self.Owner:DrawViewModel(false) end if self.Primed == 1 and not self.Owner:KeyDown(IN_ATTACK) and self.PrimaryThrow then if self.Throw < CurTime() then self.Primed = 2 self.Throw = CurTime() + 1.5 self.Weapon:SendWeaponAnim(ACT_VM_THROW) self.Owner:SetAnimation(PLAYER_ATTACK1) timer.Simple( 0.35, function() if (!self or !IsValid(self)) then return end self:ThrowFar() end) end elseif self.Primed == 1 and not self.Owner:KeyDown(IN_ATTACK2) and not self.PrimaryThrow then if self.Throw < CurTime() then self.Primed = 2 self.Throw = CurTime() + 1.5 self.Weapon:SendWeaponAnim(ACT_VM_THROW) self.Owner:SetAnimation(PLAYER_ATTACK1) timer.Simple( 0.35, function() if (!self or !IsValid(self)) then return end self:ThrowShort() end) end end end --------------------END OF THINK------------------- /*--------------------------------------------------------- ThrowFar ---------------------------------------------------------*/ function SWEP:ThrowFar() if self.Primed != 2 then return end local tr = self.Owner:GetEyeTrace() if (!SERVER) then return end local ent = ents.Create ("ent_thermaldetonator") local v = self.Owner:GetShootPos() v = v + self.Owner:GetForward() * 2 v = v + self.Owner:GetRight() * 3 v = v + self.Owner:GetUp() * -3 ent:SetPos( v ) ent:SetAngles(Angle(math.random(1,100),math.random(1,100),math.random(1,100))) ent.GrenadeOwner = self.Owner ent:Spawn() local phys = ent:GetPhysicsObject() if !IsValid(phys) then self.Weapon:SendWeaponAnim(ACT_VM_DRAW) self.Primed = 0 return end if self.Owner:KeyDown( IN_FORWARD ) then self.Force = 800 elseif self.Owner:KeyDown( IN_BACK ) then self.Force = 800 elseif self.Owner:KeyDown( IN_MOVELEFT ) then self.Force = 800 elseif self.Owner:KeyDown( IN_MOVERIGHT ) then self.Force = 800 else self.Force = 800 end phys:ApplyForceCenter(self.Owner:GetAimVector() * self.Force * 2 + Vector(0, 0, 0)) phys:AddAngleVelocity(Vector(math.random(-500,500),math.random(-500,500),math.random(-500,500))) self:TakePrimaryAmmo(1) -- self:Reload() timer.Simple(0.6, function() if self.Owner:GetAmmoCount(self.Primary.Ammo) > 0 then --self.Weapon:SendWeaponAnim(ACT_VM_DRAW) self.Primed = 0 else self.Primed = 0 -- self.Weapon:Remove() -- self.Owner:ConCommand("lastinv") end end) end /*--------------------------------------------------------- ThrowShort ---------------------------------------------------------*/ function SWEP:ThrowShort() if self.Primed != 2 then return end local tr = self.Owner:GetEyeTrace() if (!SERVER) then return end local ent = ents.Create ("ent_thermaldetonator") local v = self.Owner:GetShootPos() v = v + self.Owner:GetForward() * 2 v = v + sel
You're never calling [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Weapon/SetHoldType]Weapon:SetHoldType[/url], and you didn't overwrite [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/WEAPON/PrimaryAttack]SWEP:PrimaryAttack[/url], so it just uses the default that shoots bullets.
Dang it, I knew something was missing. Thank you for the help man I really do appreciate it!
Oops! I updated the situation under the update/edit. got some errors Iv been trying to fix for hours! Hehe. Any help?
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/DrawViewModel]Player:DrawViewModel[/url] is serverside only, you're calling it shared.
Wow another great catch by the AwfulRanger :happy: Thanks dude now everything is working! Again really appreciate it! Happy Coding!
Sorry, you need to Log In to post a reply to this thread.