I made a device that shows enemies inside a certain range through walls, like a small wallhack. This is the code:
[CODE]hook.Add("PostDrawOpaqueRenderables","SensorWallhack",function()
for k = #npcsundersensor, 1, -1 do
v = npcsundersensor[k]
render.ClearStencil()
if IsValid(v[1]) and v[1]:Health() > 0 then
cam.Start3D()
render.SetStencilEnable( true )
cam.IgnoreZ( true )
render.SetStencilWriteMask( 1 )
render.SetStencilTestMask( 1 )
render.SetStencilReferenceValue( 1 )
render.SetStencilCompareFunction( STENCIL_ALWAYS )
render.SetStencilPassOperation( STENCIL_REPLACE )
render.SetStencilFailOperation( STENCIL_KEEP )
render.SetStencilZFailOperation( STENCIL_KEEP )
render.SetBlend(0)
v[1]:DrawModel()
render.SetBlend(1)
render.SetStencilCompareFunction( STENCIL_EQUAL )
render.SetStencilPassOperation( STENCIL_KEEP )
cam.Start2D()
surface.SetAlphaMultiplier( math.Clamp(500-v[2],0,500)/500 )
surface.SetDrawColor( Color( 255, 0, 0 ) )
surface.DrawRect( 0, 0, ScrW(), ScrH() )
surface.SetAlphaMultiplier( 1 )
cam.End2D()
cam.IgnoreZ( false )
v[1]:DrawModel()
render.SetStencilEnable( false )
cam.End3D()
end
end
end)[/CODE]
The problem is that, once the NPC dies, a copy of its model is still drawn at the original position, for one or two seconds, and then it dissapears. Is there a way to prevent that?
[QUOTE=MaxShadow;49830943]The problem is that, once the NPC dies, a copy of its model is still drawn at the original position, for one or two seconds, and then it dissapears. Is there a way to prevent that?[/QUOTE]
i don't think so, since the ragdoll that npcs produce when they die arent the entity itself
also, you're creating a global variable v, you need to add local before that
[QUOTE=TrenchFroast;49830958]i don't think so, since the ragdoll that npcs produce when they die arent the entity itself
also, you're creating a global variable v, you need to add local before that[/QUOTE]
Oh, sometimes I forget to add the "local" when not using "k,v in pairs". So theres no way to prevent that duplicated model? Thats weird. If the NPC dies, the entity should stop being valid, or at least its health should be 0. I don't understand why it keeps drawing it.
[QUOTE=BillyOnWiiU;49830233]How can I create a ConVar using C++ in a module?
Obviously I can do
[CODE]LUA->GetField(-1, "CreateConVar");
LUA->PushString("gmsv_restart_file");
LUA->PushString("");
/* code for enum table */
LUA->Call(3,0);[/CODE]
To do
[CODE]CreateConVar("gmsv_restart_file","", .. )[/CODE]
But I need to find out how to
a) Create a Lua table to store the FCVAR enumerations
b) Actually get the values of the FCVAR enumerations
So how can I go about doing this?[/QUOTE]
[cpp]LUA->PushSpecial(GarrysMod::Lua::SPECIAL_GLOB);
LUA->GetField(-1, "CreateConVar");
LUA->PushString("gmsv_restart_file");
LUA->PushString("");
LUA->CreateTable();
LUA->PushNumber(1);
LUA->GetField(-6, "FCVAR_CHEAT");
LUA->SetTable(-3);
LUA->PushNumber(2);
LUA->GetField(-6, "FCVAR_NOTIFY");
LUA->SetTable(-3);
LUA->PushNumber(3);
LUA->GetField(-6, "FCVAR_REPLICATED");
LUA->SetTable(-3);
LUA->Call(3, 0);
LUA->Pop();[/cpp]
[img]http://i.imgur.com/OC2yRBM.png[/img]
[QUOTE=naTlatsyrC;49830360][lua]timer.Simple(1, function()
for k,self in pairs( player.GetAll() ) do
if !IsValid(self) then return end
if self:PS_HasItemEquipped(id) then end
for item_id, item in pairs(self.PS_Items) do
local ITEM = PS.Items[item_id]
if item.Equipped then
ITEM:OnEquip(self, item.Modifiers)
end
end
end
end)[/lua][/QUOTE]
You really need to look at the console for errors. Here is your code with proper indentation and some of my comments:
[lua]timer.Simple(1, function()
for k,ply in pairs( player.GetAll() ) do
if !IsValid(ply) then return end
if ply:PS_HasItemEquipped(id) then end -- this line does nothing
for item_id, item in pairs(ply.PS_Items) do
local ITEM = PS.Items[item_id]
if item.Equipped then
ITEM:OnEquip(ply, item.Modifiers)
end
end
end
end
-- ??? one more end missing!
)[/lua]
There is no way this ran without errors.
I asked this before but didn't get a reply -
Is there a way to load image data as an [URL="https://wiki.garrysmod.com/page/Category:IMaterial"]IMaterial[/URL] without having to save the data as a .jpg or .png and then open it again? For example, the data generated from [URL="https://wiki.garrysmod.com/page/render/Capture"]render.Capture[/URL]?
I hate to post again but I can't figure out why this won't work.
[CODE]GMOD_MODULE_OPEN()
{
LUA->PushSpecial(GarrysMod::Lua::SPECIAL_GLOB);
LUA->GetField(-1, "print");
LUA->PushString("[gmsv_restart] Loading");
LUA->Call(1, 0);
LUA->GetField(-1, "print");
LUA->PushString("[gmsv_restart] Creating concommand");
LUA->Call(1, 0);
LUA->GetField(-1, "concommand");
LUA->GetField(-1, "Add");
LUA->PushString("gmsv_restart");
LUA->PushCFunction(Restart);
LUA->Call(2,0);
LUA->GetField(-1, "print");
LUA->PushString("[gmsv_restart] Initialising ConVar");
LUA->Call(1, 0);
LUA->GetField(-1, "CreateConVar");
LUA->PushString("gmsv_restart_file");
LUA->PushString("");
LUA->CreateTable();
LUA->PushNumber(1);
LUA->GetField(-6,"FCVAR_ARCHIVE");
LUA->SetTable(-3);
LUA->PushNumber(2);
LUA->GetField(-6, "FCVAR_SERVER_CAN_EXECUTE");
LUA->SetTable(-3);
LUA->PushNumber(3);
LUA->GetField(-6, "FCVAR_UNLOGGED");
LUA->SetTable(-3);
LUA->PushNumber(4);
LUA->GetField(-6, "FCVAR_PROTECTED");
LUA->SetTable(-3);
LUA->Call(3,0);
LUA->GetField(-1, "print");
LUA->PushString("[gmsv_restart] Loaded");
LUA->Call(1, 0);
LUA->Pop(8);
return 0;
}[/CODE]
[t]http://i.imgur.com/SZ1JXdQ.png[/t]
The problematic code is
[CODE]LUA->GetField(-1, "concommand");
LUA->GetField(-1, "Add");
LUA->PushString("gmsv_restart");
LUA->PushCFunction(Restart);
LUA->Call(2,0);[/CODE]
[QUOTE=BillyOnWiiU;49832552]I hate to post again but I can't figure out why this won't work.
[CODE]GMOD_MODULE_OPEN()
{
LUA->PushSpecial(GarrysMod::Lua::SPECIAL_GLOB);
LUA->GetField(-1, "print");
LUA->PushString("[gmsv_restart] Loading");
LUA->Call(1, 0);
LUA->GetField(-1, "print");
LUA->PushString("[gmsv_restart] Creating concommand");
LUA->Call(1, 0);
LUA->GetField(-1, "concommand");
LUA->GetField(-1, "Add");
LUA->PushString("gmsv_restart");
LUA->PushCFunction(Restart);
LUA->Call(2,0);
LUA->GetField(-1, "print");
LUA->PushString("[gmsv_restart] Initialising ConVar");
LUA->Call(1, 0);
LUA->GetField(-1, "CreateConVar");
LUA->PushString("gmsv_restart_file");
LUA->PushString("");
LUA->CreateTable();
LUA->PushNumber(1);
LUA->GetField(-6,"FCVAR_ARCHIVE");
LUA->SetTable(-3);
LUA->PushNumber(2);
LUA->GetField(-6, "FCVAR_SERVER_CAN_EXECUTE");
LUA->SetTable(-3);
LUA->PushNumber(3);
LUA->GetField(-6, "FCVAR_UNLOGGED");
LUA->SetTable(-3);
LUA->PushNumber(4);
LUA->GetField(-6, "FCVAR_PROTECTED");
LUA->SetTable(-3);
LUA->Call(3,0);
LUA->GetField(-1, "print");
LUA->PushString("[gmsv_restart] Loaded");
LUA->Call(1, 0);
LUA->Pop(8);
return 0;
}[/CODE]
[t]http://i.imgur.com/SZ1JXdQ.png[/t]
The problematic code is
[CODE]LUA->GetField(-1, "concommand");
LUA->GetField(-1, "Add");
LUA->PushString("gmsv_restart");
LUA->PushCFunction(Restart);
LUA->Call(2,0);[/CODE][/QUOTE]
Call pops the Add function but not the concommand table. The next line is
[cpp]LUA->GetField(-1, "print");[/cpp]
So it tries to get the print function from the concommand table. You need to pop the concommand table after calling concommand.Add or use the global table's appropriate index at that point, which would be -2. I recommend you pop the table and make a function dedicated to printing so the code is easier to read and less prone to problems regarding the stack.
You're also overpopping the stack right now. Call pops the function and its arguments. SetTable pops the key and the value.
[QUOTE=Neat-Nit;49831962]You really need to look at the console for errors. Here is your code with proper indentation and some of my comments:
[lua]timer.Simple(1, function()
for k,ply in pairs( player.GetAll() ) do
if !IsValid(ply) then return end
if ply:PS_HasItemEquipped(id) then end -- this line does nothing
for item_id, item in pairs(ply.PS_Items) do
local ITEM = PS.Items[item_id]
if item.Equipped then
ITEM:OnEquip(ply, item.Modifiers)
end
end
end
end
-- ??? one more end missing!
)[/lua]
There is no way this ran without errors.[/QUOTE]
This is an edited chunk off of [URL="http://pointshop.burt0n.net/"]Pointshop[/URL] inside the file GarrysMod\garrysmod\addons\pointshop-master\lua\pointshop\sv_player_extension.lua
inside the first function.
[lua]function Player:PS_PlayerSpawn()
if not self:PS_CanPerformAction() then return end
-- TTT ( and others ) Fix
if TEAM_SPECTATOR != nil and self:Team() == TEAM_SPECTATOR then return end
if TEAM_SPEC != nil and self:Team() == TEAM_SPEC then return end
-- Murder Spectator Fix (they don't specify the above enums when making teams)
-- [url]https://github.com/mechanicalmind/murder/blob/master/gamemode/sv_spectate.lua#L15[/url]
if self.Spectating then return end
timer.Simple(1, function()
for k,self in pairs( player.GetAll() ) do
if !IsValid(self) then return end
if self:PS_HasItemEquipped(id) then end
for item_id, item in pairs(self.PS_Items) do
local ITEM = PS.Items[item_id]
if item.Equipped then
ITEM:OnEquip(self, item.Modifiers)
end
end
end
end)
end[/lua]
What I was trying to get it to do was when the TTT round was started. it would call the PS_PlayerSpawn function and would glitch the skin they have equipped and remove said skin visually. To which players would have to de-equip and re-equip it manually.
Was attempting to have it recognize if they already had the skins equipped or if they died/was in spectator but got out/just joined, it would still equip their skin but if they already had it equipped when they initially spawned it would take no action. I was fairly confused what to do on said sittuation. u . u
Is there a method for setting a font to a custom derma skin? Simply changing the font fields in the derma skin template doesn't seem to yield any effects
I'm trying to create nextbots that behave like normal players, but I'm struggling with eye movements.
[code]
function FakePlayerSetDesiredEyeAngles(ply,eyeangles,Sensitivity)
local CurrentAngles = ply:EyeAngles()
local DesiredAngles = eyeangles
local Final = CurrentAngles - (CurrentAngles - DesiredAngles)*FrameTime()*Sensitivity
ply:SetEyeAngles(Final)
end
[/code]
The problem is that the yaw is not efficient when calculating angles less than 0 or greater than 360. For example, if my current yaw is 359 but I want my yaw to be 1, it would subtract 358 instead of adding 2.
[QUOTE=ROFLBURGER;49835607]The problem is that the yaw is not efficient when calculating angles less than 0 or greater than 360. For example, if my current yaw is 359 but I want my yaw to be 1, it would subtract 358 instead of adding 2.[/QUOTE]
Try to normalize the angle: [url]http://wiki.garrysmod.com/page/Angle/Normalize[/url]
[QUOTE=naTlatsyrC;49833127]This is an edited chunk off of [URL="http://pointshop.burt0n.net/"]Pointshop[/URL] inside the file GarrysMod\garrysmod\addons\pointshop-master\lua\pointshop\sv_player_extension.lua
inside the first function.
[lua]function Player:PS_PlayerSpawn()
if not self:PS_CanPerformAction() then return end
-- TTT ( and others ) Fix
if TEAM_SPECTATOR != nil and self:Team() == TEAM_SPECTATOR then return end
if TEAM_SPEC != nil and self:Team() == TEAM_SPEC then return end
-- Murder Spectator Fix (they don't specify the above enums when making teams)
-- [url]https://github.com/mechanicalmind/murder/blob/master/gamemode/sv_spectate.lua#L15[/url]
if self.Spectating then return end
timer.Simple(1, function()
for k,self in pairs( player.GetAll() ) do
if !IsValid(self) then return end
if self:PS_HasItemEquipped(id) then end
for item_id, item in pairs(self.PS_Items) do
local ITEM = PS.Items[item_id]
if item.Equipped then
ITEM:OnEquip(self, item.Modifiers)
end
end
end
end)
end[/lua]
What I was trying to get it to do was when the TTT round was started. it would call the PS_PlayerSpawn function and would glitch the skin they have equipped and remove said skin visually. To which players would have to de-equip and re-equip it manually.
Was attempting to have it recognize if they already had the skins equipped or if they died/was in spectator but got out/just joined, it would still equip their skin but if they already had it equipped when they initially spawned it would take no action. I was fairly confused what to do on said sittuation. u . u[/QUOTE]
Why not just call Holster and Equip on a TTTBeginRound hook?
I can't see why you call PlayerSpawn, seems like an extra step in the way
Is there an easy way to make Radio Buttons in a tool's C-menu or will I have to settle for a drop-down list?
The wiki doesn't seem to have much, but then again, it also doesn't document [URL=https://github.com/garrynewman/garrysmod/blob/master/garrysmod/gamemodes/sandbox/entities/weapons/gmod_tool/stools/lamp.lua#L229]AddControl[/URL] so I can't be sure.
[QUOTE=Neat-Nit;49835662]Try to normalize the angle: [url]http://wiki.garrysmod.com/page/Angle/Normalize[/url][/QUOTE]
What angle would I normalize? Normalizing Final gives me the same issue.
Hey it could someone tell me why this works
[CODE]
local barminus = 0
local wavesmooth = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
for barminus = 0, 42-baramount, 1 do
wavea[barminus] = 8
wavesmooth[barminus] = math.Approach(wavesmooth[1], wavea[barminus], FrameTime())
end
[/CODE]
but this doesnt?
[CODE]
local barminus = 0
local wavesmooth = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
for barminus = 0, 42-baramount, 1 do
wavea[barminus] = 8
wavesmooth[barminus] = math.Approach(wavesmooth[barminus], wavea[barminus], FrameTime())
end
[/CODE]
Apparently barminus is nil only when in math.Approach(wavesmooth[barminus] and I have absolutely no clue why.
Also try to ignore that horrible table with ones, it was just for testing.
[QUOTE=MistyVermin;49841628] -question- [/QUOTE]
I believe this is happening because lua starts array indexing at 1, and when the loop begins 'barminus' is 0. Therefore 'wavesmooth[0]' is nil and you get an error.
[QUOTE=InfernusN;49842101]I believe this is happening because lua starts array indexing at 1, and when the loop begins 'barminus' is 0. Therefore 'wavesmooth[0]' is nil and you get an error.[/QUOTE]
Thank you so much. That was so obvious I cant believe I didn't see that.
[QUOTE=ROFLBURGER;49838550]What angle would I normalize? Normalizing Final gives me the same issue.[/QUOTE]
[lua]local TurnAngle = CurrentAngles - DesiredAngles
TurnAngle:Normalize()
local Final = CurrentAngles - TurnAngle*FrameTime()*Sensitivity[/lua]
Sorry for the confusion :P
Double-post, sorry (does facepunch still automatically merge double posts?)
I'm having trouble with a DComboBox with custom values. Relevant code:
[lua]---- at the very top, for convenience:
-- define global "enums"
SOFTLAMP_LINE = 0
SOFTLAMP_CROSS = 1
SOFTLAMP_HEXAGON = 2
---- in TOOL.BuildCPanel:
local shapes = CPanel:ComboBox("#tool.softlamp.shape", "softlamp_shape")
shapes:AddChoice( "#tool.softlamp.shape.line" , SOFTLAMP_LINE)
shapes:AddChoice( "#tool.softlamp.shape.cross" , SOFTLAMP_CROSS)
shapes:AddChoice( "#tool.softlamp.shape.hexagon" , SOFTLAMP_HEXAGON)[/lua]
Problem is, the moment the convar value is changed, whether it's changed by the combobox or by anything else), the combobox immediately shows the [i]numerical value[/i] rather than the string representing it. In visual terms:
[quote][img]https://i.gyazo.com/5f86b496aa17384badbd973085b4257b.png[/img][/quote]
↓
*click*
↓
[quote][img]https://i.gyazo.com/5f33142911626e871bfd7ed957b254da.png[/img][/quote]
But if I pick the same value a second time:
[quote][img]https://i.gyazo.com/d2b59d18ce0b85360fb59b87990e45e4.png[/img][/quote]
↓
*click*
↓
[quote][img]https://i.gyazo.com/b0140ce075c5c3fa88843d701e3f4c6b.png[/img][/quote]
The convar value didn't change so it didn't trigger the ComboBox to update.
Another problem (albeit small) is that they are sorted alphabetically by the string, rather than the value or insert order, which is inconvenient.
Hello,
I'm working on a Medic/Respawn system at the moment and I want to do 2 things that I have never done before:
1) Showing a little arrow where a dead player is, with the number of meters (or source units?) he is away.
2) Moving a ragdoll while pressing E on it.
I don't want to have a finished code from you, I just hope that anyone can give some advices on where to start or giving some useful functions.
[QUOTE=Neat-Nit;49843212]Double-post, sorry (does facepunch still automatically merge double posts?)
I'm having trouble with a DComboBox with custom values. Relevant code:
[lua]---- at the very top, for convenience:
-- define global "enums"
SOFTLAMP_LINE = 0
SOFTLAMP_CROSS = 1
SOFTLAMP_HEXAGON = 2
---- in TOOL.BuildCPanel:
local shapes = CPanel:ComboBox("#tool.softlamp.shape", "softlamp_shape")
shapes:AddChoice( "#tool.softlamp.shape.line" , SOFTLAMP_LINE)
shapes:AddChoice( "#tool.softlamp.shape.cross" , SOFTLAMP_CROSS)
shapes:AddChoice( "#tool.softlamp.shape.hexagon" , SOFTLAMP_HEXAGON)[/lua]
Problem is, the moment the convar value is changed, whether it's changed by the combobox or by anything else), the combobox immediately shows the [i]numerical value[/i] rather than the string representing it. In visual terms:
↓
*click*
↓
But if I pick the same value a second time:
↓
*click*
↓
The convar value didn't change so it didn't trigger the ComboBox to update.
Another problem (albeit small) is that they are sorted alphabetically by the string, rather than the value or insert order, which is inconvenient.[/QUOTE]
[code]
panel:AddControl( "ListBox", { Label = "#tool.rb655_lightsaber.SwingSound", Options = list.Get( "rb655_Lightsaber_swingSounds" ) } )
// Somewhere outside, called only once
list.Set( "rb655_Lightsaber_swingSounds", "#tool.rb655_lightsaber.jedi", { rb655_lightsaber_swingsound = "lightsaber/saber_swing1.wav" } )
list.Set( "rb655_Lightsaber_swingSounds", "#tool.rb655_lightsaber.sith", { rb655_lightsaber_swingsound = "lightsaber/saber_swing2.wav" } )
list.Set( "rb655_Lightsaber_swingSounds", "#tool.rb655_lightsaber.dark", { rb655_lightsaber_swingsound = "lightsaber/darksaber_swing.wav" } )[/code]
CPanel:ComboBox is a weird function.
[QUOTE=Robotboy655;49843537][code]
panel:AddControl( "ListBox", { Label = "#tool.rb655_lightsaber.SwingSound", Options = list.Get( "rb655_Lightsaber_swingSounds" ) } )
// Somewhere outside, called only once
list.Set( "rb655_Lightsaber_swingSounds", "#tool.rb655_lightsaber.jedi", { rb655_lightsaber_swingsound = "lightsaber/saber_swing1.wav" } )
list.Set( "rb655_Lightsaber_swingSounds", "#tool.rb655_lightsaber.sith", { rb655_lightsaber_swingsound = "lightsaber/saber_swing2.wav" } )
list.Set( "rb655_Lightsaber_swingSounds", "#tool.rb655_lightsaber.dark", { rb655_lightsaber_swingsound = "lightsaber/darksaber_swing.wav" } )[/code]
CPanel:ComboBox is a weird function.[/QUOTE]
Thank you.
AddControl really needs to be on the wiki... I've made a barebones page for it, probably put it in the wrong place or under the wrong parent, but I've really got NO idea where/how to find more information about it.
If you don't wanna fill in the info yourself, you could point me to the code that defines me and I'll be happy to fill in the wiki. I've [url=http://wiki.garrysmod.com/index.php?title=spawnmenu/AddPropCategory&action=history]done is before...[/url] (although I know that page could also use a better layout)
Sorry, you need to Log In to post a reply to this thread.