• What in god's name is wrong with my weapon?
    0 replies, posted
So I've taken it upon myself to create a gcombat weapon that behaves like a hybrid between the old Phaser Mk2 and the MW4 Energy Weapons I made for GCX long ago. The only problem is that this is now far more complex than the simple Flak 88 edits those energy weapons were. Problems: -does not seem to update self.TX/Y/Z variables, as self.Angle doesn't seem to compute anything except for a target vector to the map origin. -does not fire. Ever. No errors. Does anybody see what's wrong with this? I've got to be doing something wrong, this is my first foray into Lua since '07, so by all means tear this thing apart. [lua]AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include('entities/base_wire_entity/init.lua'); include('shared.lua') function ENT:Initialize() self.fire = false self.ready = false self.reloadtime = 0 self.Entity:SetModel( "models/combatmodels/tank_gun.mdl" ) self.Entity:PhysicsInit( SOLID_VPHYSICS ) -- Make us work with physics, self.Entity:SetMoveType( MOVETYPE_VPHYSICS ) --after all, gmod is a physics self.Entity:SetSolid( SOLID_VPHYSICS ) -- Toolbox self.Entity:SetColor(100,40,255,255) local phys = self.Entity:GetPhysicsObject() if (phys:IsValid()) then phys:Wake() phys:SetMass( 3 ) end self.Inputs = WireLib.CreateSpecialInputs( self.Entity, { "Fire", "Target Vector"}, {"NORMAL","VECTOR"} ) self.Outputs = Wire_CreateOutputs( self.Entity, { "Can Fire", "Angle2Target", "ReloadTime" }) self.TX = 0 self.TY = 0 self.TZ = 0 end function ENT:SpawnFunction( ply, tr) if ( !tr.Hit ) then return end local SpawnPos = tr.HitPos + tr.HitNormal * 60 local ent = ents.Create( "LanceWeapon" ) ent:SetPos( SpawnPos ) ent:Spawn() ent:Activate() return ent end --End copy/pasta function ENT:Think() --Declaring shit here local Target = Vector(self.TX, self.TY, self.TZ) local Vec2Target = (Target - self.Entity:GetPos()):GetNormal() self.Angle = math.acos(self.Entity:GetUp():DotProduct(Vec2Target)) --Run traceline variables and shit here local trace = {} trace.start = self.Entity:GetPos() + self.Entity:GetUp() * 50 trace.endpos = self.Target trace.filter = self.Entity local tr = util.TraceLine(trace) --If/Then clauses... if (self.fire == true && self.ready == true) then ENT:firelance(tr.Entity, tr.Hit) end if (self.reloadtime > 0) then self.ready = false Wire_TriggerOutput(self.Entity, "Can Fire", 0) end if (self.reloadtime <= 0) then self.ready = true Wire_TriggerOutput(self.Entity, "Can Fire", 1) end --Finalize Wire_TriggerOutput(self.Entity, "Angle2Target", math.Rad2Deg(self.Angle)) Wire_TriggerOutput(self.Entity, "ReloadTime", self.reloadtime) self.Entity:NextThink( CurTime() ) end function ENT:firelance(entityhit, endpos) if (self.ready == true) then cbt_dealnrghit(entityhit, 750, 3, endpos, endpos) local effectdata = EffectData() effectdata:SetOrigin(endpos) effectdata:SetStart(self.Entity:GetPos() + self.Entity:GetUp() * 50) util.Effect( "ClanLargeLaserBeam", effectdata ) self.reloadtime = CurTime() + 4 end end function ENT:TriggerInputs(iname, value) if (iname == "Fire") then if (value == 1) then self.fire = true end if (value == 0) then self.fire = false end end if (iname == "Target Vector") then self.TX = value.x self.TY = value.y self.TZ = value.z end end[/lua]
Sorry, you need to Log In to post a reply to this thread.