• What do you need help with V4
    639 replies, posted
  • Avatar of Hugabuga
  • [QUOTE=thejjokerr;35971604]change [lua]pl:SetModel(Teams[(pl:Team().Model)])[/lua] to [lua]pl:SetModel(Teams[pl:Team()].Model)[/lua][/QUOTE] Ah, thank you. [editline]16th May 2012[/editline] Okay, one more question. If the Loadout is a table, how would I go about giving the person all the weapons from there? This is to give a single weapon [lua]pl:Give(Teams[pl:Team()].Loadout)[/lua] - I'm pretty sure that it's a loop, tho I'm bad at thinking.
  • Avatar of cis.joshb
  • [lua] for k, v in pairs(Teams[pl:Team()].Loadout) do ply:Give(v) end [/lua] EDIT: Didn't tab, written in browser. Also look at dat postcount. [editline]15th May 2012[/editline] Is using PData all the time less efficient than assigning ply.Variable = ply:GetPData("Variable") at the beginning and then setting the PData on DC?
  • Avatar of kp3
  • I've seen other people do all kinds of "spawn-list" looking things, Even inventories should be done in some kind of loop. How are other people doing it since my way isn't working?
  • Avatar of Hugabuga
  • After trying it, it says that the table isn't there [code][@gamemodes\test\gamemode\server\player.lua:9] bad argument #1 to 'pairs' (table expected, got nil)(Hook: PlayerLoadout) [/code]
  • Avatar of cis.joshb
  • Can you do [lua] function MyConCommand(ply, _, args) blah end concommand.Add("blah", MyConCommand) [/lua] as in set cmd to _, in the style of setting k to _ in a for loop. 1k posts.
  • Avatar of Hugabuga
  • Same error. This is how the table structure looks like: [code] 1: Loadout: 1 = weapon_smg1 2 = weapon_crowbar 3 = weapon_crossbow Name = Police Model = models/police.mdl ID = 2 Color: a = 255 b = 200 g = 0 r = 0 Salary = 50 [/code]
  • Avatar of vexx21322
  • Not exactly lua specific, but more programming specific. I remember someone explaining how to get the combined binary flag int and separate all the values. How do I do this? I'm talking about the spawnflags valve uses for entities.
  • Avatar of lexic
  • [QUOTE=cis.joshb;35972543]Can you do [lua] function MyConCommand(ply, _, args) blah end concommand.Add("blah", MyConCommand) [/lua] as in set cmd to _, in the style of setting k to _ in a for loop. 1k posts.[/QUOTE] Variable names are non-compulsory. You can name anything whatever you like. For instance: [lua]datastream.Hook(name, function(who, _, _, _, data) callback(data, who); end);[/lua] _ will be set to the fourth argument's value.
  • Avatar of Hugabuga
  • Maybe the error lays in the function: [lua] function AddTeam(ID, Name, Model, Loadout, JoinMessage, Salary, Color) table.insert(Teams, {ID = ID, Name = Name, Model = Model, {Loadout = Loadout}, JoinMessage = JoinMessage, Salary = Salary, Color = Color}) end [/lua] [editline]16th May 2012[/editline] Fixed it now. The {Loadout = Loadout} should be Loadout = Loadout
  • Avatar of lukiux12
  • Dunno where to post this tbh. Anyways, will try here. I want these props or w/e you can call them to be in game, in a roleplay script and for players to be able to pick it up and use it on their character. How do I do this? Here's the picture showing what props (headgear, actually) talking about: [url]http://cloud.steampowered.com/ugc/596966984492179175/26FD575C42B0F5474430F70844257D6C9C325473/[/url]
  • Avatar of kp3
  • I'm trying to add Stamina to my gamemode. Each time the player presses Jump he loses stamina and if it's below a certain number jumping is disabled for the player until it reaches high enough again. My problem is that I don't know how to check if the player can actually jump, Because right now if I jump and press jump again while being mid air I'll still lose stamina which is kind of dumb. What's the best way of finding out if the player actually can jump?
  • Avatar of PencilOnDesk
  • There's probably a better way to do it but you could assign the player a variable checking whether or not they should lose stamina when they hit their assigned jump key by using the [B][U]OnPlayerHitGround[/U][/B] hook.
  • Avatar of vexx21322
  • [QUOTE=kp3;35980104]I'm trying to add Stamina to my gamemode. Each time the player presses Jump he loses stamina and if it's below a certain number jumping is disabled for the player until it reaches high enough again. My problem is that I don't know how to check if the player can actually jump, Because right now if I jump and press jump again while being mid air I'll still lose stamina which is kind of dumb. What's the best way of finding out if the player actually can jump?[/QUOTE] Do a check with IsOnGround() right when they press the jump key.
  • Avatar of PencilOnDesk
  • [QUOTE=vexx21322;35980482]Do a check with IsOnGround() right when they press the jump key.[/QUOTE] This is probably a lot more efficient than what I suggested.
  • Avatar of kp3
  • [QUOTE=PencilOnDesk;35980380]There's probably a better way to do it but you could assign the player a variable checking whether or not they should lose stamina when they hit their assigned jump key by using the [B][U]OnPlayerHitGround[/U][/B] hook.[/QUOTE] [QUOTE=vexx21322;35980482]Do a check with IsOnGround() right when they press the jump key.[/QUOTE] Thanks, Decided to go with what Vexx wrote because it was easier to incorporate into my code. Had to change it into OnGround though.
  • Avatar of ChrisR
  • Would it be possible to move a viewmodel to a specific position when a swep is deployed? It'd be like putting it in Ironsights, but constantly; I have a viewmodel that looks awkward but looks perfect when I mess around with the ironsight positions, and i can't think of a way to impliment it elsewhere.
  • Avatar of lexic
  • [b][url=maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexf49b.html?title=SWEP.GetViewModelPosition]SWEP.GetViewModelPosition [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] [lua]/*--------------------------------------------------------- Name: GetViewModelPosition Desc: Allows you to re-position the view model ---------------------------------------------------------*/ function SWEP:GetViewModelPosition( pos, ang ) if ( !self.IronSightsPos ) then return pos, ang end local bIron = self.Weapon:GetNetworkedBool( "Ironsights" ) if ( bIron != self.bLastIron ) then self.bLastIron = bIron self.fIronTime = CurTime() if ( bIron ) then self.SwayScale = 0.3 self.BobScale = 0.1 else self.SwayScale = 1.0 self.BobScale = 1.0 end end local fIronTime = self.fIronTime or 0 if ( !bIron && fIronTime < CurTime() - IRONSIGHT_TIME ) then return pos, ang end local Mul = 1.0 if ( fIronTime > CurTime() - IRONSIGHT_TIME ) then Mul = math.Clamp( (CurTime() - fIronTime) / IRONSIGHT_TIME, 0, 1 ) if (!bIron) then Mul = 1 - Mul end end local Offset = self.IronSightsPos if ( self.IronSightsAng ) then ang = ang * 1 ang:RotateAroundAxis( ang:Right(), self.IronSightsAng.x * Mul ) ang:RotateAroundAxis( ang:Up(), self.IronSightsAng.y * Mul ) ang:RotateAroundAxis( ang:Forward(), self.IronSightsAng.z * Mul ) end local Right = ang:Right() local Up = ang:Up() local Forward = ang:Forward() pos = pos + Offset.x * Right * Mul pos = pos + Offset.y * Forward * Mul pos = pos + Offset.z * Up * Mul return pos, ang end[/lua]
  • Avatar of kp3
  • I've been asking a shitload of questions but what would be the best way of creating some sorts of money system? I've read that NWvars are bad. Should I just make a table and umsg the value over whenever I connect / Try to use money? Yet another question, How do I make it so that I can move when my DFrame is open? I thought DermaFrame:SetMouseInputEnabled(true) and DermaFrame:SetKeyboardInputEnabled(true) would do it but it doesn't. Thanks. [QUOTE=Lexic;35983480]For your second question, try putting false instead of true.[/QUOTE] This is the opposite of what I read on the wiki. It worked though, thanks.
  • Avatar of ChrisR
  • [QUOTE=Lexic;35983162][b][url=maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexf49b.html?title=SWEP.GetViewModelPosition]SWEP.GetViewModelPosition [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] [lua]/*--------------------------------------------------------- Name: GetViewModelPosition Desc: Allows you to re-position the view model ---------------------------------------------------------*/ function SWEP:GetViewModelPosition( pos, ang ) if ( !self.IronSightsPos ) then return pos, ang end local bIron = self.Weapon:GetNetworkedBool( "Ironsights" ) if ( bIron != self.bLastIron ) then self.bLastIron = bIron self.fIronTime = CurTime() if ( bIron ) then self.SwayScale = 0.3 self.BobScale = 0.1 else self.SwayScale = 1.0 self.BobScale = 1.0 end end local fIronTime = self.fIronTime or 0 if ( !bIron && fIronTime < CurTime() - IRONSIGHT_TIME ) then return pos, ang end local Mul = 1.0 if ( fIronTime > CurTime() - IRONSIGHT_TIME ) then Mul = math.Clamp( (CurTime() - fIronTime) / IRONSIGHT_TIME, 0, 1 ) if (!bIron) then Mul = 1 - Mul end end local Offset = self.IronSightsPos if ( self.IronSightsAng ) then ang = ang * 1 ang:RotateAroundAxis( ang:Right(), self.IronSightsAng.x * Mul ) ang:RotateAroundAxis( ang:Up(), self.IronSightsAng.y * Mul ) ang:RotateAroundAxis( ang:Forward(), self.IronSightsAng.z * Mul ) end local Right = ang:Right() local Up = ang:Up() local Forward = ang:Forward() pos = pos + Offset.x * Right * Mul pos = pos + Offset.y * Forward * Mul pos = pos + Offset.z * Up * Mul return pos, ang end[/lua][/QUOTE] From what I saw with experimenting with it, it only adjusted the angle. I only want the position itself changed.
  • Avatar of vexx21322
  • [QUOTE=ChrisR;35985046]From what I saw with experimenting with it, it only adjusted the angle. I only want the position itself changed.[/QUOTE] Offset.x/y/z where x/z is moving around the screen and y is moving further/closer to the screen.
  • Avatar of Kogitsune
  • [QUOTE=vexx21322;35973893]Not exactly lua specific, but more programming specific. I remember someone explaining how to get the combined binary flag int and separate all the values. How do I do this? I'm talking about the spawnflags valve uses for entities.[/QUOTE] [code] function SplitBits( mask, max ) local res, i res = { } i = 1 max = max or 1 << 32 repeat if mask & i == i then table.insert( res, i ) end i = i << 1 until i == max return res end [/code] A possible ( untested ) way.
  • Avatar of vexx21322
  • [QUOTE=Kogitsune;35985593][code] function SplitBits( mask, max ) local res, i res = { } i = 1 max = max or 1 << 32 repeat if mask & i == i then table.insert( res, i ) end i = i << 1 until i == max return res end [/code] A possible ( untested ) way.[/QUOTE] Uh, this somehow caused a massive memory leak and almost crashed my computer. Anyways, I had to go read up on bitwise and I understand it for the most part, [del]but I don't understand what mask is.[/del] Oh wait, mask is the number I'm trying to split. I see now. Thanks, this works fine so far.
  • Avatar of lexic
  • [QUOTE=ChrisR;35985046]From what I saw with experimenting with it, it only adjusted the angle. I only want the position itself changed.[/QUOTE] Then you did something wrong I guess. Try [i]pos.x = -pox.x[/i].
  • Avatar of ChrisR
  • [QUOTE=Lexic;35988662]Then you did something wrong I guess. Try [i]pos.x = -pox.x[/i].[/QUOTE] It's not doing anything, and when I use the original code, I get consolespam with this: [lua] [addons\powertan\lua\weapons\weapon_powertan\shared.lua:81] attempt to perform arithmetic on global 'IRONSIGHT_TIME' (a nil value)(Hook: CalcView) [/lua] Does it require the cs_base or can it be used for any base?
  • Avatar of lexic
  • [lua]local IRONSIGHT_TIME = 0.25[/lua] [url=http://glua.me/bin/?path=/addons/counter-strike/lua/weapons/weapon_cs_base/shared.lua]context[/url] You shouldn't just jack code from one place to another though. That sort of thing generally has bad results.
  • Avatar of Doritos_Man
  • Is there any Lua code for formatting text to something like currency? Like from $2000 to $2,000