I want a Function that If a Player Died and another Player is in Range the player in range.. or just all player in range get freezed... It has kinda something to do with
[CODE]
-- Frighten Function
local function PlayerDeathFrighten(victim, inflictor, attacker)
if victim:Team() == TEAM_SURVIVORS then
for k,v in pairs( player.GetAll() ) do
for a,b in pairs( ents.FindInSphere( v:GetPos(), 1000 )) do
b:Freeze(true)
end
end
end
end
hook.Add("PlayerDeath", "shl_frightten_PlayerDeath", PlayerDeathFrighten)[/CODE]
But dont works i guess the main function is wrong but i never worked with ents.FindInSphere
[QUOTE=Sodak;52550539]I want a Function that If a Player Died and another Player is in Range the player in range.. or just all player in range get freezed... It has kinda something to do with
[CODE]
-- Frighten Function
local function PlayerDeathFrighten(victim, inflictor, attacker)
if victim:Team() == TEAM_SURVIVORS then
for k,v in pairs( player.GetAll() ) do
for a,b in pairs( ents.FindInSphere( v:GetPos(), 1000 )) do
b:Freeze(true)
end
end
end
end
hook.Add("PlayerDeath", "shl_frightten_PlayerDeath", PlayerDeathFrighten)[/CODE]
But dont works i guess the main function is wrong but i never worked with ents.FindInSphere[/QUOTE]
You could just do FindInSphere, and if the ent is a player, freeze him. No need for double loops here
[QUOTE=Gmod4phun;52550583]You could just do FindInSphere, and if the ent is a player, freeze him. No need for double loops here[/QUOTE]
Thank u fixed it and now it works :)
[editline]8th August 2017[/editline]
Ok now added other function to the hook.
Here the code
[CODE]-- Frighten Function
local function PlayerDeathFrighten(victim, inflictor, attacker)
if victim:Team() == TEAM_SURVIVORS then
for a,b in pairs( ents.FindInSphere( victim:GetPos(), 1000 )) do
if b:IsPlayer() and b:IsValid() and b:Team() == TEAM_SURVIVORS and !b.stunfrighten then
local randomfreeze = math.random(1,10)
randomfreeze = math.Round(randomfreeze)
if randomfreeze == 1 then
timer.Create("stun_frighten" .. b:UniqueID(), math.random(4, 6), 1, function()
if !IsValid(b) then return end
if b:Alive() then
b:SetMoveType(MOVETYPE_WALK)
b:SetRunSpeed(b.stungun_runspeed)
b:SetWalkSpeed(b.stungun_walkspeed)
end
b:SetMoveType(MOVETYPE_WALK)
b.stunfrighten = false
end)
b:SetMoveType(MOVETYPE_NONE)
b.stunfrighten = true
b.stungun_runspeed = b:GetRunSpeed()
b.stungun_walkspeed = b:GetWalkSpeed()
b:SetRunSpeed(50)
b:SetWalkSpeed(50)
else
timer.Create("stun_frighten" .. b:UniqueID(), math.random(4, 6), 1, function()
if !IsValid(b) then return end
if b:Alive() then
b:SetRunSpeed(b.stungun_runspeed)
b:SetWalkSpeed(b.stungun_walkspeed)
end
b.stunfrighten = false
end)
b.stunfrighten = true
b.stungun_runspeed = b:GetRunSpeed()
b.stungun_walkspeed = b:GetWalkSpeed()
b:SetRunSpeed(50)
b:SetWalkSpeed(50)
end
end
end
end
end
hook.Add("PlayerDeath", "shl_frightten_PlayerDeath", PlayerDeathFrighten)[/CODE]
How can i make it so.. that if randomfreeze == 1 is active not all players in range get freeze just random maybe 1 or 2 of the players but if player isAdmin he never get randomfreeze == 1 condition.
ANd Does someone know how to simulate the freeze effect.. because freeze deny the player from getting damage.
I know that i have to work with divide functions.
[QUOTE=Sodak;52550605]Thank u fixed it and now it works :)
[editline]8th August 2017[/editline]
Ok now added other function to the hook.
Here the code
[CODE]-- Frighten Function
local function PlayerDeathFrighten(victim, inflictor, attacker)
if victim:Team() == TEAM_SURVIVORS then
for a,b in pairs( ents.FindInSphere( victim:GetPos(), 1000 )) do
if b:IsPlayer() and b:IsValid() and b:Team() == TEAM_SURVIVORS and !b.stunfrighten then
local randomfreeze = math.random(1,10)
randomfreeze = math.Round(randomfreeze)
if randomfreeze == 1 then
timer.Create("stun_frighten" .. b:UniqueID(), math.random(4, 6), 1, function()
if !IsValid(b) then return end
if b:Alive() then
b:SetMoveType(MOVETYPE_WALK)
b:SetRunSpeed(b.stungun_runspeed)
b:SetWalkSpeed(b.stungun_walkspeed)
end
b:SetMoveType(MOVETYPE_WALK)
b.stunfrighten = false
end)
b:SetMoveType(MOVETYPE_NONE)
b.stunfrighten = true
b.stungun_runspeed = b:GetRunSpeed()
b.stungun_walkspeed = b:GetWalkSpeed()
b:SetRunSpeed(50)
b:SetWalkSpeed(50)
else
timer.Create("stun_frighten" .. b:UniqueID(), math.random(4, 6), 1, function()
if !IsValid(b) then return end
if b:Alive() then
b:SetRunSpeed(b.stungun_runspeed)
b:SetWalkSpeed(b.stungun_walkspeed)
end
b.stunfrighten = false
end)
b.stunfrighten = true
b.stungun_runspeed = b:GetRunSpeed()
b.stungun_walkspeed = b:GetWalkSpeed()
b:SetRunSpeed(50)
b:SetWalkSpeed(50)
end
end
end
end
end
hook.Add("PlayerDeath", "shl_frightten_PlayerDeath", PlayerDeathFrighten)[/CODE]
How can i make it so.. that if randomfreeze == 1 is active not all players in range get freeze just random maybe 1 or 2 of the players but if player isAdmin he never get randomfreeze == 1 condition.
ANd Does someone know how to simulate the freeze effect.. because freeze deny the player from getting damage.
I know that i have to work with divide functions.[/QUOTE]
I wouldn't use ents.FindInSphere. It iterates through EVERY entity on the map.
I'd just do something like:
[code]
for a,b in pairs(player.GetAll()) do
if (b:GetPos():Distance(victim:GetPos()) <= 1000) then
--Your code logic here..
end
end
--Alternatively you can use a little function like this.
function util.FindPlayersInSphere(pos, radius)
local t = {};
for k, v in pairs(player.GetAll()) do
if (v:GetPos():Distance(pos)) <= radius) then
table.insert(t, v);
end
end
return t;
end
[/code]
[QUOTE=Brassx;52551645]I wouldn't use ents.FindInSphere. It iterates through EVERY entity on the map.
I'd just do something like:
[code]
for a,b in pairs(player.GetAll()) do
if (b:GetPos():Distance(victim:GetPos()) <= 1000) then
--Your code logic here..
end
end
--Alternatively you can use a little function like this.
function util.FindPlayersInSphere(pos, radius)
local t = {};
for k, v in pairs(player.GetAll()) do
if (v:GetPos():Distance(pos)) <= radius) then
table.insert(t, v);
end
end
return t;
end
[/code][/QUOTE]
Yeah this makes quite sense... But you know how to make it so that its freeze 1 player and slow the others randomly so just pick 1 player to freeze?
Downloading over Browser and Playing it on GMOD works?
Maybe U could try:
[CODE]resource.AddFile( maps/mg_hn_compoundcourse2.bsp )[/CODE]
in a FastDL lua... Or just check the map file because big maps having trouble downloading directly from fastdl.. maybe use workshop instead?
[QUOTE=Shenesis;52554736]Some players are not able to join my server because they can't download the map from my FastDL. I asked someone (who's on Windows) for the console output and they got this:
[code]HTTP ERROR 8 downloading http://nepservers.net/downloadurl/maps/mg_hn_compoundcourse2.bsp.bz2[/code]
Clearly downloading that map through the browser works, what could be wrong? What is HTTP ERROR 8?[/QUOTE]
Since it's a client, I assume it's referring to error 408, which means the client timed out. I would try testing with a different webhost and see if that fixes the issue, because for some reason the Garry's Mod client couldn't load the page/it didn't exist.
[editline]9th August 2017[/editline]
[QUOTE=Sodak;52555030]Downloading over Browser and Playing it on GMOD works?
Maybe U could try:
[CODE]resource.AddFile( maps/mg_hn_compoundcourse2.bsp )[/CODE]
in a FastDL lua... Or just check the map file because big maps having trouble downloading directly from fastdl.. maybe use workshop instead?[/QUOTE]
resource.AddFileing maps does not work, and your syntax is invalid, anyway.
[QUOTE=Shenesis;52554736]Some players are not able to join my server because they can't download the map from my FastDL. I asked someone (who's on Windows) for the console output and they got this:
[code]HTTP ERROR 8 downloading http://nepservers.net/downloadurl/maps/mg_hn_compoundcourse2.bsp.bz2[/code]
Clearly downloading that map through the browser works, what could be wrong? What is HTTP ERROR 8?[/QUOTE]
It's a shot in the dark, and I'm not entirely sure, but I once had this same issue and it 'seemed' to fix when I uploaded the non-bzip compressed version along side the compressed one. I can't confirm if that was indeed the fix(doesn't make sense at all tbh), or if it was just my webserver being weird, but I haven't had the issue since.
[QUOTE=Brassx;52555459]It's a shot in the dark, and I'm not entirely sure, but I once had this same issue and it 'seemed' to fix when I uploaded the non-bzip compressed version along side the compressed one. I can't confirm if that was indeed the fix(doesn't make sense at all tbh), or if it was just my webserver being weird, but I haven't had the issue since.[/QUOTE]
The only reason this "worked" is because Source tries the BZ2 version first and then the non-compressed version of the file if that failed
[QUOTE=Brassx;52555459]It's a shot in the dark, and I'm not entirely sure, but I once had this same issue and it 'seemed' to fix when I uploaded the non-bzip compressed version along side the compressed one. I can't confirm if that was indeed the fix(doesn't make sense at all tbh), or if it was just my webserver being weird, but I haven't had the issue since.[/QUOTE]
It might be that the webserver is getting slammed with lots of clients and times out for some people. It's a very hard issue to reproduce, but you could try increasing thread workers or using some kind of caching.
Can someone help me with the correct way to do door ownership? I have properties which are essentially defined by their doors and when a player buys a property, the doors for that property should then be owned by the player so they can lock and unlock them.
I was going to use `door:SetNWEntity(ply)` for each door but apparently thats not correct. I could also network it manually but I'd like to know my options.
It has been brought to my attention that `Entity:Set/GetNW2*` functions exist that were supposed to replace the old `Entity:Set/GetNW*` functions, however the wiki does not list any of the `NW2*` functions.
[QUOTE=G4MB!T;52558667]It has been brought to my attention that `Entity:Set/GetNW2*` functions exist that were supposed to replace the old `Entity:Set/GetNW*` functions, however the wiki does not list any of the `NW2*` functions.[/QUOTE]
It's mainly up to you, I think darkrp networks it manually but I forgot
Is it possible to scale down prop_door_rotating and have it still work properly? Like a quarter size door with proper collisions and use detection
How do I have a swep detect if it's in the world vs. in a players inventory? For some reason the owner doesnt change upon being dropped. (TTT)
How can i deny if a Player or Bot dies a ragdoll appears.. but i dont want the player.Model as ragdoll want to use a custom model like bonepiles.. but how can i deny the playermodel ragdoll to appear?
[QUOTE=Sodak;52562366]How can i deny if a Player or Bot dies a ragdoll appears.. but i dont want the player.Model as ragdoll want to use a custom model like bonepiles.. but how can i deny the playermodel ragdoll to appear?[/QUOTE]
Using [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/DoPlayerDeath]GM:DoPlayerDeath[/url]
If its a gamemode that doesn't modify this hook and is based on "Base", you can see [URL="https://github.com/Facepunch/garrysmod/blob/master/garrysmod/gamemodes/base/gamemode/init.lua#L41-L57"]this hook in "Base" creates the player ragdoll upon death[/URL].
[QUOTE=Sodak;52551913]Yeah this makes quite sense... But you know how to make it so that its freeze 1 player and slow the others randomly so just pick 1 player to freeze?[/QUOTE]
You could try SetRunSpeed(0) and SetWalkSpeed(0) to simulate the freeze effect without actually giving the player godmode. This is untested, but I don't see any reason why it wouldn't work
[code]
local PlayersInRange = {}
for k, v in pairs(player.GetAll()) do
if v:GetPos():Distance(victim:GetPos()) <= 1000 then
table.insert(PlayersInRange, v)
end
end
local PlayerToFreeze = math.random(1, #PlayersInRange)
for k, v in pairs(PlayersInRange) do
if k == PlayerToFreeze then
v:SetRunSpeed(0)
v:SetWalkSpeed(0)
else
v:SetRunSpeed(25)
v:SetWalkSpeed(25)
end
end
[/code]
[editline]12th August 2017[/editline]
Side question: Does anybody know exactly how performance intensive nextbots are on servers?
[QUOTE=TheCloak;52563716]
Side question: Does anybody know exactly how performance intensive nextbots are on servers?[/QUOTE]
It'd depend on the nextbot really, nextbots with more complex code are going to be more intensive than simple nextbots.
[lua]
if Name == "Use" and Caller:IsPlayer() then
if Caller:Team() == TEAM_CCA and Caller:Name() == ListNames[1] && ListNames[2] or ListNames[3] or ListNames[4] then -- I'll have to set this up into some sort of table. Look at the [whatever] = true table thingie, probably will work
print("Whatever")
else return end
end
[/lua]
Got it set up in this table:
[code]
local ListNames = {}
ListNames[1] = "Union"
ListNames[2] = "RcT"
ListNames[3] = "05"
ListNames[4] = "04"
[/code]
I need it so Union is either in the name with RcT, 05 or 04. How would I do this?
[CODE]
local ListNames = {
"Union" = true,
"RcT" = true,
"05" = true,
"04" = true
}
if Name == "Use" and Caller:IsPlayer() then
if Caller:Team() == TEAM_CCA and ListNames[ Caller:Name() ] then
print("Whatever")
else
return
end
end
end
[/CODE]
[editline]12th August 2017[/editline]
Not sure if this is what you mean
[QUOTE=MPan1;52564351][CODE]
local ListNames = {
"Union" = true,
"RcT" = true,
"05" = true,
"04" = true
}
if Name == "Use" and Caller:IsPlayer() then
if Caller:Team() == TEAM_CCA and ListNames[ Caller:Name() ] then
print("Whatever")
else
return
end
end
end
[/CODE]
[editline]12th August 2017[/editline]
Not sure if this is what you mean[/QUOTE]
Sorry, I am bad at explaining this kind of thing.
The player has a name like CCA-C08-UNION-04-9275. It needs to check that the player has the combination of Union and 04 in their name. It also needs to check that the player has the combination of UNION & RcT and UNION and 05. RcT, 05 and 04 are ranks and UNION is the division.
[QUOTE=Shadow02;52564661]Sorry, I am bad at explaining this kind of thing.
The player has a name like CCA-C08-UNION-04-9275. It needs to check that the player has the combination of Union and 04 in their name. It also needs to check that the player has the combination of UNION & RcT and UNION and 05. RcT, 05 and 04 are ranks and UNION is the division.[/QUOTE]
In this case, if you want to check if the name is formatted in a certain way you should use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/string/match]string.match[/url]
Am I retarded?
[CODE]-- SERVER init.lua
function ENT:Init()
util.AddNetworkString( "bw_printer_rack" )
net.Receive( "bw_printer_rack", function( len, ply )
local ent_ = net.ReadEntity()
print( ent_:GetCreationID() .. " | " .. self:GetCreationID() )
print( ent_ )
print( self )
if ent_:GetCreationID() ~= self:GetCreationID() then return end
print( "true" )
-- do stuff to ent
end )
end
-- CLIENT cl_init.lua
function ENT:Init() -- this is just a snippet for reference, not the whole code lol
net.Start( "bw_printer_rack" )
net.WriteEntity( self )
net.SendToServer()
end
-- OUTPUT
1462 | 1463 <-- wtf
Entity [120][bw_printerrack]
Entity [121][bw_printerrack]
1463 | 1463
Entity [121][bw_printerrack]
Entity [121][bw_printerrack]
true
[/CODE]
Essentially, just trying to verify the net server side, so that I can run a func.
But self is returning the newest CreationID.
[QUOTE=thejjokerr;52567388]Take everything in the server ENT:Init outof that method and replace self with the appropriate entity[/QUOTE]
gamemodes/basewars/entities/entities/bw_printerrack/init.lua:26: attempt to index global 'ENT' (a nil value)
--> print( ent_:GetCreationID() .. " | " .. self:GetCreationID() )
changed to
--> print( ent_:GetCreationID() .. " | " .. ENT:GetCreationID() )
Can't that whole thing be simplified down to
[CODE]
-- SERVER init.lua
function ENT:Init()
print( self:GetCreationID() .. " | " .. self:GetCreationID() )
print( "true" )
-- do stuff to ent
end
[/CODE]
What's the point of networking it
[editline]13th August 2017[/editline]
Also, [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/GetCreationID]Entity:GetCreationID[/url] is serverside only?
I'm trying to render 3D text "flat" onto a door once and rotating the 3D2D matrix based on the HitNormal that the player is looking at the door.
So far its going well but there if you look at the door from the sides (i.e. when the door is open) the text rotates again making it not flat against the door.
Heres what I have now:
[t]http://i.imgur.com/UEo03Bl.jpg[/t]
Heres what I dont want to happen:
[t]http://i.imgur.com/hISqW7Z.jpg[/t]
Here is the code I'm using:
[code]
-- if the distance is <= min, 255 is returned. if distance is > min && <= max
function alphaFromDistance(vec, min, max)
/// Courtesy of Bobblehead (76561198006484623).
local distance = LocalPlayer():GetPos():Distance(vec);
return math.Clamp(-math.pow(((min - math.max(distance, min)) / (max - min)), 4) + 1, 0, 1) * 255;
end
hook.Add("PostDrawTranslucentRenderables", "", function()
local trace = LocalPlayer():GetEyeTrace();
local ent = trace.Entity;
if (IsValid(ent) == false) then return; end
-- todo replace with ent:isDoor()
if (ent:GetClass() != "func_door" && ent:GetClass() != "func_door_rotating" && ent:GetClass() != "prop_door_rotating") then return; end
local pos = ent:LocalToWorld(ent:OBBCenter());
local maxs = ent:OBBMaxs();
-- Narrow doors used in the Amber Room property have retarded bounding boxes. This hack "fixes" that.
if (ent:GetModel() == "models/props_c17/door02_double.mdl") then
maxs = ent:OBBMaxs() - Vector(0, 16, 0);
pos = ent:LocalToWorld((maxs + ent:OBBMins()) / 2);
end
local ang = ent:GetAngles();
-- Fix for the fact that brush doors dont have a rotation relative to the world.
if (util.IsValidModel(ent:GetModel()) == false) then
local size = maxs - ent:OBBMins();
size.x = math.abs(size.x);
size.y = math.abs(size.y);
size.z = math.abs(size.z);
local startpos;
if (size.z < size.x && size.z < size.y) then
startpos = pos + ent:GetUp() * size.z;
elseif (size.x < size.y) then
startpos = pos + ent:GetForward() * size.x;
elseif (size.y < size.x) then
startpos = pos + ent:GetRight() * size.y;
end
local trace = util.TraceLine({
start = startpos;
endpos = pos;
});
ang = trace.Normal:Angle();
end
ang:RotateAroundAxis(ang:Forward(), 90);
ang:RotateAroundAxis(ang:Right(), 90);
ang:RotateAroundAxis(ang:Right(), trace.HitNormal:Angle().y - math.abs(ang.y) + 90);
local alpha = alphaFromDistance(pos, 128, 384);
cam.Start3D2D(pos + ang:Up() * 2.6, ang, 0.014);
cam.IgnoreZ(true);
local nameW, nameH = draw.SimpleTextOutlined("Door name", "DoorOwner", 0, -2, ColorAlpha(color_white, alpha), TEXT_ALIGN_CENTER, TEXT_ALIGN_BOTTOM, 2, Color(255, 0, 0, alpha));
local ownerW, ownerH = draw.SimpleTextOutlined("Owner or unowned", "DoorOwner", 0, 2, ColorAlpha(color_white, alpha), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP, 2, Color(255, 0, 0, alpha));
local dividerWidth = math.max(nameW, ownerW) + 64;
draw.NoTexture();
surface.SetDrawColor(Color(255, 0, 0, alpha));
surface.DrawRect(-dividerWidth / 2, 0, dividerWidth, 10);
surface.SetDrawColor(ColorAlpha(color_white, alpha));
surface.DrawRect((-dividerWidth / 2) + 2, 2, dividerWidth - 4, 6);
cam.IgnoreZ(false);
cam.End3D2D();
end);
[/code]
Anyone know how [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/Vector/ToScreen"]Vector:ToScreen[/URL] works? I am trying to get entity positions in 2D on a renderview and then draw on those 2D positions. Or if anyone could tell me of a script/addon that does that, that works too.
[QUOTE=-Raven-;52568373]Anyone know how [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/Vector/ToScreen"]Vector:ToScreen[/URL] works? I am trying to get entity positions in 2D on a renderview and then draw on those 2D positions. Or if anyone could tell me of a script/addon that does that, that works too.[/QUOTE]
"Returns where on the screen the specified position vector would appear."
ENT:GetPos( ):ToScreen( )
[QUOTE=arow1234;52569239]"Returns where on the screen the specified position vector would appear."
ENT:GetPos( ):ToScreen( )[/QUOTE]
I know that. I meant, like, the math behind it, and what it is actually doing when you call it. I probably should have phrased that question better. Sorry. :/
Sorry, you need to Log In to post a reply to this thread.