• Problems That Don't Need Their Own Thread v2.0
    5,020 replies, posted
[QUOTE=ROFLBURGER;46729674]Unfortunately this doesn't work in this case because it isn't spawned yet. I am literally pulling my hair out because of this issue. I'm trying to make it so that there are weapons on people's backs and legs but this fucking rotation thing is driving me insane. [lua] local PBonePos, PBoneAng = ply:GetBonePosition(PBoneIndex) --later in the code ply.PrimaryObj = ClientsideModel( PModel ) local bonusangle = Angle(0,0,0) local bonusvector = Vector(0,0,0) ply.PrimaryObj:SetAngles(PBoneAng) -- go fuck yourself ply.PrimaryObj:SetPos(ply:GetPos() + bonusvector) -- works ply.PrimaryObj:FollowBone( ply, PBoneIndex ) -- works only in position [/lua] this is only called once. it doesn't even have the same fucking angles throughout. sometimes the model is one angle one time, and another angle the other time and I don't know how to fix it. I don't know how to properly rotate the fucking thing either and it's really pissing me off because literally everything else is perfect except for the actual cosmetic effect[/QUOTE] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/LocalToWorld]Global.LocalToWorld[/url]
[QUOTE=MadkillerMax;46727361]I understand the calls are asynchronous however, I do not know if they require players online to run.[/QUOTE] They shouldn't... When I start my server I have a single http request sent to compare server version. [url]https://bitbucket.org/Acecool/acecooldev_base/src/master/gamemode/addons/_version_control/sv_check_version.lua?at=master[/url] On Initialize, in a 5 second simple timer... It shows up in server console as last thing before players connect without requiring players.
[QUOTE=zerf;46730132]Pretty sure adam burton made this, it might be helpful? [url]https://dl.dropboxusercontent.com/u/55311295/ShareX/2014/12/weaponholster.lua[/url][/QUOTE] I don't see any parenting though, wouldn't this be laggy?
I saw this in few scripts. [CODE] local CreateConVar = CreateConVar local util = util local pairs = pairs local weapons = weapons local type = type local table = table local net = net local chat = chat local hook = hook local Derma_StringRequest = Derma_StringRequest local tonumber = tonumber local math = math [/CODE] What is the point of that, is it good, bad, stupid?
[QUOTE=GreenGold;46731825]I saw this in few scripts. [CODE] local CreateConVar = CreateConVar local util = util local pairs = pairs local weapons = weapons local type = type local table = table local net = net local chat = chat local hook = hook local Derma_StringRequest = Derma_StringRequest local tonumber = tonumber local math = math [/CODE] What is the point of that, is it good, bad, stupid?[/QUOTE] I'm actually wondering about this too I was fucking around in CapsAdmin's pac to see what he did for bones and I noticed that he used something like this too [QUOTE=Ott;46731087][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/LocalToWorld]Global.LocalToWorld[/url][/QUOTE] omfg you're a life saver
[QUOTE=GreenGold;46731825]I saw this in few scripts. [CODE] local CreateConVar = CreateConVar local util = util local pairs = pairs local weapons = weapons local type = type local table = table local net = net local chat = chat local hook = hook local Derma_StringRequest = Derma_StringRequest local tonumber = tonumber local math = math [/CODE] What is the point of that, is it good, bad, stupid?[/QUOTE] [QUOTE=Leystryku;46287391]Used to make code faster ( now not so much anymore since LuaJit ). But there are certain situations where it actually still makes code faster, and that significantly. However, that only counts for functions that are called often. AddCSLuaFile is a function that really shouldn't be localized. The only other reason why is to avoid overwrites - mainly for cheats and anticheats.[/QUOTE]
[QUOTE=GreenGold;46731825]I saw this in few scripts. [CODE] local CreateConVar = CreateConVar local util = util local pairs = pairs local weapons = weapons local type = type local table = table local net = net local chat = chat local hook = hook local Derma_StringRequest = Derma_StringRequest local tonumber = tonumber local math = math [/CODE] What is the point of that, is it good, bad, stupid?[/QUOTE] That's what's known as micro-optimization, which (in the case you provided) basically localizes the global libraries that the person intends to use in the following code so it's 'faster' to reference later on. It's validity is questionable though, especially since the differences in processing speed you would notice with and without these localisations is barely noticeable. You'd be better off finding out what's really slowing down your code rather than trying to compensate with this technique; you'll only be as fast as your weakest link will allow. E: At least, that's from my experience from it. If you unavoidably have to call expensive functions rapidly and in large quantities, this would definitely help some.
[QUOTE=Acecool;46731348]They shouldn't... When I start my server I have a single http request sent to compare server version. [url]https://bitbucket.org/Acecool/acecooldev_base/src/master/gamemode/addons/_version_control/sv_check_version.lua?at=master[/url] On Initialize, in a 5 second simple timer... It shows up in server console as last thing before players connect without requiring players.[/QUOTE] Alright, adding the 5 second timer worked out. Thanks acecool.
[QUOTE=GreenGold;46731825]I saw this in few scripts. [CODE] local CreateConVar = CreateConVar local util = util local pairs = pairs local weapons = weapons local type = type local table = table local net = net local chat = chat local hook = hook local Derma_StringRequest = Derma_StringRequest local tonumber = tonumber local math = math [/CODE] What is the point of that, is it good, bad, stupid?[/QUOTE] [QUOTE=ROFLBURGER;46731876]I'm actually wondering about this too I was fucking around in CapsAdmin's pac to see what he did for bones and I noticed that he used something like this too omfg you're a life saver[/QUOTE] [QUOTE=LilSumac;46731908]That's what's known as micro-optimization, which (in the case you provided) basically localizes the global libraries that the person intends to use in the following code so it's 'faster' to reference later on. It's validity is questionable though, especially since the differences in processing speed you would notice with and without these localisations is barely noticeable. You'd be better off finding out what's really slowing down your code rather than trying to compensate with this technique; you'll only be as fast as your weakest link will allow. E: At least, that's from my experience from it. If you unavoidably have to call expensive functions rapidly and in large quantities, this would definitely help some.[/QUOTE] I did some benchmarking on it. The benefits were next to nothing, and that was before some of the additional optimizations came into the game... [url]https://github.com/Facepunch/garrysmod-issues/issues/631[/url] 0.01 - 0.02 speed increase on average... Better would be to apply other optimizations to your game-mode such as HUDShouldDraw using a direct-entry table instead of using a for-each loop because HUDShouldDraw is called many times per frame, and then if there is a for-each then it'll be an exponentially growing O( n^2 ) function... 100 million times running it with a loop ( without running the frame which would've called it n more times ) costs 15 seconds while running a direct-entry table 100 million times is 0.08 seconds... [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/benchmarking_tips/benchmarking_hud_stuff.lua.html[/url] Had I simulated how it would've been over 100 million frames, the time would've been multiplied by around as many times as there are hud elements which uses it, see the list here: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/proper_hud_creation.lua.html[/url] ~33 * 15 seconds = 495 seconds and ~33 * 0.08 = 2.64 seconds [editline]17th December 2014[/editline] [QUOTE=MadkillerMax;46731989]Alright, adding the 5 second timer worked out. Thanks acecool.[/QUOTE] http may not fully initialize until the game-mode has fully loaded, so that may have been the reason why it wasn't working for you without the timer.
I need an addon for a wire machine gun just like the wire turret STool, just not configurable in game. I'd set the model, delay, spread, damage, and other attributes in the lua. I'd spawn it in via the entities menu, and then wire something to it's fire input to get it working. I recall seeing something similar fairly recently, could someone post it?
What's the best method of storing data. Like items in a player inventory, etc. Do I need to bust out MySQL?
"Best" is relative. What options are available? How many players are you aiming for. What will be stored? How many different kinds of items will there be? Etc... There can be a best for one method which may not work or work well for another method... But, for inventory you can use flat-file / json, MySQL, SQLite, etc... It's really up to you. If you do use SQL, I'd highly recommend setting up tables for items / characters - accounts / etc.. instead of just using json within a table row...
[QUOTE=Acecool;46732725]I did some benchmarking on it. The benefits were next to nothing, and that was before some of the additional optimizations came into the game... [url]https://github.com/Facepunch/garrysmod-issues/issues/631[/url] 0.01 - 0.02 speed increase on average... Better would be to apply other optimizations to your game-mode such as HUDShouldDraw using a direct-entry table instead of using a for-each loop because HUDShouldDraw is called many times per frame, and then if there is a for-each then it'll be an exponentially growing O( n^2 ) function... 100 million times running it with a loop ( without running the frame which would've called it n more times ) costs 15 seconds while running a direct-entry table 100 million times is 0.08 seconds... [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/benchmarking_tips/benchmarking_hud_stuff.lua.html[/url] Had I simulated how it would've been over 100 million frames, the time would've been multiplied by around as many times as there are hud elements which uses it, see the list here: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/proper_hud_creation.lua.html[/url] ~33 * 15 seconds = 495 seconds and ~33 * 0.08 = 2.64 seconds [editline]17th December 2014[/editline] http may not fully initialize until the game-mode has fully loaded, so that may have been the reason why it wasn't working for you without the timer.[/QUOTE] There are cases where you can receive significant benefits, for example if some heavier lookups are done on _G via metatable magic. Also anticheats/cheats use local functions because that way people can't do stuff like CreateConVar = ... after the cheat/anticheat has loaded for special procedures.
My gamemode's init file won't run, and neither of the dudes I have doing code for me seem to be able to figure out why. Would anyone be willing to help out? Truth be told I have no idea where to start with these things.
Pros of cons using SQLite vs MySQL? Not sure which one I should use (preferably the more simple one) Thanks.
I coded a SENT to rotate as it levitates up and down but its really jaggy. Does anyone know how I can make the transitions smoother? Code: [lua] function ENT:Think() if CLIENT then return end --Self.ADDNUM - Amount of times it goes up or down before going the opposite way --self.ADD - whether or not to add numbers or subtract if self.ADD then self:SetPos( Vector(self:GetPos().x,self:GetPos().y, self:GetPos().z+2)) self.ADDNUM = self.ADDNUM + 1 self:SetAngles( Angle(self:GetAngles().pitch, self:GetAngles().yaw-10, self:GetAngles().roll)) else self:SetPos( Vector(self:GetPos().x,self:GetPos().y, self:GetPos().z-2)) self.ADDNUM = self.ADDNUM - 1 self:SetAngles( Angle(self:GetAngles().pitch, self:GetAngles().yaw-10, self:GetAngles().roll)) end if self.ADDNUM >= 5 then self.ADD = false end if self.ADDNUM <= 0 then self.ADD = true end end [/lua] [editline]17th December 2014[/editline] [QUOTE=TheDoggy;46736354]Pros of cons using SQLite vs MySQL? Not sure which one I should use (preferably the more simple one) Thanks.[/QUOTE] SQLite is only for local databases stored in the sv.db file in your server. MySQL allows for you to synchronize data between multiple servers in a database. IMO SQLite it easier cause Garry already has functions for it all, but if your wanting to send data in-between servers MySQL would be your best bet.
Use FrameTime or a Delta ( change in x ) Time function to apply the rotation of x speed per y time. Then regardless of the time from one think to the next, it'll rotate at a constant speed.
[QUOTE=Acecool;46732725]http may not fully initialize until the game-mode has fully loaded, so that may have been the reason why it wasn't working for you without the timer.[/QUOTE] After playing with some other things a bit, I have noticed that when the server starts up it's first time, it will not make any http calls until a player shows up. I think when the server first starts it waits for a player to attempt connecting to initialize the gamemode however. After that, even with map changes it responds nicely.
I'm a little confused to how adding tables work. I'm basically trying to get who has the highest frags but yeah I don't understand tables. It gives me error messages about the local stats = {v{v:Frags()}} part [lua]function RTScore() local FragsTable = {} for k,v in pairs(player.GetAll()) do local stats = {v{v:Frags()}} table.Add(FragsTable,stats) end PrintTable(table.SortByKey(FragsTable)) end[/lua] Or if there's an easier way of getting the highest frags, let me know please.
[QUOTE=ROFLBURGER;46737753]I'm a little confused to how adding tables work. I'm basically trying to get who has the highest frags but yeah I don't understand tables. It gives me error messages about the local stats = {v{v:Frags()}} part [lua]function RTScore() local FragsTable = {} for k,v in pairs(player.GetAll()) do local stats = {v{v:Frags()}} table.Add(FragsTable,stats) end PrintTable(table.SortByKey(FragsTable)) end[/lua] Or if there's an easier way of getting the highest frags, let me know please.[/QUOTE] It's been a really long time since I've worked with it but table.sort is what I used. In this example the second key in the table represents the kills. [code] table.sort(KillsTable, function(a,b) return a[2] > b[2] end) [/code] This doesn't produce a new table, just reorders the table itself. I remember being on the verge of punching things many times when working with table.sort for whatever reason. Edit: Just looked at another project in which I needed to sort a table. I needed to draw things in order, or with z indexs I guess, so I used SortedPairsByTableMember. Why? I forget but it went something like this. [code] for a, b in SortedPairsByTableMember(v.children, "z") do --Code here end [/code] Which is a function I found online, I'll try to find the person to credit but here it is: [code] function SortedPairsByTableMember(tbl, key) local keys = {} local values = {} local c = 1 for k, v in next, tbl do keys[v] = k values[c] = v c = c + 1 end table.sort(values, function(a, b) return a[key] < b[key] end) local idx = 0 return function(tbl) idx = idx + 1 return keys[values[idx]], values[idx] end end [/code] If I remember some specifics as to why I chose either way I'll post back here.
[QUOTE=Dgc2002;46738003]It's been a really long time since I've worked with it but table.sort is what I used. In this example the second key in the table represents the kills. [code] table.sort(KillsTable, function(a,b) return a[2] > b[2] end) [/code] This doesn't produce a new table, just reorders the table itself. I remember being on the verge of punching things many times when working with table.sort for whatever reason. Edit: Just looked at another project in which I needed to sort a table. I needed to draw things in order, or with z indexs I guess, so I used SortedPairsByTableMember. Why? I forget but it went something like this. [code] for a, b in SortedPairsByTableMember(v.children, "z") do --Code here end [/code] Which is a function I found online, I'll try to find the person to credit but here it is: [code] function SortedPairsByTableMember(tbl, key) local keys = {} local values = {} local c = 1 for k, v in next, tbl do keys[v] = k values[c] = v c = c + 1 end table.sort(values, function(a, b) return a[key] < b[key] end) local idx = 0 return function(tbl) idx = idx + 1 return keys[values[idx]], values[idx] end end [/code] If I remember some specifics as to why I chose either way I'll post back here.[/QUOTE] I ended up doing something a bit more hacky [code] local previousfrags = 0 local winner = Entity(0) for k,v in pairs(player.GetAll()) do if previousfrags < v:Frags() then previousfrags = v:Frags() - v:Deaths() winner = v end end [/code] It doesn't get first or second place, but I'll bookmark your code just in case I need that.
[QUOTE=ROFLBURGER;46737753]I'm a little confused to how adding tables work. I'm basically trying to get who has the highest frags but yeah I don't understand tables. It gives me error messages about the local stats = {v{v:Frags()}} part [lua]function RTScore() local FragsTable = {} for k,v in pairs(player.GetAll()) do local stats = {v{v:Frags()}} table.Add(FragsTable,stats) end PrintTable(table.SortByKey(FragsTable)) end[/lua] Or if there's an easier way of getting the highest frags, let me know please.[/QUOTE] Everything in Lua is stored in a table.. There are many different ways to assign vars, functions, etc and there are many ways to obtain the reference. [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/tables/quick_intro_to_tables.lua.html[/url] Meta-tables are special tables which can have special functions assigned to actions allowing you to call them as though they were a function, or perform other tasks when data changes or gets added and many more... Think of meta-tables as objects that are cloned so each instance gets their own copy. Each player is an object and we can add meta-table functions which can reference the specific player. Here's a quick run-down of the meta-functions: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/classes/class_tutorial.lua.html[/url]
[QUOTE=ROFLBURGER;46738153]I ended up doing something a bit more hacky [code] local previousfrags = 0 local winner = Entity(0) for k,v in pairs(player.GetAll()) do if previousfrags < v:Frags() then previousfrags = v:Frags() - v:Deaths() winner = v end end [/code] It doesn't get first or second place, but I'll bookmark your code just in case I need that.[/QUOTE] Ahh okay, I guess I didn't register that you were just trying to get the single highest fragger and not a top X list of them.
Does anyone know how to properly make a player do an animation? I'm just trying to make a player dance and freezing them and running this doesn't seem to work. Am I using the right command or Entity:SetAnimation(ACT_GMOD_TAUNT_DANCE) [QUOTE=Dgc2002;46738185]Ahh okay, I guess I didn't register that you were just trying to get the single highest fragger and not a top X list of them.[/QUOTE] Well later when I release it I'll probably need highest factor. this jury rigged gamemode is just for me and my friends
[QUOTE=ROFLBURGER;46737753] Or if there's an easier way of getting the highest frags, let me know please.[/QUOTE] Use PlayerDeath hook, add to a counter if the death was a legit kill. Here's an example: One uses SetFrags, the other uses its own counter. [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_gamemode_logic/gun_race/sv_gun_race.lua.html[/url] [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_gamemode_logic/gun_race/sv_upgrade_weapons_for_kills.lua.html[/url] [editline]18th December 2014[/editline] [QUOTE=ROFLBURGER;46738223]Does anyone know how to properly make a player do an animation? I'm just trying to make a player dance and freezing them and running this doesn't seem to work. Am I using the right command or Entity:SetAnimation(ACT_GMOD_TAUNT_DANCE) Well later when I release it I'll probably need highest factor. this jury rigged gamemode is just for me and my friends[/QUOTE] if ( _p:IsPlayingTaunt( ) ) then ... end WHERE ... would prevent move in SetupMove / CreateMove... using the act / taunt system. To play a gesture / taunt / act you'd use: _p:AnimRestartGesture( GESTURE_SLOT_ATTACK_AND_RELOAD, ACT_GMOD_GESTURE_ITEM_DROP, false ); Arg1 = slot, 2 = animation / act, 3 = loop : [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/AnimRestartGesture]Player:AnimRestartGesture[/url]
Another problem (boy I post in this thread a lot) [code]local Items = {} local WeaponTable = weapons.GetList() local EntityTable = scripted_ents.GetList( ) for k,v in pairs(WeaponTable) do if v.Base == "weapon_cs_base" and v.Category == "Counter-Strike" then table.Add(Items,{WeaponTable[k].ClassName}) end end for a,b in pairs(EntityTable) do print( EntityTable[a].Category ) if b.Category == "CS:S Ammo" then table.Add(Items,{EntityTable[a].ClassName}) end end print("List:") PrintTable(Items)[/code] does scripted_ents.GetList( ) not work the same as weapons.GetList() ? print(Entity.Table[a].Category) gives me a lot of nils when it should give me the category of the entity
[QUOTE=ROFLBURGER;46740290]Another problem (boy I post in this thread a lot) does scripted_ents.GetList( ) not work the same as weapons.GetList() ? print(Entity.Table[a].Category) gives me a lot of nils when it should give me the category of the entity[/QUOTE] Post as many times as you like, there's nothing wrong with asking for help. scripted_ents.GetList( ) spawns a string indexed table of entities. weapons.GetList( ) returns a numerically indexed table of weapons. So, while scripted_ents.GetList[ "custom_entity" ] will work, weapons.GetList( )[ "weapon_toolgun" ] won't. If you want base info ( for category, base IF it is in the file ) about the swep file you'd use: weapons.Get( "swep_name" ) whereas if you want the full weapons table ( with base merged ) you'd use weapons.GetStored( "swep_name" );
--SNIP, fixed the issue all by myself!
[QUOTE=ROFLBURGER;46737753]I'm a little confused to how adding tables work. I'm basically trying to get who has the highest frags but yeah I don't understand tables. It gives me error messages about the local stats = {v{v:Frags()}} part [lua]function RTScore() local FragsTable = {} for k,v in pairs(player.GetAll()) do local stats = {v{v:Frags()}} table.Add(FragsTable,stats) end PrintTable(table.SortByKey(FragsTable)) end[/lua] Or if there's an easier way of getting the highest frags, let me know please.[/QUOTE] I finally found the kill tracker I wrote in a random folder.. [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_random/manage_mostkills_and_show_at_round_end.lua[/url]
What could be causing that in ttt frame rate is dropping after every round. Example if i start on 120fps after 10 rounds i am down on 30fps.
Sorry, you need to Log In to post a reply to this thread.