[QUOTE=Mornedil;47682224]How do I convert a color table to player color?
As far as I understand it, player color should be a vector with R, G, B values between 0 and 1, but a color table is a table with R G B A values between 0 and 255. So I think I need to take the first 3 values, divide them by 255, and turn it into a vector.. But how?[/QUOTE]
You just explained how yourself :v: You can easily construct a vector from a colour, so long as you can actually get that colour. You'd end up with something like this;
[lua]
local newCol = Color(255, 100, 0) -- This could be any way of getting a colour. GM:GetTeamColor for example.
local plyCol = Vector(newCol.r/255, newCol.g/255, newCol.b/255)
ply:SetPlayerColor(plyCol)
[/lua]
[QUOTE=Mornedil;47682224]How do I convert a color table to player color?
As far as I understand it, player color should be a vector with R, G, B values between 0 and 1, but a color table is a table with R G B A values between 0 and 255. So I think I need to take the first 3 values, divide them by 255, and turn it into a vector.. But how?[/QUOTE]
Spot on.
[lua]
Vector(mycolor.r / 255, mycolor.g / 255, mycolor.b / 255)
--or
mycolor:ToVector()
[/lua]
[editline]e[/editline]
shucks, ninja'd
[QUOTE=hexpunK;47682258]You just explained how yourself :v: You can easily construct a vector from a colour, so long as you can actually get that colour. You'd end up with something like this;
[lua]
local newCol = Color(255, 100, 0) -- This could be any way of getting a colour. GM:GetTeamColor for example.
local plyCol = Vector(newCol.r/255, newCol.g/255, newCol.b/255)
ply:SetPlayerColor(plyCol)
[/lua][/QUOTE]
What I didn't know was how to access the values of the table, that's where I got stuck.
Thanks a lot :)
I am working on playermodels with customizable colors in the pointshop by _undefined, so players can save color preference per model.
If anyone is interested in using this in their pointshop, here's the final code for the kleiner player model ( tested and works :D )
[code]
ITEM.Name = 'Kleiner'
ITEM.Price = 250
ITEM.Model = 'models/player/kleiner.mdl'
function ITEM:OnEquip(ply, modifications)
if not ply._OldModel then
ply._OldModel = ply:GetModel()
end
timer.Simple(1, function()
ply:SetModel(self.Model)
if modifications.color ~= nil then
ply:SetPlayerColor( Vector( modifications.color.r/255, modifications.color.g/255, modifications.color.b/255 ) )
else
ply:SetPlayerColor( Vector( 0.24, 0.34, 0.41) )
end
end)
end
function ITEM:OnHolster(ply)
if ply._OldModel then
ply:SetModel(ply._OldModel)
end
end
function ITEM:PlayerSetModel(ply)
ply:SetModel(self.Model)
end
function ITEM:Modify(modifications)
PS:ShowColorChooser(self, modifications)
end
function ITEM:OnModify(ply, modifications)
self:OnEquip(ply, modifications)
end
[/code]
Now all I have left to figure out is how to set all player's default model in Sandbox to so they actually need to buy a model from the shop, otherwise pointshop models kind of lose their point :p.
What's the best way to deal explosive damage? util.BlastDamage is kinda buggy and doesn't seem to damage NPCs 100% of the time.
[QUOTE=TFA;47682455]What's the best way to deal explosive damage? util.BlastDamage is kinda buggy and doesn't seem to damage NPCs 100% of the time.[/QUOTE]
ents.Create( "env_explosion" )
and set all the key values etc. That'll work nicely :smile: (it should, at least)
[editline]8th May 2015[/editline]
I wish I personally knew how to do the explosion damage trace system, then TakeDamageInfo could be an alternative method, not requiring a new entity.
[editline]8th May 2015[/editline]
[URL="http://wiki.garrysmod.com/page/Entity/TakeDamageInfo"]Read up on TakeDamageInfo[/URL]
[URL="http://wiki.garrysmod.com/page/ents/Create"]Read up on ents.Create[/URL]
[QUOTE=TFA;47682455]What's the best way to deal explosive damage? util.BlastDamage is kinda buggy and doesn't seem to damage NPCs 100% of the time.[/QUOTE]
You should be able to keep using util.BlastDamage but hook into GM:EntityTakeDamage and check if the entity is an NPC and check if the damage is blast damage and you should be able to override and/or correct the damage dealt to the NPC.
So I have a derma panel that is on screen, then using MoveTo, slides off screen
When the panel is made, I use timer.Simple to move it after x seconds. It only just hit me that technically the panel is still 'there' just not on screen. If I have a timer that uses MoveTo and then Remove after x seconds, the animation gets sort of botched. What would be the best/cleanest way to handle this? Like, I could easily do another timer within that timer to remove it but that feels a bit messy so I thought I'd quickly ask, thanks!
[QUOTE=NiandraLades;47684812]So I have a derma panel that is on screen, then using MoveTo, slides off screen
When the panel is made, I use timer.Simple to move it after x seconds. It only just hit me that technically the panel is still 'there' just not on screen. If I have a timer that uses MoveTo and then Remove after x seconds, the animation gets sort of botched. What would be the best/cleanest way to handle this? Like, I could easily do another timer within that timer to remove it but that feels a bit messy so I thought I'd quickly ask, thanks![/QUOTE]
MoveTo's last argument is a callback when it's finished so there's really no need for a timer.
Though I would personally use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/Derma_Anim]Global.Derma_Anim[/url]
MoveTo has a callback parameter that's called when the animation finishes.
Oh shit, I'm an idiot then since I never noticed that - thank you for the info
[QUOTE=Mornedil;47682429]What I didn't know was how to access the values of the table, that's where I got stuck.
Thanks a lot :)
I am working on playermodels with customizable colors in the pointshop by _undefined, so players can save color preference per model.
If anyone is interested in using this in their pointshop, here's the final code for the kleiner player model ( tested and works :D )
[code]
ITEM.Name = 'Kleiner'
ITEM.Price = 250
ITEM.Model = 'models/player/kleiner.mdl'
function ITEM:OnEquip(ply, modifications)
if not ply._OldModel then
ply._OldModel = ply:GetModel()
end
timer.Simple(1, function()
ply:SetModel(self.Model)
if modifications.color ~= nil then
ply:SetPlayerColor( Vector( modifications.color.r/255, modifications.color.g/255, modifications.color.b/255 ) )
else
ply:SetPlayerColor( Vector( 0.24, 0.34, 0.41) )
end
end)
end
function ITEM:OnHolster(ply)
if ply._OldModel then
ply:SetModel(ply._OldModel)
end
end
function ITEM:PlayerSetModel(ply)
ply:SetModel(self.Model)
end
function ITEM:Modify(modifications)
PS:ShowColorChooser(self, modifications)
end
function ITEM:OnModify(ply, modifications)
self:OnEquip(ply, modifications)
end
[/code]
Now all I have left to figure out is how to set all player's default model in Sandbox to so they actually need to buy a model from the shop, otherwise pointshop models kind of lose their point :p.[/QUOTE]
To make things simple, edit the pointshop code so that the bind for it is the context menu key; that way players shouldn't be able to access the context menu
What does returning in PANEL:PerformLayout actually do? [url]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/lua/vgui/contextbase.lua#L53[/url] It isn't documented on the wiki, and I'm hoping I'm not missing out on a feature.
How can I make an object that blocks traces (util.TraceLine) but that doesn't have any physics collisions (including bullets)?
-snip misread-
[lua]local BOTS = {}
local botsName = {"Ron",
"Bret",
"Johnathan",
"Max",
"Kyle",
"Jack",
"Marcus",
"Jay",
"Andy",
"Aran"}
concommand.Add("gm_bot_add",function(ply)
local b = player.CreateNextBot(botsName[math.random(#botsName)])
table.insert(BOTS,b)
b.Owner = ply
end)
hook.Add("PlayerSay","Bots",function(ply,text)
if(text == "!follow") then
ply.State = 1
end
if(text == "!quiet") then
ply.State = 0
end
if(text == "!attack") then
ply.State = 2
end
if(text == "!defend") then
ply.State = 3
end
end)
hook.Add("EntityTakeDamage","Defend!",function(ent,dmg)
if(ent:IsPlayer() && !ent:IsBot() && !dmg:GetAttacker():IsWorld()) then
for k,v in pairs(player.GetBots()) do
if(v.Owner == ent) then
v.Target = dmg:GetAttacker()
end
end
end
if(dmg:GetAttacker():IsPlayer() && !ent:IsWorld()) then
MsgN(ent)
for k,v in pairs(player.GetBots()) do
if(v.Owner == dmg:GetAttacker()) then
v.Target = ent
end
end
end
end)
hook.Add("StartCommand","MoveBots",function(ply,cmd)
if(IsValid(ply.Owner)) then
cmd:ClearMovement()
cmd:ClearButtons()
if(ply.Owner.State == nil) then
ply.Owner.State = 1
end
local ow = ply.Owner
local ang = ((ply:EyePos() - Vector(0,0,10))-(ow:EyePos() - Vector(0,0,10))):Angle()
local lClamp = ang + Angle(0,180,0)
ply:SetEyeAngles(Angle(math.Clamp(lClamp.p,-180,180),lClamp.y,math.Clamp(lClamp.r,-180,180)))
cmd:SetViewAngles(Angle(math.Clamp(lClamp.p,-180,180),lClamp.y,math.Clamp(lClamp.r,-180,180)))
if(ow.State == 1 or ow.State == 3) then
if(ow:GetPos():Distance(ply:GetPos()) > 128) then
cmd:SetForwardMove(750)
end
end
if(ow.State == 2) then
if(ow:GetPos():Distance(ply:GetPos()) < 72 && ow:Alive() or (ply.Ranged or false)) then
if(ow:Alive()) then
cmd:SetButtons(IN_ATTACK)
if(ow:GetPos():Distance(ply:GetPos()) < 72) then
ply:SelectWeapon("weapon_crowbar")
ply.Ranged = false
end
end
end
if(ow:GetPos():Distance(ply:GetPos()) > 256) then
if(ply:GetActiveWeapon():GetClass() != "weapon_ar2") then
ply:SelectWeapon("weapon_ar2")
ply.Ranged = true
end
end
if(ow:GetPos():Distance(ply:GetPos()) > 64) then
cmd:SetForwardMove(750)
end
cmd:SetSideMove(math.cos(RealTime())*400)
end
if(ow.State == 3) then
if(IsValid(ply.Target)) then
local ang = (ply:GetShootPos()-ply.Target:GetPos()):Angle()
if(ply.Owner:KeyDown(IN_ATTACK)) then
ang = (ply:GetShootPos()-ply.Owner:GetEyeTrace().HitPos):Angle()
end
local lClamp = ang + Angle(90,180,0)
ply:SetEyeAngles(lClamp)
cmd:SetViewAngles(lClamp)
if(ply.Target:GetPos():Distance(ply:GetShootPos()) > 256) then
if(ply:GetActiveWeapon():GetClass() != "weapon_ar2") then
ply:SelectWeapon("weapon_ar2")
ply.Ranged = true
end
else
ply:SelectWeapon("weapon_crowbar")
if(ply.Target:GetPos():Distance(ply:GetPos()) > 64) then
cmd:SetForwardMove(750)
end
end
cmd:SetButtons(IN_ATTACK)
end
end
end
end)
[/lua]
There are a few features I want to add to this:
I want to create a state 4, in which a timer of 3 that repeats forever is created, and every time the timer of 3 is done, then the bot finds a random vector to walk to. Also, if the bot has a target during this state, the timer will be destroyed and they will chase the enemy. If they lose the enemy, then the timer will be created again.
I want to automatically set the bot's state to 4 upon them being spawned
Can anyone help me with this? I can not tell you how many tutorials on player.CreateNextBot and StartCommand hooks I looked up in order to get this far already. :v:
EDIT: Or in other words we could just pause the timer if the bot has seen an enemy then restart it again once they don't have an enemy anymore.
Quick question, is there an easy way to convert a boolean to a number? I want to be able to do this:
[B]variable = variable + BOOL1 - BOOL2[/B]
(assuming True is 1, and false is 0)
a more concrete example would be:
[code]acceleration = acceleration + ply:KeyDown(IN_FORWARD) - ply:KeyDown(IN_BACK)[/code]
[QUOTE=A Fghtr Pilot;47685327]To make things simple, edit the pointshop code so that the bind for it is the context menu key; that way players shouldn't be able to access the context menu[/QUOTE]
That's a horrible idea, because.. First of all, players would still be able to change the cl_playermodel cvar to change their model. But more importantly, the context menu is used for so much more than setting the player model, so disabling it would severely cripple sandbox gameplay.
It's however possible to remove the player editor from the context menu instead, by commenting out "include( "editor_player.lua" )" in sandbox/gamemode/shared.lua.
Buuut, that still doesn't prevent players from using the cl_playermodel concommand.
[code]
acceleration = acceleration + (ply:KeyDown(IN_FORWARD) and 1 or 0) - (ply:KeyDown(IN_BACK) and 1 or 0)
[/code]
Anyone know why player:ViewPunch() might be laggy/snappy/jittery?
I'm calling ViewPunch in a PlayerFootstep hook (to simulate headbobbing), and it's always worked perfectly (shared) in singleplayer and in multiplayer local server. Nice smooth sine-wave type movement.
But I put the code on my server, where I get a pretty consistent 70ms ping, and I can't get a single ViewPunch without some horrible snap/jitter up and down.
Is there a way to disable sounds from 3rd person animation? Like shotgun pump or something
[QUOTE=TheMostUpset;47689214]Is there a way to disable sounds from 3rd person animation? Like shotgun pump or something[/QUOTE]
Not sure if this would help, but it's worth a shot.
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/EntityEmitSound]GM/EntityEmitSound[/url]
[QUOTE=James xX;47687774]What does returning in PANEL:PerformLayout actually do? [url]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/lua/vgui/contextbase.lua#L53[/url] It isn't documented on the wiki, and I'm hoping I'm not missing out on a feature.[/QUOTE]
It's where any of the child elements that are parented to your panel should be positioned at.
[CODE]
local PANEL = {}
function PANEL:Init()
self.Panel = vgui.Create("DPanel", self)
self:InvalidateLayout()
end
function PANEL:PerformLayout()
self.Panel:SetSize(300, 210)
self.Panel:SetPos(10, 10)
end
[/CODE]
So no, i don't think you are missing out on too much :)
[QUOTE=ThrowAwayAcct;47689200]Anyone know why player:ViewPunch() might be laggy/snappy/jittery?
I'm calling ViewPunch in a PlayerFootstep hook (to simulate headbobbing), and it's always worked perfectly (shared) in singleplayer and in multiplayer local server. Nice smooth sine-wave type movement.
But I put the code on my server, where I get a pretty consistent 70ms ping, and I can't get a single ViewPunch without some horrible snap/jitter up and down.[/QUOTE]
Can you show your code?
[QUOTE=AIX-Who;47689560]It's where any of the child elements that are parented to your panel should be positioned at.
[CODE]
local PANEL = {}
function PANEL:Init()
self.Panel = vgui.Create("DPanel", self)
self:InvalidateLayout()
end
function PANEL:PerformLayout()
self.Panel:SetSize(300, 210)
self.Panel:SetPos(10, 10)
end
[/CODE]
So no, i don't think you are missing out on too much :)[/QUOTE]
Oh, This is was the old way to set the padding?
[QUOTE=James xX;47689761]Oh, This is was the old way to set the padding?[/QUOTE]
I believe so, yes however i may be wrong.
I'm sure the method you're using now is absolutely fine
any way to scale X Y Z of a model independently?
I can only find entity:SetModelScale on the wiki, but it takes a single number which scales XYZ in uniform.
[QUOTE=Mornedil;47691520]any way to scale X Y Z of a model independently?
I can only find entity:SetModelScale on the wiki, but it takes a single number which scales XYZ in uniform.[/QUOTE]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/EnableMatrix]Entity:EnableMatrix[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/VMatrix/Scale]VMatrix:Scale[/url]
[QUOTE=TFA;47682455]What's the best way to deal explosive damage? util.BlastDamage is kinda buggy and doesn't seem to damage NPCs 100% of the time.[/QUOTE]
Always works for me
Unless you're dealing with SNPCs or something which I wouldn't know about
Will a trace tell when it leaves a body of water? I'm really trying to find a good way to tell how deep underwater a player is. Pretty much to find the depth, find how far it is for empty space, and track a player's movement if the trace can't find empty space. So again, the question, will a trace know at what point it leaves a body of water?
MASK_WATER
2 traces: One that starts out with the player and one with MASK_WATER. The player trace should project up from the player's shoot pos to the ceiling or top of the map, then have the hitpos of this trace become the basis for the water trace, which aims down at the player. Take the difference of the lengths and there's your depth.
I have a variable which is created by the server for each player. [B]ply.Jetpackfuel[/B]
I want to draw a "fuel bar" clientside depending on how much fuel that specific player has, but not sure how to access the variable.
Here's the code layout to show where I'm setting ply.Jetpackfuel and where I need to get the value of it:
[CODE]function ITEM:Think(ply, modifications)
if (SERVER) then
--jetpack code here, which controls ply.Jetpackfuel
end
end
function ITEM:HUDPaint()
--local i = <player's fuel variable>
if CLIENT then
--drawing the fuel bar here. local variable i controls the width of the bar
end
end[/CODE]
since HUDPaint doesn't have a player argument I'm not sure how to get the correct player's fuel variable.
Do I need to network the variable, or can I just save it to a local variable before the "if CLIENT" statement? If so, how?
Edit: I tried making a for loop to get the fuel variable for each player:
[CODE]local Players = player.GetAll()
for i = 1, table.Count(Players) do
local ply = Players[i]
local fuel = ply.Jetpackfuel / 100 -- This line doesn't work.
local x = 200
local y = 200
if CLIENT then
surface.SetDrawColor( 255,255,255,255 )
surface.DrawRect( x - 75, y + 120, 150, 15 )
surface.SetDrawColor( 0,255,0,255 )
surface.DrawRect( x - 75, y + 120, fuel*150, 15 )
end
end[/CODE]
the variable comes out as a nil value, but if I set local fuel to something random like 0.5 then the rest works. so the only thing not working is getting that variable.
[I](sorry for posting so often in this thread but I find it hard to get clarity on details like this from the wiki)[/I]
Sorry, you need to Log In to post a reply to this thread.