[QUOTE=MPan1;52850295]Sorry, try this:
[CODE]
local entTable = {
mediaplayer_tv = true,
boost_printer = true
}
hook.Add( "playerBoughtCustomEntity", "SetOwnerOnEntBuy", function( ply, enttbl, ent, price )
if entTable[ ent:GetClass() ] then
ent:CPPISetOwner( ply )
end
end )
[/CODE][/QUOTE]
Tried this and it works!
Thank you for help!
Hello, I've a trouble, I've made the 'SimpleTextOutlined' upon the entity, but it looks awful. I cannot understand, what I've done wrong
[IMG]https://pp.userapi.com/c840229/v840229488/43fc2/wgVW51V9tH0.jpg[/IMG]
[CODE]include( 'shared.lua' )
surface.CreateFont("AFont", {
size = 17,
weight = 600,
extended = true,
font = "Roboto",
})
function ENT:Draw()
self:DrawModel()
local ply = LocalPlayer()
local blackc = Color(0,0,0)
local whitec = Color(255,255,255)
local aAngle = self:GetAngles()
local AEyes = ply:EyeAngles()
aAngle:RotateAroundAxis(aAngle:Forward(), 90)
aAngle:RotateAroundAxis(aAngle:Right(), -90)
cam.Start3D2D(self:GetPos()+self:GetUp()*32, Angle(0, AEyes.y-90, 90), 0.1)
draw.SimpleTextOutlined("MedkitBig", "AFont", 0, 15, whitec, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 5, blackc)
cam.End3D2D()
end[/CODE]
[QUOTE=Status Quack;52850652]Hello, I've a trouble, I've made the 'SimpleTextOutlined' upon the entity, but it looks awful. I cannot understand, what I've done wrong[/QUOTE]
Make the 3D2D scale smaller and the font size bigger. When you use 3D2D, you're essentially stretching that size 17 font to be as big as your screen. If you make the font size larger and the 3D2D scale smaller then it will look a lot better.
[editline]3rd November 2017[/editline]
Also, instead of [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/draw/SimpleTextOutlined]draw.SimpleTextOutlined[/url], you could try using the outline parameter of [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/surface/CreateFont]surface.CreateFont[/url].
[QUOTE=MPan1;52850657]Make the 3D2D scale smaller and the font size bigger. When you use 3D2D, you're essentially stretching that size 17 font to be as big as your screen. If you make the font size larger and the 3D2D scale smaller then it will look a lot better.
[editline]3rd November 2017[/editline]
Also, instead of [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/draw/SimpleTextOutlined]draw.SimpleTextOutlined[/url], you could try using the outline parameter of [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/surface/CreateFont]surface.CreateFont[/url].[/QUOTE]
Thank you very much, it works excelent.
Im moving a car entity with setpos but occasionally it crashes the server. What could cause/fix this?
[QUOTE=Moat;52849763]You can use the trace result from the callback function in the bullet data for [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/EntityFireBullets]GM:EntityFireBullets[/url].[/QUOTE]
This was exactly what I needed to get me set on the right track, thank you!
[QUOTE=blackwidowman;52851749]Im moving a car entity with setpos but occasionally it crashes the server. What could cause/fix this?[/QUOTE]
Can we see the code for how you're doing this? If youre trying to make the car look like its driving you should not be using SetPos, if you're trying to teleport it then you should be fine.
This is probably a really stupid question, but what's the best way to check for player keypresses with a SWEP? Currently I'm checking for a player pressing +attack3 like this:
[CODE]function SWEP:Think()
if self.Owner:KeyPressed(33554432) and self.Owner:KeyDown(33554432) then
self.Weapon:TertiaryAttack()
end
end[/CODE]
I'm pretty sure that's not a very good or efficient way to do that though. Also, am I stuck using decimals for any keys that aren't covered by IN_ enums?
[QUOTE=spepus;52854163]This is probably a really stupid question, but what's the best way to check for player keypresses with a SWEP? Currently I'm checking for a player pressing +attack3 like this:
[CODE]function SWEP:Think()
if self.Owner:KeyPressed(33554432) and self.Owner:KeyDown(33554432) then
self.Weapon:TertiaryAttack()
end
end[/CODE]
I'm pretty sure that's not a very good or efficient way to do that though. Also, am I stuck using decimals for any keys that aren't covered by IN_ enums?[/QUOTE]
+attack3 isn’t a thing as far as I can tell. I’m assuming you mean middle mouse button? If that’s the case then there is a way to use KEY_ enums with prediction to control your weapon but it’s a giant pain in the ass. Are you positive there is no other way you can implement this feature?
[editline]4th November 2017[/editline]
Also how do you know that that decimal is the one for middle mouse? It’s not defined [URL="https://github.com/VSES/SourceEngine2007/blob/43a5c90a5ada1e69ca044595383be67f40b33c61/src_main/game/shared/in_buttons.h"]here[/URL] so unless it’s a new addition, I don’t think it exists. Either way I can’t test it right now but if it does exist then you could check for it in GM.KeyPress instead.
[QUOTE=YourStalker;52853887]Can we see the code for how you're doing this? If youre trying to make the car look like its driving you should not be using SetPos, if you're trying to teleport it then you should be fine.[/QUOTE]
Yeah i'm just making it teleport into a garage using setpos and I have no idea why it crashes
the server sometimes. Do I need to change the physics possibly?
[IMG]https://i.imgur.com/LgtKtew.png[/IMG]
Am I supposed to create a new table for that or is there a table for that already created? Also how do I create a table so it registers as that?
edit: fixed but now i get another error 'attempt to index a nil value'
[QUOTE=YourStalker;52854290]+attack3 isn’t a thing as far as I can tell. I’m assuming you mean middle mouse button? If that’s the case then there is a way to use KEY_ enums with prediction to control your weapon but it’s a giant pain in the ass. Are you positive there is no other way you can implement this feature?
[editline]4th November 2017[/editline]
Also how do you know that that decimal is the one for middle mouse? It’s not defined [URL="https://github.com/VSES/SourceEngine2007/blob/43a5c90a5ada1e69ca044595383be67f40b33c61/src_main/game/shared/in_buttons.h"]here[/URL] so unless it’s a new addition, I don’t think it exists. Either way I can’t test it right now but if it does exist then you could check for it in GM.KeyPress instead.[/QUOTE]
+attack3 exists and is used by Insurgency and TF2. It exists in gmod as well, but afaik is completely unused. Through some experimentation I was able to find the decimal for +attack3, which seems to be the only way to check for it.
[QUOTE=Status Quack;52850652]Hello, I've a trouble, I've made the 'SimpleTextOutlined' upon the entity, but it looks awful. I cannot understand, what I've done wrong
[IMG]https://pp.userapi.com/c840229/v840229488/43fc2/wgVW51V9tH0.jpg[/IMG]
[CODE]include( 'shared.lua' )
surface.CreateFont("AFont", {
size = 17,
weight = 600,
extended = true,
font = "Roboto",
})
function ENT:Draw()
self:DrawModel()
local ply = LocalPlayer()
local blackc = Color(0,0,0)
local whitec = Color(255,255,255)
local aAngle = self:GetAngles()
local AEyes = ply:EyeAngles()
aAngle:RotateAroundAxis(aAngle:Forward(), 90)
aAngle:RotateAroundAxis(aAngle:Right(), -90)
cam.Start3D2D(self:GetPos()+self:GetUp()*32, Angle(0, AEyes.y-90, 90), 0.1)
draw.SimpleTextOutlined("MedkitBig", "AFont", 0, 15, whitec, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 5, blackc)
cam.End3D2D()
end[/CODE][/QUOTE]
Also 5 is too big for a outline, you should use 1 or 2 max inside small fonts
I'm fucking around with PAC3 and using it to make weapon replacements to be sold with PointShop 2. In this particular case, I'm using it to make a replacement for the TTT knife SWEP's model, as can be seen here;
[video=youtube;450Lzdyzego]https://www.youtube.com/watch?v=450Lzdyzego[/video]
As you can see, it works pretty well! Everything looks more or less as it should, but something vital is missing; sound effects. I want to add sound effects to this PAC for when the user punches but doesn't hit a player, and a sound effect for when the user hits another player. As it stands, I've been unable to do either of these. I've taken a look at the tutorial for this type of thing [url=https://github.com/CapsAdmin/pac3/wiki/Playing-sounds-using-the-animation-event]here[/url], but this just outright doesn't seem to want to work for me (ignoring the fact that this solution would only solve one of the two things I stated, not both).
So my issue boils down to this; I need to make this PAC play a sound when attacking in general, and a sound when hitting another player. Any ideas?
Trying to make the a model crawl it's way out of hell using stencils. I have a hole and I want the model to be visible both inside and outside the hole, but not visible under the place where the stencil is being created (to stop the model from leaking into a ceiling). It's almost there, but I'm running into two issues.
1) The model is visible through walls despite zFail being set to Zero.
2) Looking at the stencil from specific angles causes the stencil to be redrawn but overlapping my current stencil.
[video=youtube;MlhyZaZdmsU]https://www.youtube.com/watch?v=MlhyZaZdmsU&feature=youtu.be[/video]
[lua]
/*-----------------------------------------------------
Custom render.Model func
-----------------------------------------------------*/
function render.ModelCustom( mdl, pos, ang, animation, animationspeed, scale )
local ent = ClientsideModel( mdl, RENDERGROUP_OTHER )
if ( !IsValid( ent ) ) then return end
ent:SetModel( mdl )
ent:SetNoDraw( true )
ent:SetPos( pos )
ent:SetAngles( ang )
ent:ResetSequence( ent:LookupSequence( animation ) )
ent:SetModelScale(scale)
ent:SetCycle( (CurTime()-math.floor(CurTime()))*animationspeed )
ent:DrawModel()
ent:Remove()
end
/*-----------------------------------------------------
Stencil (playermodel manipulation)
------------------------------------------------------*/
hook.Add( "PostDrawOpaqueRenderables", "SpookyPlayerSpawningStencils", function()
for k, v in pairs( ents.GetAll() ) do
if v:GetModel() == "models/props_junk/sawblade001a.mdl" then//if v:GetNWFloat("DoSpawnAnim") > CurTime() then
local angle = Angle(0, 0, 0)
local scale = 64
local pos = v:GetPos()-Vector(scale/2,-scale/2,0)//v:GetNWVector("DoSpawnPos")-Vector(scale/2,-scale/2,0)-Vector(0,0,1.8)
render.SetStencilEnable( true )
render.SetStencilWriteMask( 255 )
render.SetStencilTestMask( 255 )
/*-----------------------------------------------------
Make the hole
-----------------------------------------------------*/
render.SetStencilReferenceValue( 13 )
render.SetStencilCompareFunction( STENCIL_ALWAYS )
render.SetStencilPassOperation( STENCIL_REPLACE )
cam.Start3D2D( pos, angle, scale )
surface.SetDrawColor( Color( 0, 0, 0, 255 ) )
surface.DrawRect( 0, 0, 1, 1 ) -- a 1 x 1 square
cam.End3D2D()
/*-----------------------------------------------------
Draw Hell
-----------------------------------------------------*/
render.SetStencilCompareFunction( STENCIL_EQUAL )
cam.IgnoreZ( true )
render.SetMaterial(Material("models/misc/cube_left.png"))
render.DrawBox( pos,angle,Vector(0,-scale,-scale),Vector(0,0,0),Color(255,255,255,255),true)
render.SetMaterial(Material("models/misc/cube_right.png"))
render.DrawBox( pos,angle,Vector(scale,-scale,-scale),Vector(scale,0,0),Color(255,255,255,255),tr ue)
render.SetMaterial(Material("models/misc/cube_center.png"))
render.DrawBox( pos,angle,Vector(0,0,-scale),Vector(scale,0,0),Color(255,255,255,255),tr ue)
render.SetMaterial(Material("models/misc/cube_back.png"))
render.DrawBox( pos,angle,Vector(0,-scale,-scale),Vector(scale,-scale,0),Color(255,255,255,255),true)
render.SetMaterial(Material("models/misc/cube_bot.png"))
render.DrawBox( pos,angle,Vector(0,-scale,-scale),Vector(scale,0,-scale),Color(255,255,255,255),true)
cam.IgnoreZ( false )
/*-----------------------------------------------------
Draw player crawling out of hell
-----------------------------------------------------*/
render.SetStencilCompareFunction( STENCIL_GREATEREQUAL )
render.SetStencilPassOperation( STENCIL_REPLACE )
render.SetStencilFailOperation( STENCIL_DECR )
render.SetStencilZFailOperation( STENCIL_ZERO )
//if GetViewEntity() != LocalPlayer() then // Don't draw the model for the player spawning
cam.IgnoreZ( true )
render.ModelCustom("models/player/kleiner.mdl",pos+Vector(scale/2,-scale/2,-25),Angle(0,v:GetAngles().y,0),"zombie_climb_loop",1, 1)
cam.IgnoreZ( false )
//end
render.SetStencilEnable( false )
end
end
end )
[/lua]
Any suggestions?
[QUOTE=buu342;52857143]Trying to make the a model crawl it's way out of hell using stencils. I have a hole and I want the model to be visible both inside and outside the hole, but not visible under the place where the stencil is being created (to stop the model from leaking into a ceiling). It's almost there, but I'm running into two issues.
1) The model is visible through walls despite zFail being set to Zero.
2) Looking at the stencil from specific angles causes the stencil to be redrawn but overlapping my current stencil.
:snip:
Any suggestions?[/QUOTE]
First thing you should try is to define the stencil fail and failz operations at the top of your function. Without doing that, they retain whatever previous values they had which could have been set by any other addon (or vanilla gmod). Can cause some weird stuff, possibly your issue.
Second thing I think you should do is not use PostDrawOpaqueRenderables, or any other gamemode hook. You should either create a custom entity with a custom Render hook, or you can override an existing entity's RenderOverride (i.e. the player's render). This will make it draw at the right time every time, without trying to be drawn when it's offscreen, and also prevent it from being drawn multiple times per frame - as PostDrawOpaqueRenderables is called like 5 times every frame.
If you do that and find that it disappears when it's near the egde of your screen, you just need to modify the entity's [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetRenderBounds]render bounds[/url].
[CODE]// id = Item ID(example : paper)
// We need to add "Stock" to the function because the function returns the number of the current stock of the item.
print(GAMEMODE:paperStock()) // Working(returns 40 (pre set value))
print(GAMEMODE:..id.."Stock"..()) // does not working, it should call the function with through variable[/CODE]
[lua]util.AddNetworkString( "SprintSpeedset" )
net.Receive("SprintSpeedset", function(len, ply)
--[[if ( IsValid( ply ) and ply:IsPlayer() ) then
print( "Message from " .. ply:Nick() .. " received. Its length is " .. len .. "." )
else
print( "Message from server received. Its length is " .. len .. "." )
end]]--
if net.ReadBool() then
ply.mult = 1+math.min(math.max(Multiplikator:GetFloat(), 0.1),2 )
else
ply.mult = ply.normalSpeed
end
ServerLog("Setting Speed to "..ply.mult)
end)[/lua]
Running this code serverside producing the error ply.mult is null. Any suggestions why ?
On Local Server its working, on DDC not. Same Plugins
[QUOTE=Weexe;52857621][lua]util.AddNetworkString( "SprintSpeedset" )
net.Receive("SprintSpeedset", function(len, ply)
--[[if ( IsValid( ply ) and ply:IsPlayer() ) then
print( "Message from " .. ply:Nick() .. " received. Its length is " .. len .. "." )
else
print( "Message from server received. Its length is " .. len .. "." )
end]]--
if net.ReadBool() then
ply.mult = 1+math.min(math.max(Multiplikator:GetFloat(), 0.1),2 )
else
ply.mult = ply.normalSpeed
end
ServerLog("Setting Speed to "..ply.mult)
end)[/lua]
Running this code serverside producing the error ply.mult is null. Any suggestions why ?
On Local Server its working, on DDC not. Same Plugins[/QUOTE]
what is Multiplikator?
[editline]5th November 2017[/editline]
Also, what is ply.normalSpeed?
[QUOTE=MPan1;52857627]what is Multiplikator?
[editline]5th November 2017[/editline]
Also, what is ply.normalSpeed?[/QUOTE]
[lua]local Multiplikator = CreateConVar( "ttt_sprint_bonus_rel", "0.5", FCVAR_SERVER_CAN_EXECUTE, "The relative speed bonus given while sprinting. (0.1-2) Def: 0.5")[/lua]
ply.normalSpeed is 1
ply.mult is returned in
[lua]
hook.Add("TTTPlayerSpeed", "TTTSprint4TTTPlayerSpeed" , function(ply)
return ply.mult
end)
[/lua]
How can I hook onto players timing out? Ie server console currently says:
ServerLog: [FAdmin] playerx Disconnected
Dropped playx from server (playerx timed out)
I want to hook into this but I cant find a hook which would capture timing out only
[QUOTE=NeatNit;52857458]First thing you should try is to define the stencil fail and failz operations at the top of your function. Without doing that, they retain whatever previous values they had which could have been set by any other addon (or vanilla gmod). Can cause some weird stuff, possibly your issue.
Second thing I think you should do is not use PostDrawOpaqueRenderables, or any other gamemode hook. You should either create a custom entity with a custom Render hook, or you can override an existing entity's RenderOverride (i.e. the player's render). This will make it draw at the right time every time, without trying to be drawn when it's offscreen, and also prevent it from being drawn multiple times per frame - as PostDrawOpaqueRenderables is called like 5 times every frame.
If you do that and find that it disappears when it's near the egde of your screen, you just need to modify the entity's [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetRenderBounds]render bounds[/url].[/QUOTE]
Did as you said and nothing changed I'm afraid. The model still renders behind walls and the render bug is still there.
How is it possible to create custom damage hulls? I am in strong need of an approach for this. Help is appreciated.
[QUOTE=blackwidowman;52857837]How can I hook onto players timing out? Ie server console currently says:
ServerLog: [FAdmin] playerx Disconnected
Dropped playx from server (playerx timed out)
I want to hook into this but I cant find a hook which would capture timing out only[/QUOTE]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/gameevent/Listen]gameevent.Listen[/url] and a player_disconnect hook. Check if the reason is "Timed out!" then do what ever you want with it.
[QUOTE=txike;52857917][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/gameevent/Listen]gameevent.Listen[/url] and a player_disconnect hook. Check if the reason is "Timed out!" then do what ever you want with it.[/QUOTE]
Never heard of that before. Works great thanks
So I am trying to attach an entity to another entity but I have to offset its angles a little bit. I am using the parent entity's angles as a base to preform some math on it to create a new angle. But every time I do the math it edits the parent entity's angles as well. I am assuming this is happening because when I use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/GetAngles]Entity:GetAngles[/url] it doesn't create a copy of the angles but instead refers directly to the original angles? How would I get it to make a copy so when I edit the angle it doesn't change the parent's angle? Here is how I cam currently doing it.
[code]
local angs = self:GetAngles()
local angmath = Angle(v.ang,angs.y,(angs.z + v.rmod))
[/code]
Show the rest of the code, that bit shouldn't cause any oroblems.
[QUOTE=ralle105;52859146]Show the rest of the code, that bit shouldn't cause any oroblems.[/QUOTE]
For sure. This function is called in the INT of the entity on server side.
[code]function ENT:SpawnFlairDeployer()
for k ,v in pairs(self.FlairDeployers) do
local angs = self:GetAngles()
local angmath = Angle(v.ang,angs.y,(angs.z + v.rmod))
v.ent = ents.Create( "cas_flare_deploy" )
v.ent:SetPos( self:LocalToWorld(v.pos) )
v.ent:SetAngles(angmath)
v.ent:Spawn()
v.ent:SetNotSolid(false)
v.ent.p = self
constraint.NoCollide( self, v.ent, 0, 0 )
constraint.Weld(self, v.ent, 0,0,0, false)
v.ent.PhysgunDisabled = true
end
end[/code]
Could someone give an example on how we're supposed to use the TTTPlayerSpeedModifier hook to affect only one player?
So far I have
[code]
hook.Add("TTTPlayerSpeedModifier","tttknife",function() return 2 end)
[/code]
This works great for changing the player's speed, but it changes the speed for everyone. How do I change the speed for only a single player?
(I'm aware that this hook isn't "in production" yet)
[QUOTE=Shadari;52859479]Could someone give an example on how we're supposed to use the TTTPlayerSpeedModifier hook to affect only one player?
So far I have
[code]
hook.Add("TTTPlayerSpeedModifier","tttknife",function() return 2 end)
[/code]
This works great for changing the player's speed, but it changes the speed for everyone. How do I change the speed for only a single player?
(I'm aware that this hook isn't "in production" yet)[/QUOTE]
[url]https://github.com/Facepunch/garrysmod/blob/7afc0e9627781656216c5bdd85729b64c6d2174e/garrysmod/gamemodes/terrortown/gamemode/shared.lua#L178[/url]
First argument is the player.
Sorry, you need to Log In to post a reply to this thread.