Hi all,
I've been trying to create some weapons, with a base compatible with the SWEP Construction Kit.
Because my worldmodel is messed up due to weapon model not supporting, I have to hide it by not calling self.DrawModel(). This causes the weapon to disappear when I drop it.
Is there a good solution to this? I tried to make it so it does not become invisible when it isn't owned, but I have no idea how to do that either.
[QUOTE=8Z;52169053]Hi all,
I've been trying to create some weapons, with a base compatible with the SWEP Construction Kit.
Because my worldmodel is messed up due to weapon model not supporting, I have to hide it by not calling self.DrawModel(). This causes the weapon to disappear when I drop it.
Is there a good solution to this? I tried to make it so it does not become invisible when it isn't owned, but I have no idea how to do that either.[/QUOTE]
I don't know if your approach is good, but you can simply use: [lua]not IsValid(self:GetOwner())[/lua]
[QUOTE=NeatNit;52171426]I don't know if your approach is good, but you can simply use: [lua]not IsValid(self:GetOwner())[/lua][/QUOTE]
So I kind of solved the problem in other ways (who knew staying up late fucks my brain up?). Thanks nonetheless.
My friend my currently making a SWEP in Blender, which I will do the code for.
We're a bit confused when it comes to viewmodel animation events.
How do I trigger such an event, say a reload animation?
Furthermore: can I trigger custom anim events? (we want a certain animation to show when the player uses the flashlight key)
TL;DR: SWEPs and animations? How?
[QUOTE=Fillipuster;52172005]SWEPs and animations[/QUOTE]
Google "Blender SWEP tutorial" [URL="https://facepunch.com/forumdisplay.php?f=40"]or ask on the modelling forum[/URL]
[url]https://facepunch.com/showthread.php?t=1418871&p=45744304&viewfull=1#post45744304[/url]
[url]https://steamcommunity.com/sharedfiles/filedetails/?id=285489946[/url]
[QUOTE=MPan1;52172035]Google "Blender SWEP tutorial" [URL="https://facepunch.com/forumdisplay.php?f=40"]or ask on the modelling forum[/URL]
[url]https://facepunch.com/showthread.php?t=1418871&p=45744304&viewfull=1#post45744304[/url]
[url]https://steamcommunity.com/sharedfiles/filedetails/?id=285489946[/url][/QUOTE]
Thanks MPan! :D
I've asked the modelling guys. Do join the discussion if you (or anyone else) have any input on the matter: [URL="https://facepunch.com/showthread.php?t=1562329&p=52172310#post52172310"]Modelling Thread[/URL]
How the hell does Vector:WithinAABox actually work :\
My cursor should be inside the box according to prints from console, however its not for some reason
Inside ENT:Draw()
[code]
local hovering = self:GetHover()
cam.Start3D2D(pos + self:GetUp() * 23.9 + (-self:GetForward() * 20), self:LocalToWorldAngles(Angle(0, 90, 90)), 0.10)
surface.SetDrawColor(23, 23, 23, 185)
surface.DrawRect(minX + 20, 15, width - 40, 50)
if (hovering == "progressBar") then
draw.SimpleText(nick .. isPossesive(nick) .. " Workbench", "Icarus.craft.table.name", 0, 25,
theme.text.noticeable, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
end
cam.End3D2D()
[/code]
ENT:GetHover() + vectors
[code]
ENT.vectors = {
progressBar = {
topLeft = Vector(-20.468, -27.935, 22,120),
bottomRight = Vector(-20.468, 27.888, 17.412)
}
}
function ENT:GetHover()
local ply = LocalPlayer()
local pos = self:GetPos()
local eyePos = ply:GetPos()
local tr = self:WorldToLocal(ply:GetEyeTrace().HitPos)
local vectors = self.vectors
local progressBar = {}
progressBar.start = vectors.progressBar.topLeft
progressBar.finish = vectors.progressBar.bottomRight
OrderVectors(progressBar.start, progressBar.finish)
if (tr:WithinAABox(progressBar.start, progressBar.finish)) then
return "progressBar"
end
return "none"
end
[/code]
Prints from console:
[code]
finish = -20.468000 27.888000 22.000000
start = -20.468000 -27.934999 17.412001
tr.HitPos = -20.468750 0.050781 21.211426
hovering = none
[/code]
Your vectors don't form a box. The x of your min and max are the same. Also, creating a new variable does NOT copy a vector in Lua like it would in C++. You have to use the Vector() function as a copy constructor, ex.
[code]local progressBarStart = Vector(vectors.progressBar.topLeft)[/code]
I am trying to create an entity with a custom collision mesh to make a door.
Does anyone know why this entity will not block the player when the player is going above a certain speed? It blocks the player if I just lightly jump into it, but if I sprint and jump into it you can see the camera stutter through it very briefly like some kind of bad prediction. Props also show similar behavior, but they don't stutter when passing through like the first-person camera does with a player.
[lua]AddCSLuaFile()
ENT.Base = "base_anim"
ENT.Type = "anim"
function ENT:Initialize()
local x0,y0,z0,x1,y1,z1 = -46,-1,-44,46,3,44
self.min,self.max = Vector(x0,y0,z0),Vector(x1,y1,z1)
if SERVER then
self:PhysicsInitConvex({
Vector(x0,y0,z0),
Vector(x0,y0,z1),
Vector(x0,y1,z0),
Vector(x0,y1,z1),
Vector(x1,y0,z0),
Vector(x1,y0,z1),
Vector(x1,y1,z0),
Vector(x1,y1,z1)
})
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
self:EnableCustomCollisions(true)
self:SetUseType(SIMPLE_USE)
end
end[/lua]
Try MOVETYPE_PUSH
[QUOTE=Revenge282;52182409]I am trying to create an entity with a custom collision mesh to make a door.
Does anyone know why this entity will not block the player when the player is going above a certain speed? It blocks the player if I just lightly jump into it, but if I sprint and jump into it you can see the camera stutter through it very briefly like some kind of bad prediction. Props also show similar behavior, but they don't stutter when passing through like the first-person camera does with a player.
AddCSLuaFile()ENT.Base = "base_anim"ENT.Type = "anim"function ENT:Initialize() local x0,y0,z0,x1,y1,z1 = -46,-1,-44,46,3,44 self.min,self.max = Vector(x0,y0,z0),Vector(x1,y1,z1) if SERVER then self:PhysicsInitConvex({ Vector(x0,y0,z0), Vector(x0,y0,z1), Vector(x0,y1,z0), Vector(x0,y1,z1), Vector(x1,y0,z0), Vector(x1,y0,z1), Vector(x1,y1,z0), Vector(x1,y1,z1) }) self:SetMoveType(MOVETYPE_VPHYSICS) self:SetSolid(SOLID_VPHYSICS) self:EnableCustomCollisions(true) self:SetUseType(SIMPLE_USE) endend
[/QUOTE]
You are creating the physics mesh on the server, thus the client's prediction code isn't aware of it. I think most people solve this problem by creating a client side PhysicsObject with the same mesh.
[editline]3rd May 2017[/editline]
IIRC you have to keep the server and client in sync by updating the PhysicsObject's position/angle in [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/ENTITY/CalcAbsolutePosition"]ENT:CalcAbsolutePosition[/URL] on the client.
[QUOTE=Teklatea;52182701]Try MOVETYPE_PUSH[/QUOTE]
This fixed the player phasing through, but props still have no collisions.
[QUOTE=zoox;52182850]You are creating the physics mesh on the server, thus the client's prediction code isn't aware of it. I think most people solve this problem by creating a client side PhysicsObject with the same mesh.[/QUOTE]
Already tried it on shared, and it still showed the same results.
[QUOTE=zoox;52182850]IIRC you have to keep the server and client in sync by updating the PhysicsObject's position/angle in [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/ENTITY/CalcAbsolutePosition"]ENT:CalcAbsolutePosition[/URL] on the client.[/QUOTE]
This hasn't had any effect on anything it seems.
[QUOTE=Revenge282;52183281]This fixed the player phasing through, but props still have no collisions.
Already tried it on shared, and it still showed the same results.
This hasn't had any effect on anything it seems.[/QUOTE]
hmm. I didn't experience any collision/prediction errors with this code:
[CODE]
ENT.Spawnable = true
ENT.AdminOnly = false
ENT.Base = "base_anim"
ENT.Type = "anim"
function ENT:Initialize()
local x0,y0,z0,x1,y1,z1 = -46,-1,-44,46,3,44
self.min,self.max = Vector(x0,y0,z0),Vector(x1,y1,z1)
self:PhysicsInitConvex({
Vector(x0,y0,z0),
Vector(x0,y0,z1),
Vector(x0,y1,z0),
Vector(x0,y1,z1),
Vector(x1,y0,z0),
Vector(x1,y0,z1),
Vector(x1,y1,z0),
Vector(x1,y1,z1)
})
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
self:EnableCustomCollisions(true)
if CLIENT then
self:MakePhysicsObjectAShadow(false, false)
end
end
if CLIENT then
function ENT:CalcAbsolutePosition(pos, ang)
local physObj = self:GetPhysicsObject()
if IsValid(physObj) then
physObj:UpdateShadow(pos, ang, 0)
end
return pos, ang
end
function ENT:Draw()
self:DrawModel()
local x0,y0,z0,x1,y1,z1 = -46,-1,-44,46,3,44
debugoverlay.Cross(self:LocalToWorld(Vector(x0,y0,z0)), 10, 0)
debugoverlay.Cross(self:LocalToWorld(Vector(x0,y0,z1)), 10, 0)
debugoverlay.Cross(self:LocalToWorld(Vector(x0,y1,z0)), 10, 0)
debugoverlay.Cross(self:LocalToWorld(Vector(x0,y1,z1)), 10, 0)
debugoverlay.Cross(self:LocalToWorld(Vector(x1,y0,z0)), 10, 0)
debugoverlay.Cross(self:LocalToWorld(Vector(x1,y0,z1)), 10, 0)
debugoverlay.Cross(self:LocalToWorld(Vector(x1,y1,z0)), 10, 0)
debugoverlay.Cross(self:LocalToWorld(Vector(x1,y1,z1)), 10, 0)
end
end
[/CODE]
[QUOTE=zoox;52183527]hmm. I didn't experience any collision/prediction errors with this code:
[CODE]
ENT.Spawnable = true
ENT.AdminOnly = false
ENT.Base = "base_anim"
ENT.Type = "anim"
function ENT:Initialize()
local x0,y0,z0,x1,y1,z1 = -46,-1,-44,46,3,44
self.min,self.max = Vector(x0,y0,z0),Vector(x1,y1,z1)
self:PhysicsInitConvex({
Vector(x0,y0,z0),
Vector(x0,y0,z1),
Vector(x0,y1,z0),
Vector(x0,y1,z1),
Vector(x1,y0,z0),
Vector(x1,y0,z1),
Vector(x1,y1,z0),
Vector(x1,y1,z1)
})
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
self:EnableCustomCollisions(true)
if CLIENT then
self:MakePhysicsObjectAShadow(false, false)
end
end
if CLIENT then
function ENT:CalcAbsolutePosition(pos, ang)
local physObj = self:GetPhysicsObject()
if IsValid(physObj) then
physObj:UpdateShadow(pos, ang, 0)
end
return pos, ang
end
function ENT:Draw()
self:DrawModel()
local x0,y0,z0,x1,y1,z1 = -46,-1,-44,46,3,44
debugoverlay.Cross(self:LocalToWorld(Vector(x0,y0, z0)), 10, 0)
debugoverlay.Cross(self:LocalToWorld(Vector(x0,y0, z1)), 10, 0)
debugoverlay.Cross(self:LocalToWorld(Vector(x0,y1, z0)), 10, 0)
debugoverlay.Cross(self:LocalToWorld(Vector(x0,y1, z1)), 10, 0)
debugoverlay.Cross(self:LocalToWorld(Vector(x1,y0, z0)), 10, 0)
debugoverlay.Cross(self:LocalToWorld(Vector(x1,y0, z1)), 10, 0)
debugoverlay.Cross(self:LocalToWorld(Vector(x1,y1, z0)), 10, 0)
debugoverlay.Cross(self:LocalToWorld(Vector(x1,y1, z1)), 10, 0)
end
end
[/CODE][/QUOTE]
[vid]https://puu.sh/vEWct/324667343f.webm[/vid]
What exactly happens when you define a function like this:
[lua]function Table:FuncName( vars )
-- ...
end
[/lua]
And is it possible to rewrite it with a period rather than a colon?
[editline]fdg[/editline]
Y'all got quadruple ninja'd holy shit
If the table is a metatable, you can call that function by doing some_table_instance:FuncName (args). Since you used a colon, it will define "self" in the function as the table you're calling with. Using a dot will not provide self, and instead, you don't need a metatable to call it and will work with any table.
[QUOTE=JasonMan34;52184852]What exactly happens when you define a function like this:
:snip:
And is it possible to rewrite it with a period rather than a colon?[/QUOTE]
Defining a function like that is exactly the same thing as defining it with a dot, only difference is it will have an explicit `self` variable.
[code]
function Table:FuncName(vars)
end
-- Is exactly the same and will behave exactly the same as
function Table.FuncName(self, vars)
end
[/code]
[editline]4th May 2017[/editline]
So yes, you can overwrite it using the dot syntax.
[QUOTE=JasonMan34;52184852]What exactly happens when you define a function like this:
[lua]function Table:FuncName( vars )
-- ...
end
[/lua]
And is it possible to rewrite it with a period rather than a colon?[/QUOTE]
As code_gs has said, it the first argument supplied is self, which is the table itself.
[lua]function Table.FuncName( self, vars )
-- ...
end
[/lua]
This can be called using a colon, and you wont have to supply the self argument.
[lua]Table:FuncName( vars )
[/lua]
or with a period
[lua]Table.FuncName( Table, vars )
[/lua]
[QUOTE=JasonMan34;52184852]What exactly happens when you define a function like this:
[lua]function Table:FuncName( vars )
-- ...
end
[/lua]
And is it possible to rewrite it with a period rather than a colon?[/QUOTE]
[lua]function a:b(c, d) end
-- is the same as
function a.b(self, c, d) end
-- is the same as
a.b = function(self, c, d) end[/lua]
It basically adds the "self" parameter.
[editline]4th May 2017[/editline]
I added "a.b = function(self, ...)", none of you guys did that! It emphasizes how dynamic the whole thing is. Late or not, it's valuable info!
[QUOTE=Revenge282;52183803][vid]https://puu.sh/vEWct/324667343f.webm[/vid][/QUOTE]
So this issue is deriving from using SetParent on the entity that I am making. Is there any way to parent/follow an entity without losing the physics on it like it is showing?
You could probably use the shadow controller system and set the position/angles relative to your vehicle
-snip-
In order to track how long it took for a net message to send to a player, should I send the server's RealTime() when the function was called and compare it to the client's RealTime when the message was received or is there a better way?
example:
[lua]
-- server
net.Start("fuckers")
net.WriteFloat(RealTime())
net.SendToPlayer(ply)
-- client
net.Receive("fuckers", function(len)
local difference = RealTime() - net.ReadFloat()
end)
[/lua]
[QUOTE=thejjokerr;52186174]Damn this rubber ducky method is working
[img]http://www.smbc-comics.com/comics/1479484954-20161118%20(1).png[/img][/QUOTE]
This has happened to me so many times in this thread it's actually scary that this is a thing
No, RealTime is not synchronized; use CurTime instead (which I doubt will give you precise timing information). Why do you want to check the time between messages?
[QUOTE=Teklatea;52188114]No, RealTime is not synchronized; use CurTime instead (which I doubt will give you precise timing information). Why do you want to check the time between messages?[/QUOTE]
I'm creating physical bullets but without the use of source's physics engine.
When you fire a gun, it creates a physical bullet on the server. Then it sends the bullet information to be created on the client.
When the bullet is created, every tick it tells the bullet to move in a direction at a certain speed.
Problem is that there is that delay between when the bullet is created on the client and when the bullet is created on the server.
For example, if a bullet was created to fire along the x axis at a speed of 600 units per second and it took 0.2 seconds for the client to recieve that a bullet was created, the position of the bullet on the server would be 600*0.2 units farther than it is on the client.
Have you tried this bullet method on multiplayer with a friend?
Because I don't think it takes 0.2 seconds to send a net message containing the origin and direction of the bullet.
I think lag would be hard to detect if you simulate the bullet on the client.
[QUOTE=Teklatea;52188242]Have you tried this bullet method on multiplayer with a friend?
Because I don't think it takes 0.2 seconds to send a net message containing the origin and direction of the bullet.
I think lag would be hard to detect if you simulate the bullet on the client.[/QUOTE]
Most bullets I have travel at 600 units per second and if someone has a ping of 50ms, that's a 30 unit difference between client and server.
But will a player detect it?
[editline]5th May 2017[/editline]
And if so you could maybe give the bullet an advance according to the players ping?
[QUOTE=ROFLBURGER;52188066]In order to track how long it took for a net message to send to a player, should I send the server's RealTime() when the function was called and compare it to the client's RealTime when the message was received or is there a better way?
example:
[lua]
-- server
net.Start("fuckers")
net.WriteFloat(RealTime())
net.SendToPlayer(ply)
-- client
net.Receive("fuckers", function(len)
local difference = RealTime() - net.ReadFloat()
end)
[/lua][/QUOTE]
I don't think there's a way, even in theory, to measure one-way delay of packets. Ping always measures both ways - client->server + server->client. It's not really possible to tell the difference between 2 seconds + 2 seconds, and 0.5 seconds + 3.5 seconds. For all practical purposes they are the same.
You can measure the ping:
[lua]
-- server
net.Start("fuckers")
net.WriteFloat(SysTime())
net.SendToPlayer(ply)
-- client
net.Receive("fuckers", function(len)
net.Start("fuckers")
net.WriteFloat(net.ReadFloat())
net.SendToServer()
end)
-- server (again)
net.Receive("fuckers", function(len)
print(SysTime()-net.ReadFloat())
end)
[/lua]
[QUOTE=thejjokerr;52188964]Why can't I spawn a clientside model?
[lua]local test = ents.CreateClientProp(Model("models/props_borealis/bluebarrel001.mdl"));
test:Spawn()
test:SetPos(LocalPlayer():GetPos() + Vector(0,0,15));
[/lua]
Won't work for me and gives this in console:
[code]C_PhysPropClientside::Initialize: PhysModelParseSolid failed for entity -1.[/code]
[editline]5th May 2017[/editline]
Calling SetModel with the same model again works until I press escape. Then it just dissapears :/[/QUOTE]
[lua]
local c_Model = ents.CreateClientProp()
c_Model:SetPos( ply:GetPos() )
c_Model:SetModel( "models/props_borealis/bluebarrel001.mdl" )
c_Model:SetParent( ply )
c_Model:Spawn()[/lua]
Having never used it before, have you tried it like this? It's taken directly from the wiki.
Sorry, you need to Log In to post a reply to this thread.