Old 11-13-2008   #1 (permalink)
Newbie
 
NEDM_Insane's Avatar
 

Join Date: Nov 2008
Posts: 9
NEDM_Insane is on a distinguished road
Default ION Cannon

Ok well I've been coding for all of 3 days.... well LUA any way. I am in the process of making an ION Cannon stool for wire mod. The Tool will make an ION Cannon and have inputs of what color the ion will be and when it activates you know all kinds of cool stuff.

But I'm getting an error when i goto click on the STool in Gmod. It says it cant write to the Table, so i looked through my code to the point at code line 93 (where it said my error was) and i have an table.insert function there.

Heres the code for the STool:
Code:
TOOL.Category		= "Wire - Physics"
TOOL.Name			= "IONCannon"
TOOL.Command		= nil
TOOL.ConfigName		= ""

TOOL.ClientConVar[ "delay" ] 		= "1" 	--If automatic
TOOL.ClientConVar[ "sound" ] 		= "0"
TOOL.ClientConVar[ "damage" ] 		= "500"
TOOL.ClientConVar[ "automatic" ]	= "0"

cleanup.Register( "wire_IONCannons" )

--Sounds
Sound( "ambient.electrical_zap_3" )

if ( CLIENT ) then
	language.Add( "Tool_wire_IONCannon_name", "ION Cannon" )
	language.Add( "Tool_wire_IONCannon_desc", "Makes things go BOOM!!!!!" )
	language.Add( "Tool_wire_IONCannon_0", "Click somewhere to spawn a ION Cannon. Click on an existing ION Cannon to change it." )
	
	
	language.Add( "Tool_wire_IONCannon_sound", "Shoot Sound" )
	
	language.Add( "Undone_wire_IONCannon", "Undone ION Cannon" )
	
	language.Add( "Cleanup_wire_IONCannon", "ION Cannon" )
	language.Add( "Cleaned_wire_IONCannon", "Cleaned up all ION Cannons" )
	language.Add( "SBoxLimit_wire_IONCannon", "You've reached the ION Cannon limit!" )
end

if (SERVER) then
    CreateConVar('sbox_maxwire_IONCannons', 2)
end 

function TOOL:LeftClick( trace, worldweld )
	if ( trace.Entity && trace.Entity:IsPlayer() ) then return false end
	if (CLIENT) then return true end
	
	worldweld = worldweld or false
	
	local ply = self:GetOwner()
    local delay 		= self:GetClientNumber( "delay" ) 
	local sound 		= self:GetClientInfo( "sound" )
	local damage	 	= self:GetClientNumber( "damage" )
	
-- Shoot Existing,
	if ( trace.Entity:IsValid() && trace.Entity:GetClass() == "gmod_wire_IONCannon" && trace.Entity.pl == ply ) then

		trace.Entity:SetDamage( damage )
		trace.Entity:SetDelay( delay )
		trace.Entity:SetSound( sound )
		return true
		
	end
	
	if ( !self:GetSWEP():CheckLimit( "wire_IONCannon" ) ) then return false 
	
	end

	if ( trace.Entity != NULL && (!trace.Entity:IsWorld() || worldweld) ) then
		trace.HitPos = trace.HitPos + trace.HitNormal * 2
	else
		trace.HitPos = trace.HitPos + trace.HitNormal * 2
	end
	
	local IONCannon = MakeWireIONCannon( ply, trace.HitPos, nil, delay, damage, sound)
	
	IONCannon:SetAngles( trace.HitNormal:Angle() )
	
	local weld = WireLib.Weld(IONCannon, trace.Entity, trace.PhysicsBone, true, false, worldweld)
	
	undo.Create("WireIONCannon")
		undo.AddEntity( IONCannon )
		undo.AddEntity( weld )
		undo.SetPlayer( ply )
	undo.Finish()
	
	return true
end 

function TOOL.BuildCPanel( CPanel )
CPanel:AddControl( "Header", {TEXT = "ION Cannon", Description =  "#Tool_wire_IONCannon_desc"} )

	local params = { Label = "#Presets", MenuButton = 1, Folder = "wire_IONCannon", Options = {}, CVars = {} }

		params.Options.default = {
			wire_IONCannon_delay	=	1,
			wire_IONCannon_damage	=	500,
			wire_IONCannon_sound	=	"Zap",
			wire_IONCannon_ions		=	1,
		}
		
