• Problems That Don't Need Their Own Thread v2.0
    5,020 replies, posted
[QUOTE=Mrcreeper72;46549492]Ok So I mada function to tell me if it is invalid or valid: [CODE]function CheckValid(entity) if IsValid(entity) == true then print("entity Is Valid") else print("entity Is Invalid") end end[/CODE] and it returned invalid for ply, I have the ply = findMetaTable("Player") at the top why is it invalid?[/QUOTE] IsValid() already exists, which is why I said it :p
[QUOTE=Exho;46549504]IsValid() already exists, which is why I said it :p[/QUOTE] Yea but what do I do about it?
Okay first off change ply to plymeta or anything else just so you and I both know that this is a meta table and not a player entity (as I thought). Secondly you dont need to redeclare "id" as local each time, do it once in that block of code and just type "id = whatever". Now check IsValid(ply) either in your meta function or before you call it because your problem lies that you are trying to call a function on a nil entity. And I am pretty sure you just use "self" inside a metatable function. Oh and Willox, I want this to be openable in Notepad because this contains HUD code that people should copy
Ok so I did what you told me but Im getting that plyMeta is invalid still just in case here's my code, the mysql connect details are changed for obvious reasons. [CODE]local plyMeta = FindMetaTable("Player") require("mysqloo") -- requires the mysqloo database local db = mysqloo.connect("1234", "1234", "1234", "1234", 1234) -- custom function gives messages which show us its from database.lua local oldPrint = print local function print(i) oldPrint("Database: " .. tostring(i)) end -- Gets Called When it connects to the Database function connectDatabase() db:connect() end -- Gets the database's Version function getDatabaseInfo() print("Database Version " .. tostring(db:serverVersion())) print("Host Info " .. tostring(db:hostInfo())) end -- Calls when connected succesfully function db:onConnected() print("Connected Succesfully") getDatabaseInfo() queryTest() plyMeta:checkDatabase() end -- Calls when the connection fails function db:onConnectionFailed(err) print("Connection Failed") print("error") print(err) end --Tests the database by sending a query function queryTest() local q = db:query("SELECT * FROM wojserve_GmodServer1.WojBuildServer") -- local q = db:query("SELECT * FROM wojserve_GmodServer1.WojBuildServer WHERE EXISTS (SELECT * From WojBuildServer WHERE SteamID = 1234)") function q:onSuccess(data) print("Test Query Was Successful") -- PrintMessage(HUD_PRINTTALK, tostring(PrintTable(data))) PrintTable(data) end function q:onError(err, sql) print("Test Querry Errored") print(sql) print(err) end q:start() end function CheckValid(entity) if IsValid(entity) == true then print("entity Is Valid") else print("entity Is Invalid") end end -- get the short steam Id of the joining player function plyMeta:ShortSteamID() local id = self:SteamID() local id = tostring(id) local id = string.Replace(id, "STEAM_0:0:", "") local id = string.Replace(id, "STEAM_1:1:", "") local id = string.Replace(id, "STEAM_0:1:", "") local id = string.Replace(id, "STEAM_1:0:", "") return id end function Query(sql, callback) local q = db:query( sql ) function q:onSuccess( data ) callback( data ) end function q:onError( err ) if db:status() == mysqloo.DATABASE_NOT_CONNECTED then db:connect() return end print( "Query Errored, error:", err, " sql: ", sql ) end end function plyMeta:checkDatabase() local id = plyMeta:ShortSteamID() local q = db:query("SELECT * FROM 1234 WHERE EXISTS (SELECT * From 1234 WHERE SteamID = " .. id .. ")") if q == true then print(data) print("User Exists In Database") elseif q == false then print("User Does Not Exist In Database") else print("query Errored") end end[/CODE]
[QUOTE=Exho;46549735]Okay first off change ply to plymeta or anything else just so you and I both know that this is a meta table and not a player entity (as I thought). Secondly you dont need to redeclare "id" as local each time, do it once in that block of code and just type "id = whatever". Now check IsValid(ply) either in your meta function or before you call it because your problem lies that you are trying to call a function on a nil entity. And I am pretty sure you just use "self" inside a metatable function. Oh and Willox, I want this to be openable in Notepad because this contains HUD code that people should copy[/QUOTE] Use "\r\n" for your newlines then. Alternatively, using file.Open without the "b" binary flag and writing to the returned file object will possibly work.
[QUOTE=Willox;46549881]Use "\r\n" for your newlines then. Alternatively, using file.Open without the "b" binary flag and writing to the returned file object will possibly work.[/QUOTE] \r\n works :D
First time messing with my own materials, but it just wont work... [t]http://i.imgur.com/9cN8glS.png[/t] [lua] resource.AddFile("materials/hitmarker.vtf") [/lua] [lua] surface.SetDrawColor(0,0,0) surface.SetTexture(surface.GetTextureID("hitmarker")) surface.DrawTexturedRect(ScrW()/2, ScrH()/2, 100, 100) [/lua] [t]http://i.imgur.com/TmkJCyz.png[/t]
Use local _mat = Material( "hitmarker" ); -- extension doesn't matter unless png or so ( pngs make good materials ), set this OUTSIDE your drawing hook. Then use surface.SetMaterial( _mat ) instead of SetTexture.
It's still purple and black :tinfoil: [lua] local Hitmarker = Material("hitmarker") hook.Add( "HUDPaint", "Polygon Madness", function() surface.SetDrawColor(0,0,0) surface.SetMaterial(Hitmarker) surface.DrawTexturedRect(ScrW()/2-50, ScrH()/2-50, 100, 100) [/lua]
If you just downloaded it, you may need to restart garrysmod ( or if you dropped it in the gmod folder while it was running ). Additionally, set the draw color to color_white.
[QUOTE=Acecool;46550840]If you just downloaded it, you may need to restart garrysmod ( or if you dropped it in the gmod folder while it was running ). Additionally, set the draw color to color_white.[/QUOTE] It is still purple and black :suicide:
How does [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/SetAvoidPlayers]Player:SetAvoidPlayers[/url] work? Can I use it for things that aren't players (emulating CS:S's prop_physics_multiplayer behavior)?
Whats the best way to make an xp system? Should I use the Player meta table + networked integers + PData for saving (I have no idea for sql and such) or is there another way that's good?
Does anyone use [url=http://wiki.garrysmod.com/page/render/RedownloadAllLightmaps]render.RedownloadAllLightmaps[/url] and does it work for you? I'm changing the sun in a custom map of mine with the input FadeToPattern and it works great, but I can't get any of the static props to update. I thought that's what render.RedownloadAllLightmaps was for, but I could be wrong?
[QUOTE=Author.;46550967]It is still purple and black :suicide:[/QUOTE] Link me to the file? If the vmt / vtf files don't correspond with each other then it'll stay purple / black. Basically, the text file needs to link to the texture if you use it ( it isn't required in all cases, but png would be better to use ) Here's an example of one of mine: [code]"LightmappedGeneric" { "$basetexture" "acrp/asphalt/roadquad_v2" "$seamless_scale" "1.0" "$surfaceprop" "Rock" "$surfaceprop2" "Gravel" } [/code] [QUOTE=_Entity;46551004]Whats the best way to make an xp system? Should I use the Player meta table + networked integers + PData for saving (I have no idea for sql and such) or is there another way that's good?[/QUOTE] The "best" way? It depends on your definition. You can set one up using SQLite and it'll work with no problems. Setting up Meta-Table functions will always help make things easier in terms of adding xp / updating, but you should probably set up your own meta-table ( [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/classes/class_tutorial.lua.html[/url] / [url]https://bitbucket.org/Acecool/acecooldev_base/src/master/gamemode/shared/classes/networking/class_lrecipientfilter_sv.lua?at=master[/url] ) and save data using SteamID. If you set up the base functions to use SteamID, you can set up the player meta-table functions to call the xp meta-table with the player steamid as an argument ( doing it this way will allow you to read / save / update xp for players whose objects are no longer valid [ disconnected before saving happens for example ] ) The xp "meta-table" doesn't even need to be a meta-table, it could simply be a table of functions ( no need to create a new instance for each player ): [url]https://bitbucket.org/Acecool/acecooldev_base/src/master/gamemode/shared/classes/class_data.lua?at=master[/url] Also, if you use SQLite to store data, I'd recommend rewriting the queries in Set/GetPData because converting from that data form is terrible!!! Example ( If you want to convert to MySQL in the future, you will need to grab the data, and split it up because it is stored as such: <uniqueid>[<column_name>] || <data> where || splits the column-name from column-data in row ): [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/database/converting_sv_db_to_mysql.lua.html[/url] You can always use SQLite Manager, a Firefox plugin, to browse the SV.DB though, converting is annoying and it wouldn't be too hard to rewrite the SQL to save data differently. [QUOTE=BlackAwps;46551007]Does anyone use [url=http://wiki.garrysmod.com/page/render/RedownloadAllLightmaps]render.RedownloadAllLightmaps[/url] and does it work for you? I'm changing the sun in a custom map of mine with the input FadeToPattern and it works great, but I can't get any of the static props to update. I thought that's what render.RedownloadAllLightmaps was for, but I could be wrong?[/QUOTE] Yeah, one of my friends says he got it to work by calling render.RedownloadLightmaps as the client is joining, but I haven't gotten it to work. I use a fog trick to make the static objects look darker and ignore render.RedownloadAllLightmaps ( especially because it causes a stutter from 100 - 1000 ms ).
Lets say I have a sent. The sent when it exists spawns a prop. When the entity is deleted or undone, how would I go about deleting the prop? My idea right now consists of finding a way to determine when the sent is removed and using that to know when to delete the prop.
In my hitmarker.vmt, I had "hitmarkert" and not "hitmarker"... :suicide:
[QUOTE=TheMrFailz;46551260]Lets say I have a sent. The sent when it exists spawns a prop. When the entity is deleted or undone, how would I go about deleting the prop? My idea right now consists of finding a way to determine when the sent is removed and using that to know when to delete the prop.[/QUOTE] You can add a function that gets executed when the prop is deleted. I'd recommend also setting up a table ( self.SpawnedProps = { }; ) or whatever inside of the ENT Initialize function. Any time you spawn a prop inside the ENT, do table.insert( self.SpawnedProps, _ent ) where _ent is the local _ent = ents.Create( ... ); Then, in your on remove function, do: [code]for k, v in pairs( self.SpawnedProps ) do SafeRemoveEntity( v ); end[/code] so it'd look something like: [code]function ENT:Initialize( ) // ... Other code for the Entity... // Vars self.SpawnedProps = { }; // On Remove, kill props... self:CallOnRemove( "MyOnRemove" .. self:EntIndex( ), function( ) for k, v in pairs( self.SpawnedProps ) do SafeRemoveEntity( v ); end end ); end function ENT:AddProp( ) local _ent = ents.Create( "example" ); if ( !IsValid( _ent ) ) then error( "_ent wasn't created..." ); end _ent:SetPos( vector_origin ); _ent:SetAngles( angle_zero ); _ent:Spawn( ); _ent:Activate( ); table.insert( self.SpawnedProps, _ent ); end[/code] Edit: With comments: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/entities/on_remove_remove_spawned_props.lua.html[/url] [editline]22nd November 2014[/editline] [QUOTE=Author.;46551291]In my hitmarker.vmt, I had "hitmarkert" and not "hitmarker"... :suicide:[/QUOTE] That'll do it :-) I find it easier in most cases to use a png, also a vmt isn't always required ( mainly used if alternate settings, or additional settings are needed ).
[QUOTE=Acecool;46551316]:words:[/QUOTE] The table.insert bit keeps claiming that I'm giving it a bad argument. (It claims I give NIL as an argument when it's actually: [code]table.insert(self.SpawnedProps, ent1 );[/code] And yes, I defined the spawned props table with [code]self.SpawnedProps = { };[/code] No idea why it's doing this. EDIT: Fixed! Just replace- [code]table.insert(self.SpawnedProps, ent1 );[/code] with [code]table.insert(self.SpawnedProps, 0, ent1 );[/code] Edit: Ok well that didn't work at all. (Accidentally had a duplicate spawnedprops table directly in the ent creation function. After removing... It's broken again.)
[QUOTE=TheMrFailz;46551473]The table.insert bit keeps claiming that I'm giving it a bad argument. (It claims I give NIL as an argument when it's actually: [code]table.insert(self.SpawnedProps, ent1 );[/code] And yes, I defined the spawned props table with [code]self.SpawnedProps = { };[/code] No idea why it's doing this.[/QUOTE] Because ent1 is nil. Show the complete code.
Ok here we go: [code]function ENT:Initialize() self:SetModel( "models/props_combine/combine_mine01.mdl" ) self.Entity:SetHealth( 50 ) self:PhysicsInit( SOLID_VPHYSICS ) self:SetMoveType( MOVETYPE_VPHYSICS ) self:SetSolid( SOLID_VPHYSICS ) self.Entity:shieldbuild() local phys = self:GetPhysicsObject() if (phys:IsValid()) then phys:Wake() phys:SetMass( 100000 ) end self.SpawnedProps = { }; self:CallOnRemove( "MyOnRemove" .. self:EntIndex(), function( ) for k, v in pairs( self.SpawnedProps ) do SafeRemoveEntity( v ); end end ); end function ENT:shieldbuild() self.Entity:EmitSound ("vo/aperture_ai/05_part1_entry-2.wav"); if (!SERVER) then return end; local ent1 = ents.Create ("prop_physics"); ent1pos = Vector(self.Entity:GetPos().x, self.Entity:GetPos().y, (self.Entity:GetPos().z + 10)) ent1:SetPos (self.Entity:GetPos()); ent1:SetModel("models/props_combine/combine_lock01.mdl") ent1:SetSolid( SOLID_NONE ) local angle1 = Angle( 0, 0, 0) ent1:SetAngles (angle1); ent1:Spawn(); ent1:Activate( ); constraint.Weld( self, ent1, 0, 0, 0, false, false) table.insert(self.SpawnedProps, 0, ent1 ); end[/code] I probably did something stupid. That's the relevant code anyway.
How can you make it so a DLabel scales depending on Screen Res
[lua] pnl:SetSize( ScrW() * (0-1), ScrH() * (0-1) ) [/lua] Basicly replace 0-1 with decimals of 0. For example, 0.5 is half of the screen, etc. If you make it fit using that method, it will look the same on other resolutions.
Problem: Im Trying to open a Derma with a key bind after many attempts and failing, i hope someone can help me! [LUA] include("shared.lua") function set_team() local Ready = vgui.Create( "DFrame" ) Ready:Center() Ready:SetSize( 400, 150 ) Ready:SetTitle( "Welcome to Firestorm, Choose your team!" ) Ready:SetVisible( true ) Ready:SetDraggable( true ) Ready:ShowCloseButton( true ) Ready:MakePopup() local ready1 = vgui.Create( "DButton", Ready ) ready1:SetPos( 20, 25 ) ready1:SetSize( 140, 40 ) ready1:SetText( "Team Red" ) ready1.DoClick = function() local Data = {["Team"]=0} net.Start("FS_ChangeTeam") net.WriteTable(Data) net.SendToServer() Ready:SetVisible( false ) end local ready2 = vgui.Create( "DButton", Ready ) ready2:SetPos( 20, 70 ) ready2:SetSize( 140, 40 ) ready2:SetText( "Team Blue" ) ready2.DoClick = function() local Data = {["Team"]=1} net.Start("FS_ChangeTeam") net.WriteTable(Data) net.SendToServer() Ready:SetVisible( false ) end end hook.Add( "Initialize", "Teamselect", set_team) [/LUA]
Server: [code] util.AddNetworkString("OpenMyMenu") hook.Add("ShowSpare1", "NetTheMenu", function(ply) net.Start("OpenMyMenu") net.Send(ply) --Only open it on the player who presses f3 end) [/code] clientside: [code] net.Receive("OpenMyMenu", set_team) [/code] Im not too sure on binding it to the H key for example since I've never tried it [editline]23rd November 2014[/editline] [QUOTE=Author.;46551824][lua] pnl:SetSize( ScrW() * (0-1), ScrH() * (0-1) ) [/lua] Basicly replace 0-1 with decimals of 0. For example, 0.5 is half of the screen, etc. If you make it fit using that method, it will look the same on other resolutions.[/QUOTE] Didn't work. I need it so it changes size on different resolutions because the DLabel text is too big when I change for instance down to 1280 x 600 because it stayed the same size.
Well what is your code?
[QUOTE=Author.;46552538]Well what is your code?[/QUOTE] [code] local TicketPrice = vgui.Create("DLabel", LuckFrame) TicketPrice:SetPos(LuckFrame:GetWide() /3.2, LuckFrame:GetTall() /5 ) TicketPrice:SetSize(ScrW() * (0.5), ScrH() * (0.5) ) -- what i was changing TicketPrice:SetText("Ticket Price: "..config.ticketPrice) TicketPrice:SetTextColor(Color(0,0,0)) TicketPrice:SetFont("pl_font") [/code] if i change the height it only moves it and if I change the width it doesn't really do anything
[QUOTE=_Entity;46552595][code] local TicketPrice = vgui.Create("DLabel", LuckFrame) TicketPrice:SetPos(LuckFrame:GetWide() /3.2, LuckFrame:GetTall() /5 ) TicketPrice:SetSize(ScrW() * (0.5), ScrH() * (0.5) ) -- what i was changing TicketPrice:SetText("Ticket Price: "..config.ticketPrice) TicketPrice:SetTextColor(Color(0,0,0)) TicketPrice:SetFont("pl_font") [/code] if i change the height it only moves it and if I change the width it doesn't really do anything[/QUOTE] Take a look at this: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/understanding_hardcoding_of_screensizes.lua.html[/url] [editline]23rd November 2014[/editline] [QUOTE=TheMrFailz;46551654]Ok here we go: [code]function ENT:Initialize() self:SetModel( "models/props_combine/combine_mine01.mdl" ) self.Entity:SetHealth( 50 ) self:PhysicsInit( SOLID_VPHYSICS ) self:SetMoveType( MOVETYPE_VPHYSICS ) self:SetSolid( SOLID_VPHYSICS ) self.Entity:shieldbuild() local phys = self:GetPhysicsObject() if (phys:IsValid()) then phys:Wake() phys:SetMass( 100000 ) end self.SpawnedProps = { }; self:CallOnRemove( "MyOnRemove" .. self:EntIndex(), function( ) for k, v in pairs( self.SpawnedProps ) do SafeRemoveEntity( v ); end end ); end function ENT:shieldbuild() self.Entity:EmitSound ("vo/aperture_ai/05_part1_entry-2.wav"); if (!SERVER) then return end; local ent1 = ents.Create ("prop_physics"); ent1pos = Vector(self.Entity:GetPos().x, self.Entity:GetPos().y, (self.Entity:GetPos().z + 10)) ent1:SetPos (self.Entity:GetPos()); ent1:SetModel("models/props_combine/combine_lock01.mdl") ent1:SetSolid( SOLID_NONE ) local angle1 = Angle( 0, 0, 0) ent1:SetAngles (angle1); ent1:Spawn(); ent1:Activate( ); constraint.Weld( self, ent1, 0, 0, 0, false, false) table.insert(self.SpawnedProps, 0, ent1 ); end[/code] I probably did something stupid. That's the relevant code anyway.[/QUOTE] A few things I'm seeing. self.Entity is deprecated, use self. When you create another entity within an entity, or regardless of where, you should add an IsValid check right after because it may be possible that the entity class doesn't exist, or ent limit is reached. Why is ent1pos a global? [code]local _ent = ents.Create( "blah" ); if ( !IsValid( _ent ) ) then return; end ... [/code] For your table.insert, it has 2 args, you're just inserting 0 over and over. Instead of this: [code]ent1pos = Vector(self.Entity:GetPos().x, self.Entity:GetPos().y, (self.Entity:GetPos().z + 10))[/code] You can do:[code]local ent1pos = self:LocalToWorld( Vector( 0, 0, 10 ) );[/code] which increases readability, but it doesn't seem like you use it at all...
You can also divide the ScrW/ScrH with numbers. For example, ScrW() / 2 gives half of the screen. [editline]23rd November 2014[/editline] [QUOTE=Acecool;46553340]Take a look at this: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/understanding_hardcoding_of_screensizes.lua.html[/url][/QUOTE] Thank god, I was actually trying to make a formula that did this right this moment. (I am doing some hardcore Polygon UI, where this is the first time I'm using polygons) [editline]23rd November 2014[/editline] Turned them into functions if interested: [lua] function SizeW(width) local screenwidth = 1280 return width*ScrW()/screenwidth end function SizeH(height) local screenheight = 600 return height*ScrH()/screenheight end function SizeWH(width, height) local screenwidth = 1280 local screenheight = 600 return width*ScrW()/screenwidth, height*ScrH()/screenheight end [/lua] [editline]23rd November 2014[/editline] Only reminaing problem is the font sizes.. any good solutions here?
[QUOTE=Acecool;46553340]Take a look at this: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/understanding_hardcoding_of_screensizes.lua.html[/url] [editline]23rd November 2014[/editline] Instead of this: [code]ent1pos = Vector(self.Entity:GetPos().x, self.Entity:GetPos().y, (self.Entity:GetPos().z + 10))[/code] *You can do:[code]local ent1pos = self:LocalToWorld( Vector( 0, 0, 10 ) );[/code] which increases readability, but it doesn't seem like you use it at all...[/QUOTE] *Just started getting the thing together and forgot to set the pos to the ent1pos. Realized that immediately after posting. Also, I fixed the global ent pos bit. Will report back with how fixing it all up went. edit: And god I wish entities auto updated when their lua code was changed like with sweps and what not. It gets annoying when you have to wait 30 seconds to a minute for an entity reload because you need to make a tiny change. Edit: Woo it works. Thanks Ace.
Sorry, you need to Log In to post a reply to this thread.