I'm trying to write in a TTT Swep that will spawn an entity when used but when I click with it nothing happens. Here's the function for the entity spawn. Is it correct?
[CODE]
function SWEP:PrimaryAttack()
if SERVER && self:Clip1() > 0 then
self:TakePrimaryAmmo(1)
local ply = self.Owner
dick=ents.Create("turret_rail")
dick:SetPos(Vector(0,0,0))
dick:Spawn()
dick.Owner = ply
dick.OnTTT = true
end
end
[/CODE]
[QUOTE=Scu11y;51849378]I'm trying to write in a TTT Swep that will spawn an entity when used but when I click with it nothing happens. Here's the function for the entity spawn. Is it correct?
[CODE]
function SWEP:PrimaryAttack()
if SERVER && self:Clip1() > 0 then
self:TakePrimaryAmmo(1)
local ply = self.Owner
dick=ents.Create("turret_rail")
dick:SetPos(Vector(0,0,0))
dick:Spawn()
dick.Owner = ply
dick.OnTTT = true
end
end
[/CODE][/QUOTE]
You're spawning the Entity at the map origin (0, 0, 0). You want to spawn it at ply:GetShootPos(), ply:GetPos() ,ply:GetEyeTrace().HitPos, or a mixture of these.
[code]
function SWEP:PrimaryAttack()
if SERVER && self:Clip1() > 0 then
self:TakePrimaryAmmo(1)
local ply = self.Owner
dick=ents.Create("turret_rail")
dick:SetOwner(ply);
dick:SetPos(ply:GetShootPos())--You can change this to the position you want the ent to spawn at. This will spawn it at about eye level.
dick:Spawn()
dick.OnTTT = true
end
end
[/code]
I know how to edit the spawnlist text files, which is how I have objects with custom skins in my spawnlist, but I can't find out how to make bodygroups apart from setting "body" to something!
I've tried setting it to "1", "100000000", "000000001", the name of the bodygroup; Nothing works! What do I set it to?:rollout:
P.S. I actually did make a thread about this, but it's not getting any replies that aren't mine so I decided to post here too:hiddendowns:
[QUOTE=dx9er;51859937]What's wrong with this? It's a clientside script that is supposed to display a prop's health when a player looks at it (The health is just a networked int, and when it hits 0, the prop gets destroyed).
:snip:
And it spits out:
:snip:
Saving the script makes it work sometimes, but just on some props.
And the problem shouldn't be serverside, as GetEyeTrace is done clientside for the player.
Also, is there a way to get the size of a prop/model?[/QUOTE]
As noted on the wiki page for [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/LocalPlayer]LocalPlayer[/url], it will return NULL up until the client has loaded and all the entities are initialized.
Create your ply variable inside the hook. Also, I'd suggest storing the result of the trace entity before the loop.
Edit:
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/OBBMins]Entity:OBBMins[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/OBBMaxs]Entity:OBBMaxs[/url]
[QUOTE=dx9er;51859937]...[/QUOTE]
Why are you finding and looping through all the prop_physics entities to just show what you are looking at?
Also you can't cache the Player object from LocalPlayer() outside of the hook until the player spawns in. And it's not intensive to just grab it.
[B]Untested:[/B]
[code]
hook.Add('HUDPaint', 'PropHealth', function()
local trace = LocalPlayer():GetEyeTrace()
local ent = trace.Entity
if not IsValid(ent) or ent:GetClass() ~= 'prop_physics' then return end
local pos = ent:LocalToWorld(ent:OBBCenter()):ToScreen()
if ent:GetNWInt("damaged") <= 50 and ent:GetNWInt("damaged") > 25 then
draw.DrawText(ent:GetNWInt("damaged"), "ChatFont", pos.x, pos.y, Color(255,255,0,255), TEXT_ALIGN_CENTER)
elseif ent:GetNWInt("damaged") <= 25 then
draw.DrawText(ent:GetNWInt("damaged"), "ChatFont", pos.x, pos.y, Color(255,0,0,255), TEXT_ALIGN_CENTER)
else
draw.DrawText(ent:GetNWInt("damaged"), "ChatFont", pos.x, pos.y, Color(0,255,0,255), TEXT_ALIGN_CENTER)
end
end)
[/code]
[b]Edit:[/b] Lol, I also just noticed you [i]return[/i] when an entity in the loop is not the one you are looking at so it would essentially never work.
Is there a more efficient way of doing shit like this. I always find myself making different ranks for different thinks and having this fat chunk of if then statements looks dumb. Forgive my ignorance.
[CODE]
-- Names --
local function DrawNames()
local glow = math.abs(math.sin(CurTime() / 2) * 255);
local ply = LocalPlayer()
local playerRank = ply:GetNWString("EV_UserGroup")
if playerRank == "guest" then
draw.DrawText(ply:GetName(), "medium", ScrW()/2 - 2, ScrH() - 30, Color(0, 0, 0), 1)
draw.DrawText(ply:GetName(), "medium", ScrW()/2 - 2 - 1, ScrH() - 30 - 1, Color(255, 255, 255, 200), 1)
end
if playerRank == "respected" then
draw.DrawText(ply:GetName(), "medium", ScrW()/2 - 2, ScrH() - 30, Color(0, 0, 0), 1)
draw.DrawText(ply:GetName(), "medium", ScrW()/2 - 2 - 1, ScrH() - 30 - 1, Color(0, 0, glow, 220), 1)
end
if playerRank == "vip" then
draw.DrawText(ply:GetName(), "medium", ScrW()/2 - 2, ScrH() - 30, Color(0, 0, 0), 1)
draw.DrawText(ply:GetName(), "medium", ScrW()/2 - 2 - 1, ScrH() - 30 - 1, Color(glow, 0, 0, 220), 1)
end
if playerRank == "mod" then
draw.DrawText(ply:GetName(), "medium", ScrW()/2 - 2, ScrH() - 30, Color(0, 0, 0), 1)
draw.DrawText(ply:GetName(), "medium", ScrW()/2 - 2 - 1, ScrH() - 30 - 1, Color(glow, 0, 212, 220), 1)
end
if ply:IsAdmin() then
draw.DrawText(ply:GetName(), "medium", ScrW()/2 - 2, ScrH() - 30, Color(0, 0, 0), 1)
draw.DrawText(ply:GetName(), "medium", ScrW()/2 - 2 - 1, ScrH() - 30 - 1, Color(41, glow-40, 0, 220), 1)
end
if ply:IsSuperAdmin() then
draw.DrawText(ply:GetName(), "medium", ScrW()/2 - 2, ScrH() - 30, Color(0, 0, 0), 1)
draw.DrawText(ply:GetName(), "medium", ScrW()/2 - 2 - 1, ScrH() - 30 - 1, Color(glow, 136, 0, 220), 1)
end
if playerRank == "owner" then
draw.DrawText(ply:GetName(), "medium", ScrW()/2 - 2, ScrH() - 30, Color(0, 0, 0), 1)
draw.DrawText(ply:GetName(), "medium", ScrW()/2 - 2 - 1, ScrH() - 30 - 1, Color(0, glow, 225, 220), 1)
end
end
[/CODE]
[QUOTE=Moat;51861897]use a table
[lua]
local rank_glow = math.abs(math.sin(CurTime() / 2) * 255)
local rank_colors = {
["guest"] = Color(255, 255, 255, 200),
["respected"] = Color(0, 0, rank_glow, 220),
["vip"] = Color(rank_glow, 0, 0, 220),
["mod"] = Color(rank_glow, 0, 212, 220),
["admin"] = Color(41, rank_glow-40, 0, 220),
["superadmin"] = Color(rank_glow, 136, 0, 220),
["owner"] = Color(0, rank_glow, 225, 220)
}
local function DrawNames()
local playerRank = (LocalPlayer():IsSuperAdmin() and "superadmin") or (LocalPlayer():IsAdmin() and "admin") or LocalPlayer():GetNWString("EV_UserGroup")
rank_glow = math.abs(math.sin(CurTime() / 2) * 255)
draw.DrawText(ply:GetName(), "medium", ScrW()/2 - 2, ScrH() - 30, Color(0, 0, 0), 1)
draw.DrawText(ply:GetName(), "medium", ScrW()/2 - 2 - 1, ScrH() - 30 - 1, rank_colors[playerRank], 1)
end
[/lua][/QUOTE]
This wouldn't work unless either the rank_colors table was generated inside the function or the table contained functions that generated the color.
Here's another option that maintains the efficiency of not creating the table as well as cleaning the code a bit by moving duplicated code out of the blocks.
[lua]
local function DrawNames()
local ply = LocalPlayer()
draw.DrawText(ply:GetName(), "medium", ScrW() / 2 - 2, ScrH() - 30, color_black, TEXT_ALIGN_CENTER)
local playerRank = ply:GetNWString("EV_UserGroup")
local rankColor
if playerRank == "respected" then
rankColor = Color(0, 0, glow, 220)
elseif playerRank == "vip" then
rankColor = Color(glow, 0, 0, 220)
elseif playerRank == "mod" then
rankColor = Color(glow, 0, 212, 220)
elseif playerRank == "owner" then
rankColor = Color(41, glow - 40, 0, 220)
elseif ply:IsSuperAdmin() then
rankColor = Color(0, glow, 225, 220)
elseif ply:IsAdmin() then
rankColor = Color(glow, 136, 0, 220)
else
-- guests and others
rankColor = Color(255, 255, 255, 200)
end
draw.DrawText(ply:GetName(), "medium", ScrW() / 2 - 3, ScrH() - 31, rankColor, TEXT_ALIGN_CENTER)
end
[/lua]
If you don't care, then Moat's version is fine if you move the variables inside the function.
[editline]22nd February 2017[/editline]
Also Moat got rid of the ply variable definition
[QUOTE=Moat;51862006]I think you might have read it wrong or something, but my code should work fine :v[/QUOTE]
I see what zerf means.
[lua]local rank_glow = math.abs(math.sin(CurTime() / 2) * 255)[/lua]
This needs to be inside the function, or it will only be ran once, and thus, the colors would not glow.
[editline]![/editline]
Actually, it looks like your code puts that inside the function too. Forget I even said anything I don't have time to properly read all of this.
[editline]![/editline]
Wait. I think I get it. The colors in the table wouldn't be updated just because the glow color is updated. You have to update all the colors, or create them all in the function.
Here's my next attempt:
[lua]
local rankColorGenerators = {
["guest"] = function(glow) Color(255, 255, 255, 200) end,
["respected"] = function(glow) Color(0, 0, glow, 220) end,
["vip"] = function(glow) Color(glow, 0, 0, 220) end,
["mod"] = function(glow) Color(glow, 0, 212, 220) end,
["admin"] = function(glow) Color(41, glow - 40, 0, 220) end,
["superadmin"] = function(glow) Color(glow, 136, 0, 220) end,
["owner"] = function(glow) Color(0, glow, 225, 220) end,
}
local function DrawNames()
local ply = LocalPlayer()
draw.DrawText(ply:GetName(), "medium", ScrW() / 2 - 2, ScrH() - 30, color_black, TEXT_ALIGN_CENTER)
local glow = math.abs(math.sin(CurTime() / 2) * 255)
local rank = ply:IsSuperAdmin() and "superadmin" or (ply:IsAdmin() and "admin" or ply:GetNWString("EV_UserGroup"))
local rankColor = rankColorGenerators[rank](glow)
draw.DrawText(ply:GetName(), "medium", ScrW() / 2 - 3, ScrH() - 31, rankColor, TEXT_ALIGN_CENTER)
end
[/lua]
[editline]22nd February 2017[/editline]
Whoops, I forgot to account for his original code prioritizing being owner > being superadmin > being admin > other groups. Here's more complex code that takes that into account and also handles the situation of their group not being in the table as code_gs brough up.
[lua]
local rankColorGenerators = {
["respected"] = function(glow) Color(0, 0, glow, 220) end,
["vip"] = function(glow) Color(glow, 0, 0, 220) end,
["mod"] = function(glow) Color(glow, 0, 212, 220) end,
}
local function GetRankColorForPlayer(ply, glow)
if ply:GetNWString("EV_UserGroup") == "owner" then
-- owner color takes priority over admin-ness
return Color(0, glow, 225, 220)
elseif ply:IsSuperAdmin() then
return Color(glow, 136, 0, 220)
elseif ply:IsAdmin() then
return Color(41, glow - 40, 0, 220)
else
local generator = rankColorGenerators[ply:GetNWString("EV_UserGroup")]
if generator then
return generator(glow)
else
return Color(255, 255, 255, 200)
end
end
end
local function DrawNames()
local ply = LocalPlayer()
draw.DrawText(ply:GetName(), "medium", ScrW() / 2 - 2, ScrH() - 30, color_black, TEXT_ALIGN_CENTER)
local glow = math.abs(math.sin(CurTime() / 2) * 255)
local rankColor = GetRankColorForPlayer(ply, glow)
draw.DrawText(ply:GetName(), "medium", ScrW() / 2 - 3, ScrH() - 31, rankColor, TEXT_ALIGN_CENTER)
end
[/lua]
Is there any way to use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/render/RenderView]render.RenderView[/url] in [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/cam/Start3D2D]cam.Start3D2D[/url] without the game screwing up extremely
[QUOTE=MPan1;51872471]Is there any way to use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/render/RenderView]render.RenderView[/url] in [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/cam/Start3D2D]cam.Start3D2D[/url] without the game screwing up extremely[/QUOTE]
What are you trying to do?
[QUOTE=Promptitude;51872639]What are you trying to do?[/QUOTE]
Kinda like a camera screen sort of thing - mainly just for fun
[editline]25th February 2017[/editline]
[QUOTE=swadicalrag;51872642]render.RenderView inside cam.Start3D inside cam.Start3D2D :v:[/QUOTE]
That still destroys the game for me
well now I really want to know what it does, but am too lazy to boot up gmod and try it
I'm having issues with fake syncing between client and serverside variables. The spread of a weapon is networked properly (self:NetworkVar()) to track the spread of a weapon, but in order for the crosshair to look smooth, I made a clientside only variable that's independent of the networked variable.
The handling of the spread (networked + client variables) is handled by a Think hook. For some reason, turning off vsync and having a fps larger than 60 will cause the client exclusive spread to greatly desync with the networked spread. FrameTime() clientside returns 66, the server's tickrate, no matter the FPS. I looked it up and I noticed that Think runs every frame on client, Think runs every tick on server.
What's the proper way to sync clientside Think with Serverside think?
[QUOTE=ROFLBURGER;51872842]I'm having issues with fake syncing between client and serverside variables. The spread of a weapon is networked properly (self:NetworkVar()) to track the spread of a weapon, but in order for the crosshair to look smooth, I made a clientside only variable that's independent of the networked variable.
The handling of the spread (networked + client variables) is handled by a Think hook. For some reason, turning off vsync and having a fps larger than 60 will cause the client exclusive spread to greatly desync with the networked spread. FrameTime() clientside returns 66, the server's tickrate, no matter the FPS. I looked it up and I noticed that Think runs every frame on client, Think runs every tick on server.
What's the proper way to sync clientside Think with Serverside think?[/QUOTE]
Tick or SWEP:Think are synced.
I'm trying to override GetName, Nick, and Name so I can apply custom character names to this new gamemode I'm working on, if anyone could point me in the right direction to doing this, that would be great. Thanks!
[code]
local meta = FindMetaTable("Player")
meta.NickOld = meta.NickOld or meta.Nick
function meta:Nick()
return self.CustomName or self:NickOld()
end
[/code]
untested
[QUOTE=TFA;51874517][code]
local meta = FindMetaTable("Player")
meta.NickOld = meta.NickOld or meta.Nick
function meta:Nick()
return self.CustomName or self:NickOld()
end
[/code]
untested[/QUOTE]
works, thank you!
Trying to get my DModelPanel to hold a weapon, getting the code from [URL="https://facepunch.com/showthread.php?t=1464352"]here[/URL], however it just isn't working.
[CODE] local CharacterModel = vgui.Create("DModelPanel", CharacterPreviewPanel)
function CharacterModel:LayoutEntity( Entity ) return end
CharacterModel:SetModel(SelectedModel or "models/player/group01/male_01.mdl")
CharacterModel:SetPos(20, 50)
CharacterModel:SetSize(CharacterPreviewPanel:GetWide() - 40, CharacterPreviewPanel:GetTall() - 100)
local eyepos = CharacterModel.Entity:GetBonePosition( CharacterModel.Entity:LookupBone( "ValveBiped.Bip01_Spine" ) )
eyepos:Add( Vector( 0, 0, 2 ) ) -- Move up slightly
CharacterModel:SetLookAt( eyepos )
CharacterModel:SetCamPos( eyepos-Vector( -45, 0, -5 ) )
CharacterModel.Entity:SetEyeTarget( eyepos-Vector( -12, 0, 0 ) )
local v = ents.CreateClientProp(Model("weapons/w_rif_m4a1.mdl"))
v:Spawn()
v:SetParent(CharacterModel.Entity, CharacterModel.Entity:LookupAttachment("anim_attachment_RH"))
v:AddEffects(EF_BONEMERGE)
v:SetNoDraw(true)
CharacterModel.WeaponModel = v
function CharacterModel:UpdateWeapon(wepclass)
local wep = weapons.Get(wepclass)
if !wep then return end
v:SetModel(Model(wep.WorldModel))
v:SetParent(CharacterModel.Entity, CharacterModel.Entity:LookupAttachment("anim_attachment_RH"))
local anim = ActIndex[wep.HoldType]
self.Entity:SetSequence(anim)
end[/CODE]
It's fairly late at night and I'm making some dumb mistakes, so if you could help me that would be greatly appreciated.
[QUOTE=bobbleheadbob;51876354]Anyone can create a material. It's just a picture file.[/QUOTE]
then how do i apply to the specific part of the player model?
Calling glua magicians!
[del]Are there any ways of making a bullet go through and not collide with Player 2 [B]if[/B] it was shot by Player 1?[/del]
Solving this by making my own FiteBullets function, but there's still one problem to tackle... The physgun beam! Any way anything can be done regarding that as to prevent it from hitting Player 2 if it belongs to Player 1?
[QUOTE=Author.;51876498]Solving this by making my own FiteBullets function, but there's still one problem to tackle... The physgun beam! Any way anything can be done regarding that as to prevent it from hitting Player 2 if it belongs to Player 1?[/QUOTE]
Perhaps this helps you:
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/DrawPhysgunBeam]GM:DrawPhysgunBeam[/url]
[url]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/gamemodes/sandbox/gamemode/cl_init.lua#L90-L126[/url]
[QUOTE=markusmarkusz;51876668]Perhaps this helps you:
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/DrawPhysgunBeam]GM:DrawPhysgunBeam[/url]
[url]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/gamemodes/sandbox/gamemode/cl_init.lua#L90-L126[/url][/QUOTE]
That only allows me to change whether or not it draws (and wether the outline/halo draws), while what I need is that the beam goes through the player and can interact with other entities behind it or vice versa, which is the tricky part to figure out 😬
[QUOTE=Author.;51876679]That only allows me to change whether or not it draws (and wether the outline/halo draws), while what I need is that the beam goes through the player and can interact with other entities behind it or vice versa, which is the tricky part to figure out [/QUOTE]
I'm guessing this is impossible without actually forking the physgun, which you can't do because it's not written in Lua and the code isn't public.
Have you tried, [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PhysgunPickup]GM:PhysgunPickup[/url] ? It allows you to return false and prevent the target entity from being physgunned.
[QUOTE=Fantym420;51877057]Have you tried, [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PhysgunPickup]GM:PhysgunPickup[/url] ? It allows you to return false and prevent the target entity from being physgunned.[/QUOTE]
I think that would just make him not grab anything. What he wants is to grab something on the other side of the player, so the trace goes through the player.
well, I wasn't meaning return false on everything, I meant check if it's another player and then return false, I'll test it later.
[b]Edited:[/b]
I was wrong, it doesn't make it pass through. I thought it might have because the beam looks like it narrows.
hurray math.... and curves....
Would someone be able to help me with an interpolation function?
I have three points: start, middle, and end.
[t]http://zombine.me/ss/Photoshop-26.02.17379.png[/t]
The goal is to generate a curve such that by the time the midpoint is reached, the tangent of the curve is the same as the normal of (end - middle). Think the arc of the headcrab canisters, how they arc up and then straighten out. I'm looking at the source code for the canisters, but they do things too differently than me.
[QUOTE=Z0mb1n3;51878704]hurray math.... and curves....
Would someone be able to help me with an interpolation function?
I have three points: start, middle, and end.
The goal is to generate a curve such that by the time the midpoint is reached, the tangent of the curve is the same as the normal of (end - middle). Think the arc of the headcrab canisters, how they arc up and then straighten out. I'm looking at the source code for the canisters, but they do things too differently than me.[/QUOTE]
That's just a parabola/quadratic graph. I would read up on parametric equations and how you can generate coordinates for an equation over time: [url]http://www.nabla.hr/PC-ParametricEqu2.htm[/url]
Essentially, with t being time, your equation would be:
[code]y = S * -(t * R)^2 + T[/code]
Where S is the scale (stretch or shrink) of the parabola, R is the rate (how quickly you want time to progress), and T is the vertical transformation (how high or low you want it to start).
Sorry, you need to Log In to post a reply to this thread.