->>> HERE is problem		table.insert{ params.CVars, "wire_IONCannon_delay"	}
		table.insert{ params.CVars, "wire_IONCannon_damage"	}
		table.insert{ params.CVars, "wire_IONCannon_sound"	}
		
	CPanel:AddControl{ "ComboBox", params }
	
	--ION Cannon Sound
	
	local IONSounds = { Label = "#Tool_wire_IONCannon_sound", MenuButton = 0, Options{}, CVars{}}
		IONSounds["options"]["#No Sound"]	=	{ wire_IONCannon_sound = "" }
		IONSounds["options"]["#Zap1"]		=	{ wire_IONCannon_sound = "ambient.electrical_zap_3"}
		IONSounds["Options"]["#Zap2"]		=	{ wire_IONCannon_sound = "ambient.electrical_zap_2"}
		IONSounds["Options"]["#Zap3"]		=	{ wire_IONCannon_sound = "ambient.electrical_zap_1"}
		
	CPanel:Addcontrol{"ComboBox", IONSounds}

	if ( SinglePlayer ()) then
		CPanel:AddControl{ "Slider", { Label = "#Number of IONs",
										Type	= "Integer",
										Min		= 1,
										Max		= 3,
										Command = "wire_IONCannon_ions" } }
	end
	
	
	--Delay Between The IONs
	if ( SinglePlayer()) then
		CPanel:AddControl{ "Slider", { Label = "#Delay",
										Type 	= "Float",
										Min		= 1,
										Max		= 20,
										Command	= "wire_IONCannon_delay" } }
	
	
		--Damage Of Each ION
		CPanel:AddControl{ "Slider", { Label = "#Damage",
										Type 	= "Integer",
										Min		= 500,
										Max		= 100000,
										Command	= "wire_IONCannon_delay" } }
	else
		CPanel:AddControl{ "Slider", { Label = "#Delay",
										Type 	= "Float",
										Min		= 1,
										Max		= 25,
										Command	= "wire_IONCannon_delay" } }
	
	
		--Damage Of Each ION
		CPanel:AddControl{ "Slider", { Label = "#Damage",
										Type 	= "Integer",
										Min		= 500,
										Max		= 10000,
										Command	= "wire_IONCannon_delay" } }
	end 
end
So what did i do wrong?
NEDM_Insane is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Old 11-14-2008   #2 (permalink)
COMPLETE BLOODY BASTARD

 
AzraelUK's Avatar
 

Join Date: Aug 2007
Location: Camelot, it is a silly place.
Posts: 581
AzraelUK is on a distinguished road
Send a message via MSN to AzraelUK
Default Re: ION Cannon

Have you tried just doing:
Code:
params.CVars = { "wire_IONCannon_delay", "wire_IONCannon_damage", "wire_IONCannon_sound" }
__________________
A designer knows he has achieved perfection not when there is nothing left to add, but when there is nothing left to take away.
—Antoine De Saint-Exupery
AzraelUK is online now  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-14-2008   #3 (permalink)
Advanced Member
 
CAANz's Avatar
 

Join Date: Mar 2008
Location: On the planet Earth... Simple is that.
Posts: 182
CAANz is on a distinguished road
Send a message via MSN to CAANz
Default Re: ION Cannon

You could make better sounds...

Believe me the zap sounds are bad.
__________________
Steps to take before asking about a broken wiremod or tools.



Don't Read This!

If you did you lose...
CAANz is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-14-2008   #4 (permalink)
Newbie
 
NEDM_Insane's Avatar
 

Join Date: Nov 2008
Posts: 9
NEDM_Insane is on a distinguished road
Default Re: ION Cannon

Quote:
Originally Posted by AzraelUK View Post
Have you tried just doing:
Code:
params.CVars = { "wire_IONCannon_delay", "wire_IONCannon_damage", "wire_IONCannon_sound" }
No, ill try it.

Quote:
You could make better sounds...

Believe me the zap sounds are bad.
Yeah i know i will be getting better sounds once i get this down.
NEDM_Insane is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-14-2008   #5 (permalink)
Newbie
 
NEDM_Insane's Avatar
 

Join Date: Nov 2008
Posts: 9
NEDM_Insane is on a distinguished road
Default Re: ION Cannon

Quote:
Originally Posted by AzraelUK View Post
Have you tried just doing:
Code:
params.CVars = { "wire_IONCannon_delay", "wire_IONCannon_damage", "wire_IONCannon_sound" }
Ok so, i put that insdead of the tables like this... id this right?
Code:
function TOOL.BuildCPanel( CPanel )
CPanel:AddControl( "Header", {TEXT = "ION Cannon", Description =  "#Tool_wire_IONCannon_desc"} )

	local params = { Label = "#Presets", MenuButton = 1, Folder = "wire_IONCannon", Options = {}, CVars = {} }

		params.CVars = { "wire_IONCannon_delay""wire_IONCannon_damage","wire_IONCannon_sound", "wire_IONCannon_ions"}
		
		
	CPanel:AddControl{ "ComboBox", params }
	
	--ION Cannon Sound
	
	local IONSounds = { Label = "#Tool_wire_IONCannon_sound", MenuButton = 0, Options{}, CVars{}}
		IONSounds["options"]["#No Sound"]	=	{ wire_IONCannon_sound = "" }
		IONSounds["options"]["#Zap1"]		=	{ wire_IONCannon_sound = "ambient.electrical_zap_3"}
		IONSounds["Options"]["#Zap2"]		=	{ wire_IONCannon_sound = "ambient.electrical_zap_2"}
		IONSounds["Options"]["#Zap3"]		=	{ wire_IONCannon_sound = "ambient.electrical_zap_1"}
		
	CPanel:Addcontrol{"ComboBox", IONSounds}
