[QUOTE=hogofwar;39006760]Where are some decent tutorials? The wiki seems painfully lacking.[/QUOTE]
The wiki only gives the basics. I find that if you have some knowledge of Lua, that's all you need.
Unless I'm totally missing your point here :/
[QUOTE=CaptainFab;39006776]The wiki only gives the basics. I find that if you have some knowledge of Lua, that's all you need.
Unless I'm totally missing your point here :/[/QUOTE]
I still would like a tutorial to work off of, showing the basic structure.
I think there used to be some that I read a long while ago, which I think may have been on the wiki at some point...
[URL]http://wiki.garrysmod.com/page/Lua/Tutorials[/URL]
But there is hardly anything there right now anyway.
A simple example of an addon would work too, or a fully working but simple addon I can work off of.
What the hell, I swear there were loads of basic Lua tutorials on that page not so long ago
[editline]28th December 2012[/editline]
[img]http://puu.sh/1GsCw[/img]
what the fuck
trying to fix an old jihad bomb swep (the non OP as fuck one)
the player who activates it is supposed to turn red, then when he detonates it/respawns next round, he's supposed to be normal again. However, the player still appears as red.
Additionally, the the player is supposed to autodetonate after 20 seconds of charging the bomb, but nothing happens. The timer just goes into the negatives.
Any ideas?
[lua]-- Suicide Bomb By Manmax75 :D Made For Taconation
-- Visit [url]www.taconation.net[/url]
if SERVER then
AddCSLuaFile("shared.lua")
resource.AddFile("materials/VGUI/ttt/icon_suicidebomb.vmt") -- Suicide Bomb
end
if CLIENT then
SWEP.PrintName = "Suicide Bomb"
SWEP.Instructions = "Secondary Fire to arm, wait 10 seconds\n then Primary Fire to detonate."
SWEP.Slot = 6
SWEP.ViewModelFOV = 10
SWEP.EquipMenuData = {
type="Weapon",
model="models/weapons/w_c4_planted.mdl",
name="Suicide Bomb",
desc="Powerful Bomb\nUse to blow yourself up.\n\nSecondary Fire to arm, wait 10 seconds\n then Primary Fire to detonate.\nBe Warned You Only Have 20 Seconds..."
};
SWEP.Icon = "VGUI/ttt/icon_suicidebomb"
end
SWEP.Base = "weapon_tttbase" -- Must be from tttbase unless you want lua death...
SWEP.ViewModel = "models/weapons/v_c4.mdl"
SWEP.WorldModel = "models/weapons/w_c4.mdl"
SWEP.Weight = 50
SWEP.HoldType = "slam"
SWEP.Kind = WEAPON_EQUIP
SWEP.CanBuy = {ROLE_TRAITOR} -- Traitor only weap.. dah
SWEP.WeaponID = SUICIDE_BOMB
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"
SWEP.Primary.Delay = 5.0
SWEP.AllowDrop = false
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
SWEP.Secondary.Delay = 1.0
SWEP.NoSights = true
SWEP.arming = false
SWEP.armedandready = false
SWEP.arming_time = 11
SWEP.loopingSound = nil
SWEP.ply = nil
SWEP.curhealth = nil
SWEP.takehealth = nil
SWEP.takepercentage = nil
function SWEP:Reload()
return false
end
function SWEP:ShouldDropOnDie()
self:Remove()
end
function SWEP:OnRemove()
if CLIENT then
BarRemove()
end
end
function SWEP:Equip(newowner)
if not newowner:IsActiveTraitor() then
self:Remove()
end
end
if CLIENT then
local hudtxt = {
{text="Primary Fire To Detonate When Charged.", font="TabLarge", xalign=TEXT_ALIGN_RIGHT},
{text="Secondary Fire To Begin Charging.", font="TabLarge", xalign=TEXT_ALIGN_RIGHT}
};
function SWEP:DrawHUD()
local x = ScrW() - 80
hudtxt[1].pos = {x, ScrH() - 80}
draw.TextShadow(hudtxt[1], 2)
hudtxt[2].pos = {x, ScrH() - 60}
draw.TextShadow(hudtxt[2], 2)
end
function BarDraw(data)
local activate = data:ReadBool()
local entvalue = data:ReadShort()
local charply = data:ReadEntity()
local chardone = false
local locply = LocalPlayer()
local timeleft = 15
end_time = CurTime() + 10
autodes_end_time = 0
if charply == locply then
if activate == true then
bar = vgui.Create("TTTProgressBar") -- Progress Bar
bar:SetSize(370, 35)
bar:SetPos(0, 0)
bar:CenterHorizontal()
bar:SetMin(1)
bar:SetMax(100)
bar:SetValue(1)
bar:LabelAsPercentage()
state = vgui.Create("DLabel", bar) -- Status
state:SetSize(0, 35)
state:SetPos(10, 6)
state:SetFont("Trebuchet22")
state:SetText("READY TO CHARGE")
state:SetTextColor(COLOR_WHITE)
state:SizeToContents()
function bar:Think()
if locply:Alive() and locply:IsValid() then
if bar:GetValue() <= 100 and chardone == false then
bar:SetValue(100 - ((end_time - CurTime()) / 0.1))
bar:SetColor(COLOR_RED)
state:SetText("CHARGING")
state:SizeToContents()
else
if chardone == false then
chardone = true
bar:SetColor(COLOR_BLUE)
state:SetText("READY FOR DETONATION...AUTO DETONATE")
state:SizeToContents()
autodes_end_time = CurTime() + 20
RunConsoleCommand("ttt_suicidebomb-done", entvalue);
bar:SetValue(1)
else
timeleft = timeleft - 1
state:SetText("READY FOR DETONATION...Auto Detonate")
bar:SetValue(10 + ((autodes_end_time - CurTime()) / 0.2275))
end
end
else
if bar:IsValid() then
bar:Remove()
end
end
end
else
if bar:IsValid() then
bar:Remove()
end
end
end
end
function BarRemove()
if bar:IsValid() then
bar:Remove()
end
end
usermessage.Hook("SuicideBombBar", BarDraw);
end
if SERVER then
function TTTSuicideDone(ply, cmd, args)
local idx = tonumber(args[1])
local self = ents.GetByIndex(idx)
if self:IsValid() then
if self.arming == true and self.AllowDrop == false then
self.loopingSound:Stop()
self.armedandready = true
self.arming = false
self.Owner:PrintMessage(4,"You only have 20 seconds until you auto detonate...")
timer.Create("autodetonate", 20, 1, AutoDetonate, self)
end
end
end
concommand.Add("ttt_suicidebomb-done", TTTSuicideDone)
end
function AutoDetonate(self)
if !self or !self:IsValid( ) then return end
self.Owner.SetColor(self.Owner ,255, 255, 255, 255) -- Colour again
ownr = self.Owner
umsg.Start("SuicideBombBar", ownr);
umsg.Bool(false);
umsg.End();
self.DetonateBomb(self)
end
function SWEP:Deploy()
self.ply = self.Owner
self.curhealth = self.ply:Health() -- These lines are all the percentage math crap
self.takehealth = self.curhealth / 100 * 80
self.takepercentage = self.takehealth
self.curhealth = math.Round(self.curhealth - self.takehealth)
if self.curhealth > 1 then
self.ply.SetHealth(self.ply ,self.curhealth)
end
self.ply.SetColor(self.ply, 255, 0, 0, 255) -- Setting player red WOOOT
end
function SWEP:PreDrop()
if self.AllowDrop == false then
if self.loopingSound:IsPlaying() then
self.loopingSound:Stop() -- Stop the sound if you die mid-charge
ownr = self.Owner
end
umsg.Start("SuicideBombBar", ownr);
umsg.Bool(false);
umsg.End();
self.arming = false
self.armedandready = false
self.arming_time = 11
self.Owner.SetColor(self.Owner ,255, 255, 255, 255) -- Set you back to normal colour so you don't spawn like a cherry
self.AllowDrop = true
else
self.arming = false
self.armedandready = false -- Other condition cleaning up
self.arming_time = 11
self.curhealth = self.Owner:Health()
takepercent = self.takepercentage
self.curhealth = math.Clamp(math.Round(self.curhealth + takepercent), 1, 100)
self.Owner.SetHealth(self.Owner, self.curhealth) -- Fixing your health so it adds %80 back
self.Owner.SetHealth(self.Owner, self.curhealth)
self.Owner.SetColor(self.Owner ,255, 255, 255, 255)
[QUOTE=Soleeedus;39007783]trying to fix an old jihad bomb swep (the non OP as fuck one)
the player who activates it is supposed to turn red, then when he detonates it/respawns next round, he's supposed to be normal again. However, the player still appears as red.
Additionally, the the player is supposed to autodetonate after 20 seconds of charging the bomb, but nothing happens. The timer just goes into the negatives.
Any ideas?
[lua]alot of lau[/lua]
[editline]28th December 2012[/editline]
(I have RemoveRed() commented out because it would make every player in the server turn red)[/QUOTE]
1. You should also comment out the line that adds the hook considering there is no RemoveRed function anymore
2. Skimming over the code I saw this on line 199:
[lua]self.ply.SetColor(self.ply, 255, 0, 0, 255) -- Setting player red WOOOT[/lua]
Shouldn't it be called as:
[lua]self.ply:SetColor(Color(255,0,0,255))[/lua]
[QUOTE=Bandit Kitteh;39006695]I'm pretty sure Glon still exists.[/QUOTE]
Nope. it's all JSON now.
[url]http://garrysmod.com/post/34237807320/garrys-mod-update-143[/url]
absolute very last thing in the list.
RE: jihad bomb
[code] timer.Create("autodetonate", 20, 1, AutoDetonate, self)[/code]
I believe should be something like this.
[code]
timer.Create("autodetonate", 20, 1, function() AutoDetonate(self) end)
[/code]
thanks, the timer worked. however, ply colors are still a little weird.
[IMG]http://puu.sh/1Gx3M[/IMG]
after holstering the suicide bomb instead of detonating it, the player remains purple unless he uses the suicide bomb, to which he turns red
after using the suicide bomb/round is over, the player respawns. He remains purple, regardless of whether he's t or inno
[IMG]http://puu.sh/1Gx7V[/IMG]
any idea?
[editline]28th December 2012[/editline]
and yes, that's when I used hyperiguana's fix
Does it even blow up on your server? I tried testing and it doesn't work. Only errors I get are
[code]
[ERROR] .../terrortown/entities/weapons/weapon_ttt_jihad/shared.lua:155: attempt to index global 'bar' (a nil value)
1. BarRemove - .../terrortown/entities/weapons/weapon_ttt_jihad/shared.lua:155
2. unknown - .../terrortown/entities/weapons/weapon_ttt_jihad/shared.lua:66
[/code]
yeah, it blows up
Garry's Mod defaults to purple if the color inputted can't be read correctly.
Try replacing Color(0,0,0) to just 0,0,0
edit:
:v:
How do I remove FPP from my DarkRP server without breaking shit? I've already tried removing the folder from darkrp/gamemode etc
How do I use a variable as a variables name?
Example
[CODE]list = {"c1","c2"}
for k,v in pairs(list) do
{k} = "hi"
print(c1)
end[/CODE]
Ouput = "hi"
[QUOTE=tissue902;39012747]How do I use a variable as a variables name?
Example
[CODE]list = {"c1","c2"}
for k,v in pairs(list) do
{k} = "hi"
print(c1)
end[/CODE]
Ouput = "hi"[/QUOTE]
In this case, list is a table where element 1 is "c1" and element 2 is "c2".
In your for loop, k is the key (so the element number) and v is the value (c1 or c2).
[code]list = {"c1, "c2"}
for k,v in pairs(list) do
list[k] = "hi"
print( list[k] )
end[/code]
I believe this is what you were trying to do.
Not really. For example in assembly i guess its like:
local ("category" .. k ) = "hi"
so its taking and the actual variable name would be category_c1 and if you printed category_c1 you'd get hi back.
sorry if the {k} threw you off. PHP is something like that.
[editline]29th December 2012[/editline]
Or i guess another way around this would be how to make Collapsable derma panels to change the ones below it? Parent them?
[editline]29th December 2012[/editline]
Except then the parent would need to still have a different name which goes back to my issue before.
[QUOTE=tissue902;39012816]Not really. For example in assembly i guess its like:
local ("category" .. k ) = "hi"
so its taking and the actual variable name would be category_c1 and if you printed category_c1 you'd get hi back.
sorry if the {k} threw you off. PHP is something like that.[/QUOTE]
I think I see what you're trying to do.
You can set a variable on the global table like so:
[code]_G[ "hello" ] = "world"
print( hello )[/code]
If you didn't want to fill the global table with crap and have the variable only be set inside a certain function, you can do this:
[code]local env = setmetatable( {}, { __index = _G } )
function MyFunc()
env[ "hello" ] = "world"
print( hello )
end
setfenv( MyFunc, env )[/code]
You might also want to look into the debug module, specifically debug.setupvalue.
_G["category"_k] = "hi"?
[CODE]for k,wl in pairs(Categories) do
local _G["category"_k] = vgui.Create("DFrame", WeaponsPanel)
_G["category"_k]:SetPos( 10,ypos )
_G["category"_k]:SetSize( WeaponsPanel:GetWide()-35, 100 )
_G["category"_k]:SetExpanded( 0 )
_G["category"_k]:SetLabel( k )
ypos = ypos + 100
end[/CODE]
gives me unexpected [
[editline]29th December 2012[/editline]
Just realized you cant do local _G[] duh
[QUOTE=tissue902;39012934][CODE]for k,wl in pairs(Categories) do
local _G["category"_k] = vgui.Create("DFrame", WeaponsPanel)
_G["category"_k]:SetPos( 10,ypos )
_G["category"_k]:SetSize( WeaponsPanel:GetWide()-35, 100 )
_G["category"_k]:SetExpanded( 0 )
_G["category"_k]:SetLabel( k )
ypos = ypos + 100
end[/CODE]
gives me unexpected [
[editline]29th December 2012[/editline]
Just realized you cant do local _G[] duh[/QUOTE]
It would be easier to just have a local table and store your variables in that table.
Still need help - why are these tooltips so small
[img]http://puu.sh/1FLcR[/img]
Also, how can I get the current active page URL on a DHTML element? My FinishedURL and OpeningURL functions don't seem to be called. Do I use AddFunction now or something?
[QUOTE=centran;39010421]Does it even blow up on your server? I tried testing and it doesn't work. Only errors I get are
[code]
[ERROR] .../terrortown/entities/weapons/weapon_ttt_jihad/shared.lua:155: attempt to index global 'bar' (a nil value)
1. BarRemove - .../terrortown/entities/weapons/weapon_ttt_jihad/shared.lua:155
2. unknown - .../terrortown/entities/weapons/weapon_ttt_jihad/shared.lua:66
[/code][/QUOTE]
[URL="http://www.solidfiles.com/d/0dc1be1767/"]these[/URL] is the actual files that i'm using, try that
Can file.Read be used on a server from the client? If so, could one post an example code? Thanks.
Also, my friend wants to know this. I dunno why, but he told me to ask.
Edit: Hey man, I just put it in his words. Don't rate me dumb for shit I don't know about... :(
[QUOTE=deaded38;39014868]Can file.Read be used on a server from the client? If so, could one post an example code? Thanks.
Also, my friend wants to know this. I dunno why, but he told me to ask.
Edit: Hey man, I just put it in his words. Don't rate me dumb for shit I don't know about... :([/QUOTE]
Use console commands or net messages to request it, send the data back to the client via net messages
But don't trust the client, don't give them any input as to which files are read. Let the server handle it. You don't want, for example, someone requesting "../cfg/server.cfg", then the server handing it over to them
Treat every message from the client as if it was sent from a hacker, because they all potentially are
[QUOTE=tissue902;39012934][CODE]for k,wl in pairs(Categories) do
local _G["category"_k] = vgui.Create("DFrame", WeaponsPanel)
_G["category"_k]:SetPos( 10,ypos )
_G["category"_k]:SetSize( WeaponsPanel:GetWide()-35, 100 )
_G["category"_k]:SetExpanded( 0 )
_G["category"_k]:SetLabel( k )
ypos = ypos + 100
end[/CODE]
gives me unexpected [
[editline]29th December 2012[/editline]
Just realized you cant do local _G[] duh[/QUOTE]
I think what you are trying to do is something like this:
[lua]
for k, v in pairs( Categories ) do
WeaponsPanel[k] = vgui.Create( "DFrame", WeaponsPanel )
WeaponsPanel[k]:SetPos( 10, ypos )
WeaponsPanel[k]:SetSize( WeaponsPanel:GetWide()-35, 100 )
WeaponsPanel[k]:SetExpanded( 0 )
WeaponsPanel[k]:SetLabel( k )
ypos = ypos + 100
end
[/lua]
yeah I finally got it at 4am last night, thank you though.
I am however having trouble with net library. When I'm in single player, the weapons list gets sent to the client no problem. When i put it on a server, the first time the client joins, it just sits there waiting for weapons list. Then when you reconnect it loads right away. I'm really confused by this.
[CODE]net.Receive("WeaponsList", function()
WeaponsList = net.ReadTable()
print("Weapons Retrieved.")
end)
timer.Create("LoadWeapons",0,0, function()
-- Timer loops until Weapons list is received --
if type(WeaponsList) == "table" then
if table.Count(WeaponsList) == 0 then
-- No weapons in list --
WeaponsText:SetVisible(true)
WeaponsText:SetText("No Weapons Have Been Added.")
else
-- Weapons exist --
WeaponsText:SetVisible(false)
local Categories = {}
for k,Weapon in pairs(WeaponsList) do
if Weapon["category"] != "" && Weapon["category"] != nil && Weapon["category"] != NULL then
-- Has category so lets make it a spot in our table --
if Categories[Weapon["category"]] == nil then Categories[Weapon["category"]] = {} end
table.insert(Categories[Weapon["category"]], Weapon)
else
-- Doesnt have a category so since we are generous human beings lets give it one for free --
if Categories["Other"] == nil then Categories["Other"] = {} end
table.insert(Categories["Other"], Weapon)
end
end
for k,wl in pairs(Categories) do
-- Lets add these categories to the panel --
local CategoryHeader = vgui.Create("DCollapsibleCategory")
CategoryHeader:SetVisible(false)
CategoryHeader:SetPos( 25,50 )
CategoryHeader:SetSize( 200, 50 )
CategoryHeader:SetExpanded( 1 )
CategoryHeader:SetLabel(k .. " Weapons")
WeaponsPanel:AddItem(CategoryHeader)
local CategoryContainer = vgui.Create("DPanelList")
CategoryContainer:SetParent(CategoryHeader)
CategoryContainer:EnableHorizontal(true)
CategoryContainer:EnableVerticalScrollbar(true)
CategoryContainer:SetPadding(5)
CategoryContainer:SetSpacing(5)
CategoryContainer:SetPos(0,25)
local height = ( math.ceil( (table.Count(wl)*85) / WeaponsPanel:GetWide() ) ) * 85
for _,Weapon in pairs(wl) do
local Weapons = vgui.Create("SpawnIcon")
ToolTip = "Name: "..tostring(Weapon["name"]).."\nCost: $"..tostring(Weapon["cost"]).."\nAmmo: "..tostring(Weapon["ammo"]).."\nDamage: "..tostring(Weapon["damage"]).."\n"..tostring(Weapon["about"])
Weapons:SetModel(Weapon["mdl"])
Weapons:SetToolTip(ToolTip)
Weapons.DoClick = function() surface.PlaySound( "ui/buttonclickrelease.wav" ) end
Weapons:SetSize(75,75)
CategoryContainer:AddItem(Weapons)
end
CategoryContainer:SetSize(WeaponsPanel:GetWide()-25,height)
end
end
timer.Destroy("LoadWeapons")
else
WeaponsText:SetVisible(true)
WeaponsText:SetText("Loading Weapons List...")
end
end)[/CODE]
and GM:PlayerInitialSpawn calls
[CODE]function GetWeaponsList(pl)
-- Connect to the database --
local db = mysqloo.connect(SQLIP, SQLUSER, SQLPASS, SQLDB, SQLPORT)
function db:onConnected()
local q = self:query("SELECT * FROM weapons")
q.onSuccess = function(data)
WeaponsList = {}
if table.Count(data:getData()) > 0 then WeaponsList = data:getData() end
-- Send Timer Info To Client --
util.AddNetworkString("WeaponsList")
net.Start("WeaponsList")
net.WriteTable(WeaponsList)
net.Send(pl)
end
q.onError = function(err, sql) pl:PrintMessage(HUD_PRINTTALK, "Fatal Error: Could Not Query.") end
q:start()
end
function db:onConnectionFailed(err)
pl:PrintMessage(HUD_PRINTTALK, "Fatal Error: Could Not Connect.")
end
db:connect()
end[/CODE]
Any ideas? I also tried putting a timer around the net.receive but that didnt work.
Edit*
Should i just always broadcast the weaponslist? Its only something the player needs once so thats why i figured itd be better to send it only on initial spawn.
[QUOTE=tissue902;39019102]yeah I finally got it at 4am last night, thank you though.
I am however having trouble with net library. When I'm in single player, the weapons list gets sent to the client no problem. When i put it on a server, the first time the client joins, it just sits there waiting for weapons list. Then when you reconnect it loads right away. I'm really confused by this.
-code-
Any ideas? I also tried putting a timer around the net.receive but that didnt work.
Edit*
Should i just always broadcast the weaponslist? Its only something the player needs once so thats why i figured itd be better to send it only on initial spawn.[/QUOTE]
move util.AddNetworkString("WeaponsList") outside the function. It only needs to be called once, calling it more than once might be the source of the issue
That may have worked... doing some testing.
[editline]29th December 2012[/editline]
Yep, I'm going to say it worked. Thank you good sir. Now I just have to remember not to do that again in the future.
I'm struggling to make a code that when someone in the server types !darkrp it will switch servers, also with !ttt ect. Anyone familiar with this and could help?
[QUOTE=robz;39020031]I'm struggling to make a code that when someone in the server types !darkrp it will switch servers, also with !ttt ect. Anyone familiar with this and could help?[/QUOTE]
A fairly broad issue, what part in particular are you struggling with?
Recognizing the !command or switching servers or what? Show us the code you have so far. If you don't have any, I suggest you either learn a little Lua or check out the hiring thread!
[QUOTE=Trumple;39020427]A fairly broad issue, what part in particular are you struggling with?
Recognizing the !command or switching servers or what? Show us the code you have so far. If you don't have any, I suggest you either learn a little Lua or check out the hiring thread![/QUOTE]
[lua]
--serverside
local servers = {
[1] = {
cmd = "!ttt",
ip = "1.1.1.1:27015",
},
[2] = {
cmd = "!darkrp",
ip = "2.2.2.2:27015",
},
}
hook.Add("PlayerSay", "ChatHook", function(ply,text,public )
for _,v in pairs(servers) do
if string.lower(string.Trim(text)) == v.cmd then
ply:ConCommand("connect "..v.ip)
end
end
end)
[/lua]
Sorry, you need to Log In to post a reply to this thread.