Hey there. I'm trying to create a function for a gamemode I'm working on. The function is supposed to give bot players, added in through the console command "bot" a certain weapon. How am I supposed to pull this off? I'll post the code I have so far right here: [code] function GiveBotsWeapons()
if (SERVER) then
RunConsoleCommand( "bot_sendcmd give weapon_aimbot_galil" ) [/code]
Note: This isn't finished; I haven't even added what the client is supposed to do yet.
[QUOTE=A Fghtr Pilot;47137096][code] --[[
Based on math from
https://github.com/garrynewman/garrysmod/blob/4eb9bb19dcfac06007691376ecaf2dbc56efa6b2/garrysmod/lua/includes/extensions/util.lua#L36-L48
]]--
function SWEP:Initialize()
--[[
optimizations -
TraceResult SWEP.out | output of trace
Trace SWEP.trace | table of trace information
]]--
self.out = {};
self.trace = {
output = self.out;
mask = MASK_SHOT;
filter = {self};
};
end
function SWEP:Think()
--[[ localized for speed ]]--
local out = self.out;
local trace = self.trace;
local owner = self:GetOwner();
if(IsValid(owner)) then
-- being held
local direction = owner:GetAimVector();
local shoot_pos = owner:GetShootPos();
trace.start = shoot_pos;
trace.endpos = shoot_pos + direction * 4096 * 8;
--[[ we already added the weapon to the filter table ]]--
trace.filter[2] = owner;
util.TraceLine(trace);
if(IsValid(out.Entity) and out.Entity:IsPlayer()) then
self:PrimaryAttack();
end
end
end [/code]
Hey there, I need some help with getting the following code above to automatically target players. I'm working on an AI system but my main problem is that I can't get this code to make the user autotarget others.[/QUOTE]
[code]
--[[
Based on math from
https://github.com/garrynewman/garrysmod/blob/4eb9bb19dcfac06007691376ecaf2dbc56efa6b2/garrysmod/lua/includes/extensions/util.lua#L36-L48
]]--
--[[
how long after last seeing target do
we find a new one?
(in seconds)
]]--
SWEP.target_lost_time = 5;
SWEP.target_fov = 70;
--[[
speed_of_aim will be how much fov you will move per second
]]--
SWEP.speed_of_aim = 50;
SWEP.target_fov = SWEP.target_fov / 2;
function SWEP:Initialize()
--[[
optimizations -
TraceResult SWEP.out | output of trace
Trace SWEP.trace | table of trace information
Trace SWEP.tracevis | table of trace information for seeing
TraceResult SWEP.outvis | ouput of trace for seeing
]]--
hook.Add("StartCommand", self, self.StartCommand);
self.outvis = {};
self.tracevis = {
output = self.outvis;
mask = MASK_SHOT;
filter = {self};
};
self.last_saw_target = CurTime();
self.out = {};
self.trace = {
output = self.out;
mask = MASK_SHOT;
filter = {self};
};
end
function SWEP:CanOwnerSee(ply)
local owner = self:GetOwner();
if(not IsValid(owner) or not IsValid(ply)) then return false; end
local startpos = owner:EyePos();
local endpos = ply:EyePos();
--[[ fov check ]]--
local delta = endpos - startpos;
delta:Normalize();
local forward = owner:GetForward();
forward:Normalize();
local fov = math.NormalizeAngle(math.deg(math.acos(forward:Dot(delta))));
if(math.abs(fov) > self.target_fov) then
return false;
end
local trace = self.tracevis;
local out = self.outvis;
trace.filter[2] = owner;
trace.start = startpos;
trace.endpos = endpos;
util.TraceLine(trace);
print(out.Entity);
print(out.MatType);
print(out.StartSolid);
return out.Entity == ply;
end
function SWEP:StartCommand(ply, cmd)
self.last_lerp_time = self.last_lerp_time or CurTime();
if(ply == self:GetOwner() and ply:GetActiveWeapon() == self) then
--[[
since we are just adding this to an event
we will need to check if the hook gets
called with the right player
]]--
local owner = self:GetOwner();
print(self.target);
local target = self.target;
if(not IsValid(target)) then
for i, v in next, player.GetAll() do
if(v ~= ply and self:CanOwnerSee(v)) then
target = v;
break;
end
end
end
self.target = target;
if(IsValid(target)) then
if(self:CanOwnerSee(target)) then
self.last_saw_target = CurTime();
local current_angle = cmd:GetViewAngles();
local target_angle = (target:GetAttachment(1).Pos - owner:GetShootPos()):Angle();
cmd:SetViewAngles(Lerp(CurTime() - self.last_lerp_time, target_angle, current_angle));
elseif(CurTime() - self.last_saw_target > self.target_lost_time) then
self.target = nil;
end
end
end
self.last_lerp_time = CurTime();
end
function SWEP:Think()
--[[ localized for speed ]]--
local out = self.out;
local trace = self.trace;
local owner = self:GetOwner();
if(IsValid(owner)) then
-- being held
local direction = owner:GetAimVector();
local shoot_pos = owner:GetShootPos();
trace.start = shoot_pos;
trace.endpos = shoot_pos + direction * 4096 * 8;
--[[ we already added the weapon to the filter table ]]--
trace.filter[2] = owner;
util.TraceLine(trace);
if(IsValid(out.Entity) and out.Entity:IsPlayer()) then
self:PrimaryAttack();
end
end
end
[/code]
i got bored and was feeling like i should be helpful so here you go!
[QUOTE=Acecool;47140041]
Hopefully this helps: [url]http://wiki.garrysmod.com/page/Creating_Binary_Modules[/url][/QUOTE]
Thanks for that, only other thing is using engine functions in modules, is that possible?
[editline]14th February 2015[/editline]
Is it possible to load C++ modules in the menu state?
So, I tried to do some audio visualizer stuff, ended up like this:
[t]http://i.imgur.com/epGv4iY.png[/t]
While it works perfectly and it's very accurate, it just looks so bad, how could I make it look "cooler"?
[QUOTE=Author.;47141195]So, I tried to do some audio visualizer stuff, ended up like this:
[t]http://i.imgur.com/epGv4iY.png[/t]
While it works perfectly and it's very accurate, it just looks so bad, how could I make it look "cooler"?[/QUOTE]
[sp]drugs[/sp]
When I see audio visualizers I think the colors help out, and having bars of a decent size to represent it. Possible even a color gradient overlay, idk, where the lower threshold is more of a green and the higher threshold hue shifts to red. That's as much as I think I can help, just trying to explain what I think is fitting for a typical visualizer.
[t]http://www.venuesupply.com/images_products/ColorTubeEQ-Animation2.gif[/t][t]http://mason.gmu.edu/~eraether/blog-media/visualizer/music-visualizer.gif[/t][t]http://stavestrand.no/cava.gif[/t][t]http://stream1.gifsoup.com/webroot/animatedgifs/43200_o.gif[/t]
[B]edited:[/B]
So I guess another thing to note is how different bars represent a good amount of different frequencies. You don't get a ton of bars, you get maybe 20 that sum up the entire range.
[QUOTE=Author.;47141195]So, I tried to do some audio visualizer stuff, ended up like this:
[t]http://i.imgur.com/epGv4iY.png[/t]
While it works perfectly and it's very accurate, it just looks so bad, how could I make it look "cooler"?[/QUOTE]
Colors and bigger bars.
[QUOTE=meharryp;47140846]Thanks for that, only other thing is using engine functions in modules, is that possible?
[editline]14th February 2015[/editline]
Is it possible to load C++ modules in the menu state?[/QUOTE]
The menustate can load gmsv-prefixed modules. My GitHub profile has a few examples of gmod modules (don't forget to look at the archive repo too).
[url=https://github.com/wiox]https://github.com/wiox[/url]:
[url]https://github.com/wiox/archive/tree/master/gmsv_refresh-master[/url] (technically doens't use any source-engine libraries)
[url]https://github.com/wiox/gmod-no-loadingurl[/url]
[url]https://github.com/wiox/gmod-no-screencap[/url]
[url]https://github.com/wiox/plugin_mount[/url] (source plugin, not glua module)
[url]https://github.com/wiox/gmcl_vprof[/url]
[url]https://github.com/gmodcoders/gm_stringtable[/url]
And one I never released: [url]https://www.dropbox.com/s/r4mbg67sccqb15k/gm_menu_util.7z?dl=0[/url]
[QUOTE=bobbleheadbob;47136667][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/WorldToLocal]Global.WorldToLocal[/url][/QUOTE]
If it isn't too much trouble, care to give an example of how to use that function in this context? For example, say I want to set the angle of [I]bone 5[/I] so that it points toward [I]Vector(0, 0, 0)[/I] on the map.
Hey, I've got some HTTP console errors when running some code.
Error:
[code]
Aborting HTTP request because pResponse->BSetBodyData() failed. URL: /gid/[g:1:2081]
Aborting HTTP request because pResponse->BSetBodyData() failed. URL: /gid/[g:1:5115552]
// Repeat above for each of the groups
[/code]
Code:
[lua]
function clantag.Scan(ply, callback)
SAPI.GetUserGroupList(ply:SteamID64(), function(groups)
for id32, _ in pairs(groups) do
local url = "http://steamcommunity.com/gid/[g:1:"..id32.."]"
local function onsuccess(body, len, headers, code)
local sstr, estr = "<span class=\"grouppage_header_abbrev\" style=\"\">", "</span>"
local idstart, idend = string.find(body, sstr), string.find(body, endstr, idstart)
local tag = string.sub(body, idstart+#sstr, idend)
print(tag)
clantag.PlayerTags[ply][tag] = true
clantag.PlayerTags[ply].count = clantag.PlayerTags[ply].count and (clantag.PlayerTags[ply].count + 1) or 0
end
local function onfailure(err)
PrintMessage(HUD_PRINTTALK, "ZERF FAILED: "..err)
end
http.Fetch(url, onsuccess, onfail)
end
if callback then callback(clantag.PlayerTags[ply]) end
end)
end
[/lua]
If you're wondering, SAPI.GetUserGroupList returns a table of a user's groups in this format:
[code]
6239770 = true
5115552 = true
2081 = true
// etc.
// Keeps going for each of the groups
[/code]
[editline]14th February 2015[/editline]
Yeah I'm aware of the unrelated logic error on line 11
This might be stupid, but just out of curiosity.
Is IsUserGroup("superadmin") and IsSuperAdmin() the same thing?
I'm aware that user group is used to check for your own custom groups if you want, but in this situation are they the same?
I've always wondered this and they seem like they are. So, why do IsSuperAdmin() and IsAdmin() exist?
[QUOTE=TheLuaNoob;47143382]This might be stupid, but just out of curiosity.
Is IsUserGroup("superadmin") and IsSuperAdmin() the same thing?
I'm aware that user group is used to check for your own custom groups if you want, but in this situation are they the same?
I've always wondered this and they seem like they are. So, why do IsSuperAdmin() and IsAdmin() exist?[/QUOTE]
[url]https://github.com/garrynewman/garrysmod/blob/4eb9bb19dcfac06007691376ecaf2dbc56efa6b2/garrysmod/lua/includes/extensions/player_auth.lua#L5-L22[/url]
Addons can change this.
Hey, I'm making a custom gamemode and for some reason the kill feed isn't showing up, and it's not showing kills/when people die in console. What might be causing this? I do have a custom death hook, but I don'tt hink that's it. I have a Workshop HUD that spams errors in the RCon, could that be it? Here's a link
[url]http://steamcommunity.com/sharedfiles/filedetails/?id=169557505[/url]
I need help with getting a value when the player disconnects, currently it appears that by the time it tries to call a function on said player ply is NULL, I have no idea how to get the value before it becomes null.
Here is the code to show
[code]hook.Add( "PlayerDisconnected","PointSave.SaveDisconnect", function(ply)
local id = ply:SteamID()
local points = ply:GetSavedPoints()
BMTZombies.Points.findBySteamId(id)
:Then(function( plyData )
if plyData and points > 0 then
plyData.points = plyData.points + points
plyData:save()
end
end)
end )[/code]
I have a small problem,
Currently im making a notification system, and im having troubles with the frame overlapping the other frame
I've said this before but, heres a picture of my problem,
[t]http://puu.sh/fWLfh/d5bb9cb439.jpg[/t]
how can i check if my frame already exists and if it does set its new pos times the old pos.
ive tried some simple shit like, if ( frame ) then y = y * 100 end, but no luck :(
I could also give you guys my vgui code if you need it.
You could add it to a table, then when a new notification pop up, it checks in the table, gets the position the current notification is at, then add some pixels to the position of the new frame to make it go beneath, or simply remove the previous notification.
[QUOTE=Author.;47145103]You could add it to a table, then when a new notification pop up, it checks in the table, gets the position the current notification is at, then add some pixels to the position of the new frame to make it go beneath, or simply remove the previous notification.[/QUOTE]
I could remove the previous notfication but when you said "add i to the table" what did you mean by that?
care to give a small example?
[QUOTE=Invule;47145124]I could remove the previous notfication but when you said "add i to the table" what did you mean by that?
care to give a small example?[/QUOTE]
If you wish to have only one notification at a time here is how I did it.
[LUA]
FoxedBot.ShowTime = 30
FoxedBot.announcements = {} -- Notifications queue
FoxedBot.announcement = false -- Tells the script that no notifications are being displayed
hook.Add("Think", "FoxedBot_AnnounceThink", function()
for k, v in pairs(FoxedBot.announcements) do -- Loops through the queue
if not FoxedBot.announcement then -- Checks if no notifications are being displayed
local panel = vgui.Create("FoxedBot_Announce") -- Creates your notification blah blah...
FoxedBot.announcement = true -- Tells the script that a notification is being displayed
panel:SetPos(ScrW() * -0.3125, ScrH() * 0.1388)
panel:SetText(v)
panel:SetAlpha(0)
panel:MoveTo(0, ScrH() * 0.1388, 0.5, 0, 0.5, function( anim, pan ) -- Opening animation
pan:MoveTo(ScrW() * -0.3125, ScrH() * 0.1388, 0.5, FoxedBot.ShowTime, 0.5, function( anim, pan ) -- Closing animation
pan:Remove()
FoxedBot.announcement = false --Tells the script that the notifications was removed
end)
pan:AlphaTo(0, 0.5, FoxedBot.ShowTime)
end)
panel:AlphaTo(255, 0.5)
surface.PlaySound("garrysmod/save_load2.wav")
table.remove(FoxedBot.announcements, k)
end
end
end)
net.Receive("FoxedBot_Announce", function()
local text = net.ReadString()
table.insert(FoxedBot.announcements, text) -- Puts the text of the notification in a queue (table)
MsgC(Color(111, 160, 165), "FoxedBot Announcement:\n"..text.."\n")
end)
[/LUA]
How would I find the exact center of a surface.DrawRect() and then surface.DrawText() in the center, since it also renders text from the corner, not aligned.
TL;DR: I need some text to be in the center of a drawrect, how to?
[QUOTE=ryankingstone;47145196]How would I find the exact center of a surface.DrawRect() and then surface.DrawText() in the center, since it also renders text from the corner, not aligned.
TL;DR: I need some text to be in the center of a drawrect, how to?[/QUOTE]
You could use the draw library instead, [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/draw/SimpleText]draw.SimpleText[/url] for example, as you can xAlign and yAlign the text (center, etc) and just set the position to the rect's position plus half of its width or height depending on how you use yAlign. (I'm sure that's how it works, I could be wrong)
[QUOTE=ryankingstone;47145196]How would I find the exact center of a surface.DrawRect() and then surface.DrawText() in the center, since it also renders text from the corner, not aligned.
TL;DR: I need some text to be in the center of a drawrect, how to?[/QUOTE]
[lua]
local rectX, rectY = 100, 100 -- location of the rect
local rectW, rectH = 200, 200 -- size of the rect
surface.SetDrawColor(255,255,255)
surface.DrawRect(rectX, rectY, rectW, rectH)
surface.SetFont("font")
local text = "Middle!"
local textw, texth = surface.GetTextSize(text)
surface.SetTextColor(0,0,0)
surface.SetTextPos(rectX+(rectW/2)-textw/2, rectY+(rectH/2)-texth/2)
surface.DrawText(text)[/lua]
[t]http://i.imgur.com/XAT2KPt.png[/t]
(Don't worry about it floating in the air, it's just that I'm currently messing with 3D2D, and just threw it in there to test)
Thanks for such detailed answer, you solved my problem.
[editline]15th February 2015[/editline]
I've got another problem with my drawrects, this happens when I [B]look at an entity, and have my physgun out:[/B]
[IMG]http://i.imgur.com/dn4JkW9.png[/IMG]
[QUOTE=ryankingstone;47145784]Thanks for such detailed answer, you solved my problem.
[editline]15th February 2015[/editline]
I've got another problem with my drawrects, this happens when I [B]look at an entity, and have my physgun out:[/B]
[pic][/QUOTE]
What does it look like normally?
[QUOTE=Neat-Nit;47146002]What does it look like normally?[/QUOTE]
[IMG]https://trello-attachments.s3.amazonaws.com/54e0c6ba2c7249e163f58ea7/772x349/748de3129d3ccf0700dd05bf45156f4a/2XIA51g.jpg[/IMG]
Post the code for this HUD.
-snip found solution snip-
Edit: For those who wonder - don't use DrawTexturedRect without a texture :)
[QUOTE=ryankingstone;47146083]-snip found solution snip-
Edit: For those who wonder - don't use DrawTexturedRect without a texture :)[/QUOTE]
:eng101:
how do I make diagonal things in derma? I want to make my HUD look like \____/ but i can only get it to look like |_____| :(
Don't do derma for HUDs, also use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/surface/DrawPoly]surface.DrawPoly[/url]
[QUOTE=Pazda;47146229]how do I make diagonal things in derma? I want to make my HUD look like \____/ but i can only get it to look like |_____| :([/QUOTE]
Well, you can use Paint functions, [URL="http://wiki.garrysmod.com/page/surface/DrawPoly"]surface.DrawPoly[/URL], or if you're lazy, use a PNG image.
ok cool i'm using that and I copy/pasted their triangle script and moved it around and stuff, but I can't seem to add a point. I'm just adding an x/y coord to the table like the others, why won't that change it?
[CODE]
local trapezoid = {
{ x = 950, y = 0 },
{ x = 600, y = 100 },
{ x = 550, y = 0 },
{ x = 800, y = 200 },
}
[/CODE]
its not picking up the (800,200). no matter how i make the table it only registers the first three entriesx
Sorry, you need to Log In to post a reply to this thread.