[QUOTE=James xX;47621551]Do you already have the entity or are you searching for it? If you already have it, some maths on the individual coordinates of the vectors should provide some help (Higher level of maths than I ever bothered to understand, so you will have to ask someone who is studying maths at university). But to answer your question, yes, it's more than possible.[/QUOTE]
Math student here.
You can't do that with a series of points alone. You need to define edges between them and then faces between the edges.
[QUOTE=Drakehawke;47625590]Math student here.
You can't do that with a series of points alone. You need to define edges between them and then faces between the edges.[/QUOTE]
The points could define a convex hull though. Either way I have no idea how to intersect a convex hull with another convex hull efficiently, even if one of them is an AABB. The internet probably knows.
EDIT: interpreting it as a convex hull is equivalent to implicitly defining edges and faces I guess
[QUOTE=Drakehawke;47625590]Math student here.
You can't do that with a series of points alone. You need to define edges between them and then faces between the edges.[/QUOTE]
That's what I meant. In my head, the way I would do it is get the connecting vectors in series, and calculate a virtual gradient and intercept for a function of a line that crosses the points. Once all the line functions have been calculated, get the position of the entity, and check (with the x,y and z component), which line functions to use (one on either side per dimension). That way, you are only doing 6 comparisons. If all return true, then it is within the defined boundary.
What would be the most efficient way for me to network data for an entity, i currently use ent:SetNWVar which i know is terrible, so advice on something that is more efficient for the server would be great. The data would be getting updated now and then but i need it to stay synchronized between server and client.
I have looked at entity data tables however it would error when i try to call the getX function for the entity
[QUOTE=AIX-Who;47626600]What would be the most efficient way for me to network data for an entity, i currently use ent:SetNWVar which i know is terrible, so advice on something that is more efficient for the server would be great. The data would be getting updated now and then but i need it to stay synchronized between server and client.
I have looked at entity data tables however it would error when i try to call the getX function for the entity[/QUOTE]
I'd look into creating my own networked var style of method of doing it, using the net library.
[QUOTE=Author.;47626721]I'd look into creating my own networked var style of method of doing it, using the net library.[/QUOTE]
Okay will do, if i feel that the code is good enough and if it actually works i will release it for others to use :)
I have made a small script that adds a play count tally for the map currently being played to a database but I am having trouble calling the function again when the map changes.
At the moment I am using the Initialize hook, which works great on server start but does not get called again when the map changes. Looking through the wiki, I seem to be overseeing the hook I need.
So my question, is there a hook that can be called every time the server changes map but at a point where it can read game.GetMap()?
[QUOTE=James xX;47624235][url]http://facepunch.com/showthread.php?t=1089200&p=32614030&viewfull=1#post32614030[/url][/QUOTE]
This doesn't work inside 3D2Ds, guess I'll have to use multiple 3D2D to rotate the text.
[QUOTE=danjono;47627053]I have made a small script that adds a play count tally for the map currently being played to a database but I am having trouble calling the function again when the map changes.
At the moment I am using the Initialize hook, which works great on server start but does not get called again when the map changes. Looking through the wiki, I seem to be overseeing the hook I need.
So my question, is there a hook that can be called every time the server changes map but at a point where it can read game.GetMap()?[/QUOTE]
InitPostEntity?
[QUOTE=AIX-Who;47627191]InitPostEntity?[/QUOTE]
I tried this but it still didn't call the hook after the map was changed.
I should point out I am using mysqloo in this function.
[QUOTE=danjono;47627337]I tried this but it still didn't call the hook after the map was changed.
I should point out I am using mysqloo in this function.[/QUOTE]
Try printing something on initpostentity and see if that works, if it does then it's a problem with your mysqloo code.
[CODE]function ENT:Think()
if ( self:HaveEnemy() ) then
self:EmitSound( "npc/combine_soldier/vo/gosharp.wav" )
end
local ent = ents.Create("ent_nz_grenade")
if ( self:GetEnemy() and IsValid( self:GetEnemy() ) ) then
ent:SetPos(self:EyePos() + Vector(0,0,100))
ent:Spawn()
ent:SetOwner( self )
local phys = ent:GetPhysicsObject()
if phys:IsValid() then
local ang = self:EyeAngles()
ang:RotateAroundAxis(ang:Forward(), math.Rand(-10, 10))
ang:RotateAroundAxis(ang:Up(), math.Rand(-10, 10))
phys:SetVelocityInstantaneous(ang:Forward() * math.Rand( 1000, 1500 ))
end
end
end
[/CODE]
I'm making a nextbot. Everything in this code works fine, but there is one thing I'm trying to add. What I'm trying to do is make it so that the nextbot can't throw a grenade every second, but I have no idea how to add a delay to them shooting...
[QUOTE=danjono;47627053]I have made a small script that adds a play count tally for the map currently being played to a database but I am having trouble calling the function again when the map changes.
At the moment I am using the Initialize hook, which works great on server start but does not get called again when the map changes. Looking through the wiki, I seem to be overseeing the hook I need.
So my question, is there a hook that can be called every time the server changes map but at a point where it can read game.GetMap()?[/QUOTE]
When the map changes, players are not asked to reconnect or even to be re-authenticated. This means that you need to keep track of players who join and leave right from the beginning.
Using the following code:
[lua]
local fmt = "[%s] %s has connected.";
gameevent.Listen("player_connect");
hook.Add("player_connect", "player_connect", function(data)
print(string.format(fmt, "player_connect", data.name));
end)
hook.Add("CheckPassword", "CheckPassword", function(steamID64, ipAddress, svPassword, clPassword, name)
print(string.format(fmt, "CheckPassword", name));
end);
hook.Add("PlayerAuthed", "PlayerAuthed", function(ply, steamid, uniqueid)
print(string.format(fmt, "PlayerAuthed", ply:Name()));
end);
hook.Add("PlayerConnect", "PlayerConnect", function(name, ip)
print(string.format(fmt, "PlayerConnect", name));
end);
hook.Add("PlayerInitialSpawn", "PlayerInitialSpawn", function(ply)
print(string.format(fmt, "PlayerInitialSpawn", ply:Name()));
end);
hook.Add("InitPostEntity", "InitPostEntity", function()
print("[InitPostEntity] Called");
for k,v in pairs(player.GetAll()) do
print("\tJoining player: " .. v:Name());
end
end);
[/lua]
This is the order in which the hooks are called:
[code]
- ServerBoot -
+ InitPostEntity
+ CheckPassword
+ PlayerConnect
+ player_connect
+ PlayerInitialSpawn
+ PlayerAuthed
- Changemap -
+ InitPostEntity
+ PlayerInitialSpawn
+ PlayerAuthed
[/code]
The only way I know of to track connected players after a map change is to hook into PlayerConnect/PlayerDisconnected (Or the game events) and use those.
It should go without saying (Since players are not asked to reconnect), players are not disconnected on a map change.
How do I correctly offset an angle? I posted some of my code in a help thread about hats, and I remembered that my angle offsets were acting funky. This is the code I am using:
[lua]
ang:RotateAroundAxis(ang:Right(), self.Offset[index].Angle.r);
ang:RotateAroundAxis(ang:Up(), self.Offset[index].Angle.p);
ang:RotateAroundAxis(ang:Forward(), self.Offset[index].Angle.y);
[/lua]
Where an example offset for the model "models/props_2fort/hardhat001.mdl" would be Angle(90,0,-90). The problem is, the yaw member offsets in the same plane as the pitch member, which to me isn't always a problem, but obviously needs to be fixed. Can anyone provide some insight on how to add an offset to an angle correctly? Thanks.
solved: For anyone wondering, it was the order in which I was editing the angle:
[lua]
ang:RotateAroundAxis(ang:Up(), self.OffsetAngle.p);
ang:RotateAroundAxis(ang:Forward(), self.OffsetAngle.y);
ang:RotateAroundAxis(ang:Right(), self.OffsetAngle.r);
[/lua]
[t]http://rp.braxnet.org/scr/2015-04-30_11-14-11.jpg[/t]
[del]any idea why this is happening? just using a material override and it stretches like that[/del]
scratch that, had a bad uv map
[IMG]http://puu.sh/hwbBI/192e8b4b20.jpg[/IMG]
Any idea what might cause a DPanel to get pushed over a few pixels when it is refreshed?
[QUOTE=101kl;47631118][IMG]http://puu.sh/hwbBI/192e8b4b20.jpg[/IMG]
Any idea what might cause a DPanel to get pushed over a few pixels when it is refreshed?[/QUOTE]
How are you positioning it?
[QUOTE=Phoenixf129;47631461]How are you positioning it?[/QUOTE]
Went over the code for a third time and worked it out, thanks anyway :v:
[QUOTE=AIX-Who;47627662]Try printing something on initpostentity and see if that works, if it does then it's a problem with your mysqloo code.[/QUOTE]
[QUOTE=G4MB!T;47627876]When the map changes, players are not asked to reconnect or even to be re-authenticated. This means that you need to keep track of players who join and leave right from the beginning.
Using the following code:
[lua]
local fmt = "[%s] %s has connected.";
gameevent.Listen("player_connect");
hook.Add("player_connect", "player_connect", function(data)
print(string.format(fmt, "player_connect", data.name));
end)
hook.Add("CheckPassword", "CheckPassword", function(steamID64, ipAddress, svPassword, clPassword, name)
print(string.format(fmt, "CheckPassword", name));
end);
hook.Add("PlayerAuthed", "PlayerAuthed", function(ply, steamid, uniqueid)
print(string.format(fmt, "PlayerAuthed", ply:Name()));
end);
hook.Add("PlayerConnect", "PlayerConnect", function(name, ip)
print(string.format(fmt, "PlayerConnect", name));
end);
hook.Add("PlayerInitialSpawn", "PlayerInitialSpawn", function(ply)
print(string.format(fmt, "PlayerInitialSpawn", ply:Name()));
end);
hook.Add("InitPostEntity", "InitPostEntity", function()
print("[InitPostEntity] Called");
for k,v in pairs(player.GetAll()) do
print("\tJoining player: " .. v:Name());
end
end);
[/lua]
This is the order in which the hooks are called:
[code]
- ServerBoot -
+ InitPostEntity
+ CheckPassword
+ PlayerConnect
+ player_connect
+ PlayerInitialSpawn
+ PlayerAuthed
- Changemap -
+ InitPostEntity
+ PlayerInitialSpawn
+ PlayerAuthed
[/code]
The only way I know of to track connected players after a map change is to hook into PlayerConnect/PlayerDisconnected (Or the game events) and use those.
It should go without saying (Since players are not asked to reconnect), players are not disconnected on a map change.[/QUOTE]
Thank you both very much for your help.
Turns out that mysqloo was not calling the function again when the map was changed. I figured this might be the case as the module uses the Think hook, which was not getting called again until a player connected.
What I did to combat this is using the information that G4MB!T provided, I changed my script to look like this.
[lua]function MapCount()
if #player.GetAll() == 1 then
[mysqloo code here]
end
end
hook.Add( "PlayerInitialSpawn", "mapCount2DB", mapCount )[/lua]
This means the function would be called when anyone would connect but would only be called when the player count is at 1 player. It has its flaws like it would still be called if the server had only one player and they disconnect/reconnect it would poll on the database for the map being played but it's a minor one.
Any way I could improve this you think? Thanks again for your help though :)
Which hook do I use to detect if I damaged an entity or just hit the world?
[QUOTE=TheMostUpset;47633396]Which hook do I use to detect if I damaged an entity or just hit the world?[/QUOTE]
In what way is the damage being dealt? Shooting? You can use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/EntityTakeDamage]GM/EntityTakeDamage[/url] but that isnt called if you shoot the world. If you MUST know if you hit the world, use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/EntityFireBullets]GM/EntityFireBullets[/url]. I THINK the following should work:
[lua]
hook.Add("EntityFireBullets", "EntityFireBullets", function(ent, data)
local cb = data.Callback;
data.Callback = function(ply, tr, dmginfo)
if (IsValid(tr.Entity)) then
// We hit something
else
// We hit the world
end
end;
end);
[/lua]
[editline]30th April 2015[/editline]
[QUOTE=danjono;47632034]Thank you both very much for your help.
Turns out that mysqloo was not calling the function again when the map was changed. I figured this might be the case as the module uses the Think hook, which was not getting called again until a player connected.
What I did to combat this is using the information that G4MB!T provided, I changed my script to look like this.
[lua]function MapCount()
if #player.GetAll() == 1 then
[mysqloo code here]
end
end
hook.Add( "PlayerInitialSpawn", "mapCount2DB", mapCount )[/lua]
This means the function would be called when anyone would connect but would only be called when the player count is at 1 player. It has its flaws like it would still be called if the server had only one player and they disconnect/reconnect it would poll on the database for the map being played but it's a minor one.
Any way I could improve this you think? Thanks again for your help though :)[/QUOTE]
I thought you were storing the amount of players on the current map? If so then wouldnt you want to update it whenever someone joins or leaves?
[QUOTE=G4MB!T;47633589]In what way is the damage being dealt? Shooting? You can use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/EntityTakeDamage]GM/EntityTakeDamage[/url] but that isnt called if you shoot the world. If you MUST know if you hit the world, use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/EntityFireBullets]GM/EntityFireBullets[/url]. I THINK the following should work:
[lua]
hook.Add("EntityFireBullets", "EntityFireBullets", function(ent, data)
local cb = data.Callback;
data.Callback = function(ply, tr, dmginfo)
if (IsValid(tr.Entity)) then
// We hit something
else
// We hit the world
end
end;
end);
[/lua]
[/QUOTE]
Shooting using trace, not bullets
I want to use this simple ulx voting command to switch gamemodes by activating an rcon command doing "gamemode {insert gamemode here}". It is on the server properly, and the vote shows up, yet at the end it doesnt switch the gamemode or let alone give any feedback.
I would greatly appreciate any help at all, I am just trying to learn :)
[CODE]-- Gamemode voting
function ulx.votegm( calling_ply, title, ... )
if ulx.voteInProgress then
ULib.tsayError( calling_ply, "There is already a vote in progress. Please wait for the current one to end.", true )
return
end
ulx.doVote( title, { ... }, voteDone )
ulx.fancyLogAdmin( calling_ply, "#A started a vote (#s)", title )
end
local votegm = ulx.command( "GamemodeVote", "ulx votegm", ulx.votegm, "!gm" )
votegm:addParam{ type=ULib.cmds.StringArg, hint="title" }
votegm:addParam{ type=ULib.cmds.StringArg, hint="options", ULib.cmds.takeRestOfLine, repeat_min=2, repeat_max=10 }
votegm:defaultAccess( ULib.ACCESS_ADMIN )
votegm:help( "Starts a gamemode vote." )
local function votegmDone( t )
local results = t.results
local winner
local winnernum = 0
for id, numvotes in pairs( results ) do
if numvotes > winnernum then
winner = id
winnernum = numvotes
end
end
local str
if (t.options[ winner ] == "prop_hunt") then
ulx.rcon("gamemode prop_hunt")
elseif (t.options[ winner ] == "hideandseek") then
ulx.rcon("gamemode hideandseek")
else
str = "Vote results: No option won because no one voted!"
end
end
[/CODE]
[QUOTE=danjono;47632034]Thank you both very much for your help.
Turns out that mysqloo was not calling the function again when the map was changed. I figured this might be the case as the module uses the Think hook, which was not getting called again until a player connected.
What I did to combat this is using the information that G4MB!T provided, I changed my script to look like this.
[lua]function MapCount()
if #player.GetAll() == 1 then
[mysqloo code here]
end
end
hook.Add( "PlayerInitialSpawn", "mapCount2DB", mapCount )[/lua]
This means the function would be called when anyone would connect but would only be called when the player count is at 1 player. It has its flaws like it would still be called if the server had only one player and they disconnect/reconnect it would poll on the database for the map being played but it's a minor one.
Any way I could improve this you think? Thanks again for your help though :)[/QUOTE]
If you want your timers to start running straight away you can on InitPostEntity spawn a bot then kick it 1 frame later.
This is what I use
[lua]--Force timer start by spawning bots
hook.Add("InitPostEntity", "suss_keepalive_bothack", function()
print("Workaround to begin keepalive timer while no players are on, spawn a bot")
timer.Simple(0, function()
RunConsoleCommand("bot")
timer.Simple(0.1, function()
for k,v in pairs(player.GetAll()) do
if v:IsBot() then v:Kick("No longer needed") end
end
print("Timers should now be running ok, even with no players connected")
end)
end)
end)[/lua]
I get this error
[QUOTE]
[ERROR] lua/includes/extensions/math.lua:188: attempt to perform arithmetic on local 'num' (a string value)
1. Round - lua/includes/extensions/math.lua:188
2. unknown - addons/gmodinvestor/lua/autorun/client/cl_init.lua:150
[/QUOTE]
this is what I have for the check value
[CODE]function frame:Think(ply, w, h)
if LocalPlayer():GetGCash() >= 999999 then
frame.Paint = function(self, w, h)
draw.RoundedBox( 0, 0, 0, w, h, Color( 220, 76, 60, 255) )
draw.DrawText("GM Capitalists", "MyFont", 5, 2.5, Color(255,255,255,255))
draw.DrawText("GMCash:$"..math.Round(string.format("E", LocalPlayer():GetGCash()),2).."Million" , "gcash", 300, 12.5, Color(255,255,255,255))
end
end
end[/CODE]
The problem in the code is the string.format, I want it to make it right the GCash into scientific notation.
[QUOTE=funnygamemake;47634077]I get this error
this is what I have for the check value
[CODE]function frame:Think(ply, w, h)
if LocalPlayer():GetGCash() >= 999999 then
frame.Paint = function(self, w, h)
draw.RoundedBox( 0, 0, 0, w, h, Color( 220, 76, 60, 255) )
draw.DrawText("GM Capitalists", "MyFont", 5, 2.5, Color(255,255,255,255))
draw.DrawText("GMCash:$"..math.Round(string.format("E", LocalPlayer():GetGCash()),2).."Million" , "gcash", 300, 12.5, Color(255,255,255,255))
end
end
end[/CODE]
The problem in the code is the string.format, I want it to make it right the GCash into scientific notation.[/QUOTE]
[B]math.Round(string.format([/B]
You are passing a string to math.Round . Swap them around, so you pass your rounded number to string.format?
[QUOTE=wh1t3rabbit;47634020]If you want your timers to start running straight away you can on InitPostEntity spawn a bot then kick it 1 frame later.
This is what I use
[lua]--Force timer start by spawning bots
hook.Add("InitPostEntity", "suss_keepalive_bothack", function()
print("Workaround to begin keepalive timer while no players are on, spawn a bot")
timer.Simple(0, function()
RunConsoleCommand("bot")
timer.Simple(0.1, function()
for k,v in pairs(player.GetAll()) do
if v:IsBot() then v:Kick("No longer needed") end
end
print("Timers should now be running ok, even with no players connected")
end)
end)
end)[/lua][/QUOTE]
Dont do that. Use the PostGamemodeLoaded hook.
[editline]30th April 2015[/editline]
[QUOTE=TheMostUpset;47633700]Shooting using trace, not bullets[/QUOTE]
Then check what the tr.Entity is of your trace?
How do I make a lua file run a ulx rcon command when something reaches certain parameters. Such as something like:
if ( num > 2) then
ulx.rcon(gamemode sandbox)
elseif (num < 2) then
ulx.rcon(gamemode terrortown)
end
Something like that, I don't know what the code is to make it run a command in game.
I would appreciate any help!
What's the best way to stop rendering the world?
I want to have their name and location displayed in to the chat like so: <name> connected from <location>
example: Invule connected from Norway
I can do the name but I have no idea how to do the location, if anyone could point me in the right direction that'd be great. Thanks!
Sorry, you need to Log In to post a reply to this thread.