• Problems That Don't Need Their Own Thread v3.0
    5,003 replies, posted
[QUOTE=MaxShadow;49670741]I always store all ordered npcs into a table, and then I use a constant timer to check if they are at a certain distance from their target position in a for loop.[/QUOTE] OK, cool. I wonder if doing that slows or lags anything
WithinAABox seems to always be returning false, I had it working on a past map but cannot get it working now. [lua] local Start = Vector(-10919.388672, 14790.270508, 10046.089844) local Start1 = Vector(-10513.226563, 13777.234375, 9441.031250) if v:GetPos():WithinAABox(Start, Start1) then print("yes") else print("no") end [/lua] Players position is "-10735.693359 13976.206055 9504.031250" which afaik is in between those two vectors?
[QUOTE=Mrkrabz;49673854]WithinAABox seems to always be returning false, I had it working on a past map but cannot get it working now. CODE Players position is "-10735.693359 13976.206055 9504.031250" which afaik is in between those two vectors?[/QUOTE] If I had to guess how the function worked I'd say it's because the y and z vectors are bigger on the first vector than on the second
[QUOTE=bigdogmat;49674416]If I had to guess how the function worked I'd say it's because the y and z vectors are bigger on the first vector than on the second[/QUOTE] Ah good point, didn't even think of that. Edit: Shouldn't ents.FindInBox act the same way if that is the case? As it works fine.
[QUOTE=Mrkrabz;49674472]Ah good point, didn't even think of that. Edit: Shouldn't ents.FindInBox act the same way if that is the case? As it works fine.[/QUOTE] I had the same thought in my failed attempt of using WithinAABox. The wiki does name the arguments different in the two functions though. If you have any luck, please let me know!
Is there a way to remove an effect prematurely? As far as I know, the functions used to create effects don't return a reference to them.
[QUOTE=MaxShadow;49674815]Is there a way to remove an effect prematurely? As far as I know, the functions used to create effects don't return a reference to them.[/QUOTE] Wondering about this myself as well.
How can I get my scripted NPC to spawn standing still until I give it somewhere to move? I've got a scripted NPC based off the npc_shop example. I gave it the capability of walking with this: [code] self:CapabilitiesAdd( CAP_MOVE_GROUND ) [/code] But now when it spawns it automatically wanders off randomly around the whole map. I tried both of these in ENT:Initialize() but they didn't do anything. [code] self:SetSchedule(SCHED_NONE) and self:SetSchedule(SCHED_IDLE_STAND) [/code]
On a map change, this code... [code] local chatcommands = {}; function GAMEMODE:PlayerSay(ply, text, teamc, alive) local chat_string = string.Explode(" ", text); for k, v in pairs( chatcommands ) do if( chat_string[1] == k ) then table.remove(chat_string, 1); v(ply, chat_string); return ""; end if( string.find(k, chat_string[1]) != nil ) then local start, endp, word = string.find(k, chat_string[1]); if( endp - (start - 1) > 2 ) then ply:ChatPrint("Invalid command! Did you mean '"..tostring( k ).."'?"); return ""; end end end return text; end function RegisterChatCommand(strCommand, Func) if( !strCommand || !Func ) then return; end for k, v in pairs( chatcommands ) do if( strCommand == k ) then return; end end chatcommands[ tostring( strCommand ) ] = Func; end -- Chat commands -- Test command RegisterChatCommand("!fuckyou", function(ply, args) if( ply:IsSuperAdmin() ) then local pname = args[1]; for _, v in pairs( player.GetAll() ) do if( string.find(v:Nick(), pname) ) then v:ChatPrint("Hey man, fuck you."); end end end end) -- Screengrab RegisterChatCommand("!screengrab", function(ply, args) if ply:IsSuperAdmin() then ply:ConCommand("screengrab") end end) [/code] ...will no longer work and spew out this error in console: [code] [ERROR] lua/autorun/wf_chatcommands.lua:3: attempt to index global 'GAMEMODE' (a nil value) 1. unknown - lua/autorun/wf_chatcommands.lua:3 [/code]
[QUOTE=Windwhistle;49675739]On a map change, this code... -code- ...will no longer work and spew out this error in console: [code] [ERROR] lua/autorun/wf_chatcommands.lua:3: attempt to index global 'GAMEMODE' (a nil value) 1. unknown - lua/autorun/wf_chatcommands.lua:3 [/code][/QUOTE] You have to use a hook instead of replacing the gamemode's default hook. Use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/hook/Add]hook.Add[/url] instead.
[QUOTE=Mrkrabz;49673854]WithinAABox seems to always be returning false, I had it working on a past map but cannot get it working now. [lua] local Start = Vector(-10919.388672, 14790.270508, 10046.089844) local Start1 = Vector(-10513.226563, 13777.234375, 9441.031250) if v:GetPos():WithinAABox(Start, Start1) then print("yes") else print("no") end [/lua] Players position is "-10735.693359 13976.206055 9504.031250" which afaik is in between those two vectors?[/QUOTE] The arguments for WithinAABox are min and max, so each x, y and z for min must be <= max's corresponding axis. Makes it a little difficult to use, but it does work.
[QUOTE=GGG KILLER;49675786]You have to use a hook instead of replacing the gamemode's default hook. Use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/hook/Add]hook.Add[/url] instead.[/QUOTE] Thank you so much. :P
[QUOTE=bigdogmat;49674416]If I had to guess how the function worked I'd say it's because the y and z vectors are bigger on the first vector than on the second[/QUOTE] It has to be in the right order on x/y/z based on world orientation too is there a function that fixes this when inputting two vectors? always a pain to get it right
[QUOTE=jd0124;49675558]How can I get my scripted NPC to spawn standing still until I give it somewhere to move? I've got a scripted NPC based off the npc_shop example. I gave it the capability of walking with this: [code] self:CapabilitiesAdd( CAP_MOVE_GROUND ) [/code] But now when it spawns it automatically wanders off randomly around the whole map. I tried both of these in ENT:Initialize() but they didn't do anything. [code] self:SetSchedule(SCHED_NONE) and self:SetSchedule(SCHED_IDLE_STAND) [/code][/QUOTE] I still can't find a solution to this. I found that if I override ENT:SetSchedule like this: [code] function ENT:SelectSchedule(iNPCState ) end [/code] then the NPC doesn't walk at the start, but then I can't get it to walk anywhere.
[QUOTE=jd0124;49677271]I still can't find a solution to this. I found that if I override ENT:SetSchedule like this: [code] function ENT:SelectSchedule(iNPCState ) end [/code] then the NPC doesn't walk at the start, but then I can't get it to walk anywhere.[/QUOTE] save the base method ENT.SelectSchedule then in whichever way you want, call that function to make it walk
[QUOTE=Giraffen93;49676918]is there a function that fixes this when inputting two vectors? always a pain to get it right[/QUOTE] You could do this: [lua] local function GetMinMax(a, b) local min = Vector(0, 0, 0); local max = Vector(0, 0, 0); for i = 1, 3 do if (a[i] >= b[i]) then max[i] = a[i]; min[i] = b[i]; else max[i] = b[i]; min[i] = a[i]; end end return min, max; end [/lua]
[QUOTE=>>oubliette<<;49677586]You could do this: [lua] local function GetMinMax(a, b) local min = Vector(0, 0, 0); local max = Vector(0, 0, 0); for i = 1, 3 do if (a[i] >= b[i]) then max[i] = a[i]; min[i] = b[i]; else max[i] = b[i]; min[i] = a[i]; end end return min, max; end [/lua][/QUOTE] Aren't vectors indexed by x, y, z instead of numbers?
I'm trying to use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/HandlePlayerJumping]GM/HandlePlayerJumping[/url] to prevent the jumping animation from playing but it seems like this hook is just never called. I've left it empty and put prints in there and not even the prints seem to run. How could I stop the jumping animations from playing? [editline]5th February 2016[/editline] I have also looked at [url=https://github.com/garrynewman/garrysmod/blob/3e138636eb1b0ad6ed785dedf350020755cff5f1/garrysmod/gamemodes/base/gamemode/animations.lua#L2]this[/url] and have tried changing values such as ply.m_bJumping and ply.CalcIdeal in my hook but nothing happened.
[QUOTE=YourStalker;49678047]I'm trying to use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/HandlePlayerJumping]GM/HandlePlayerJumping[/url] to prevent the jumping animation from playing but it seems like this hook is just never called. I've left it empty and put prints in there and not even the prints seem to run. How could I stop the jumping animations from playing? [editline]5th February 2016[/editline] I have also looked at [url=https://github.com/garrynewman/garrysmod/blob/3e138636eb1b0ad6ed785dedf350020755cff5f1/garrysmod/gamemodes/base/gamemode/animations.lua#L2]this[/url] and have tried changing values such as ply.m_bJumping and ply.CalcIdeal in my hook but nothing happened.[/QUOTE] That's the base gamemode, did you check the files from the gamemode you're currently using to see if it ever calls that hook?
[QUOTE=GGG KILLER;49678127]That's the base gamemode, did you check the files from the gamemode you're currently using to see if it ever calls that hook?[/QUOTE] The main gamemode I tested in was Sandbox so it should be called, right?
[QUOTE=GGG KILLER;49678024]Aren't vectors indexed by x, y, z instead of numbers?[/QUOTE] Both: [img]http://i.imgur.com/uKG6elB.png[/img] Vector.__index is defined in C so I can't show source for it. But I doubt it strays afar from [url=https://github.com/ValveSoftware/source-sdk-2013/blob/0d8dceea4310fde5706b3ce1c70609d72a38efdf/mp/src/public/mathlib/vector.h#L589]Valve's C++ operator[] overload[/url].
[QUOTE=>>oubliette<<;49678416]Both: [img]http://i.imgur.com/uKG6elB.png[/img] Vector.__index is defined in C so I can't show source for it. But I doubt it strays afar from [url=https://github.com/ValveSoftware/source-sdk-2013/blob/0d8dceea4310fde5706b3ce1c70609d72a38efdf/mp/src/public/mathlib/vector.h#L589]Valve's C++ operator[] overload[/url].[/QUOTE] Oh thanks, I didn't knew about that! [editline]5th February 2016[/editline] [QUOTE=YourStalker;49678259]The main gamemode I tested in was Sandbox so it should be called, right?[/QUOTE] Technically yes, it should but apparently, from a [url=https://github.com/garrynewman/garrysmod/search?utf8=%E2%9C%93&q=HandlePlayerJumping&type=Code]quick search[/url] it doesn't calls the hook anywhere.
[code] local ourMat = Material( "materials/hudmodels/lightsaber.vtf" ) surface.SetDrawColor( 255, 255, 255, 255 ) surface.SetMaterial( ourMat ) surface.DrawTexturedRect( ScrW() / 100, ScrH () / 1.3, 70, 40 ) [/code] Just incase you need the code :p Anyways, the problem is that the material shows as purple and black, the lightsaber.vtf IS in \Steam\steamapps\common\GarrysMod\garrysmod\materials\hudmodels.vtf But it doesn't do it :/, could it be because the code is in darkrp modification? please help!
Another problem with this script... [code] local chatcommands = {}; hook.Add("PlayerSay", "Commands Base", function(ply, text, teamc, alive) local chat_string = string.Explode(" ", text); for k, v in pairs( chatcommands ) do if( chat_string[1] == k ) then table.remove(chat_string, 1); v(ply, chat_string); return ""; end if( string.find(k, chat_string[1]) != nil ) then local start, endp, word = string.find(k, chat_string[1]); if( endp - (start - 1) > 2 ) then ply:ChatPrint("Invalid command! Did you mean '"..tostring( k ).."'?"); return ""; end end end return text; end ) function RegisterChatCommand(strCommand, Func) if( !strCommand || !Func ) then return; end for k, v in pairs( chatcommands ) do if( strCommand == k ) then return; end end chatcommands[ tostring( strCommand ) ] = Func; end -- Chat commands -- Test command RegisterChatCommand("!fuckyou", function(ply, args) if( ply:IsSuperAdmin() ) then local pname = args[1]; for _, v in pairs( player.GetAll() ) do if( string.find(v:Nick(), pname) ) then v:ChatPrint("Hey man, fuck you."); end end end end) -- Screengrab RegisterChatCommand("!screengrab", function(ply, args) if ply:IsAdmin() then ply:ConCommand("screengrab") end end) [/code] It breaks my Spectator Deathmatch for my TTT server. I don't know why or how, but it does.
[QUOTE=Windwhistle;49680420]snip[/QUOTE] Returning a non-nil value from a hook will prevent other hooked functions from being called. Remove [CODE]return text;[/CODE] and only return from hooks when you have to
I'm working on my first STOOL. I've been looking inside some example tools, and I noticed that all of them work serverside. Even for simple functions like measuring the distance between two points, all of them have this line inside LeftClick or RightClick: [CODE]if(CLIENT) then return true end[/CODE] Also, I noticed that if the tool has to do something on the client, some people send a message from the server to the client, and then it sends the results back to the server. Is there any reason why I shouldn't do clientside stuff directly inside the LeftClick and RightClick hooks?
[QUOTE=Ehmmett;49681506]er sorry if this thread is for lua only or what but I'm trying to make a GMA and i'm positive i've done everything correctly but when I open gmod it tells me this the two .gmas i've made are being unused? I don't know why or how to fix this.[/QUOTE] That happens when you're not subscribed to those mods. Perhaps they were removed from the workshop (with those names, it's quite probable) Edit: I just noticed you said that those mods are yours. Did you upload them to the workshop? As far as I know, GMOD won't load unsuscribed gmas unless its in offline mode.
[QUOTE=Ehmmett;49681556]Well yeah I'm not subscribed to it, I've only just made the gma. It's not ready to go on the workshop yet. So I have to publish it to mount it? I don't remember it always being like that.[/QUOTE] Yeah you have to, or go into offline mode, unless there's a command to force load gmas. If you just want to test them, put the contents in a subfolder inside "addons", you don't need a gma.
[QUOTE=swadicalrag;49681009]Returning a non-nil value from a hook will prevent other hooked functions from being called. Remove [CODE]return text;[/CODE] and only return from hooks when you have to[/QUOTE] Thanks so much! :D
[QUOTE=Ehmmett;49681506]er sorry if this thread is for lua only or what but I'm trying to make a GMA and i'm positive i've done everything correctly but when I open gmod it tells me this the two .gmas i've made are being unused? I don't know why or how to fix this.[/QUOTE] Put the .gmas inside an addon folder or outside of the addon folder.
Sorry, you need to Log In to post a reply to this thread.