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]
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=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.
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
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]
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?
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=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.
[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.
-never mind, I'm late-
[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.
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.
[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]
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.
For your second question, try putting false instead of true.
[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.
[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.
[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.
[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.
[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].
[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?
[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.
anyone have any experience when compiling modules for Mac?
Is there any Lua code for formatting text to something like currency?
Like from $2000 to $2,000
[QUOTE=Doritos_Man;35997933]Is there any Lua code for formatting text to something like currency?
Like from $2000 to $2,000[/QUOTE]
[lua]function util.FormatNumber( n )
if (!n or type(n) != "number") then
return 0
end
if n >= 1e14 then return tostring(n) end
n = tostring(n)
sep = sep or ","
local dp = string.find(n, "%.") or #n+1
for i=dp-4, 1, -3 do
n = n:sub(1, i) .. sep .. n:sub(i+1)
end
return n
end[/lua]
Not sure who wrote it, I usually put credits in (raBBish?)
usage is
util.FormatNumber( 500000 )
output 500,000
There's not a really good way to do it and get locale support, but something like
[code]function string.ToCurrency( str )
local z, out, i, q
z, out = str:match( "([^%.]+)(%.%d+)$" )
i = 0
repeat
i = i + 1
q = z:sub( #z, #z )
z = z:sub( 1, #z - 1 )
out = q .. out
if i == 3 and #z > 0 then
out = "," .. out
i = 0
end
until #z == 0
return out
end[/code]
Eh, ninja'd. It's what I get for walking away mid post.
[QUOTE=Banana Lord.;35997973][lua]function util.FormatNumber( n )
if (!n or type(n) != "number") then
return 0
end
if n >= 1e14 then return tostring(n) end
n = tostring(n)
sep = sep or ","
local dp = string.find(n, "%.") or #n+1
for i=dp-4, 1, -3 do
n = n:sub(1, i) .. sep .. n:sub(i+1)
end
return n
end[/lua]
Not sure who wrote it, I usually put credits in (raBBish?)
usage is
util.FormatNumber( 500000 )
output 500,000[/QUOTE]
Thanks, that worked quite nicely.
[QUOTE=Lexic;35989839][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.[/QUOTE]
I know.
I don't need ironsights, though. I just used it as an example. I just want the viewmodel in one certain position at all times.
[lua]function DrawWaypoints()
if(#waypoints == 0)then return end
for i, v in pairs(waypoints) do
cam.Start3D2D(v, Angle(0, 0, 0), 1 )
draw.RoundedBox(8, 0, 0, 64, 64, Color(55,55,55,200))
draw.DrawText(tostring(i), "ScoreboardText", 0, 0, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER )
cam.End3D2D()
end
end
hook.Add("HUDPaint", "DrawWaypoints", DrawWaypoints)
[/lua]
Earlier I've done table.insert(waypoints, ply:GetPos()) and the coords are valid.
But that won't draw, and I simply don't get why. :/ I've also tried with render.DrawBeam, but that apparently couldn't be done outside an entity(?).
I'm just trying to create a way to visually see where the waypoints are, and ideally imply where the next waypoint is. Any input as to why this isn't working? There's no errors, I simply can't see it in game.