Theres more but it's just what i have above. Now the Stool Doesn't Show up at all.

EDIT: Wait..... after posting it i see the problem 1 sec let me see if it will work if i correct it.

EDIT2: Man i must suck at LUA or something. I got another error where it's looking for a table. UGGGG.

Error:
sandbox\gamemode\spawnmenu\controlpanel.lua:99: ControlPanelBuildFunction Error: includes/extensions/table.lua:402: bad argument #1 to 'pairs' (table expected, got nil)

I'm looking through the code now.

EDIT3: So there arent any calls to a table in my whole thing, and i dont have 402 lines so im guessing some terribly wrong happened?

Last edited by NEDM_Insane; 11-14-2008 at 06:37 PM..
NEDM_Insane is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-14-2008   #6 (permalink)
Newbie
 
SERPENT711's Avatar
 

Join Date: Sep 2008
Posts: 2
SERPENT711 is on a distinguished road
Default Re: ION Cannon

Shouldn't the bad lines be:

Code:
table.insert( params.CVars, "wire_IONCannon_delay"	)
table.insert( params.CVars, "wire_IONCannon_damage"	)
table.insert( params.CVars, "wire_IONCannon_sound"	)
I'm not that good at lua. But I thought table.insert took a table and value. Before you were just passing a table and the value was nil.

Your use of braces {} instead of parentheses () in the CPanel Method might also be your other problem.

Last edited by SERPENT711; 11-14-2008 at 08:54 PM..
SERPENT711 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-15-2008   #7 (permalink)
Newbie
 
NEDM_Insane's Avatar
 

Join Date: Nov 2008
Posts: 9
NEDM_Insane is on a distinguished road
Default Re: ION Cannon

Quote:
Originally Posted by SERPENT711 View Post
Shouldn't the bad lines be:

Code:
table.insert( params.CVars, "wire_IONCannon_delay"	)
table.insert( params.CVars, "wire_IONCannon_damage"	)
table.insert( params.CVars, "wire_IONCannon_sound"	)
I'm not that good at lua. But I thought table.insert took a table and value. Before you were just passing a table and the value was nil.

Your use of braces {} instead of parentheses () in the CPanel Method might also be your other problem.
Yeah i took those out and put in the different code. I did use the {}, im going to try it again see if it doesn't work.
NEDM_Insane is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-15-2008   #8 (permalink)
Newbie
 
NEDM_Insane's Avatar
 

Join Date: Nov 2008
Posts: 9
NEDM_Insane is on a distinguished road
Default Re: ION Cannon

ok with the tables in the code i am getting this error:

Code:
sandbox\gamemode\spawnmenu\controlpanel.lua:99: ControlPanelBuildFunction Error: weapons\gmod_tool\stools/wire_IONCannon.lua:95: wrong number of arguments to 'insert'
I don't know what it means by arguments. Well, i know what arguments means, but i have the right number it goes

table:insert{ table,value }

So why is it not working?

Last edited by NEDM_Insane; 11-16-2008 at 09:11 AM..
NEDM_Insane is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-17-2008   #9 (permalink)
Newbie
 
SERPENT711's Avatar
 

Join Date: Sep 2008
Posts: 2
SERPENT711 is on a distinguished road
Default Re: ION Cannon

Quote:
Originally Posted by NEDM_Insane View Post
table:insert{ table,value }

So why is it not working?
It isn't working because by using {table, value} you are making a table with "table" and "value" as its members and passing that 1 table to the insert method. Try using:

Code:
table:insert( table,value )
Which passes the arguments table and value as separate arguments instead of as 1 table.
SERPENT711 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-18-2008   #10 (permalink)
Advanced Member
 
itsbth's Avatar
 

Join Date: Feb 2007
Location: Norway
Posts: 280
itsbth is on a distinguished road
Send a message via MSN to itsbth
Default Re: ION Cannon

It's table.insert(tbl, value)
__________________
Wire developer. Currently working at: Topaz (A scripting language written in Lua)
<Fox682> itsbot: follow the white rabbit
<ITSBOT> i don't want to follow that.
itsbth is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -7. The time now is 11:48 PM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.

Page top