• Problems That Don't Need Their Own Thread v5
    4,111 replies, posted
[QUOTE=thejjokerr;52257643]I'd put the active trade panel in a property of the localplayer and route all net messages through that panel so practically all business logic is in the panel.[/QUOTE] Thank you, don't know how I didn't think of storing the panel on the player earlier
I can't seem to draw a texture over my editable panel I have made. I'm capturing a renderview which causes a little lag (stuttering for a fraction of a second), its probably not the best way to take a picture of an NPC's eye view but it works. Anyhow I've tried surface.DrawTexturedRect Panel:DrawTexturedRect and draw.TexturedQuad and none of them seem to work I want to overlay the panel with a material and get rid of it 5 seconds later along with the panel. The problem is it just seems to not want to draw, or it does draw but behind the panel, ive tried a timer.simple as well. [url]https://pastebin.com/qcMBDCmh[/url]
-snip-
Is there a simpler way to get only the 2nd value returned by [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/string/find]string.find[/url]? I'm currently doing this [lua]local var, var = string.find( "idk some string", "some st" ) var = var + 1 -- I need to use the 2nd value returned + 1[/lua]
[QUOTE=JasonMan34;52261182]Is there a simpler way to get only the 2nd value returned by [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/string/find]string.find[/url]? I'm currently doing this [lua]local var, var = string.find( "idk some string", "some st" ) var = var + 1 -- I need to use the 2nd value returned + 1[/lua][/QUOTE] select(2, string.find( "idk some string", "some st" ))
How does [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/CheckPassword]GM:CheckPassword[/url] work? Seems like it's not waiting for http.Fetch before returning [lua]local hours = 50000 -- Just for testing hook.Add( "CheckPassword", "KickForPlayTime", function( SteamID64 ) local shouldConnect = true http.Fetch( "http://steamcommunity.com/profiles/" .. SteamID64 .. "/?xml=1", function( body, size, headers, code ) local Table = string.Split( body, "\n" ) for k, v in ipairs( Table ) do if string.find( v, "GarrysMod" ) then local start = select( 2, string.find( Table[k-1], "<hoursOnRecord>" ) ) + 1 local End = string.find( Table[k-1], "</hoursOnRecord>" ) - 1 local time = tonumber( string.Replace( string.sub(Table[k-1],start,End), ",", "" ) ) if time < hours then shouldConnect = false break end end end end ) print( shouldConnect ) timer.Simple( 1, function() print( shouldConnect ) end ) return shouldConnect, "You must have at least " .. hours .. " hours on record to play on this server" end )[/lua] [t]https://image.prntscr.com/image/8fc0b1b8586a4c27bc5729b442f268c8.png[/t] [QUOTE=Coffeee;52261358]No hooks/anything will wait for asynchronous functions to finish[/QUOTE] Well shit, [DEL]guess I'll have to use PlayerInitialSpawn[/DEL] [QUOTE=bigdogmat;52261375]I'd suggest using [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/game/KickID]game.KickID[/url] inside the callback as then you don't have to wait until they spawn to kick them.[/QUOTE] Thanks! That's exactly what I was looking for
[QUOTE=JasonMan34;52261325]How does [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/CheckPassword]GM:CheckPassword[/url] work? Seems like it's not waiting for http.Fetch before returning [lua]local hours = 50000 -- Just for testing hook.Add( "CheckPassword", "KickForPlayTime", function( SteamID64 ) local shouldConnect = true http.Fetch( "http://steamcommunity.com/profiles/" .. SteamID64 .. "/?xml=1", function( body, size, headers, code ) local Table = string.Split( body, "\n" ) for k, v in ipairs( Table ) do if string.find( v, "GarrysMod" ) then local start = select( 2, string.find( Table[k-1], "<hoursOnRecord>" ) ) + 1 local End = string.find( Table[k-1], "</hoursOnRecord>" ) - 1 local time = tonumber( string.Replace( string.sub(Table[k-1],start,End), ",", "" ) ) if time < hours then shouldConnect = false break end end end end ) print( shouldConnect ) timer.Simple( 1, function() print( shouldConnect ) end ) return shouldConnect, "You must have at least " .. hours .. " hours on record to play on this server" end )[/lua] [t]https://image.prntscr.com/image/8fc0b1b8586a4c27bc5729b442f268c8.png[/t][/QUOTE] No hooks/anything will wait for asynchronous functions to finish
What are the main drawbacks of not using the steam ID as a primary key in a SQL database? EDIT: For example if I wanted to use the player's ID primary key as a foreign key in my item table wouldn't using steamID as primary key ruin this concept and actually make queries bigger?
[QUOTE=JasonMan34;52261325]How does [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/CheckPassword]GM:CheckPassword[/url] work? Seems like it's not waiting for http.Fetch before returning :snip: [t]https://image.prntscr.com/image/8fc0b1b8586a4c27bc5729b442f268c8.png[/t][/QUOTE] The entire reason [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/http/Fetch]http.Fetch[/url] uses a callback function is so it doesn't wait for the request to finish before returning. If it did wait, it'd halt the entire server until the request was finished. You're either going to have to figure out another way to disallow them to connect, or you're gonna have to find an http module that's halting. I'd suggest using [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/game/KickID]game.KickID[/url] inside the callback as then you don't have to wait until they spawn to kick them. Edit: Ninja'd [editline]22nd May 2017[/editline] [QUOTE=bilbasio;52261372]What are the main drawbacks of not using the steam ID as a primary key in a SQL database?[/QUOTE] The point of using a primary key is that it uniquely identifies the row, alongside this it also indexes the row which improves performance when using it with `where`, `join`, etc, etc. Other than what I've already said I couldn't say more without knowing the structure of your table.
Here's my table structure: [code] Query("CREATE TABLE items (ID int(20) NOT NULL AUTO_INCREMENT, steamid varchar(32), itemid int(20), quantity int(20), PRIMARY KEY(ID))") Query("CREATE TABLE players (ID int(10) NOT NULL AUTO_INCREMENT, steamid varchar(32), steamname varchar(32), name varchar(40), money int(10), rank int(1), playtime int(20), inventory varchar(100), PRIMARY KEY(ID))")[/code] I think main problem is in the items table since every time there's an item manipulation it updates the table and has to use the huge steam ID on every query. So my thinking is that I should put the player's primary key into the item table to reduce query size. As for the player's table, is there a way to directly access the row using the primary key kind of like lua does? Kind of like players[steamid] but in SQL?
[QUOTE=bilbasio;52261414]Here's my table structure: [code] Query("CREATE TABLE items (ID int(20) NOT NULL AUTO_INCREMENT, steamid varchar(32), itemid int(20), quantity int(20), PRIMARY KEY(ID))") Query("CREATE TABLE players (ID int(10) NOT NULL AUTO_INCREMENT, steamid varchar(32), steamname varchar(32), name varchar(40), money int(10), rank int(1), playtime int(20), inventory varchar(100), PRIMARY KEY(ID))")[/code] I think main problem is in the items table since every time there's an item manipulation it updates the table and has to use the huge steam ID on every query. So my thinking is that I should put the player's primary key into the item table to reduce query size. As for the player's table, is there a way to directly access the row using the primary key kind of like lua does? Kind of like players[steamid] but in SQL?[/QUOTE] Use SteamID64 as your identifying key for players and inventories. Using the STEAM_A:B:C format is grossly larger and inefficient. If you use SteamID64, just use the datatype of BIGINT unsigned. Saves you quite a bit of bytes on your tables, and the smaller your primary keys, the faster your indexing is. Definitely look at the data types for the rest of your columns too. You seem to not be aware of the other variations available.
[QUOTE=Revenge282;52261447]Use SteamID64 as your identifying key for players and inventories. Using the STEAM_A:B:C format is grossly larger and inefficient. If you use SteamID64, just use the datatype of BIGINT unsigned. Saves you quite a bit of bytes on your tables, and the smaller your primary keys, the faster your indexing is. Definitely look at the data types for the rest of your columns too. You seem to not be aware of the other variations available.[/QUOTE] Thank you, originally I went to with SteamID but I've since changed for SteamID64. I'll also look into other data types. My real question is how would I go about linking the player's table to the item table for faster queries. Could I create a auto increment ID field in the player's table and store it in the item's table and use that to lower the size of item's queries?
[QUOTE=Revenge282;52261447]Use SteamID64 as your identifying key for players and inventories. Using the STEAM_A:B:C format is grossly larger and inefficient. If you use SteamID64, just use the datatype of BIGINT unsigned. Saves you quite a bit of bytes on your tables, and the smaller your primary keys, the faster your indexing is. Definitely look at the data types for the rest of your columns too. You seem to not be aware of the other variations available.[/QUOTE] Or you can use AccountID and only have to use 32 bits.
[QUOTE=code_gs;52261477]Or you can use AccountID and only have to use 32 bits.[/QUOTE] I keep forgetting about that one, but it also has to be converted to be used outside of the database really, and that's a pain. At least 64 applicable to steam community stuff and steam auth. [editline]22nd May 2017[/editline] [QUOTE=bilbasio;52261471]Thank you, originally I went to with SteamID but I've since changed for SteamID64. I'll also look into other data types. My real question is how would I go about linking the player's table to the item table for faster queries. Could I create a auto increment ID field in the player's table and store it in the item's table and use that to lower the size of item's queries?[/QUOTE] I don't get why you're obsessing over "size". You should use 64 as your key in the player table and in the inventory table you should use 64 and the item ID as the key.
[QUOTE=Revenge282;52261531]I keep forgetting about that one, but it also has to be converted to be used outside of the database really, and that's a pain. At least 64 applicable to steam community stuff and steam auth. [editline]22nd May 2017[/editline] I don't get why you're obsessing over "size". You should use 64 as your key in the player table and in the inventory table you should use 64 and the item ID as the key.[/QUOTE] I thought you could only have 1 primary key? And item ID as primary key wouldn't since it's not unique wouldn't it. As for size, if I give an item to a player, it creates a new row in the item table with his steamID which I guess make queries bigger? Whereas I could possibly put a uniqueID in relation to the player's table?
[QUOTE=bilbasio;52261562]I thought you could only have 1 primary key? And item ID as primary key wouldn't since it's not unique wouldn't it. As for size, if I give an item to a player, it creates a new row in the item table with his steamID which I guess make queries bigger? Whereas I could possibly put a uniqueID in relation to the player's table?[/QUOTE] You can have only one primary key, but you can have multiple columns in a key. In your case, you can only have one player with a specific SteamID64, so in your players table, we identify the primary key as SteamID64. In the inventory table, you can have multiple instances of a SteamID64, since a player can have more than one item. You can also have multiple instances of an item ID since more than one player can have an apple (just an example). But one player can only have one item (or a "stack" of items in your case, since you use a quantity column), so we can make the primary key SteamID64 and item ID. This ensure that a player can have only one instance of each item stack. You would need a combined primary key in your inventory table either way, no matter what your player primary key is.
[QUOTE=Revenge282;52261732]You can have only one primary key, but you can have multiple columns in a key. In your case, you can only have one player with a specific SteamID64, so in your players table, we identify the primary key as SteamID64. In the inventory table, you can have multiple instances of a SteamID64, since a player can have more than one item. You can also have multiple instances of an item ID since more than one player can have an apple (just an example). But one player can only have one item (or a "stack" of items in your case, since you use a quantity column), so we can make the primary key SteamID64 and item ID. This ensure that a player can have only one instance of each item stack. You would need a combined primary key in your inventory table either way, no matter what your player primary key is.[/QUOTE] Alright that makes sense thank you for taking the time to answer my questions.
snip-
Is [B]table.remove( Table, Key )[/B] the same as [B]Table[Key] = nil[/B] ?
[QUOTE=JasonMan34;52264355]Is [B]table.remove( Table, Key )[/B] the same as [B]Table[Key] = nil[/B] ?[/QUOTE] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/table/remove]table.remove[/url] can't remove a string key. It also attempts to shift down any elements above the one you're removing, e.g. [code] local t = {1, 2, 3, 4} table.remove(t, 2) -- `t` is now {1, 3, 4} [/code]
It's table.remove( Table, [B]Index[/B] ), and it's different in that it shifts every index as described on the wiki page [editline]23rd May 2017[/editline] ninja'd
Is it possible to edit the Garry's Mod prop limit message? "You've hit the Prop limit".
[QUOTE=TheCrankyGuy;52264623]Is it possible to edit the Garry's Mod prop limit message? "You've hit the Prop limit".[/QUOTE] Probably just override that to keep it from showing, then make your own.
[QUOTE=TheCrankyGuy;52264623]Is it possible to edit the Garry's Mod prop limit message? "You've hit the Prop limit".[/QUOTE] You could override this hook: [URL]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/gamemodes/sandbox/gamemode/cl_init.lua#L32[/URL] Keep in mind that overriding a hook might break other addons that depend on the hook being triggered
[QUOTE=JasonMan34;52264355]Is [B]table.remove( Table, Key )[/B] the same as [B]Table[Key] = nil[/B] ?[/QUOTE] Answer has been posted twice already, but I just wanted to mention that I prefer the official Lua reference/manual when it comes to built-in functions and libraries. [url=https://www.lua.org/manual/5.1/manual.html#pdf-table.remove]table.remove[/url]: [quote]table.remove (table [, pos]) Removes from table the element at position pos, shifting down other elements to close the space, if necessary. Returns the value of the removed element. The default value for pos is n, where n is the length of the table, so that a call table.remove(t) removes the last element of table t.[/quote]
i got these errors in my custom gamemode how to fix? [ERROR] gamemodes/metro_online/gamemode/init.lua:26: ')' expected near '"models/player/Group03/female_02.mdl"' 1. unknown - gamemodes/metro_online/gamemode/init.lua:0 Couldn't Load Init Script: 'metro_online/gamemode/init.lua' AddCSLuaFile( "shared.lua" ) AddCSLuaFile( "cl_init.lua" ) include( "shared.lua" ) local open = false function GM:PlayerSpawn( ply ) self.BaseClass:PlayerSpawn( ply ) ply:SetGravity ( 0.75 ) ply:SetMaxHealth( 100, true ) ply:SetWalkSpeed( 325 ) ply:SetRunSpeed ( 325 ) ply:Give( "weapon_fists" ) end function GM:PlayerSetModel( ply ) ply:SetModel("models/player/Group03/female_01.mdl") end function GM:PlayerCanSeePlayersChat( text, teamOnly, listener, speaker ) local dist = listener:GetPos():Distance ( speaker:GetPos() ) if ( dist <= 400 ) then return true end end function GM:PlayerCanHearPlayersVoice( listener, speaker ) return( listener:GetPos():Distance( speaker:GetPos() ) < 400) end
Im looking for a good gamemode base. Anyone know one?
[QUOTE=RasmusG5;52267816]i got these errors in my custom gamemode how to fix? [ERROR] gamemodes/metro_online/gamemode/init.lua:26: ')' expected near '"models/player/Group03/female_02.mdl"' 1. unknown - gamemodes/metro_online/gamemode/init.lua:0 Couldn't Load Init Script: 'metro_online/gamemode/init.lua' AddCSLuaFile( "shared.lua" ) AddCSLuaFile( "cl_init.lua" ) include( "shared.lua" ) local open = false function GM:PlayerSpawn( ply ) self.BaseClass:PlayerSpawn( ply ) ply:SetGravity ( 0.75 ) ply:SetMaxHealth( 100, true ) ply:SetWalkSpeed( 325 ) ply:SetRunSpeed ( 325 ) ply:Give( "weapon_fists" ) end function GM:PlayerSetModel( ply ) ply:SetModel("models/player/Group03/female_01.mdl") end function GM:PlayerCanSeePlayersChat( text, teamOnly, listener, speaker ) local dist = listener:GetPos():Distance ( speaker:GetPos() ) if ( dist <= 400 ) then return true end end function GM:PlayerCanHearPlayersVoice( listener, speaker ) return( listener:GetPos():Distance( speaker:GetPos() ) < 400) end[/QUOTE] First, use [lua] tags. Second, the code looks fine, but it's obviously not the source of the error. The error lists "female_02" but the code has only "female_01". Either you gave us the wrong version of the code/error, or another addon with broken code is being loaded instead of the code you have. garrysmod/addons/<name>/gamemodes/metro_online/gamemode/init.lua, if it exists (for any <name>), will be loaded instead of garrysmod/gamemodes/metro_online/gamemode/init.lua.
Yooo, Two items ( martyrdom and Energyshield, both passive items ) are carrying on through rounds in TTT, when they should disappear on round end/round start. Anyone have an ideas?
[QUOTE=Caaiin;52268352]Yooo, Two items ( martyrdom and Energyshield, both passive items ) are carrying on through rounds in TTT, when they should disappear on round end/round start. Anyone have an ideas?[/QUOTE] TTT strips all of your weapons when a new round starts, then gives you the loadout weapons. Either they're loadout, or somewhere in the code there's a [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/Give]Player:Give[/url] that gives the weapon to the player
Sorry, you need to Log In to post a reply to this thread.