What i'm trying to do is make a missile launcher. This code here is suppose to stop the launcher from spawning another missile if v:GetClass is one of the missiles so it doesn't spawn missiles inside each-other. But even if the missile is nearby its still running the reload function. if (v:GetClass() == "aim_120d_amraam_dumb") then return end, why is this not returning end and still runs the function
[CODE]for k,v in pairs(ents.FindInSphere(self:GetPos(),100)) do
if (not self:IsValid()) then return end
if (v:GetClass() == "aim_120d_amraam_dumb") then return end
if (iname == "Reload") then
if (value >= 1) then
if not (self.Reloaded) then
self:Reload()
end
end
end
end[/CODE]
maby someone can make this work? or make it better
Are you 1000% sure that "aim_120d_amraam_dumb" is the class name? Do a print(v:GetClass()) before that line to be sure.
yes, i did a print to the console and copy paste the class name over to the code, idk why it wants to run the function still
[editline]3rd June 2017[/editline]
I even did a test changing from get class to if v:IsPlayer and it detects me but it still launches the darn missile even tho im telling it to return end if it detects me.......
What is self
[editline]3rd June 2017[/editline]
Also, I think you meant to check if v:IsValid rather than if self:IsValid (since you started the loop by using self:GetPos() which may not be valid)
self is the missile launcher itself. Parts of the code is for wire inputs, therefore i'm checking if the launcher is valid so when its removed wire-mod doesn't freek out with lua errors when its removed because it would be trying to make wire inputs even if the entity is removed. That's why if(iname == "Reload") is there. I'm using wire-mod to actually launch the missiles. So i wire a button from wire-mod to my launcher and press the button, The missile spawns and launches.
[editline]3rd June 2017[/editline]
I think I figured something out that I'm happy with. It's just not as advanced as I'd like but I just created a timer to make a delay in-between rounds so it only can launch a missile every 3 seconds. They aren't getting stuck in each other now. Thanks for taking time out to help me though, It is always appreciated. :P
Here's the code if your interested :P
[CODE]AddCSLuaFile( "cl_init.lua" ) -- Make sure clientside
AddCSLuaFile( "shared.lua" ) -- and shared scripts are sent.
include('shared.lua')
function ENT:Initialize()
if (SERVER) then
self:SetModel( "models/props_phx/box_amraam.mdl" )
self:PhysicsInit( SOLID_VPHYSICS ) -- Make us work with physics,
self:SetMoveType(MOVETYPE_VPHYSICS) -- after all, gmod is a physics
self:SetSolid( SOLID_VPHYSICS ) -- Toolbox
local phys = self:GetPhysicsObject()
if (phys:IsValid()) then
phys:Wake()
end
self:SetTrigger(true)
self.Reloaded = false
if not (WireAddon == nil) then self.Inputs = Wire_CreateInputs(self, { "Fire Dumb","Fire Guided"}) end -- wiremod Inputs
end
end
function ENT:TriggerInput(iname, value)-- Tells launcher to spawn missile and launch it using wiremod
if (not self:IsValid()) then return end
if (iname == "Fire Dumb") then
if (value >= 1) then
if not (self.Reloaded) then
self:Reload()
end
end
end
if (iname == "Fire Guided") then
if (value >= 1) then
if not (self.Reloaded) then
self:ReloadGuided()
end
end
end
end
function ENT:Reload()--Simple missile launcher function
Amraam = ents.Create( "AIM_120D_AMRAAM_Dumb" )-- Create missile
Amraam:SetPos( self:GetPos() )
Amraam:SetAngles(Angle(self:GetAngles()))
Amraam:Spawn()
Amraam:Launch()
local phys = Amraam:GetPhysicsObject()
phys:SetVelocity(Amraam:GetForward()*900 )
self:EmitSound( "self.Launch",75,100,1,CHAN_AUTO )
self.Reloaded = true
timer.Simple( 3, function()---Delay between rounds
self.Reloaded = false
end)
end
function ENT:ReloadGuided()
AmraamG = ents.Create( "AIM_120D_AMRAAM_Guided" )-- Create missile
AmraamG:SetPos( self:GetPos() )
AmraamG:SetAngles(Angle(self:GetAngles()))
AmraamG:Spawn()
AmraamG:Launch()
local phys = AmraamG:GetPhysicsObject()
phys:SetVelocity(AmraamG:GetForward()*900 )
self:EmitSound( "self.Firesound",75,100,1,CHAN_AUTO )
self.Reloaded = true
timer.Simple( 3, function()---Delay between rounds
self.Reloaded = false
end)
end
function ENT:Fire()--Fires the missile--- NOT USED CURRENTLY
--Amraam:Launch()
--Amraam:SetParent(nil, 2)
end
function ENT:OnRemove()--Removes spawned missiles
if (not Amraam:IsValid()) then return end
if (not AmraamG:IsValid()) then return end
Amraam:Remove()
AmraamG:Remove()
end
[/CODE]
Have you tried print(iname)? It seems weird to have that as a global variable
Sorry, you need to Log In to post a reply to this thread.