• What do you need help with? V3
    6,419 replies, posted
I've been working a bit on a gamemode mainly for learning purposes but I've ran into a problem I can't seem to figure out on my own, the problem I have is that the function E.DrawInit won't appear unless I set the alpha (transparency) to 0 of the textures inside the function E.DrawBG(). Before this I used alot of various if statements and functions to call and remove PaintHUD hooks and I had a similiar problem where some functions containing surface.DrawText (for example) would simply disappear randomly as I added new unique PaintHUD hooks, if statements and functions. If anyone could help with explaining what the present issue is or the one I had then I would greatly appreciate it. The overwritten GM:HUDPaint(): [lua] function GM:HUDPaint() E.DebugHUD() E.DrawBG() E.DrawInit() end [/lua] These are the functions: [lua] function E.DrawBG() draw.TexturedQuad { texture = surface.GetTextureID "vgui/bg", color = Color( 255, 255, 255, 255 ), x = ScrW() * 0.0005, y = ScrH() * 0, w = ScrW(), h = ScrH() } draw.TexturedQuad { texture = surface.GetTextureID "vgui/logo", color = Color( 255, 255, 255, 255 ), x = ScrW() / 2 - 512, y = ScrH() / 2 - 704, w = 1024, h = 1024 } end function E.DebugHUD() draw.DrawText( "PRE-ALPHA ".. E.VersionN, E.Font, 0, 0, Color( 200, 200, 200, 255 ), TEXT_ALIGN_LEFT ) end function E.DrawInit() draw.DrawText( "Please wait while Emanation initializes." , E.Font, ScrW() / 2, ScrH() / 2, Color( 200, 200, 200, 255 ), TEXT_ALIGN_CENTER ) end [/lua]
Hey, For my gamemode I want to restrict propspawning for normal users So only premiums and admins can spawn props. premium: ply:GetUserGroup() == "premium" Admin + Superadmin: ply:IsAdmin()
Can someone find whats going wrong here? im getting a strange error! D: Error:[CODE] [ERROR] addons/classic doom/lua/entities/doom_barrel/init.lua:91: attempt to call method 'IsValid' (a nil value) 1. v - addons/classic doom/lua/entities/doom_barrel/init.lua:91 2. unknown - lua/includes/modules/hook.lua:82 [/CODE] Relevant Code: [CODE]function(ent, dmginfo) if inflictor:IsValid() && (inflictor:GetClass() == "doom_barrel") && inflictor.attacker:IsValid() then dmginfo:SetAttacker(inflictor.attacker) end end)[/CODE] I know its supposed to be formatted differently... but what would that look like? The "why your scripts are now broken" page didnt help to much D:
[QUOTE=Zedrux;39084850]I've been working a bit on a gamemode mainly for learning purposes but I've ran into a problem I can't seem to figure out on my own, the problem I have is that the function E.DrawInit won't appear unless I set the alpha (transparency) to 0 of the textures inside the function E.DrawBG(). Before this I used alot of various if statements and functions to call and remove PaintHUD hooks and I had a similiar problem where some functions containing surface.DrawText (for example) would simply disappear randomly as I added new unique PaintHUD hooks, if statements and functions. If anyone could help with explaining what the present issue is or the one I had then I would greatly appreciate it. [/QUOTE] I copy/pasted your code to try it out, substituting your textures with random others I had, and the problem you're experiencing is not occurring for me. With your code my screen is covered with the vgui textures and in the middle is the text from E.DrawInit. Did you mean that you couldn't see E.DebugHUD? Because to fix that you simply just have to run E.DebugHUD [I]after[/I] you run E.DrawBG so it would look like this instead. [lua] function GM:HUDPaint() E.DrawBG() E.DebugHUD() E.DrawInit() end [/lua] [QUOTE=reenesj;39086475]Hey, For my gamemode I want to restrict propspawning for normal users So only premiums and admins can spawn props. premium: ply:GetUserGroup() == "premium" Admin + Superadmin: ply:IsAdmin()[/QUOTE] Something like this? [lua] function GM:PlayerSpawnProp(p,mdl) return ( p:GetUserGroup() == "premium" or p:IsAdmin() ) end [/lua] [QUOTE=triset;39087731]Can someone find whats going wrong here? im getting a strange error! D: Relevant Code: [CODE]function(ent, dmginfo) if inflictor:IsValid() && (inflictor:GetClass() == "doom_barrel") && inflictor.attacker:IsValid() then dmginfo:SetAttacker(inflictor.attacker) end end)[/CODE] I know its supposed to be formatted differently... but what would that look like? The "why your scripts are now broken" page didnt help to much D:[/QUOTE] Is inflictor defined somewhere? Perhaps you meant to use ent instead? [HR][/HR] I have a few problems myself I would like to get some help with. First of all, I can't seem to consistently obtain the SteamID from players when they disconnect. It's like half of the time I get it, half of the time I don't. I've tried using the GM:EntityRemoved hook instead to check for disconnecting players, but it does not help. However, the server I'm using to test this is just a default server created by the game so perhaps it is just screwing up since the server is also shutting down when I disconnect. The second thing is that I've setup an inventory system that saves to the SQLite base, but I'm not sure if it is efficient/optimized as best as it could be. This basically demonstrates how it's setup right now. [table="width: 500, class: grid, align: left"] [tr] [td]SteamID[/td] [td]weapon_shotgun[/td] [td]weapon_357[/td] [td]etc.[/td] [/tr] [tr] [td]STEAM_0:1:17540908[/td] [td]1[/td] [td]0[/td] [td]-[/td] [/tr] [tr] [td]STEAM_0:1:17540909[/td] [td]2[/td] [td]1[/td] [td]-[/td] [/tr] [/table] (there will be a column for every item in the game which will be ~50 when it's done)
[QUOTE=Sparky-Z;39087864]I copy/pasted your code to try it out, substituting your textures with random others I had, and the problem you're experiencing is not occurring for me. With your code my screen is covered with the vgui textures and in the middle is the text from E.DrawInit. Did you mean that you couldn't see E.DebugHUD? Because to fix that you simply just have to run E.DebugHUD [I]after[/I] you run E.DrawBG so it would look like this instead. [lua] function GM:HUDPaint() E.DrawBG() E.DebugHUD() E.DrawInit() end [/lua] [/QUOTE] Yes exactly, I mixed up E.DrawInit with E.DebugHUD. Didn't believe it was gonna be that simple. Thank you.
How would I go along shooting a sprite from a SWEP? :downs: thanks
[QUOTE=Sparky-Z;39087864] I have a few problems myself I would like to get some help with. First of all, I can't seem to consistently obtain the SteamID from players when they disconnect. It's like half of the time I get it, half of the time I don't. I've tried using the GM:EntityRemoved hook instead to check for disconnecting players, but it does not help. However, the server I'm using to test this is just a default server created by the game so perhaps it is just screwing up since the server is also shutting down when I disconnect. The second thing is that I've setup an inventory system that saves to the SQLite base, but I'm not sure if it is efficient/optimized as best as it could be. This basically demonstrates how it's setup right now. [table="width: 500, class: grid, align: left"] [tr] [td]SteamID[/td] [td]weapon_shotgun[/td] [td]weapon_357[/td] [td]etc.[/td] [/tr] [tr] [td]STEAM_0:1:17540908[/td] [td]1[/td] [td]0[/td] [td]-[/td] [/tr] [tr] [td]STEAM_0:1:17540909[/td] [td]2[/td] [td]1[/td] [td]-[/td] [/tr] [/table] (there will be a column for every item in the game which will be ~50 when it's done)[/QUOTE] Just save their inventory when they receive/use/drop/doWhateverWith an item instead of relying on the disconnect hook, I think it's a much safer way.
[QUOTE=brandonj4;39088559]Just save their inventory when they receive/use/drop/doWhateverWith an item instead of relying on the disconnect hook, I think it's a much safer way.[/QUOTE] I'll try that instead, thanks.
Alright, I'm at a loss here, I'm trying to create a crafting system here and I've gotten to the point of where I need to create the command and I just can't seem to figure it out... Can anyone help? Here's all relative things: [lua] --A recipe just for example: local RECIPE = {} RECIPE.Output = "Flashlight" RECIPE.Slots = {"Empty","Empty","Empty","Wood Chunk","Empty","Wood Chunk","Empty","Empty","Empty"} RegisterRecipe(RECIPE) --No problems with this --Here's the command that I can't get past. concommand.Add("grp_craft_item",function(player,cmd,args) local rebuildTbl = {} if args then for k,v in pairs(global_recipes) do if table.IsEqual(v.Slots,args) then for a,b in pairs(args) do if b != "Empty" then if !rebuildTbl[b] then rebuildTbl[b] = 1 else rebuildTbl[b] = rebuildTbl[b] + 1 end end end for a,b in pairs(rebuildTbl) do local i, amt = player:GetInventoryItem(a) local tbl = player:GetItemSlots(a) for c,d in pairs(tbl) do for i = 1, b do player:SetInventoryItem(c,a,amt - 1) break end end end break end end end end) --I know it's terrible, I can't really wrap my head around how to do this(It takes away every single item that matches what's in there, so if I have 3 wood and the recipe uses 2 it will take all 3 wood away) --Oh and for the input that the player sends in, it's sent from here(Client side of crafting.: RunConsoleCommand("grp_craft_item",craftSlots[1],craftSlots[2],craftSlots[3],craftSlots[4],craftSlots[5],craftSlots[6],craftSlots[7],craftSlots[8],craftSlots[9]) [/lua]
I have this weird issue where when its loaded its saying the ent bushalt does not exist and then gives a timer error.? I have added the bushalt folder in the entities folder. This is my main code. [lua]local BusBeginSpawn = { Vector(309, 13559, 90.4), Angle(0, -90, 0) } local BusStopSpawns = { {Vector(-6841.4838, -10456.2119, 71.0312), Angle(0, 0, 0)}, {Vector(-6370, -4671, 72), Angle(0, 0, 0)}, {Vector(-8278, -9024, 74), Angle(0, 180, 0)}, {Vector(-5000, 12435, 185), Angle(0, 180, 0)}, {Vector(875, 13176, 75), Angle(0, 180, 0)}, {Vector(115, 13176, 75), Angle(0, 0, 0)}, {Vector(3792, -6097, 58), Angle(0, 90, 0)}, {Vector(-2639, -995, 68), Angle(0, 90, 0)}, {Vector(387, 5976, 68), Angle(0, 180, 0)}, } local function SpawnBus ( ) local Blah = ents.Create("bushalt"); Blah:SetModel("models/car/bushalt1.mdl") Blah:SetPos(BusBeginSpawn[1]) Blah:SetAngles(BusBeginSpawn[2]) Blah:Spawn() Blah:Activate() for k, v in pairs(BusStopSpawns) do local Blah = ents.Create("bushalt") Blah:SetModel("models/sickness/busstop_01.mdl") Blah:SetPos(v[1]) Blah:SetAngles(v[2]) Blah:Spawn() Blah:Activate() end end; timer.Simple(1, SpawnBus);[/lua] and heres the int or the bushalt ent. [lua]AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) function ENT:Initialize() self.Entity:PhysicsInit(SOLID_VPHYSICS) self.Entity:SetMoveType(MOVETYPE_VPHYSICS) self.Entity:SetSolid(SOLID_VPHYSICS) self.Entity:SetUseType(SIMPLE_USE) if(self.Entity:GetPhysicsObject():IsValid()) then self.Entity:GetPhysicsObject():EnableMotion(false) end end[/lua]
[QUOTE=craigy09;39089986] [lua]timer.Simple(1, SpawnBus);[/lua] [/QUOTE] Welcome to Garry's Mod 13. [lua] timer.Simple(1, function() SpawnBus() end) [/lua] EDIT: Oops. You need to make the SpawnBus function global by removing the 'local' from it's declaration, or copypaste it's code instead of the SpawnBus in the timer. The code I posted above wouldn't work.
How would I go about sending a table with something like this in it {"Superman", "Batman" } to the client using the net library?
How would I go about creating a team mid game by a player? I understand you need to define teams both client and server wide, but how would i get the team list to update for the other clients that are not the one that created it? As of right now I'm creating the team in the cl_init on a button click and then netting the info to the server and creating the team there. Any suggestions would be great.
[QUOTE=prang123;39090351]How would I go about sending a table with something like this in it {"Superman", "Batman" } to the client using the net library?[/QUOTE] Serverside: [lua] util.AddNetworkString("BatmanTable") --Call only once, such as when gamemode initializes. net.Start("BatmanTable") net.WriteTable({"Batman", "Superman"}) -- Now either send to an exact player: net.Send(ply) -- Or send to all clients net.Broadcast() [/lua] Clientside: [lua] net.Receive("BatmanTable", function() local batmantable = net.ReadTable() end) [/lua]
[QUOTE=Sparky-Z;39087864]The second thing is that I've setup an inventory system that saves to the SQLite base, but I'm not sure if it is efficient/optimized as best as it could be. This basically demonstrates how it's setup right now. [table="width: 500, class: grid, align: left"] [tr] [td]SteamID[/td] [td]weapon_shotgun[/td] [td]weapon_357[/td] [td]etc.[/td] [/tr] [tr] [td]STEAM_0:1:17540908[/td] [td]1[/td] [td]0[/td] [td]-[/td] [/tr] [tr] [td]STEAM_0:1:17540909[/td] [td]2[/td] [td]1[/td] [td]-[/td] [/tr] [/table] (there will be a column for every item in the game which will be ~50 when it's done)[/QUOTE] A more efficient way would be to have a table like this. [table="width: 500, class: grid, align: left"] [tr] [td]SteamID[/td] [td]Weapon[/td] [td]Quantity[/td] [/tr] [tr] [td]STEAM_0:1:17540908[/td] [td]weapon_shotgun[/td] [td]1[/td] [/tr] [tr] [td]STEAM_0:1:17540909[/td] [td]weapon_shotgun[/td] [td]2[/td] [/tr] [tr] [td]STEAM_0:1:17540909[/td] [td]weapon_357[/td] [td]1[/td] [/tr] [/table] This means you don't have to modify the table when you add/remove/change a weapon within the gamemode. Your SQL query to lookup what weapons a player owns might look like this (I'm a little rusty on SQL): [code]SELECT Weapon,Quantity FROM `myweapons` WHERE (SteamID='STEAM_0:1:17540908');[/code] [editline]4th January 2013[/editline] [QUOTE=tissue902;39090469]How would I go about creating a team mid game by a player? I understand you need to define teams both client and server wide, but how would i get the team list to update for the other clients that are not the one that created it? As of right now I'm creating the team in the cl_init on a button click and then netting the info to the server and creating the team there. Any suggestions would be great.[/QUOTE] Setup the team serverside as you'd normally do, then use the net library to broadcast the team information to all clients where they'd then setup the team too. [editline]4th January 2013[/editline] [QUOTE=khuba;39090316]Welcome to Garry's Mod 13. [lua] timer.Simple(1, function() SpawnBus() end) [/lua] EDIT: Oops. You need to make the SpawnBus function global by removing the 'local' from it's declaration, or copypaste it's code instead of the SpawnBus in the timer. The code I posted above wouldn't work.[/QUOTE] The timer itself is fine, since SpawnBus has no parameters. The problem is that the entity code is not being loaded for some reason. Check your entity code is in the right place and sits in a folder called "bushalt" and not "busalt" or something.
Is it possible to code a ninja rope in lua? Like you have a swep, and you can shoot a rope at where you are looking. I just can't think of a way do calculate the rope physics and drawing.
Quick question: How to create one Sound.Add entry with multiple sound files? Like rndwave in sound scripts.
I'm getting an annoying little error while setting up my HUD, I've set up a few custom fonts which work nicely (using surface.CreateFont), but whenever I refresh my code and the client reinitializes, it throws up an error that surface is nil, which leads me to believe that at that point surface hasn't been defined yet. Everything works, the fonts show up and stuff, but if I could just get rid of the error that pops up on initialization, that'd be great. I guess my question is, when is "surface" defined?
[QUOTE=Ericson666;39095064]I'm getting an annoying little error while setting up my HUD, I've set up a few custom fonts which work nicely (using surface.CreateFont), but whenever I refresh my code and the client reinitializes, it throws up an error that surface is nil, which leads me to believe that at that point surface hasn't been defined yet. Everything works, the fonts show up and stuff, but if I could just get rid of the error that pops up on initialization, that'd be great. I guess my question is, when is "surface" defined?[/QUOTE] You could put the script into a timer that runs on the next frame. That's what most do.
How can I get a SpawnIcons model onto a variable?when I press it? I tried doing the following: [lua] for _, model in pairs(GModZ.Config[ value .. " Survivor Models"]) do local Icon = vgui.Create( "SpawnIcon") Icon:SetSize( 60, 60 ) Icon:SetModel( model ) Icon:SetToolTip(nil) Icon.DoClick = function( icon ) charmdl = Icon:GetModel() -- GetModel() isn't valid. end [/lua]
[QUOTE=Persious;39097172]How can I get a SpawnIcons model onto a variable?when I press it? I tried doing the following: [lua] for _, model in pairs(GModZ.Config[ value .. " Survivor Models"]) do local Icon = vgui.Create( "SpawnIcon") Icon:SetSize( 60, 60 ) Icon:SetModel( model ) Icon:SetToolTip(nil) Icon.DoClick = function( icon ) charmdl = Icon:GetModel() -- GetModel() isn't valid. end [/lua][/QUOTE] I'm speculating that you should call icon:GetModel() (lower case I).
Oh yeah, my bad, I changed it after. Still the same error tho.
Recently i've been stuck. I've been working on expanding the pikmin mod, after updating it for gmod 13. I found it rather silly that npcs get bombarded with hoardes of pikmin but make NO effort to shoot them. I've been pondering on what sort of function I would need to create so the pikmin are targeted by hostile npcs who are also hostile towards the player. so the code should find the npc realtionships towards the player, and if that relationship is hate, I want the npcs to associate that hate with the pikmin, and hate the pikmin just as much. What would code for something like this look like! D: im so stuck! [IMG]http://cloud-2.steampowered.com/ugc/903235963586926179/3F06280A3806A532F45834FBDEE48504FBDBF434/637x358.resizedimage[/IMG] -the pikmin and enemy npcs
[QUOTE=triset;39097415]Recently i've been stuck. I've been working on expanding the pikmin mod, after updating it for gmod 13. I found it rather silly that npcs get bombarded with hoardes of pikmin but make NO effort to shoot them. I've been pondering on what sort of function I would need to create so the pikmin are targeted by hostile npcs who are also hostile towards the player. so the code should find the npc realtionships towards the player, and if that relationship is hate, I want the npcs to associate that hate with the pikmin, and hate the pikmin just as much. What would code for something like this look like! D: im so stuck! [IMG]http://cloud-2.steampowered.com/ugc/903235963586926179/3F06280A3806A532F45834FBDEE48504FBDBF434/637x358.resizedimage[/IMG] -the pikmin and enemy npcs[/QUOTE] Whenever an NPC is spawned [lua] NPC:AddRelationship("pikmin_entity_here D_HT 999") [/lua] ? Also, the wiki page on player animations says that later on we will be able to "mount" new ones, is there anything similar we can do now short of purely lua based animations (which iirc wouldn't work anymore because of the removeal of buildbonepositions)?
[QUOTE=Persious;39097331]Oh yeah, my bad, I changed it after. Still the same error tho.[/QUOTE] [lua] for _, model in pairs(GModZ.Config[ value .. " Survivor Models"]) do local Icon = vgui.Create( "SpawnIcon") Icon:SetSize( 60, 60 ) Icon:SetModel(model) Icon.Mdl = model Icon:SetToolTip(nil) Icon.DoClick = function(self) charmdl = self.Mdl end end [/lua] ????
[QUOTE=shadowndacorner;39097477]Whenever an NPC is spawned [lua] NPC:AddRelationship("pikmin_entity_here D_HT 999") [/lua] ? Also, the wiki page on player animations says that later on we will be able to "mount" new ones, is there anything similar we can do now short of purely lua based animations (which iirc wouldn't work anymore because of the removeal of buildbonepositions)?[/QUOTE] yes.. I know.. but what would the code for "whenever an npc is spawned add the relationship to the npcs to hate pikmin." look like? with the code you gave me id have to go into every single npcs I have and add that to their relationships.
Is there any way to access an entity's information and tables if they're not spawned? Making a gungame mod, and I want to show the next and previous weapons on the HUD. One of the main things about the gamemode is how you just need to put the weapon's folder w/ the shared.lua in the ents folder, and then put the name of the entity in weapon list. The gamemode handles randomizing and leveling up everyone with no further configuration. If it wasn't for this, I could just write another table with PrintNames and get them with a for loop, but that would require more configuration when it comes to adding/removing weapons, and it'd be a lot easier if I could get to the PrintName that's already in each weapon's shared.lua Now that leads me to the small issue of getting the PrintName from a SWEP for the last/next weapon thing on the HUD. I can send the name of the entity from the weapon list ("gy_m249" for example) easily, but I'd rather have the actual PrintName, not the entity name. [lua]ply:GetActiveWeapon().PrintName[/lua] Using ^that, I can get the current weapon's name, but that's not really helping me with the previous and next weapon's PrintNames. Is there any way that I can look through the tables [URL="http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index0a10.html"](like with this)[/URL] of an entity that isn't currently spawned?
[QUOTE=triset;39097607]yes.. I know.. but what would the code for "whenever an npc is spawned add the relationship to the npcs to hate pikmin." look like? with the code you gave me id have to go into every single npcs I have and add that to their relationships.[/QUOTE] Misread it, thought you said you already had it setting the player to hate. It really depends on how you're making them attack. The easiest method I can think of is by modifying the swep you made to control them and, whenever you tell them to attack, make them hate the player ([b][url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index4efc.html]NPC.AddEntityRelationship [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]) and pikmin (function I already provided). You don't have to set relationships before they spawn, you can do it on the fly.
Reposting a problem I'm having because I really need to fix it soon: [CODE]matPlayer = Material("models/humans/male/group01/citizen_sheet") matPlayer:SetTexture("$basetexture", Material("models/player/uniform"):GetTexture("$basetexture"))[/CODE] It's suppose to swap out the default player model texture for a custom one, but it doesn't (no errors too).
[QUOTE=karolisoz;39098397]Reposting a problem I'm having because I really need to fix it soon: [CODE]matPlayer = Material("models/humans/male/group01/citizen_sheet") matPlayer:SetTexture("$basetexture", Material("models/player/uniform"):GetTexture("$basetexture"))[/CODE] It's suppose to swap out the default player model texture for a custom one, but it doesn't (no errors too).[/QUOTE] Put a print function (print("CHANGING MATERIALS") or something) where you're doing that to make sure the code is actually running. [editline]January 4 2013[/editline] Actually, it should be SetMaterialTexture, not SetTexture. Ex. [lua] oldMaterial:SetMaterialTexture("$basetexture", GetHandsTexture(model):GetMaterialTexture("$basetexture")) [/lua]
Sorry, you need to Log In to post a reply to this thread.