• Problems That Don't Need Their Own Thread v3.0
    5,003 replies, posted
Does anybody know how to set the world model's bodygroups on a SWEP? I'm using RCS. I made a thread about this but I just got ratings and no actual responses so I guess it doesn't actually need its own thread.
[QUOTE=Shadico;48061011]Does anybody know how to set the world model's bodygroups on a SWEP? I'm using RCS. I made a thread about this but I just got ratings and no actual responses so I guess it doesn't actually need its own thread.[/QUOTE] [code]self:GetModel():SetBodyGroup()[/code] or [code]self.Owner:GetActiveWeapon():GetModel():SetBodyGroup()[/code] :v: GetModel() on a weapon always returns the world model, so yah that should work fine.
[QUOTE=A Fghtr Pilot;48060968]Don't use v.PrintName(it would work totally fine but there is no need to), use Weapon:GetPrintName(). [editline]26th June 2015[/editline] Here's a nice bump:[/QUOTE] That doesn't work because I'm not dealing with an actual weapon, I'm dealing with the weapons table. My problem is that I have both values, but dlang:AddChoice only picks up the first one.
-snip, moved to a thread-
[QUOTE=B10H4Z4RD;48061188]That doesn't work because I'm not dealing with an actual weapon, I'm dealing with the weapons table. My problem is that I have both values, but dlang:AddChoice only picks up the first one.[/QUOTE] I don't know if I'm right, but since weapons.GetList() returns ALL SWEPs in the game, you might be iterating through SWEPs that don't have that variable ClassName set up. Or you might not have put the variable in the SWEP code(if the SWEP you run into while iterating through the table has the variable) shared. EDIT: Okay, apparently weapons.GetList() shows the classname of the weapon. My bad!
[QUOTE=A Fghtr Pilot;48061106][code]self:GetModel():SetBodyGroup()[/code] or [code]self.Owner:GetActiveWeapon():GetModel():SetBodyGroup()[/code] :v: GetModel() on a weapon always returns the world model, so yah that should work fine.[/QUOTE] Using both of those caused this error: [code][ERROR] addons/nutscript 1.1/lua/weapons/nut_akmmod1.lua:509: attempt to index a string value with bad key ('SetBodyGroup' is not part of the string library) 1. error - [C]:-1 2. __index - lua/includes/extensions/string.lua:310 3. unknown - addons/nutscript 1.1/lua/weapons/nut_akmmod1.lua:509 4. SelectWeapon - [C]:-1 5. unknown - gamemodes/sandbox/gamemode/commands.lua:699 6. unknown - lua/includes/modules/concommand.lua:54 [/code] It isn't RCS, as a SWEP I made with swep_base also had that problem.
[QUOTE=Kogitsune;48060037] [code] net.WriteInt( n:EntIndex( ), 16 ) index = net.ReadInt( 16 ) Entity( index )[/code][/QUOTE] why don't you just use [url=https://github.com/garrynewman/garrysmod/blob/ead2b4d7f05681e577935fef657d4a4d962091e6/garrysmod/lua/includes/extensions/net.lua#L50]net.WriteEntity[/url] and just see if index is 0? doesn't make much of a difference but it's less code to write
[QUOTE=A Fghtr Pilot;48061106] GetModel() on a weapon always returns the world model, so yah that should work fine.[/QUOTE] Is this sarcasm? You're aware that GetModel returns a string containing the path of the entity's model, right?
[QUOTE=PortalGod;48061874]why don't you just use [url=https://github.com/garrynewman/garrysmod/blob/ead2b4d7f05681e577935fef657d4a4d962091e6/garrysmod/lua/includes/extensions/net.lua#L50]net.WriteEntity[/url] and just see if index is 0? doesn't make much of a difference but it's less code to write[/QUOTE] Because I didn't think of that :(
-snip-
How would I go making a bullet tracer similar to the Machina's in Team Fortress 2? Don't need code, just indications on which hooks and functions I should use.
You'd create an effect and set the .Tracer property of the bullet to that. Check out [url=https://github.com/garrynewman/garrysmod/blob/master/garrysmod/gamemodes/base/entities/effects/tooltracer.lua]ToolTracer[/url] to see how to do it. You'd need to just adjust how long it lasts and change your material, really.
Help, noone's helping and I don't know what to do [url]http://facepunch.com/showthread.php?t=1473185&p=48065711#post48065711[/url] :tinfoil:
[QUOTE=A Fghtr Pilot;48066744]Help, noone's helping and I don't know what to do [url]http://facepunch.com/showthread.php?t=1473185&p=48065711#post48065711[/url] :tinfoil:[/QUOTE] "Problems That Don't Need Their Own Thread" [B]Makes own thread anyway[/B]
did awesomium/youtube update? i can't seem to play hd content in-game anymore...
Can someone edit this so that during the event there is one player they can play the round as a RUNNER? With the "do we need death" and dr_min_players (cvar set to 1) it sets the player as a death and repeatedly respawns the player and causes a buffer overflow on the client. I am lost on this, and our community coder is too busy IRL now to help with coding. [lua] ROUND_WAITING = 0 ROUND_PREPARING = 1 ROUND_ACTIVE = 2 ROUND_ENDING = 3 SetGlobalInt( "Deathrun_RoundPhase", ROUND_WAITING ) SetGlobalInt( "Deathrun_RoundTime", 0 ) local minplayers = CreateConVar( "dr_min_players", 2, FCVAR_ARCHIVE ) ] function GM:SetRoundTime( time ) return SetGlobalInt( "Deathrun_RoundTime", CurTime() + (tonumber(time or 5) or 5) ) end CreateConVar( "dr_death_rate", 0.25, FCVAR_ARCHIVE ) CreateConVar( "dr_death_max", 6, FCVAR_ARCHIVE ) function GM:DoWeNeedDeath() local rate = math.Clamp( GetConVarNumber( "dr_death_rate" ), 0.1, 0.9 ) local plys = #player.GetAll() local md = math.max( GetConVarNumber("dr_death_max"), 2 ) local num = #team.GetPlayers(TEAM_DEATH) local need = math.floor(math.Clamp( plys * rate, 1, md )) if num >= need then return false end return true end function GM:SortPlayers( freezePlayers ) local pool = {} for k, v in pairs( player.GetAll() ) do if v:Team() == TEAM_DEATH then pool[#pool+1] = v end v:SetTeam(TEAM_SPECTATOR) end local pool2 = {} for k, v in RandomPairs( player.GetAll() ) do local need = self:DoWeNeedDeath() local stop = false if need then if not table.HasValue(pool, v) then v:SetTeam(TEAM_DEATH) else pool2[#pool2+1] = v stop = true end else v:SetTeam(TEAM_RUNNER) end if not stop then v:Spawn() end end if #pool2 > 2 then for k, v in RandomPairs( pool2 ) do if not IsValid(v) then continue end local need = self:DoWeNeedDeath() if need then v:SetTeam(TEAM_DEATH) v:PrintMessage( HUD_PRINTCONSOLE, "Sorry! We need more deaths." ) else v:SetTeam(TEAM_RUNNER) end v:Spawn() end end if freezePlayers then for k, v in pairs( player.GetAll() ) do v:Freeze(true) end end end local RTVoted = false local ShowRounds = CreateConVar( "dr_notify_rounds_left", "1", FCVAR_ARCHIVE ) GM.RoundFunctions = { [ROUND_WAITING] = function( gm ) gm:NotifyAll( "Invite your friends to play! We can't start without more people!" ) gm:SetRoundTime( 0 ) end, [ROUND_PREPARING] = function( gm ) game.CleanUpMap() gm:SetRoundTime( 5 ) gm:SortPlayers( true ) local rounds = math.max(GetGlobalInt( "dr_rounds_left", 1 ), 0) if rounds > 0 and ShowRounds:GetInt() == 1 then gm:NotifyAll( "The map will change in "..rounds.." rounds." ) end end, [ROUND_ACTIVE] = function( gm ) gm:SetRoundTime( GetConVarNumber( "dr_roundtime_seconds" ) or 300 ) for k, v in pairs( player.GetAll() ) do v:Freeze(false) gm:PlayerLoadout( v ) end gm:NotifyAll( "The round has started!" ) end, [ROUND_ENDING] = function( gm, winner ) gm:SetRoundTime( 5 ) gm:NotifyAll( winner == 123 and "Time is up!" or team.GetName(winner).."s have won!" ) local rounds = math.max(GetGlobalInt( "dr_rounds_left", 1 ) - 1, 0) SetGlobalInt( "dr_rounds_left", rounds ) if rounds <= 1 and not RTVoted then RTV.Start() RTVoted = true end end, } function GM:SetRound( round, ... ) if not self.RoundFunctions[round] then return end local args = {...} SetGlobalInt( "Deathrun_RoundPhase", round ) self.RoundFunctions[round]( self, unpack(args) ) hook.Call( "OnRoundSet", self, round, unpack(args) ) end function GetRoundState() return GetGlobalInt( "Deathrun_RoundPhase" ) end local function GetAlivePlayersFromTeam( t ) local pool = {} for k, v in pairs( team.GetPlayers(t) ) do if v:Alive() then pool[#pool+1] = v end end return pool end local HasDoneCheck = false GM.ThinkRoundFunctions = { [ROUND_WAITING] = function( gm ) if #player.GetAll() < minplayers:GetInt() then return end gm:SetRound( ROUND_PREPARING ) end, [ROUND_PREPARING] = function( gm ) if gm:GetRoundTime() <= 0 then gm:SetRound( ROUND_ACTIVE ) end end, [ROUND_ACTIVE] = function( gm ) local time = gm:GetRoundTime() if time <= 0 then gm:SetRound( ROUND_ENDING, 123 ) return elseif not HasDoneCheck and time <= GetConVarNumber( "dr_roundtime_seconds" )*0.5 then HasDoneCheck = true for k, v in pairs( player.GetAll() ) do if v:Alive() and not v._HasPressedKey then v._HasPressedKey = true v:Kill() PrintMessage( HUD_PRINTTALK, "Automatically killed "..v:Nick().." for being AFK." ) end end end local numa = #GetAlivePlayersFromTeam( TEAM_RUNNER ) local numb = #GetAlivePlayersFromTeam( TEAM_DEATH ) if numa == 0 then gm:SetRound( ROUND_ENDING, TEAM_DEATH ) elseif numb == 0 then gm:SetRound( ROUND_ENDING, TEAM_RUNNER ) end end, [ROUND_ENDING] = function( gm ) if gm:GetRoundTime() <= 0 then gm:SetRound( ROUND_PREPARING ) return end end, } function GM:RoundThink() local cur = self:GetRound() if cur != ROUND_WAITING then if #player.GetAll() < 2 then self:SetRound(ROUND_WAITING) return end end if self.ThinkRoundFunctions[cur] then self.ThinkRoundFunctions[cur]( self ) end end [/lua]
Does anyone know how i could prevent the user from turning their view to the left or right, but maintaining up and down?
[QUOTE=101kl;48069591]Does anyone know how i could prevent the user from turning their view to the left or right, but maintaining up and down?[/QUOTE] I haven't used this before, but it sounds like this would do. [url]http://wiki.garrysmod.com/page/CUserCmd/SetMouseX[/url]
[QUOTE=man with hat;48069751]I haven't used this before, but it sounds like this would do. [URL]http://wiki.garrysmod.com/page/CUserCmd/SetMouseX[/URL][/QUOTE] Thanks, but found a better way to do what i wanted. Question two: local pos = ent:GetPos()ent:SetPos(Vector(pos.x+50, pos.y, pos.z)) This sets the vector x axis to be + 50 but it is not relative to where the entity already was. How do you you alter the vector of an entity to be altered relative to it's angle? (ex: forward + 50) I have tried [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/Entity/GetForward"]Entity:GetForward[/URL] but that did not seem to work. [B][edit][/B] Solved. Turns out the entity was trying to manipulate did not have it's pos set initially.
If anyone can help me with this: [code] local tbl = {"FirstString!","Another String!","Yet another!"} local bah = {} print(tbl[1]) print(tbl[2]) print(tbl[3]) bah[tbl[1]][tbl[2]] = tbl[3] -- < I Need help with this bit, I don't want to use table.insert -- IS it even possible? PrintTable(bah) [/code] Is it possible for bah to be [code] FirstString!: Another String! = Yet another! [/code] ? Edit: I dont want to [u]Overwrite[/u] what was already in the table of bah[tbl[1]], Just to add tbl[2] = tbl[3] into it Edit2: FIXED, by making sure bah[tbl[1]] was a table.
Would anyone know how I would go about splitting up a string into smaller strings? I know about string.Explode( " ", lastsaid) But if I was to type !kick "aaa bbb" Would return a table with { "!kick", ""aaa", "bbb""} But I need it to return {"!kick", "aaa bbb"} Any ideas?
[QUOTE=bigdogmat;48070138]Would anyone know how I would go about splitting up a string into smaller strings? I know about string.Explode( " ", lastsaid) But if I was to type !kick "aaa bbb" Would return a table with { "!kick", ""aaa", "bbb""} But I need it to return {"!kick", "aaa bbb"} Any ideas?[/QUOTE] Explode by quotation marks? If not, pattern matching would do the job.
[QUOTE=bigdogmat;48070138]Would anyone know how I would go about splitting up a string into smaller strings? [/QUOTE] You're close. [lua] string.Explode( "!kick", string) [/lua] Will return {"", "aaa bbb"}
[QUOTE=101kl;48070240]You're close. string.Explode( "!kick", string) Will return {"", "aaa bbb"}[/QUOTE] I was just using !kick "aaa bbb" as an example, I'm going to use more than one string in the command which is why I needed to get every string out of it. So if I type !ban "name name" "reason reason" , I could get a table with { "!ban", "name name", "reason reason"} [QUOTE=Revenge282;48070152]Explode by quotation marks? If not, pattern matching would do the job.[/QUOTE] Tried that and it returned something that would take a bit of work to make look right because of how it would split it. And I kinda knew I would have to use pattern matching but I have no idea how I would for what I want.
Since it's been 2 days, I'll repost my question again encase some people missed it [QUOTE=smithy285;48054573]Is there anyway to stop the player animations when a player runs/walks? I am setting a gesture on the player but the running/walking animations seem to overwrite it and cause the hands to go inside the body and strange stuff[/QUOTE] Thanks
[QUOTE=bigdogmat;48070321]I was just using !kick "aaa bbb" as an example, I'm going to use more than one string in the command which is why I needed to get every string out of it. So if I type !ban "name name" "reason reason" , I could get a table with { "!ban", "name name", "reason reason"} Tried that and it returned something that would take a bit of work to make look right because of how it would split it. And I kinda knew I would have to use pattern matching but I have no idea how I would for what I want.[/QUOTE] [lua] function string.Tokenize(str) local res, word = {}, {} local quot, esc for ch in str:Trim():gmatch(".") do -- in quoted segment? if quot then if esc or (ch ~= '"' and ch ~= "\\") then word[#word + 1] = ch esc = false elseif ch == "\\" then esc = true else -- end of quoted segment -- don't check if #word>0. it was quoted on purpose. res[#res + 1], word = table.concat(word), {} quot = false end elseif ch == '"' then -- beginning of quoted segment if #word > 0 then res[#res + 1], word = table.concat(word), {} end quot = true elseif ch == " " then -- break between arguments if #word > 0 then res[#res + 1], word = table.concat(word), {} end else word[#word + 1] = ch end end if #word > 0 then res[#res + 1] = table.concat(word) end return res end [/lua] [code]> table.Print(string.Tokenize([[!kick "bob \"pineapple\" dole" 0 "that ones for hawaii"]])) 1 = "!kick", 2 = "bob "pineapple" dole", 3 = "0", 4 = "that ones for hawaii"[/code] string.find might be better, but I haven't benchmarked that.
[QUOTE]If I wanted to draw a renderview on the player's viewmodel, would I need to use cam.Start2D or cam.Start2D3D? edit: Ok what I'm actually doing is drawing on a texture that's on the player's viewmodel. I guess I need Start2D then?[/QUOTE] Ugggh this is infuriating. Basically I'm replacing a texture on a viewmodel with a rendertarget and drawing a renderview in said rendertarget. The problem is that that the rendertarget is completely ignoring everything I do to it.* [code] function SWEP:DrawHud() -- Note there is other crap in here but it's irrelevant to this. if CLIENT then self.RenderTarget = GetRenderTarget( "ssf_dynam_scope_1", ScrW(), ScrH(), false ) local mat mat = Material( "models/weapons/v_models/snip_awp/v_awp_scope" ) mat:SetTexture( "$basetexture", self.RenderTarget ) end end function SWEP:ViewModelDrawn( ) -- And before you ask: Yes, this was originally from http://facepunch.com/showthread.php?t=1079050 (the last post) local old old = render.GetRenderTarget( ) render.SetRenderTarget( self.RenderTarget ) render.SetViewPort( 0, 0, 64, 64 ) render.Clear( 255, 255, 255, 255, true ) local viewstats = {} viewstats.angles = self.Owner:EyeAngles() viewstats.origin = self.Owner:EyePos() viewstats.x = 0 viewstats.y = 0 viewstats.w = ScrW() viewstats.h = ScrH() viewstats.drawhud = false viewstats.drawviewmodel = false viewstats.fov = 45 cam.Start2D() -- Note: I know for a fact that the surface draw color is not doing anything. I've tried other colors and it always comes back black. surface.SetDrawColor( color_black ) surface.DrawRect( 0, 00, 64, 7 ) surface.DrawRect( 0, 57, 64, 7 ) render.RenderView(viewstats) cam.End2D() render.SetRenderTarget( old ) render.SetViewPort( 0, 0, ScrW( ), ScrH( ) ) end [/code] edit: * And as a result is just replacing the texture with solid black. I know my renderview is working because I can draw it straight to my screen no problem.
[QUOTE=MatureGamersNetwork;48067431]Can someone edit this so that during the event there is one player they can play the round as a RUNNER? With the "do we need death" and dr_min_players (cvar set to 1) it sets the player as a death and repeatedly respawns the player and causes a buffer overflow on the client. I am lost on this, and our community coder is too busy IRL now to help with coding. [/QUOTE] If I've understood you correctly try changing your DoWeNeedDeath function: [lua] function GM:DoWeNeedDeath() local rate = math.Clamp( GetConVarNumber( "dr_death_rate" ), 0.1, 0.9 ) local plys = #player.GetAll() -- Insert this line below if plys == 1 then return false end local md = math.max( GetConVarNumber("dr_death_max"), 2 ) local num = #team.GetPlayers(TEAM_DEATH) local need = math.floor(math.Clamp( plys * rate, 1, md )) if num >= need then return false end return true end [/lua] For the second part of your question if it keeps ending the round with one player you may need to edit the think round function for ROUND_ACTIVE: [lua] [ROUND_ACTIVE] = function( gm ) -- snip -- Guarding the block in this if statement will stop it running when there's only 1 player if #player.GetAll() > 1 then local numa = #GetAlivePlayersFromTeam( TEAM_RUNNER ) local numb = #GetAlivePlayersFromTeam( TEAM_DEATH ) if numa == 0 then gm:SetRound( ROUND_ENDING, TEAM_DEATH ) elseif numb == 0 then gm:SetRound( ROUND_ENDING, TEAM_RUNNER ) end end end [/lua]
What's the best way to block the undoing of props? I'm creating an undo as such: [lua] undo.Create( "ent" ) undo.AddEntity( ent ) undo.AddFunction( function( tab, arg2 ) -- Give cash back etc end ) undo.SetPlayer( ply ) undo.Finish() [/lua] This works, however upon using the hook OnUndo it's not being called at all (client side). [lua] hook.Add( "OnUndo", "plyremovedprop", function(name) print(name .. " Removed!") end ) [/lua] Another issue is that if a prop is removed with the remover tool, you can still undo a non existent entity. Is it possible to access the undo table at all?
Anyone know how to create a weapon entity that can't be picked up by players? Like, you know how when you create a SWEP, there's an entity with the same class name as it that is instantly picked up upon a player walking over it? Yeah, I want to prevent the "instant pick up upon walking over it" thing. This is the code I'm using right now(using it on a nextbot): [code]function ENT:GiveWeapon(wep) local att = "anim_attachment_RH" local shootpos = self:GetAttachment(self:LookupAttachment(att)) local wep = ents.Create(wep) wep:SetOwner(self) wep:SetPos(shootpos.Pos) wep:Spawn() wep:SetSolid(SOLID_NONE) wep:SetParent(self) wep:Fire("setparentattachment", "anim_attachment_RH") wep:AddEffects(EF_BONEMERGE) wep:SetAngles(self:GetForward():Angle()) Weap = wep end [/code]
Sorry, you need to Log In to post a reply to this thread.