hey how can you tell what type of material you are looking at? Basically if I get the material that the player is looking at it should tell me if it is wood,dirt, or metal
Is there any way to make a reliable continuous use entity? I need it to run a function after the player holds the key down for ~4 seconds. I've come up with a cheap way of doing it with a boolean that checks on the think hook, but there has to be a better way of doing it.
[editline]23rd July 2014[/editline]
[QUOTE=bran92don;45479220]hey how can you tell what type of material you are looking at? Basically if I get the material that the player is looking at it should tell me if it is wood,dirt, or metal[/QUOTE]
[url]http://wiki.garrysmod.com/page/Structures/TraceResult[/url]
Check out MatType.
[QUOTE=JakeAM;45478213]Getting an odd error, can anyone else?
[code]
--defaults
defaultTime = 0.1
defaultGMMapList = file.Read("maplist.txt", "DATA")
defultVoteTime = 5
mapTable = {}
--net
util.AddNetworkString("JAMV")
util.AddNetworkString("JAMV Vote")
--dynamic vars
timeLeft = defaultTime * 60
voteTime = defultVoteTime
--timer
timer.Create("TimeUntilVote", 1, timeLeft, function() timeLeft = timeLeft - 1 RunConsoleCommand("say", timeLeft) StartVote() end)
--funcs
function StartVote()
if(timeLeft == 0) then
local mapGMTable = RemoveDuplicateValues(RemoveNewlines(GetGMS(MapListToTable(defaultMapList))))
SendToClients(sortGMTable(mapGMTable))
PrintTable(SortGMTable(mapTable))
end
end
function MapListToTable(s)
local mapList = string.Explode(",", s)
local returnTable = {}
for i,v in pairs(mapList) do
returnTable[i] = string.Explode(" ", v)
end
return returnTable
end
function SortGMTable(t)
local returnTable = SortTableKeys(RemoveDuplicateValues(RemoveNewlines(GetGMS(MapListToTable(t)))))
return returnTable
end
function SortTableKeys(t)
local returnTable = {}
for k,v in pairs(t) do
table.insert(returnTable, v)
end
return returnTable
end
function GetGMS(t)
local returnTable = {}
for i,v in pairs(t) do
for ii,vv in pairs(v) do
if(ii == 1) then
returnTable[i] = vv
end
end
end
return returnTable
end
function RemoveDuplicateValues(t)
local tempTable = {}
for k,v in pairs(t) do
if(tempTable[v] == nil) then
tempTable[v] = true
end
end
local returnTable = {}
for k,v in pairs(t) do
if(tempTable[v]) then
returnTable[k] = v
tempTable[v] = nil
end
end
return returnTable
end
function GetMapsForGM(t, s)
local returnTable = {}
for i,v in pairs(t) do
for ii,vv in pairs(v) do
returnTable[i] = vv
end
end
return returnTable
end
function RemoveNewlines(t)
local returnTable = {}
for k,v in pairs(t) do
local char = string.gsub(v, "\n", "")
table.insert(returnTable, char)
end
return returnTable
end
function SendToClients(t)
net.Start("JAMV")
net.WriteTable(t)
net.Broadcast()
end[/code][/QUOTE]
Odd error. [ERROR] lua/includes/extensions/string.lua:44: bad argument #1 to 'string_gmatch' (string expected, got nil)
Post full error with stack trace.
-snip-
[QUOTE=Netheous;45475587]Just wondering, does GMod handle functional Photoshop layers well? Or is there other way to achieve this effect:
[img]http://docs.worldviz.com/vizard/images/postprocess_boxblur.jpg[/img]
[editline]23rd July 2014[/editline]
Forgot to mention, ways other than:
[code]Derma_DrawBackgroundBlur( self, self.m_fCreateTime )[/code][/QUOTE]
Tried to use some post-processing effects? In sandbox was "Motion Blur" or something.. take a look at this:
[URL]http://wiki.garrysmod.com/page/render/BlurRenderTarget[/URL]
... or search in [B]render[/B] library :)
[QUOTE=TheWindow;45479232]Is there any way to make a reliable continuous use entity? I need it to run a function after the player holds the key down for ~4 seconds. I've come up with a cheap way of doing it with a boolean that checks on the think hook, but there has to be a better way of doing it.
[editline]23rd July 2014[/editline]
[url]http://wiki.garrysmod.com/page/Structures/TraceResult[/url]
Check out MatType.[/QUOTE]
Figured out a pretty good way to do this.
[code]
function ENT:Think()
if !IsValid(self.User) then return end
if (!self.User:KeyDownLast(IN_USE) or self.User:GetVelocity():Length() > 100) and self.BeingUsed then
self.BeingUsed = false
self.User:ChatPrint(tostring(self.BeingUsed))
self.UseAmount = 0
elseif (self.BeingUsed) then
self.UseAmount = self.UseAmount+1
self.User:ChatPrint(tostring(self.UseAmount))
end
end
function ENT:AcceptInput( name, activator, caller )
if name == "Use" and caller:IsPlayer() and !caller:KeyDownLast(IN_USE) then
self.BeingUsed = true
self.User = activator
self.UserPos = activator:GetPos()
self.UseAmount = 0
activator:ChatPrint(tostring(self.BeingUsed))
end
end
[/code]
Ok I'm stuck... I have custom entity([B]some_entity.lua[/B] and I want to call server-side([B]init.lua[/B]) function (in my gamemode), how can I do this? Any ideas?
Is there any easy universal method to check if a player is reloading?
-snip-
[QUOTE=Dexter127;45480258]Ok I'm stuck... I have custom entity([B]some_entity.lua[/B] and I want to call server-side([B]init.lua[/B]) function (in my gamemode), how can I do this? Any ideas?[/QUOTE]
If you're just calling a serverside gamemode function it should be as easy as throwing in SomeFunction(arguments) into the serverside hook you need.
I have a table of string options that I want to be voted on, to keep track of how many votes each has inside that table. How would I do that ?
[QUOTE=JakeAM;45480858]I have a table of string options that I want to be voted on, to keep track of how many votes each has inside that table. How would I do that ?[/QUOTE]
[lua]
local table = {
{ name = "voteoption1", votes = 0 },
{ name = "voteoption2", votes = 0 }
}
[/lua]
How would I go about replacing the weapon selection "menu"?
Mainly overriding what happens when the mousewheel is scrolled
[QUOTE=TheWindow;45481757]How would I go about replacing the weapon selection "menu"?
Mainly overriding what happens when the mousewheel is scrolled[/QUOTE]
check PlayerBindPressed for mwheelup, mwheeldown, and slot0-10 for what you need to draw, and RunConsoleCommand("use", classname) for actual weapon switching
[B][I]SOLVED[/I][/B]
i have a question, can i use 2 if statement on the same line? like
if ply:SteamID() then
if ply:IsUserGroup("VIP") then
etc.
I'm having some incredibly annoying issues with the way presumably Garry coded the gmod_tool STool.
Basically, imagine there are 2 players on the server that are using the same tool. This tool has stuff that gets called in TOOL:Init() that is meant to be run [B]once per client[/B]. For example, adding a hook on the client that requires TOOL's [B]self[/B]. It's fine that TOOL:Init() gets called again when the player dies and respawns -- I get that.
The problem, however, is that not only does TOOL:Init() get called when your specific client respawns, it gets called [B]when other clients respawn as well[/B]. It's the same thing with TOOL:Holster and (probably) TOOL:Deploy.
Essentially, other players are able to fuck up my current tool's state because every time someone else respawns or holsters/deploys their toolgun, it calls the corresponding function on my client as well.
The simplest way to see this is to add any print statement inside TOOL:Init() and have other players kill themselves. Every time [B]they[/B] respawn, TOOL:Init() will be called on [B]your[/B] client.
Is there seriously a reason the gmod_tool was coded like this, and is there anything I can do about it that doesn't require editing it?
[QUOTE=Scarface3353;45482462]i have a question, can i use 2 if statement on the same line? like
if ply:SteamID() then
if ply:IsUserGroup("VIP") then
etc.[/QUOTE]
use [LUA] [!/LUA] quotes check op for that and the answer on your question yes you can
[lua]if ply:SteamID() and ply:IsUserGroup("VIP") then[/lua]
Anyone with good understanding of the navmesh / CNavArea libraries willing to help me work out a few things?
[QUOTE=Hoffa1337;45483649]Anyone with good understanding of the navmesh / CNavArea libraries willing to help me work out a few things?[/QUOTE]
You will have to post your questions/problem if you want help.
[QUOTE=Robotboy655;45483863]You will have to post your questions/problem if you want help.[/QUOTE]
Well since NextBot is an abomination if you wanna do anything other than monsters / melee NPCs and I much prefer having the good old regular bots drive my vehicles I've hit a snag with path finding. Rather than reinventing the wheel for the millionth time I'd rather try and use the NavMash library. The problem is it crashes ALOT so I can't quite figure out in what order I have to do things and how frequent I can actually call the methods without impacting performance. Basically the bots are regular good old bots, engine treats them like player objects which works awesomely well with my vehicle system meaning I don't have to do any changes to my vehicle base in order to let AI use them. Everything from finding a tank in LOS, entering it, starting it up and finding targets works just fine. The problem is I need to find the closest safe vector for the bot to move to when the variable/field "Target" exists on the bot.
Did some testing last night
[code]
local ply = player.GetAll()[1]
local pos = ply:GetEyeTrace().HitPos
local NavAreas = navmesh.GetNavArea( ply:GetPos(), 1000 )
NavAreas:Draw() -- this turns up as a big flat surface ontop of the ground
NavAreas:DrawSpots() -- this doesnt seem to do anything (tested on gm_flatgrass)
print( NavAreas:GetClosestPointOnArea( pos ) ) --and this crashes the game if you call it too often?
[/code]
Just as an example, but this seems to crash my game. What's a safe method to continuously find the closest safe vector for the bot + tank to move to? I already have the moving part figured out it's just that I need to get the closest safe vector leading up to the bots target rather than just checking if we can see the target and then move.
Have you generated a nav mesh for the map?
You could also look at how nextbot calls those functions.
[QUOTE=Robotboy655;45483964]Have you generated a nav mesh for the map?
You could also look at how nextbot calls those functions.[/QUOTE]
I did look at nextbot and it refers to loco all over the place. Wasn't too helpful. I started out by generating the navmesh before i tested the above code. It crashes alot.
Edit:
I don't need the player movement to work. I just need a proper and non resource intensive method to find the closest safe vector.
[QUOTE=TheWindow;45480772]If you're just calling a serverside gamemode function it should be as easy as throwing in SomeFunction(arguments) into the serverside hook you need.[/QUOTE]
I don't think so.. Or I can't understand hooking...
[CODE]function CallSetObjective( objective )
print( "Your objective is: "..objective)
// Need to call SetObjective() function from init.lua
end
function ENT:AcceptInput( name, activator, caller, data )
if ( name == "SetObjective" ) then CallSetObjective( data ) return true end
return false
end[/CODE]
this is some code in [B]some_entity.lua[/B]
and I want to call a function [B]SetObjective()[/B] from [B]init.lua[/B], and I have no idea how to do it.
And this function needs to be called with argument!
[B] OKEY IT'S SOLVED [/B]
used:
hook.Add in init.lua and hooked onto SetObjective() function
hook.Call in some_entity.lua and called added hook
How badly did I murder this? I am attempting to load a pac outfit using pointshop. (Default Pointshop)
I dont want to disable anything until I can get the pac part working, and I dont know how to reference pac right.
[CODE]ITEM.Name = 'PacExample'
ITEM.Price = 1000
ITEM.Model = 'models/xqm/jetengine.mdl' --not really used
ITEM.Bone = 'ValveBiped.Bip01_Spine2' --not really used
function ITEM:OnEquip(ply, modifications)
local outfit = pac.luadata.ReadFile("pac3/mech.txt")
ply:PS_AddClientsideModel(self.ID)
self:AttachPACPart(outfit)
pac.SetupENT(ENT) -- this can also be used in initialize using "self" instead of "ENT" Can I change this to ply?
end
function ITEM:OnHolster(ply)
ply:PS_RemoveClientsideModel(self.ID)
self:RemovePACPart(outfit)
end
function ITEM:ModifyClientsideModel(ply, model, pos, ang) -- Left over
model:SetModelScale(0.5, 0)
pos = pos + (ang:Right() * 7) + (ang:Forward() * 6)
return model, pos, ang
end
function ITEM:Think(ply, modifications) -- Left over stuff from Jump Pack
if ply:KeyDown(IN_JUMP) then
ply:SetVelocity(ply:GetUp() * 6)
end
end[/CODE]
Getting this error...
[quote] [ERROR] lua/includes/modules/net.lua:10: attempt to index local 'name' (a nil value)
1. Receive - lua/includes/modules/net.lua:10
2. func - addons/test/lua/autorun/server/server.lua:39
3. unknown - lua/includes/modules/net.lua:32
[/quote]
Server:
[code]
util.AddNetworkString("vote")
defaultGMMapList = {
{gm = "sandbox", map = "gm_construct"},
{gm = "ttt", map = "ttt_office"},
{gm = "sandbox", map = "gm_flatgrass"}
}
function CreateGMTable(t)
local returnTable = {}
for i,v in pairs(t) do
table.insert(returnTable, {name = v.gm, votes = 0})
end
return returnTable
end
function CreateMapTable(t, s)
local returnTable = {}
for i,v in pairs(t) do
if(v.gm == s) then
table.insert(returnTable, {name = v.map, votes = 0})
end
end
return returnTable
end
function SendToClients(t)
net.Start("vote")
net.WriteTable(t)
net.Broadcast()
end
gmVoteTable = CreateGMTable(defaultGMMapList)
SendToClients(gmVoteTable)
net.Receive("vote", function(l, c)
for i,v in pairs(gmVoteTable) do
if(gmVoteTable.name == net.Receive()) then
gmVoteTable[i].vote = gmVoteTable[i].vote + 1
end
end
PrintTable(gmVoteTable)
print(net.Receive().." received a vote!")
end)[/code]
Client:
[code]function OpenVoteMenu(t)
local votePanel = vgui.Create("DFrame")
votePanel:SetPos(100, 100)
votePanel:SetSize(200, (GetTableLength(t) * 50) + 50)
votePanel:SetTitle("Vote Now!")
votePanel:SetVisible(true)
votePanel:SetDraggable(true)
votePanel:ShowCloseButton(true)
votePanel:MakePopup()
for k,v in pairs(t) do
local dermaButton = vgui.Create( "DButton" )
dermaButton:SetParent(votePanel)
dermaButton:SetText(v.name)
dermaButton:SetPos(25, (k * 50) - 15)
dermaButton:SetSize(150, 50)
dermaButton.DoClick = function()
net.Start("vote")
net.WriteString(v.name)
net.SendToServer()
votePanel:Close()
end
end
end
function GetTableLength(t)
local count = 0
for k,v in pairs(t) do
if(v ~= nil) then
count = count + 1
end
end
return count
end
net.Receive("vote", function(l, c)
OpenVoteMenu(net.ReadTable())
end)[/code]
Any help :( ?
[QUOTE=JakeAM;45486135]
[code]net.Receive("vote", function(l, c)
for i,v in pairs(gmVoteTable) do
if(gmVoteTable.name == net.Receive()) then
gmVoteTable[i].vote = gmVoteTable[i].vote + 1
end
end
PrintTable(gmVoteTable)
print(net.Receive().." received a vote!")
end)[/code]
[/QUOTE]
you're using net.Receive when you should be using net.ReadString, and net variables can only be read once (the print will be wrong).
also, if you plan on releasing this (or even just using this), don't use Write/ReadTable, you can easily make functions for those tables
[lua]
function net.WriteVoteInfo(t)
net.WriteUInt(#t - 1, 5) --this goes up to 32 items
for k, v in pairs(t) do
net.WriteString(v.name)
net.WriteUInt(v.votes, 6) --this goes up to 63 votes
end
end
function net.ReadVoteInfo()
local ret = {}
local len = net.ReadUInt(5) + 1
for i = 1, len do
local name = net.ReadString()
local votes = net.ReadUInt(6)
table.insert(ret, {name = name, votes = votes})
end
return ret
end[/lua]
Hey, when gmod updated a few months ago, something changed with particles and this was a really common issue. Does anyone remember what the fix for it was?
[code]
Tried to use invalid object (type CLuaEmitter) (Object was NULL or not of the right type)
[/code]
[QUOTE=NiandraLades;45486269]Hey, when gmod updated a few months ago, something changed with particles and this was a really common issue. Does anyone remember what the fix for it was?
[code]
Tried to use invalid object (type CLuaEmitter) (Object was NULL or not of the right type)
[/code][/QUOTE]
Don't call CLuaEmitter:Finish() on emitters you intend to use.
Sorry, you need to Log In to post a reply to this thread.