Not really a problem but more of trying to understand some unknown behavior of net library.
Some days ago I was making a code that made use of net.WriteInt and net.ReadInt, some time later I realized that I hadn't but a bitCount parameter on net.WriteInt neither on net.ReadInt, but the script still worked perfectly.
So, does net.Read/WriteInt REQUIRES a bitCount parameter or is it an optional parameter?
How do I send a vector from a net.receive to another function?
[QUOTE=keeperman;49683496]How do I send a vector from a net.receive to another function?[/QUOTE]
Function arguments?
[QUOTE=geferon;49683514]Function arguments?[/QUOTE]
That's what I'm using but I can't get it to work
Error: (Vector expected, got nil)
[QUOTE=keeperman;49683520]That's what I'm using but I can't get it to work
Error: (Vector expected, got nil)[/QUOTE]
Thats because the vector is not being sent, or you're reading it wrong. Are you sure you're reading variables in the right order?. Can you show us some of your code?
Yea sure.
[code]function SWEP:SecondaryAttack( len )
local ply = self.Owner
local part = EffectData()
if ply ~= NULL then
part:SetOrigin( net.ReadVector() )
part:SetScale( 1 )
util.Effect( "effect", part)
end
end
net.Receive( "Net", SWEP:SecondaryAttack() )
net.Start( "Net" )
net.WriteVector( v.modelEnt:GetPos() )
net.WriteAngle( v.modelEnt:GetAngles() )
net.SendToServer() [/code]
I tried somethings before and I felt too lazy to revert
[QUOTE=keeperman;49683825]Yea sure.
[code]function SWEP:SecondaryAttack( len )
local ply = self.Owner
local part = EffectData()
if ply ~= NULL then
part:SetOrigin( net.ReadVector() )
part:SetScale( 1 )
util.Effect( "effect", part)
end
end
net.Receive( "Net", SWEP:SecondaryAttack() )
net.Start( "Net" )
net.WriteVector( v.modelEnt:GetPos() )
net.WriteAngle( v.modelEnt:GetAngles() )
net.SendToServer() [/code]
I tried somethings before and I felt too lazy to revert[/QUOTE]
That apart from bad code practice is still wrong, the correct code would be:
[lua]
function SWEP:SecondaryAttack( vec )
local ply = self.Owner
local part = EffectData()
if ply ~= NULL then
part:SetOrigin( vec )
part:SetScale( 1 )
util.Effect( "effect", part)
end
end
net.Receive( "Net", function() SWEP:SecondaryAttack( net.ReadVector ( ) ) end)
net.Start( "Net" )
net.WriteVector( v.modelEnt:GetPos() )
net.WriteAngle( v.modelEnt:GetAngles() )
net.SendToServer()
[/lua]
I also recommend you don't use such broad words for net messages as any other addon could be using them too.
[QUOTE=GGG KILLER;49683851]That apart from bad code practice is still wrong, the correct code would be:
function SWEP:SecondaryAttack( vec ) local ply = self.Owner local part = EffectData() if ply ~= NULL then part:SetOrigin( vec ) part:SetScale( 1 ) util.Effect( "effect", part) endendnet.Receive( "Net", function() SWEP:SecondaryAttack( net.ReadVector ( ) ) end)net.Start( "Net" ) net.WriteVector( v.modelEnt:GetPos() ) net.WriteAngle( v.modelEnt:GetAngles() )net.SendToServer()
I also recommend you don't use such broad words for net messages as any other addon could be using them too.[/QUOTE]
Oh thanks.
[QUOTE]I also recommend you don't use such broad words for net messages as any other addon could be using them too.[/QUOTE]
You mean the "Net"? Well its a placeholder, I'm being a bit "sneaky" about what I'm working on
Anyone know why this doesn't work?
[CODE]
local query = vgui.Create "DFrame"
query:SetTitle ''
query:SetDraggable(false)
query:ShowCloseButton(false)
query:SetSize(400, 400)
query:Center()
query:MakePopup()
--[[query.starttime = SysTime()
function query:Paint(w, h)
drawBaseStyle(self, w, h)
end]]--
timer.Simple(10, function() query:Close(); base:SetVisible(true) end)
-- Confirmation text
local message = query:Add "DLabel"
message:SetFont "ChatFont"
message:SetText "Are you sure? This can't be undone."
message:SizeToContents()
message:SetContentAlignment(5)
message:SetPos(200, 200)
[/CODE]
SetContentAlignment doesn't seem to work at all, it stays aligned to the right like it normally would
[QUOTE=bigdogmat;49684435]Anyone know why this doesn't work?
[CODE]
local query = vgui.Create "DFrame"
query:SetTitle ''
query:SetDraggable(false)
query:ShowCloseButton(false)
query:SetSize(400, 400)
query:Center()
query:MakePopup()
--[[query.starttime = SysTime()
function query:Paint(w, h)
drawBaseStyle(self, w, h)
end]]--
timer.Simple(10, function() query:Close(); base:SetVisible(true) end)
-- Confirmation text
local message = query:Add "DLabel"
message:SetFont "ChatFont"
message:SetText "Are you sure? This can't be undone."
message:SizeToContents()
message:SetContentAlignment(5)
message:SetPos(200, 200)
[/CODE]
SetContentAlignment doesn't seem to work at all, it stays aligned to the right like it normally would[/QUOTE]
Ehm, "message" should be [code]local message = vgui.Create( "DLabel", query )[/code]
[QUOTE=keeperman;49684493]Ehm, "message" should be [code]local message = vgui.Create( "DLabel", query )[/code][/QUOTE]
It's the same thing, both create a new panel and set its parent
[QUOTE=bigdogmat;49684435]Anyone know why this doesn't work?
[CODE]
local query = vgui.Create "DFrame"
query:SetTitle ''
query:SetDraggable(false)
query:ShowCloseButton(false)
query:SetSize(400, 400)
query:Center()
query:MakePopup()
--[[query.starttime = SysTime()
function query:Paint(w, h)
drawBaseStyle(self, w, h)
end]]--
timer.Simple(10, function() query:Close(); base:SetVisible(true) end)
-- Confirmation text
local message = query:Add "DLabel"
message:SetFont "ChatFont"
message:SetText "Are you sure? This can't be undone."
message:SizeToContents()
message:SetContentAlignment(5)
message:SetPos(200, 200)
[/CODE]
SetContentAlignment doesn't seem to work at all, it stays aligned to the right like it normally would[/QUOTE]
What are you trying to do?
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Panel/SetContentAlignment]Panel:SetContentAlignment[/url]
Are yo trying to do something like on the wiki's photo?
[QUOTE=geferon;49684742]What are you trying to do?
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Panel/SetContentAlignment]Panel:SetContentAlignment[/url]
Are yo trying to do something like on the wiki's photo?[/QUOTE]
Yes
[QUOTE=bigdogmat;49684791]Yes[/QUOTE]
Could be because you SizeToContents your label, making the size so tight it can't align anything?
[QUOTE=ms333;49684814]Could be because you SizeToContents your label, making the size so tight it can't align anything?[/QUOTE]
I thought that may be the issue, though I re-sized the DFrame to be 400x400 and still didn't work.
[IMG]http://puu.sh/mYhIs/c486a5648c.jpg[/IMG]
This is what it looks like currently
[QUOTE=bigdogmat;49685138]I thought that may be the issue, though I re-sized the DFrame to be 400x400 and still didn't work.
-img-
This is what it looks like currently[/QUOTE]
I think he meant your label's SizeToContents, did you try removing it?
I have this piece of code inside a "RenderScreenspaceEffects" hook. It draws a 3D2D text in the mid point of a beam.
[CODE]
if GetConVarNumber("patrolroutes_showchance") != 0 then
cam.Start3D2D(pos,Angle(0,ang.y,90),0.5)
draw.DrawText("Chance: "..PatrolLinks[i][3],"default",2,2,col,TEXT_ALIGN_CENTER)
cam.End3D2D()
end
if pPrev == effect then render.DrawBeam(pPrev:GetPos() +offset,p:GetPos() +offset,5,0,0,colHighlighted)
else render.DrawBeam(pPrev:GetPos() +offset,p:GetPos() +offset,5,0,0,col) end
[/CODE]
The problem is that I can't draw both. If the text is drawn, then the beam isn't. Any ideas?
[QUOTE=GGG KILLER;49685224]I think he meant your label's SizeToContents, did you try removing it?[/QUOTE]
Yes I did
EDIT: I wish the wiki page for SetContentAlignment included the code for the example, would make this a lot easier.
Anyone know why an animation might only be playing when the entity is moving?
[editline]6th February 2016[/editline]
I have ent:SetPlaybackRate(1) and am using ent:SetSequence() to set the sequence.
Is there any reason for ENT:SetAngles() placed within ENT:PhysicsSimulate() to cause all movement (besides the angle movement) to be very slowed?
Anyone have some example code for creating a minimap? I just need a snippet that'll put me in the right direction, like converting world positions of x/y/z to x/y coordinates of a 2D rectangle.
[editline]7th February 2016[/editline]
[QUOTE=YourStalker;49686266]Anyone know why an animation might only be playing when the entity is moving?
[editline]6th February 2016[/editline]
I have ent:SetPlaybackRate(1) and am using ent:SetSequence() to set the sequence.[/QUOTE]
What type of entity is it?
[QUOTE=MaximLaHaxim;49687335]What type of entity is it?[/QUOTE]
Anim
Trying to use drag'n'drop and tracking when there is no dragging at all. I have a panel with the required :Droppable('Mover') and :Receiver('Mover',highlight) functions required, and it works pretty well. It highlights the receiver as wanted.
However, I also want to know when the user isn't dragging these boxes.
I asked about it previously and someone encouraged me to use the mouse's X and Y, but I've ran into a problem:
setting OnMousePressed and OnMouseReleased breaks the dragging completely. No returning true or false either; as long as they're set, drag won't work.
Not sure if that's expected behaviour, but it's breaking my plans. Any alternative to get mouse coords on click on the instant the user presses and stops pressing their mouse1 key?
EDIT: Fixed it. For the next timetraveller coming up here with my problem:
you can force dragging with PANEL:DragMousePress( MOUSEKEY ) and PANEL:DragMouseRelease( (SAME)MOUSEKEY ). So, as it turns out, you can use OnMousePressed.
The final code to distinguish between clicks and drags:
[code]
PANEL:Droppable('Mover')
PANEL:Receiver('Mover',FunctionForReceivingWhatever)
PANEL.OnMousePressed = function()
PANEL.MX = gui.MouseX()
PANEL.MY = gui.MouseY()
PANEL:DragMousePress( MOUSE_LEFT )
end
PANEL.OnMouseReleased = function()
if PANEL.MX and PANEL.MX == gui.MouseX() and PANEL.MY and PANEL.MY == gui.MouseY() then
--Stuff for single click
else
--Stuff for having dragged; you probably have more info on panel:receiver function, though.
end
PANEL:DragMouseRelease( MOUSE_LEFT )
end
[/code]
1 Posts
I'm making a BMRP server using DarkRP, and when I disabled the default jobs and replaced them with new ones, they dont show up either way.
--[[---------------------------------------------------------------------------
The disabled default jobs. true to disable, false to enable.
NOTE: If you disable a job and remake it, expect things that rely on the job to stop working
e.g. you disable the gundealer and you make a new job as TEAM_GUN. If you want the shipments/door groups/etc. to
work for your custom job, remake them to include your job as well.
---------------------------------------------------------------------------]]
DarkRP.disabledDefaults["jobs"] = {
["chief"] = true,
["citizen"] = true,
["cook"] = false, --Hungermod only
["cp"] = true,
["gangster"] = true,
["gundealer"] = true,
["hobo"] = true,
["mayor"] = true,
["medic"] = true,
["mobboss"] = true,
}
and
--[[---------------------------------------------------------------------------
DarkRP custom jobs
---------------------------------------------------------------------------
This file contains your custom jobs.
This file should also contain jobs from DarkRP that you edited.
Note: If you want to edit a default DarkRP job, first disable it in darkrp_config/disabled_defaults.lua
Once you've done that, copy and paste the job to this file and edit it.
The default jobs can be found here:
[url]https://github.com/FPtje/DarkRP/blob/master/gamemode/config/jobrelated.lua[/url]
For examples and explanation please visit this wiki page:
[url]http://wiki.darkrp.com/index.php/DarkRP:CustomJobFields[/url]
Add jobs under the following line:
---------------------------------------------------------------------------]]
TEAM_CITIZEN = DarkRP.createJob("Visitor", {
color = Color(20, 150, 20, 255),
model = {
"models/player/Group01/Female_01.mdl",
"models/player/Group01/Female_02.mdl",
"models/player/Group01/Female_03.mdl",
"models/player/Group01/Female_04.mdl",
"models/player/Group01/Female_06.mdl",
"models/player/group01/male_01.mdl",
"models/player/Group01/Male_02.mdl",
"models/player/Group01/male_03.mdl",
"models/player/Group01/Male_04.mdl",
"models/player/Group01/Male_05.mdl",
"models/player/Group01/Male_06.mdl",
"models/player/Group01/Male_07.mdl",
"models/player/Group01/Male_08.mdl",
"models/player/Group01/Male_09.mdl"
},
description = [[You are a visitor to Black Mesa.]],
weapons = {},
command = "citizen",
max = 0,
salary = GAMEMODE.Config.normalsalary,
admin = 0,
vote = false,
hasLicense = false,
candemote = false
})
TEAM_POLICE = DarkRP.createJob("Security Guard"),
color = Color(25, 25, 170, 255),
model = {"models/player/police.mdl", "models/player/police_fem.mdl"},
description = [[Security Guarrds patrol Black Mesa making sure nothing goes wrong.
Type /wanted <name> to alert the Black Mesa to the presence of a criminal.]],
weapons = {"arrest_stick", "unarrest_stick", "weapon_glock2", "stunstick", "door_ram", "weaponchecker"},
command = "cp",
max = 4,
salary = GAMEMODE.Config.normalsalary * 1.45,
admin = 0,
vote = true,
hasLicense = true,
ammo = {
["pistol"] = 60,
}
})
TEAM_MEDIC = DarkRP.createJob("Doctor"),
color = Color(47, 79, 79, 255),
model = "models/player/kleiner.mdl",
description = [[You have to heal people who get injured in Black Mesa.
Left click with the Medical Kit to heal other players.
Right click with the Medical Kit to heal yourself.]],
weapons = {"med_kit"},
command = "medic",
max = 3,
salary = GAMEMODE.Config.normalsalary,
admin = 0,
vote = false,
hasLicense = false,
medic = true
})
TEAM_CHIEF = DarkRP.createJob("Head of Security"),
color = Color(20, 20, 255, 255),
model = "models/player/combine_soldier_prisonguard.mdl",
description = [[You are the head of the entire Black Mesa Security Force. You can command the security officers around. Don't abuse your job however!]],
weapons = {"arrest_stick", "unarrest_stick", "weapon_deagle2", "stunstick", "door_ram", "weaponchecker"},
command = "chief",
max = 1,
salary = GAMEMODE.Config.normalsalary * 1.67,
admin = 0,
vote = false,
hasLicense = true,
chief = true,
NeedToChangeFrom = TEAM_POLICE,
ammo = {
["pistol"] = 60,
}
})
TEAM_MAYOR = DarkRP.createJob("Administrator"),
color = Color(150, 20, 20, 255),
model = "models/player/breen.mdl",
description = [[You are the administrator of Black Mesa. You have 100% control of the facility
and you need to make sure the facility keeps running in a working order.]],
weapons = {},
command = "mayor",
max = 1,
salary = GAMEMODE.Config.normalsalary * 1.89,
admin = 0,
vote = true,
hasLicense = false,
mayor = true
})
TEAM_CITIZEN = DarkRP.createJob("Research Associate"),
color = Color(20, 150, 20, 255),
model = {
"models/player/Group01/Female_01.mdl",
"models/player/Group01/Female_02.mdl",
"models/player/Group01/Female_03.mdl",
"models/player/Group01/Female_04.mdl",
"models/player/Group01/Female_06.mdl",
"models/player/group01/male_01.mdl",
"models/player/Group01/Male_02.mdl",
"models/player/Group01/male_03.mdl",
"models/player/Group01/Male_04.mdl",
"models/player/Group01/Male_05.mdl",
"models/player/Group01/Male_06.mdl",
"models/player/Group01/Male_07.mdl",
"models/player/Group01/Male_08.mdl",
"models/player/Group01/Male_09.mdl"
},
description = [[]]
weapons = {},
command = "citizen",
max = 0,
salary = GAMEMODE.Config.normalsalary,
admin = 0,
vote = false,
hasLicense = false,
candemote = false
})
TEAM_CITIZEN = DarkRP.createJob("Research and Development"),
color = Color(20, 150, 20, 255),
model = {
"models/player/Group01/Female_01.mdl",
"models/player/Group01/Female_02.mdl",
"models/player/Group01/Female_03.mdl",
"models/player/Group01/Female_04.mdl",
"models/player/Group01/Female_06.mdl",
"models/player/group01/male_01.mdl",
"models/player/Group01/Male_02.mdl",
"models/player/Group01/male_03.mdl",
"models/player/Group01/Male_04.mdl",
"models/player/Group01/Male_05.mdl",
"models/player/Group01/Male_06.mdl",
"models/player/Group01/Male_07.mdl",
"models/player/Group01/Male_08.mdl",
"models/player/Group01/Male_09.mdl"
},
description = [[]]
weapons = {},
command = "citizen",
max = 0,
salary = GAMEMODE.Config.normalsalary,
admin = 0,
vote = false,
hasLicense = false,
candemote = false
})
TEAM_CITIZEN = DarkRP.createJob("Head Research and Development"),
color = Color(20, 150, 20, 255),
model = {
"models/player/Group01/Female_01.mdl",
"models/player/Group01/Female_02.mdl",
"models/player/Group01/Female_03.mdl",
"models/player/Group01/Female_04.mdl",
"models/player/Group01/Female_06.mdl",
"models/player/group01/male_01.mdl",
"models/player/Group01/Male_02.mdl",
"models/player/Group01/male_03.mdl",
"models/player/Group01/Male_04.mdl",
"models/player/Group01/Male_05.mdl",
"models/player/Group01/Male_06.mdl",
"models/player/Group01/Male_07.mdl",
"models/player/Group01/Male_08.mdl",
"models/player/Group01/Male_09.mdl"
},
description = [[]]
weapons = {},
command = "citizen",
max = 0,
salary = GAMEMODE.Config.normalsalary,
admin = 0,
vote = false,
hasLicense = false,
candemote = false
})
TEAM_CITIZEN = DarkRP.createJob("Survey Team"),
color = Color(20, 150, 20, 2
Use [code][/code] tags around your code and don't bump your post two times within a 24 minute time period please.
Anyways, it looks like you're constantly redefining TEAM_CITIZEN for some reason, which I doubt is what you want to do.
I'm attempting to do a clientside ViewPunch outside of a weapon context, but it seemingly has no effect. What should I do? Note that even doing lua_run_cl Entity(1):ViewPunch(Angle(-10,0,0)) has no effect.
Does anyone know if it is possible to derive a nextbot/npc entity from an existing NPC in gmod?
[QUOTE=MaxShadow;49685356]I have this piece of code inside a "RenderScreenspaceEffects" hook. It draws a 3D2D text in the mid point of a beam.
[CODE]
if GetConVarNumber("patrolroutes_showchance") != 0 then
cam.Start3D2D(pos,Angle(0,ang.y,90),0.5)
draw.DrawText("Chance: "..PatrolLinks[i][3],"default",2,2,col,TEXT_ALIGN_CENTER)
cam.End3D2D()
end
if pPrev == effect then render.DrawBeam(pPrev:GetPos() +offset,p:GetPos() +offset,5,0,0,colHighlighted)
else render.DrawBeam(pPrev:GetPos() +offset,p:GetPos() +offset,5,0,0,col) end
[/CODE]
The problem is that I can't draw both. If the text is drawn, then the beam isn't. Any ideas?[/QUOTE]
Nevermind, I had to draw them in two different "for" iterations, like this:
[CODE]
for i = 1,num do
cam.Start3D(EyePos(),EyeAngles())
-- Render the beam
cam.End3D()
end
if GetConVarNumber("patrolroutes_showchance") != 0 then
for i = 1,num do
cam.Start3D(EyePos(),EyeAngles())
cam.Start3D2D(pos,Angle(0,ang.y,90),0.5)
-- Draw text
cam.End3D2D()
cam.End3D()
end
end
end
[/CODE]
I tried to do it in the same "for" block but it didn't work. Also, I don't know why, but I had to start 3D2D inside a 3D, or the text wouldn't show at all.
I have a TTT server, and I have 2 problems, very simple problems.
1:Voice chat from other players is bugged, I hear extremely choppy audio and their name icon doesn't even appear when they voice chat.
2:Hud glitch where the names and radar icons fly upwards or downwards on my screen when I get close to them, unless I'm in the skybox in spectator.
[QUOTE=Ricky Spanish;49688124]I have a TTT server, and I have 2 problems, very simple problems.
1:Voice chat from other players is bugged, I hear extremely choppy audio and their name icon doesn't even appear when they voice chat.
2:Hud glitch where the names and radar icons fly upwards or downwards on my screen when I get close to them, unless I'm in the skybox in spectator.[/QUOTE]
unless these things broke after you changed some code, you're likely to have better luck in [URL="https://facepunch.com/forumdisplay.php?f=16"]Garry's Mod Help and Support[/URL].
Sorry, you need to Log In to post a reply to this thread.