[QUOTE=Moat;51756046]You can override the function(s) that makes the divider draggable. [URL="https://github.com/garrynewman/garrysmod/blob/784cd57576d85712fa13a7cea3a9523b4df966b0/garrysmod/lua/vgui/dhorizontaldivider.lua#L130-L151"][Here][/URL]
Or you could use [URL="http://wiki.garrysmod.com/page/Panel/Dock"]docking[/URL] on the panels.[/QUOTE]
Is there an easy way to weigh the docking spacing to be 75% in favor of one panel?
Quick Question.
I'm trying to make a scoreboard for a team-based gamemode. The problem I have is there doesn't seem to be a way to sort a table of player.GetAll(). What I want to do is more or less do a table.SortByMember(player_list, team#, false), so I can organize my scoreboard by team.
The only way I can think of getting this to work is to return the player table to a localized table, reorganize the local table into {name, team, frags, deaths, ping}, and then organize THAT by team, and then print everything out... That seems extremely tedious though and I don't think that's the most efficient way to do it.
[QUOTE=Rory;51757849]Quick Question.
I'm trying to make a scoreboard for a team-based gamemode. The problem I have is there doesn't seem to be a way to sort a table of player.GetAll(). What I want to do is more or less do a table.SortByMember(player_list, team#, false), so I can organize my scoreboard by team.
The only way I can think of getting this to work is to return the player table to a localized table, reorganize the local table into {name, team, frags, deaths, ping}, and then organize THAT by team, and then print everything out... That seems extremely tedious though and I don't think that's the most efficient way to do it.[/QUOTE]
Just use the default [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/table/sort]table.sort[/url] function, will allow you to do any logic on players inside the sorter function. Example 2 shows what I'm talking about.
[editline]31st January 2017[/editline]
[QUOTE=Rocket;51758007]I would just use team.GetPlayers to get the players of teach team and table.concat to concatenate them together so you preserve the order.[/QUOTE]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/table/concat]table.concat[/url] returns a string out of a table full of strings, I don't believe this is what they're asking for.
[QUOTE=Minteh Fresh;51754072]So basically, making it so when a player spawns props - it'll say how many they've spawned after they've stopped spawning. So basically if a player spawned 20 props, 5 seconds later it'll say "Minty Fresh has spawned 20 props." Upon clicking the "20 props" section of the text, it'll then print a list of the props to console. However, whilst using InsertClickableTextStart/End it just resizes the text and doesn't actually make it clickable. I feel like I might be doing something wrong, halp.
[code]function chatbox:ActionSignal( action, intent )
if ( action == "TextClicked" ) then
if ( intent == "PrintProps" ) then
RunConsoleCommand("kill")
end
end
end[/code]
However I believe it should be set up correctly...
[code]chatbox:InsertClickableTextStart("PrintProps")
chatbox:AppendText( args[2].. " props." )
chatbox:InsertClickableTextEnd()[/code][/QUOTE]
Question too difficult it got passed on ;)
The code you posted would work perfectly fine, somewhere else is making it go wrong.
[QUOTE=bigdogmat;51758010]Just use the default [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/table/sort]table.sort[/url] function[/QUOTE]
I will give that a shot, I overlooked table.sort. Thank you! If that doesn't do what I anticipate that it WILL do, I'll use Rocket's idea to sort each team out to the board. That should definitely, though I am assuming table.sort will be more efficient.
[QUOTE=Rory;51757849]Quick Question.
I'm trying to make a scoreboard for a team-based gamemode. The problem I have is there doesn't seem to be a way to sort a table of player.GetAll(). What I want to do is more or less do a table.SortByMember(player_list, team#, false), so I can organize my scoreboard by team.
The only way I can think of getting this to work is to return the player table to a localized table, reorganize the local table into {name, team, frags, deaths, ping}, and then organize THAT by team, and then print everything out... That seems extremely tedious though and I don't think that's the most efficient way to do it.[/QUOTE]
Sorting algorithms have a property called "stability", if a sort is stable, it will output the values in the same order they were input, except where the value you are sorting on is unequal.
For example, let's say you have these 4 hard drives:
[code]
HD#1 1TB $80
HD#2 2TB $50
HD#3 3TB $100
HD#4 4TB $80
[/code]
And you want to sort by price. An unstable sort might give you this:
[code]
HD#2 2TB $50
HD#4 4TB $80
HD#1 1TB $80
HD#3 3TB $100
[/code]
Where a stable sort will always give you this:
[code]
HD#2 2TB $50
HD#1 1TB $80
HD#4 4TB $80
HD#3 3TB $100
[/code]
So if you want or organize so members of a team are grouped together, and each group has highest frags on top, you would sort in the reverse order (sort by frags first, then by team).
I know default Lua's table.sort() is not stable, I haven't tested LuaJIT's but at random guess I would say it's also not stable.
[QUOTE=Apickx;51759167]
-original post clipped-
[/QUOTE]
That is a great explanation of sorting, thank you. I took Programming & Algorithms I/II, so I definitely understand what you're getting at. Just a little complicated when it comes to putting it into action.
The method that I quoted above worked. The end result was:
[code]
-- Called to draw each individual panel.
local function PlayerPanels(parent)
local player_table = player.GetAll()
table.sort(player_table, function(a,b)
return b:Team() > a:Team()
end)
-- loop through the table to print the player panels
end
[/code]
Team 1 is at the top, which is the VIP (one-player team) which was perfect.
Team 2 is below them
Team 3 was below them.
Utilize what you told me about sorting, I'm going to sort it by points then team. I'm just wondering what the more stable/more efficient sorting algorithm would be, unless [b]table.sort[/b] is the only option without digging into bare Lua, outside the gmod library. Would be nice to also know what sorting algorithm table.sort uses.
I'm thinking;
[code]
-- Called to draw each individual panel.
local function PlayerPanels(parent)
local player_table = player.GetAll()
-- Define Points() in sv/meta.lua
table.sort(player_table, function(a,b)
return b:Points() > a:Points()
end)
table.sort(player_table, function(a,b)
return b:Team() > a:Team()
end)
-- loop through the table to print the player panels
end
[/code]
[QUOTE=Rory;51761178]I'm just wondering what the more stable/more efficient sorting algorithm would be, unless [b]table.sort[/b] is the only option without digging into bare Lua, outside the gmod library. Would be nice to also know what sorting algorithm table.sort uses.
[/QUOTE]
I'm pretty sure that you would need to write your own stable sort, if you don't want to,[URL="http://lua.2524044.n2.nabble.com/A-stable-sort-td7648892.html"] "S. Fisher"'s sort [/URL]seems to be the one everyone uses.
You sparked my interest about what table.sort actually does, so I dug into the lua source, and in ltablib.c line 165 I found:
[code]
/*
** {======================================================
** Quicksort
** (based on `Algorithms in MODULA-3', Robert Sedgewick;
** Addison-Wesley, 1993.)
*/
[/code]
Going by the comments, it looks like a merge sort with some swapping.
[code]JOB_DB = {}
function GM:LoadJob(tbl)
JOB_DB[tbl.ID] = tbl
print("Loaded "..tbl.Name.." job.")
team.SetUp(tbl.ID, tbl.Name, tbl.Color)
end[/code]
So i've put this function in shared.lua and then try to print the amount of Jobs in JOB_DB
in SERVER it print 2 which is correct
but in CLIENT it keep printing out 0
i still confused about how shared shit work :l
[QUOTE=YoutoYokodera;51763207][code]JOB_DB = {}
function GM:LoadJob(tbl)
JOB_DB[tbl.ID] = tbl
print("Loaded "..tbl.Name.." job.")
team.SetUp(tbl.ID, tbl.Name, tbl.Color)
end[/code]
So i've put this function in shared.lua and then try to print the amount of Jobs in JOB_DB
in SERVER it print 2 which is correct
but in CLIENT it keep printing out 0
i still confused about how shared shit work :l[/QUOTE]
Think of a shared file as 2 separate files with the same contents, one is client side, one is server side. There's no data shared between the 2, you're going to have to network it.
So basically, I'm making a chatbox / console that basically lets everyone know everything and anything that happens - clientside lua errors on a specific person, prop spawns, kills/deaths, connects, etc.
[quote][img]http://puu.sh/tKEEt/bd4a9d8483.jpg[/img][/quote]
But for some reason, when a prop spawn notification has occured - it breaks the .GetAll() for everything. Scoreboard, spawnmenu etc.
[quote][img]http://puu.sh/tKEIN/44df7b7971.jpg[/img][/quote]
EDIT-- Fixed, I was using player = net.ReadEntity() replacing player with pl fixed .GetAll()...
I'm a rookie...
Any ideas of what's going on x'D ?
[video]https://youtu.be/QVaFiVtKKKY[/video]
[QUOTE=guigui30110;51766552]Any ideas of what's going on x'D ?
[video]https://youtu.be/QVaFiVtKKKY[/video][/QUOTE]
Need some code.
But i think you aren't removing the effect when you remove the entities, so it go to the origin of the map
[QUOTE=guigui;51766681]Need some code.
But i think you aren't removing the effect when you remove the entities, so it go to the origin of the map[/QUOTE]
Here the code ...
[CODE]
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua')
function ENT:Initialize()
self:SetModel("models/props_2fort/groundlight001.mdl")
self:PhysicsInit(SOLID_NONE)
self:SetMoveType(MOVETYPE_NONE)
self:SetSolid(SOLID_VPHYSICS)
end
local speed = 50
function ENT:Think()
if #self:GetChildren() == 1 then
self:Remove()
end
local children = self:GetChildren()[1]
if !IsValid(children) then return end
local ang = children:GetAngles();
ang:RotateAroundAxis(self:GetUp() , FrameTime()*speed);
children:SetAngles(ang);
self:NextThink( CurTime() )
return true
end
function ENT:OnRemove()
for k,v in pairs(self:GetChildren()) do
print(v)
v:Fire("KillHierarchy")
v:Fire("LightOff")
v:Remove()
end
self:Remove()
end
local function getRandomWeapon()
local weaponList = {"weapon_357","weapon_ar2","weapon_crossbow","weapon_crowbar","weapon_frag","weapon_physcannon","weapon_pistol","weapon_rpg","weapon_shotgun","weapon_slam","weapon_smg1","weapon_stunstick"}
return weaponList[ math.random( #weaponList ) ]
end
function ENT:SpawnFunction( ply, tr )
if ( !tr.Hit ) then return end
local ent = ents.Create("usl_weapon")
ent:SetPos( tr.HitPos)
ent:Spawn()
local light = ents.Create("point_spotlight")
light:SetPos( ent:GetPos()+Vector(0,0,1) )
light:Spawn()
light:Activate()
light:SetAngles(Angle(-90,0,0))
light:SetKeyValue("SpotlightLength", 64) -- 'distance' is equivalent to the radius of your light
light:SetKeyValue("SpotlightWidth", 10)
light:SetKeyValue("_light","255 0 0")
light:Fire("color","255 0 0",0)
light:Fire("LightOn")
light:SetParent( ent )
local WeaponToSpawn = getRandomWeapon()
local ent1 = ents.Create(WeaponToSpawn)
ent1:SetPos( ent:GetPos() + GetCorPos(ent1))
ent1:SetAngles( Angle(-25,0,0) )
ent1:SetParent(ent)
ent1:Spawn()
return ent
end
function GetCorPos(ent1)
local ModelWeapon = ents.Create("prop_physics")
ModelWeapon:SetModel(ent1:GetModel())
local Max = ModelWeapon:OBBMaxs()
local CorPos = Vector(0,0,ModelWeapon:OBBMaxs().z + 50) + ModelWeapon:OBBCenter()/2
ModelWeapon:Remove()
return CorPos
end
[/CODE]
[quote=]Huge Issue... Game-breaking problem.
I have it set to where players joining the game are set to spectator team (4) and put into spectator mode. Everything worked fine, until I made my gamemode's development map with only one info_player_deathmatch for my spectators to spawn at.
The bots joining the game spawn inside each other, and kill each other. I can see them, and everything. No clue what to do about this, because I can't find a flaw in the code.
The first bot in the game will spawn, and be invisible, in spectator mode just fine. As soon as the next bot loads into the game, the previous one dies, and his body appears, ragdolling to the ground.
[code]
function SetSpectator(ply, obs) -- Need to fix later using meta
if obs == 1 then
ply:Spectate(6)
ply:SpectateEntity(nil)
ply:SetMoveType(MOVETYPE_NOCLIP)
ply:SetNotSolid(true)
ply:SetNoTarget(true)
elseif obs == 0 then
ply:UnSpectate()
ply:SetMoveType(MOVETYPE_WALK)
ply:SetNoTarget(false)
ply:SetNotSolid(false)
end
end
function GM:PlayerInitialSpawn(ply)
ply:SetNoCollideWithTeammates(true)
ply:SetModel("models/gman.mdl")
ply:Points(0)
ply:SetTeam(4)
ply:SetNWInt("TimesPres",0)
SetSpectator(ply, 1)
end
[/code]
I also added this to make sure I could also get collisions to shut off to keep the Spectators from killing each other, but didn't work.
[code]
function GM:ShouldCollide(ent1, ent2)
if ent1:IsPlayer() and ent2:IsPlayer() then
if ent1:Team() == ent2:Team() then
return false
else
return true
end
else
return true
end
end
[/code]
[/quote]
[b]Solved.[/b]
Since I made my own gamemode, I never overwrote [b]GM:IsSpawnpointSuitable()[/b]. That function, in it's base form, kills anyone occupying that spawn space. It's not that the players were colliding - They were just being told to die from that function.
[QUOTE=Rory;51769490][code]
function SetSpectator(ply, obs) -- Need to fix later using meta
if obs == 1 then
ply:Spectate(6)
ply:SpectateEntity(nil)
ply:SetMoveType(MOVETYPE_NOCLIP)
ply:SetNotSolid(true)
ply:SetNoTarget(true)
elseif obs == 0 then
ply:UnSpectate()
ply:SetMoveType(MOVETYPE_WALK)
ply:SetNoTarget(false)
ply:SetNotSolid(false)
end
end
function GM:PlayerInitialSpawn(ply)
ply:SetNoCollideWithTeammates(true)
ply:SetModel("models/gman.mdl")
ply:Points(0)
ply:SetTeam(4)
ply:SetNWInt("TimesPres",0)
SetSpectator(ply, 1)
end
[/code]
I also added this to make sure I could also get collisions to shut off to keep the Spectators from killing each other, but didn't work.
[code]
function GM:ShouldCollide(ent1, ent2)
if ent1:IsPlayer() and ent2:IsPlayer() then
if ent1:Team() == ent2:Team() then
return false
else
return true
end
else
return true
end
end
[/code][/QUOTE]
Why are you using numbers instead of the proper global names for enumerations and teams?
[QUOTE=sannys;51769585]Why are you using numbers instead of the proper global names for enumerations and teams?[/QUOTE]
Because it wasn't working either way, and I'm desperate to try anything.
[Edit]
SOLVED - See above for the answer to this EXTREMELY agitating problem.
[QUOTE=guigui30110;51766819]Here the code ...
-snip-
[/QUOTE]
What does the print in OnRemove() print when you remove the entities?
ps: You don't need to call "self:Remove()" in the "OnRemove" hook.
Can somebody maybe go back to page 7, please?
[QUOTE=guigui;51770154]What does the print in OnRemove() print when you remove the entities?
ps: You don't need to call "self:Remove()" in the "OnRemove" hook.[/QUOTE]
It's print "spotlight" / "beam" / some other stuff
And yeah I know, I was kind of desperate ^^
With some testing it appears that if I kill the spotlight a few moments before the parent entity, there is no problem ... But I don't know if it's possible to overwrite the remove function to do somethink like
[CODE]
function removing()
self:GetChildren()[1]:Fire("LightOff")
timer.Simple(0.1, function()
self:Remove()
end)
end
[/CODE]
[B]Question moved to a more appropriate thread located at [url]https://facepunch.com/showthread.php?t=1551590&p=51783583#post51783583[/url][/B]
How does one get a players last used weapon? (Not a weapon they've picked up and dropped but the current weapon they have but is not currently in use (I.e. Holstered))
Quick Edit: I cannot provide a [B]specific[/B] class name for the weapon as it is being checked against a table.
So I was trying to use PData to save the title ( a string ) of a player, but this line
[CODE]local title = ply:GetPData("Title")[/CODE]
gives the following error.
[CODE]attempt to index a string value with bad key ('GetPData' is not part of the string library)[/CODE]
This also happens in a different addon when I try to save and retrieve an integer value.
[QUOTE=8Z;51774990]So I was trying to use PData to save the title ( a string ) of a player, but this line
[CODE]local title = ply:GetPData("Title")[/CODE]
gives the following error.
[CODE]attempt to index a string value with bad key ('GetPData' is not part of the string library)[/CODE]
This also happens in a different addon when I try to save and retrieve an integer value.[/QUOTE]
Your `ply` variable is a string
[QUOTE=Aeternal;51774919]How does one get a players last used weapon? (Not a weapon they've picked up and dropped but the current weapon they have but is not currently in use (I.e. Holstered))
Quick Edit: I cannot provide a [B]specific[/B] class name for the weapon as it is being checked against a table.[/QUOTE]
Store the previous weapon to a player variable in this hook: [url]https://wiki.garrysmod.com/page/GM/PlayerSwitchWeapon[/url]
[QUOTE=bigdogmat;51774993]Your `ply` variable is a string[/QUOTE]
Thank you so much. PlayerConnect gives me a name, not ply itself...
(Solved) - Original Problem:
[quote=]
[code]
function GM:Initialize()
CreateConVar("test_roundtime", "360", true, "Sets the time per round")
CreateConVar("test_preptime", "12", true, "Sets how long preparation takes")
CreateConVar("test_breaktime", "6", true, "Sets how long preparation takes")
end
-- More code in here, not applicable
local round = {}
round.intermission = GetConVar("test_breaktime"):GetInt()
round.time = GetConVar("test_roundtime"):GetInt()
round.prep_time = GetConVar("test_preptime"):GetInt()
round.in_progess = false
round.count = 0
round.timeleft = -1
round.status = "STALE"
[/code]
[quote=]
[ERROR] gamemodes/<gamemode>/gamemode/init.lua:105: attempt to index a nil value
1. unknown - gamemodes/<gamemode>/gamemode/init.lua:105
Couldn't Load Init Script: '<gamemode>/gamemode/init.lua'
[ERROR] gamemodes/<gamemode>/gamemode/init.lua:106: attempt to index a nil value
1. unknown - gamemodes/<gamemode>/gamemode/init.lua:106
Couldn't Load Init Script: '<gamemode>/gamemode/init.lua'
[ERROR] gamemodes/<gamemode>/gamemode/init.lua:107: attempt to index a nil value
1. unknown - gamemodes/<gamemode>/gamemode/init.lua:107
Couldn't Load Init Script: '<gamemode>/gamemode/init.lua'
[/quote]
What am I doing wrong? First time making ConVar's. The idea is to let the server owner/admins set the times they want to use for said values.
[Update] Changing it to a hook into Initialize doesn't make a difference.
[/quote]
[Edit]
Solved. ConVar had to be declared at the top of my init.lua before it was ever requested. Not within the Initialize function.
[QUOTE=Rory;51776543][code]
function GM:Initialize()
CreateConVar("test_roundtime", "360", true, "Sets the time per round")
CreateConVar("test_preptime", "12", true, "Sets how long preparation takes")
CreateConVar("test_breaktime", "6", true, "Sets how long preparation takes")
end
-- More code in here, not applicable
local round = {}
round.intermission = GetConVar("test_breaktime"):GetInt()
round.time = GetConVar("test_roundtime"):GetInt()
round.prep_time = GetConVar("test_preptime"):GetInt()
round.in_progess = false
round.count = 0
round.timeleft = -1
round.status = "STALE"
[/code]
What am I doing wrong? First time making ConVar's. The idea is to let the server owner/admins set the times they want to use for said values.[/QUOTE]
You're overwriting GM:Initialize instead of hooking into it.
[QUOTE=8Z;51775818]PlayerConnect gives me a name, not ply itself...[/QUOTE]
Yeah, if you're using "GM:PlayerConnect", ply is a string, not an entity. I guess the player hasn't been on long enough yet for the game to register it as an entity object.
Check out: [url]http://wiki.garrysmod.com/page/GM/PlayerConnect[/url]
Versus: [url]http://wiki.garrysmod.com/page/GM/PlayerDeath[/url]
Notice the difference in parameters.
"ply itself" is irrelevant. "ply" is just a variable that means nothing until you give it something.
[code]
local ply = "Sandwich"
-- Would give you a string "sandwich".
local ply = player.GetAll()[1]
-- Would give you an Entity of requested player.
[/code]
[QUOTE=txike;51776558]You're overwriting GM:Initialize instead of hooking into it.[/QUOTE]
[del]Hook or overwriting, didn't make a difference. Either way the ConVar should be getting created.
No matter, I changed it to a hook, still no-go.[/del]
They had to be declared at the top of the init.lua file, not within a function. Works perfectly now.
Sorry, you need to Log In to post a reply to this thread.