It does works shared but usually the physics object is only initialized serverside.
When I try to use my for num,item (replacement vars for k,v), I get this error when trying to preform math on num
[lua]
[ERROR] <0:0:58178275|Flex><flex_npc_shop.lua>:116: bad argument #1 to '__mul' (string expected, got number)
[/lua]
[lua]
for num,item in pairs(FBoxTestItems) do
local itemtab = vgui.Create("DPanel",buytab)
itemtab:SetSize(buytab:GetWide()-26,100)
itemtab:SetPos(0,(105*num)-105)
function itemtab.Paint()
draw.RoundedBoxEx(4,0,0,itemtab:GetWide(),itemtab:GetTall()/2,Color(237,237,237),true,true,false,false)
draw.RoundedBoxEx(4,0,itemtab:GetTall()/2,itemtab:GetWide(),itemtab:GetTall()/2,Color(217,217,217),false,false,true,true)
end
[/lua]
If I try to tonumber(num), it gives me "tried to preform arithmetic on nil"
do print(num,item) and see whether num is a number at all, which I suspect it isn't.
[QUOTE=Robotboy655;46419679]do print(num,item) and see whether num is a number at all, which I suspect it isn't.[/QUOTE]
It's not, cause I was using this for my item info table
[lua]
local FBoxTestItems = {}
FBoxTestItems.Melon = {
name = "Melon",
desc = "Your standard food item.",
price = 50,
model = "models/props_junk/watermelon01.mdl",
class = "item_fbox_melon"
}
[/lua]
So it just prints out Melon and then the table ID. Welp, time to find another workaround.
Probably a dumb question, but I'm very bad with string manipulation. I have my hook all rigged up on the clientside using chat. What I'm looking for is how I would make it where I could use colorcodes in it. When someone types something like [red] it replaced is with Color(255,0,0) to be used in the chat.AddText function. That and how would I make it loop through every word/every letter to do it unlimited times so you could have a dozen different colors in one message.
I'm trying to make an entity do a 2D orbit. at a set height (Z)
Circle math isn't my thing, but this is what I've got :P
This is what im doing, the movement works, alothough it's pretty rubberbandy until it gets into a nice circle (rubber bands as it hits the path).
If you've got better ideas for the movement, i'd appreciate it.
The Angle is more my issue, this seemed to work but then just goes random, it seems to sometimes try and align itself but is pretty horrible at it.
[lua]function ENT:GetVecPos( Rad , Deg , Height ) -- This func returns the vector coord's around the circle at a radius of "Rad" and "Deg" degrees around the circle. Height being the height :P
X = Rad * math.sin( math.rad( Deg ) )
Y = Rad * math.cos( math.rad( Deg ) )
return Vector( X , Y , Height or self:GetPos().z )
end
function ENT:PhysicsSimulate( phys, deltatime )
self.Speed = self.Speed or 20
self.ZTarget = self.ZTarget or 50
self.OrbitCenter = self.OrbitCenter or Vector( 0 , 0 , 0 )
self.OrbitSize = self.OrbitSize or 100
phys:Wake()
local SelfAng = phys:GetAngles()
local SelfAddForce = Vector( 0 , 0 , 0 )
local SelfAngForce = Vector( 0 , 0 , 0 )
self.TargetAngles = Angle( 0 , 135 , 0 )
local AngleDiff = ( self.TargetAngles - SelfAng )
AngleDiff.yaw = ( ( CurTime() * -self.Speed) + 20 - SelfAng.yaw )
AngleDiff:Normalize()
local Torque = Vector( 0 , 0 , 0 )
local TempAxis = Vector( 0 , 1 , 0 )
TempAxis:Rotate( Angle( SelfAng.yaw , 0 , 0 ) )
Torque = Torque + TempAxis * AngleDiff.roll * 30
TempAxis:Rotate( Angle( 90 , 0 , 0 ) )
Torque = Torque + TempAxis * AngleDiff.pitch * 30
TempAxis:Rotate( Angle( 0 , 0 , 90 ) )
Torque = Torque + TempAxis * AngleDiff.yaw * 50
SelfAngForce = SelfAngForce + ( Torque - phys:GetAngleVelocity() * 50 )
local TargetPos = self.OrbitCenter + self:GetVecPos( self.OrbitSize , CurTime() * 20 , 0 )
local Distance = TargetPos:Distance( phys:GetPos() )
local SelfAddForce = ( Vector(0,0,1) * ( ( self.ZTarget - self:GetPos().z ) / 2 ) * phys:GetMass() * 0.05 ) / 2
local Linear = ( TargetPos - phys:GetPos() ) / 3 * 1 + SelfAddForce - phys:GetVelocity() / 2
return SelfAngForce, Linear, SIM_GLOBAL_ACCELERATION
end[/lua]
I'm using CurTime()*20 to get the angle, as it's about the speed i want it to travel.
-nvm-
apparantly self.Owner:SetFOV(0) sets the default FOV which could've been useful to know 300 lines ago
Scratch that, figured it out.
[QUOTE=LUModder;46420009]It's not, cause I was using this for my item info table
[lua]
local FBoxTestItems = {}
FBoxTestItems.Melon = {
name = "Melon",
desc = "Your standard food item.",
price = 50,
model = "models/props_junk/watermelon01.mdl",
class = "item_fbox_melon"
}
[/lua]
So it just prints out Melon and then the table ID. Welp, time to find another workaround.[/QUOTE]
Well, there's your obvious problem, as I said, Melon is a string.
You'd need to have a table in of this format, with numeric keys:
[lua]
local FBoxTestItems = {}
table.insert( FBoxTestItems, {
name = "Melon",
desc = "Your standard food item.",
price = 50,
model = "models/props_junk/watermelon01.mdl",
class = "item_fbox_melon"
} )
[/lua]
to use num as a number.
What you can do is:
[code]
local num = 0
for name,item in pairs(FBoxTestItems) do
num = num + 1
-- Use num here
end[/code]
How do I keep a util.effect running until I stop it? At the moment I've got
[code]
local effectdata = EffectData()
effectdata:SetOrigin( entity:GetPos() )
effectdata:SetMagnitude( 2 )
effectdata:SetRadius( 8 )
util.Effect( "Sparks", effectdata, true, true )
[/code]
I was assuming it'd be in the effectdata but I can't find anything in the wiki about it.
[QUOTE=Adzter;46430577]How do I keep a util.effect running until I stop it? At the moment I've got
[code]
local effectdata = EffectData()
effectdata:SetOrigin( entity:GetPos() )
effectdata:SetMagnitude( 2 )
effectdata:SetRadius( 8 )
util.Effect( "Sparks", effectdata, true, true )
[/code]
I was assuming it'd be in the effectdata but I can't find anything in the wiki about it.[/QUOTE]
You don't. You can either use a custom Lua effect or put it in a loop or something.
Any good weapon base around there? please don't say M9K
people keep complaining of headshots being extremely hard to do on my server, how does one make the head hitbox bigger on TTT? currently the only area that seems to headshot is the neck, or would it be simpiler to just lag compensate my weapons?
[QUOTE=AJ10017;46441738]lag compensate my weapons?[/QUOTE]
Step 1.
I'm under the belief that lag compensation is currently broken for changes in players' pitch.
How to add buttons to the F2 menu on Fretta
Is is possible you can get the model from just the class string?
ie if ("weapon_ar2"):GetModel() worked it would give you the model for the ar2
[QUOTE=ROFLBURGER;46442682]Is is possible you can get the model from just the class string?
ie if ("weapon_ar2"):GetModel() worked it would give you the model for the ar2[/QUOTE]
yes but this works only if you are doing it on a scripted swep
local model = weapons.GetStored("weapon_m9k_genericshittygun").WorldModel
[editline]8th November 2014[/editline]
for hl2 I'd just advise setting up a table of classes and their respective model strings, then referencing the model strings with the class.
So is there no way to grab a string with the Gamemode game?
[QUOTE=Exho;46443651]So is there no way to grab a string with the Gamemode game?[/QUOTE]
[url]http://wiki.garrysmod.com/page/engine/ActiveGamemode[/url]
[QUOTE=BFG9000;46442928]yes but this works only if you are doing it on a scripted swep
local model = weapons.GetStored("weapon_m9k_genericshittygun").WorldModel
[editline]8th November 2014[/editline]
for hl2 I'd just advise setting up a table of classes and their respective model strings, then referencing the model strings with the class.[/QUOTE]
Thank you, this opens a bunch of new doors for me.
What is the lowest recourse intense model in gmod? I am trying to make it where a gun loaded with fire ammo leaves fire effects if it doesn't hit a player or npc. Obviously the entity wouldn't be rendered and also it would have a low chance of creating the entity every-time the gun fires to help git rid of lag.
--------------------------------------------Edit
I'm a idiot I can just use particle effects and tracers. Now I just need to find a good particle effect because I have no clue how to make my own.
I need to know how to make turn a 2 values into %.
[lua]
local xp = ply.xp or 0;
local nextLVL = ply:needXPToLevel();
local xpProcent = -- ?? how to turn this into procent using current amount of xp (xp) and the needed xp to level up (nextLVL)
[/lua]
Printing those values using [lua] local xpProcent = ( nextLVL / xp ); -- which doesn't return procent as I want cause the calcaution is incorrect [/lua]
and having 5 xp and being lvl 3 (you need 110 xp to level up)
[lua]
Procent 22
nextLVL 110
xp 5
[/lua]
-never mind-
[QUOTE=Klaes4Zaugen;46444111]I need to know how to make turn a 2 values into %.
[lua]
local xp = ply.xp or 0;
local nextLVL = ply:needXPToLevel();
local xpProcent = -- ?? how to turn this into procent using current amount of xp (xp) and the needed xp to level up (nextLVL)
[/lua]
Printing those values using [lua] local xpProcent = ( nextLVL / xp ); -- which doesn't return procent as I want cause the calcaution is incorrect [/lua]
and having 5 xp and being lvl 3 (you need 110 xp to level up)
[lua]
Procent 22
nextLVL 110
xp 5
[/lua][/QUOTE]
[lua]
local xp = ply.xp or 0;
local nextLVL = ply:needXPToLevel();
local percent = math.floor(xp/nextLVL*100)
[/lua]
?
Is there any way in ttt to check if weapon was used/owner/shoot wenn another player is picking it up. I found Weapon:LastShootTime( ) but i guess its not finished ( Description: Returns the time since a weapon was last fired at a float variable. Always returns 0. )
[QUOTE=GreenGold;46447704]Is there any way in ttt to check if weapon was used/owner/shoot wenn another player is picking it up. I found Weapon:LastShootTime( ) but i guess its not finished ( Description: Returns the time since a weapon was last fired at a float variable. Always returns 0. )[/QUOTE]
On weapon drop, setting a lastOwner element on the weapon entity should work.
[QUOTE=jakej78b;46420641]Probably a dumb question, but I'm very bad with string manipulation. I have my hook all rigged up on the clientside using chat. What I'm looking for is how I would make it where I could use colorcodes in it. When someone types something like [red] it replaced is with Color(255,0,0) to be used in the chat.AddText function. That and how would I make it loop through every word/every letter to do it unlimited times so you could have a dozen different colors in one message.[/QUOTE]
[b][url=http://gmodwiki.net/Lua/Libraries/string/gmatch]Lua/Libraries/string/gmatch[img]http://gmodwiki.net/favicon.ico[/img][/url][/b]
something like
[lua]
local colors = {
white = Color(255, 255, 255),
black = Color(0, 0, 0),
}
for token in string.gmatch(something, "%[(.*)%]") do
local color = colors[token:lower()] or colors.white
end
[/lua]
Does anyone know how Zombie Survival decides how many points a player should get for damage/kills?
I'd assume they are using the [url=http://wiki.garrysmod.com/page/GM/ScalePlayerDamage]ScalePlayerDamage[/url] hook, and giving points regarding what body part they shoot? I've never played Zombie Survival, so I'm just assuming.
Sorry, you need to Log In to post a reply to this thread.