The stool spawns a scripted entity, and the stool menu sets certain values of the entity.
Almost all of the code for the Stool was copied from another stool and then edited, so I might have forgotten to erase something.
EDIT: When I try to place the entity it says [@lua\weapons\gmod_tool\stools\killcounterstool.lua:59] Tried to use a NULL entity!
Code For Stool:
[lua]
TOOL.Category = "Survival Props" // Name of the category
TOOL.Name = "#KillCounter Stool" // Name to display
TOOL.Command = nil // Command on click (nil for default)
TOOL.ConfigName = "" // Config file name (nil for default)
function DEBUG_Msg (mesg)
--Msg (mesg)
end
if CLIENT then
language.Add ("Tool_KillCounterStool_name", "KillCounter Stool")
language.Add ("Tool_KillCounterStool_desc", "Create a KillCounter for use with survival games.")
language.Add ("Tool_KillCounterStool_0", "Left-click: Spawn KillCounter Right-click: Reset Money")
else
cleanup.Register( "KillCounter" )
function SpawnKillCounter (pl, Pos, Ang, startmoney, killmoney)
local ent = ents.Create ("KillCounter")
ent:SetKeyValue("startmoney", startmoney)
ent:SetKeyValue("Money Per Kill", killmoney)
ent:SetPos (Pos)
ent:SetAngles (Ang)
ent:Spawn()
ent:Activate()
--scary scary numpad stuff (I find it scary anyway)
AllocateNumpadFunctions (pl, ent)
end
duplicator.RegisterEntityClass("KillCounter", SpawnKillCounter, "Pos", "Ang", "startmoney", "killmoney")
end
TOOL.ClientConVar ["startmoney"] = "0"
TOOL.ClientConVar ["killmoney"] = "1"
function TOOL:LeftClick (trace)
DEBUG_Msg ("Left-click.\n")
if not self:GetSWEP():CheckLimit( "KillCounter" ) then return false end
if CLIENT then return true end
if trace.Entity:GetClass() == "KillCounter" then
ent = trace.Entity
self:SetKVs (ent)
return true
end
ent = ents.Create ("KillCounter")
self:SetKVs (ent)
ent:SetPos (trace.HitPos)
ent:SetAngles (Angle (1, -1, 1))
ent:Spawn ()
ent:Activate()
AllocateNumpadFunctions (self:GetOwner(), ent)
return true
end
function TOOL:RightClick (trace)
totalmoney = startingmoney
end
function TOOL:SetKVs (ent)
ent:SetKeyValue("startmoney", math.min (self:GetClientInfo ("startmoney"), 10000))
ent:SetKeyValue("killmoney", math.min (self:GetClientInfo ("killmoney"), 1000))
DEBUG_Msg ("entindex: "..self:GetOwner():EntIndex().."\n")
ent:SetKeyValue("ply", self:GetOwner():EntIndex())
end
function TOOL.BuildCPanel (cp)
cp:AddControl("Header", {Text = "#Tool_KillCounter_name", Description = "#Tool_KillCounter_desc"})
--Starting Money select
cp:AddControl("Slider", {Label = "Starting Money",
Type = "Integer",
Min = 0,
Max = 10000,
Command = "KillCounter_startmoney",
Description = "The amount of money the player starts with."})
--Money Per Kill select
cp:AddControl("Slider", {Label = "Money Per Kill",
Type = "Integer",
Min = 1,
Max = 1000,
Command = "KillCounter_killmoney",
Description = "The amount of money the player earns for each kill."})
end
function TOOL:Reload (trace)
// The SWEP doesn't reload so this does nothing :(
DEBUG_Msg( "RELOAD\n" )
end
function TOOL:Think()
end
[/lua]
Shared code of Entity (KillCounter)
[lua]
ENT.Type = "anim"
ENT.Base = "base_gmodentity"
ENT.Category = "SurvivalProps"
ENT.PrintName = "KillCounter"
ENT.Author = "Sangheili868"
ENT.Contact = "Don't"
ENT.Purpose = "Use with other survival props to make survival game. This keeps track of your kills and money."
ENT.Spawnable = true
ENT.AdminSpawnable = false
[/lua]
Cl_init Code for KillCounter
[lua]
include('shared.lua') --Include shared.lua
function ENT:Initialize()
var = "0"
end
function ENT:Draw()
self:DrawModel() --Draw the model, without this. You'll get a invisible, modeless entity.
end
function ENT:Think()
--Recieves the money from init.lua
local function RecvMyUmsg( data )
var = data:ReadString()
end
usermessage.Hook( "MyUsermessage", RecvMyUmsg );
--Draws the money in the HUD
function myhud()
local client = LocalPlayer()
if !client:Alive() then return end
if(client:GetActiveWeapon() == NULL or client:GetActiveWeapon() == "Camera") then return end
draw.RoundedBox(3, 5, 5, 100, 50, Color(51, 58, 51, 255))
draw.SimpleText("Money: " .. var, "ScoreboardText", 25, 25, Color(255, 255, 255, 255), 0, 0)
end
hook.Add("HUDPaint", "myhud", myhud)
end
[/lua]
Init Code for KillCounter
[lua]
--[[
KillCounter created by Sangheili868
Used with the WeaponShop to create zombie survival games.
Use constant values to specify how much money you earn per kill.
Money displayed on HUD.
(You can also use the wire outputs to display the money or kills on screens)
--]]
AddCSLuaFile( "cl_init.lua" ) --Send cl_init.lua to the client
AddCSLuaFile( "shared.lua" ) --Send shared.lua to the client
include( 'shared.lua' ) --Include shared.lua
ENT.killmoney = 0
ENT.startmoney = 0
function ENT:Initialize()
self:SetModel( "models/props_lab/servers.mdl" )
self:PhysicsInit( SOLID_VPHYSICS )
self:SetMoveType( MOVETYPE_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )
local phys = self:GetPhysicsObject()
self.NextThink = CurTime() + 1
if (phys:IsValid()) then
phys:Wake()
end
--Creates an input for the money earned per kill(specified by a constant value)
self.Inputs = Wire_CreateInputs(self.Entity, {"MoneyPerKill", "StartingMoney"})
--Creates outputs for the kills and money
self.Outputs = Wire_CreateOutputs(self.Entity, {"Kills", "Money"})
self.FirstInput = 0
self.SecondInput = 0
end
function ENT:SpawnFunction( ply, tr )
kills = 0 --Number of kills the player has
totalmoney = 0 --Total amount of money the player has earned
money = 0 --Current amount of money the player has
spent = 0 --Total amount of money the player has spent
if ( !tr.Hit ) then return end
local SpawnPos = tr.HitPos + tr.HitNormal * 36
local ent = ents.Create( "KillCounter" )
ent:SetPos( SpawnPos )
ent:Spawn()
ent:Activate()
return ent
end
--Increases kills for every npc kille
hook.Add("OnNPCKilled", "OnNPCKilled 0x5AE6CCAE", function(npc)
kills = kills + 1
end)
function ENT:TriggerInput(name, value)
if name == "MoneyPerKill" then
self.FirstInput = value
end
if name == "StartingMoney" then
self.SecondInput = value
end
end
function ENT:Use()
end
function ENT:OnRemove()
Dev_Unlink_All(self:GetTable().conduit)
end
function ENT:Think()
if self.FirstInput = 0 then
perkill = self.killmoney
else
perkill = self.FirstInput
end
if self.SecondInput = 0 then
startcash = self.startmoney
else
startcash = self.SecondInput
end
--Outputs the outputs
Wire_TriggerOutput(self, "Kills", kills)
Wire_TriggerOutput(self, "Money", money)
--Multiplies the number of kills by money per kill to get the total money earned
totalmoney = kills * perkill + startcash
--Takes the total money and subtracts from it the total spent to get the current money
money = totalmoney - spent
--Sends money to cl_init.lua so it can be shown on the HUD
umsg.Start( "MyUsermessage" );
umsg.String( tostring(money) );
umsg.End();
end
[/lua]
So what's your problem? "Help making this stool" is incredibly unspecific.
[QUOTE=Entoros;28159664]So what's your problem? "Help making this stool" is incredibly unspecific.[/QUOTE]
Sorry I put this thread together really fast because I had to go somewhere. It's fixed now
this is the good o'l morris stool
[IMG]http://images.meredith.com/wood/images/2009/05/p_morris-chair-exploded.jpg[/IMG]
i found this by using google
you could also put a cushion on the chair to make it more comfortable
btw that is a chair
[QUOTE=Andriko1;28177923]btw that is a chair[/QUOTE]
[LUA]
function GM:PlayerInitalSpawn(ply)
ply.item = "Stool"
end
function gun4chair(ply)
if ply.item == "Chair" then
ply:Give("weapon_m16")
end
end
[/LUA]
damn girl you solved mah Lua problem
i just had to change my item to "Chair" instead of stool
here comes the trollbait..... [sp] :PPPP XDDDDD[/sp]
Sorry, you need to Log In to post a reply to this thread.