• What do you need help with? V3
    6,419 replies, posted
Well I don't have it installed in my addons so I'm not sure. And I heard it ships with gmod now anyway
[QUOTE=343N;39340073]Well I don't have it installed in my addons so I'm not sure. And I heard it ships with gmod now anyway[/QUOTE] 99% sure it doesn't, did you check both legacy addons (stored in the old addons/ folder) and workshop addons? It might also be somewhere in your lua folder if you installed it that way
I feel like I'm being completely ignored D: :tinfoil: [QUOTE=luavirusfree;39335855]Lol, damn. I guess I'm missing an '=' here? [ERROR] lua_run:1: '=' expected near '<eof>' 1. unknown - lua_run:0 Also, what tag do you put errors in to make them look like that one comment on this thread? [lua]if (SERVER) then return nil end -- We only draw on the client. There is no screen for the server, EVER, even if the host is the server, it's the computer, not them. True for laptops and desktops!hud = {} -- Creates a lonely table for ONE function.--hud.maxammo = {} -- Table to get our current weapon's max ammo.hud.maxammo = 18 -- Max ammo for the pistol. This will change if we have the SMG1.-- I will comment this so that anyone can understand if they want to make their own HUD. --function MetroHud() -- Main bulk of the code, loops on. if hidden then return end -- The player wanted to hide the HUD. Too bad D: we do nothing! local Scrw, Scrh = ScrW(), ScrH() -- Creates two variables, screen width Scrw, and screan height Scrh. They are exactly equal to the true game resolution. local HudBG = { -- Names the table of settings. texture = surface.GetTextureID "CombineHud/met_comb_ovr_2048", -- What texture to use color = Color(255,255,255,255), -- What color (this color does no change) (RED,GReeN,BLUe,Alpha) x = 0, -- 0 is the exact start of the width (X is width) y = 0, -- 0 is the exact start of the height (Y is height) w = Scrw, -- Cover the entire screen. Width = w h = Scrh -- Cover the entire screen. Height = h } -- Ends the table. local Client = LocalPlayer() -- The player that sees the HUD. Always him or her, never a connected player. draw.TexturedQuad( HudBG ) -- Draws what the {table} above, HudBG, says to draw. local HealthBackMet = surface.GetTextureID "CombineHud/met_health_bg" -- Background image for the health readout. local HealthBarMet = surface.GetTextureID "CombineHud/met_health_bar" -- Image of the actual meter for shields. local SuitBackMet = surface.GetTextureID "CombineHud/met_shld_lvl" -- Background image for the shield readout. local SuitBarMet = surface.GetTextureID "CombineHud/met_shld_lvl" -- Image of the actual meter for shields. local CommandPost = surface.GetTextureID "CombineHud/met_command" -- Not used yet! local Criminal = surface.GetTextureID "CombineHud/met_criminal" -- Not used yet! local Promotion = surface.GetTextureID "CombineHud/met_promo" -- Not used yet! local MeterWidth = Scrw / 4 -- The meter's actual size is one forth of the screen's width. local MeterWidthBarEnd = MeterWidth-(MeterWidth*math.min((Client:Health()/40),1)*0.5) -- Max health as a metro cop? 40. This sets up the bar for health. local MeterWidthBar = MeterWidth-(MeterWidth*math.min((Client:Armor()/25),1)*0.5) -- Max shield as a metro cop? 25. This sets up the bar for shield. local MeterHeight = MeterWidth/4 -- Since the texture resolution for width is 4x the height, we take one forth of our width for height. surface.SetTexture( HealthBackMet ) -- This tells the game what image to draw. surface.DrawTexturedRectRotated(Scrw/4,Scrh+MeterHeight,MeterWidth,MeterHeight,0) -- This draws an image. Format: Position <>, position ^v, Width <>, Height &v, Counter Clock Rotation surface.SetTexture( HealthBarMet ) -- This tells the game what image to draw, and overrides the last time it was set so we don't keep drawing the same thing. surface.DrawTexturedRectUV(Scrw/4,Scrh+MeterHeight,MeterWidthBarEnd,MeterHeight,MeterWidthBarEnd,MeterHeight) -- Draws the image. Format: Pos Wide, Pos Tall, Image Width, Image Height, How much to show texture wide, same for height. local PosShieldsX = Scrw-MeterWidth-(Scrw/4) -- Variable. Used so that we draw on the other side of the screen mathematically.-- local PosShldMetX = Scrw-(MeterWidth*1.5)-(Scrw/4) -- Half way further away because we didn't flip it. -- This was removed when we did flip it. surface.SetTexture( SuitBackMet ) -- Set and replace image... surface.DrawTexturedRectRotated(PosShieldsX,Scrh,MeterWidth,MeterHeight,0) -- This draws an image. Format: Position <>, position ^v, Width <>, Height &v, Counter Clock Rotation surface.SetTexture( SuitBarMet ) -- Set and replace image... surface.DrawTexturedRectUV(PosShieldsX,Scrh,MeterWidthBar,MeterHeight,MeterWidthBarEnd,MeterHeight) -- Draws the image. Format: Pos Wide, Pos Tall, Image Width, Image Height, How much to show texture wide, same for height. if Client:GetActiveWeapon():GetPrintName() == "USP Match mod" then hud.maxammo = 18 -- The max ammo for the pistol is 18, 19 with chamber. elseif Client:GetActiveWeapon():GetPrintName() == "STUNSTICK" then hud.maxammo = -1 -- The Stunstick has 100% ammo, 100 Guass Energy 'rounds'. elseif Client:GetActiveWeapon():GetPrintName() == "MP7A1 mod" then hud.maxammo = 45 -- The MP7 (SMG1) has 45 rounds, 46 with chamber. elseif Client:GetActiveWeapon():GetPrintName() == "SPAS-12 mod" then hud.maxammo = 6 -- The shotgun has a 6 round 'clip', with no chamber. elseif Client:GetActiveWeapon():GetPrintName() == "Pulse Rifle" then hud.maxammo = 30 end -- The shotgun has a 30 round 'clip', with no chamber.endhook.Add( "HUDPaint", "MetroHUD", MetroHud ) -- This tells the game to draw the function as the HUD. Format: What to do, A unique name (what purpose?), What function to use to do it. Called before every frame that is drawn.function HideHUD( name ) -- Allow the combine elements, hide the regular. if !hidden then -- If the HUD is hidden, then do this: if name == "CHudHealth" then return false end -- Says that we don't want the DEFAULT health display. if name == "CHudBattery" then return false end -- Says that we don't want the DEFAULT battery display. if name == "CHudAmmo" then return false end -- Says that we don't want the DEFAULT ammo display. if name == "CHudSecondaryAmmo" then return false end -- Says that we don't want the DEFAULT alt-fire ammo display. if name == "CHudCrosshair" then return false end -- Says that we don't want the DEFAULT crosshair. if name == "CHudDeathNotice" then return false end -- Says that we don't want to know who killed who, and who died. if name == "CHudWeaponSelection" then return false end -- Says that we don't want the DEFAULT weapon selection. if name == "CHudSquadStatus" then return false end -- Says that we don't want the squad display, for rebels. if name == "CHudZoom" then return false end -- Says that we don't want things darker when we zoom. if name == "CHudHistoryResource" then return false end -- Says that we don't want to know what we have picked up, ammo-wise. end -- Closes the first "if" statement. The other ones close themselves.return true -- Should we make "the drawing" of these things do what we say? true. Otherwise, false.-- Format is: if name(default HUD function set) ==(is exactly) "Individual Function Name, case sensitive) then(Do this:) return(Give an answer) bool(false=no, true=yes) end(finishes it)end -- We are done with this function, so stop it here.hook.Add("HUDShouldDraw","HideHUD",HideHUD) -- Should we draw? Everything that the function doesn't say no to. Act, Name, Function.local hidden = false -- Create the variable why don't we?function hud.hideme() -- function used to hide this HUD. if hidden == false then -- If we're not hidden, then hidden = true --*cry* ... Hide us! elseif hidden == true then -- If we're already hidden, then (elseif means that we add an if statement to this code block. We don't need to end the if we started with.) hidden = false --oh now you want me back. Show us! end -- Done. We now know what to do.end -- Done, we have nothing else to do =Pconcommand.Add("****hud_toggle","Hide Combine Hud",hud.hideme) -- Create the console command t
[HTML]hook.Add("PlayerDeath", "PS_PlayerDeath", function(victim, inflictor, attacker) if attacker:IsValid() and attacker:IsPlayer() and ( victim != attacker ) then attacker:PS_GivePoints(250) attacker:PS_Notify('Kill Point 250+ !!') end end)[/HTML] But, The trail does not disappear after the death.. Please Quickly Help me!
Okay :x how do i add jobs in darkrp? the old TEAM_FACEPUNCH[CODE][CODE] does not work anymore.... There is a new way like TEAM_FACEPUNCH create_team facepunch <---- (0,12,12,255) | with alot of spaces and stuff.. D: | can someone make me a barebones for this gm13 darkrp?| Oh , and , also , how do i add entities for jobs? custom jobs? like id want to create a merchant that sells fruits , how do i add erm like fruit entities or something like that? I am new c: so please be patient with me! >:DD because i don't understand why so many spaces like }-- | | |{end} | | }-- ;-;
Is there such a thing as a hook that is called when a table changes?
How can I scan through an array to find data and then do something with that? For example: [LUA] if ply:Name() --[is inside]-- == list_of_names[] --[this array]-- then --Do something end[/LUA]
[QUOTE=vinylrain;39340956]How can I scan through an array to find data and then do something with that? For example: [LUA] if ply:Name() --[is inside]-- == list_of_names[] --[this array]-- then --Do something end[/LUA][/QUOTE] Don't be stupid. Divran already helped you with that, and it's even on this page! [url]http://www.facepunch.com/showthread.php?t=1160598&p=39334355&viewfull=1#post39334355[/url]
[QUOTE=ms333;39340967]Don't be stupid. Divran already helped you with that, and it's even on this page! [url]http://www.facepunch.com/showthread.php?t=1160598&p=39334355&viewfull=1#post39334355[/url][/QUOTE] I'm sorry. I didn't scroll through the whole thing to see if my question was answered before I asked it.
[QUOTE=Bilsta1000;39340761]Is there such a thing as a hook that is called when a table changes?[/QUOTE] Yes, there are [URL="http://lua-users.org/wiki/MetamethodsTutorial"]meta methods[/URL] you can change. table. __newindex handles values in a table changing. [editline]hi[/editline] V listen to this guy V
[QUOTE=Bilsta1000;39340761]Is there such a thing as a hook that is called when a table changes?[/QUOTE] [url]http://www.lua.org/manual/5.2/manual.html#2.4[/url] __newindex is called when writing a value with a key that is not already present in the table. __index is called in every other situation (when reading from or writing to the table) EDIT: Ninja'd. However, the guy before me is slightly wrong, since __newindex doesn't work as you'd expect. It isn't called when writing a key that already exists.
[QUOTE=Divran;39341062][url]http://www.lua.org/manual/5.2/manual.html#2.4[/url] __newindex is called when writing a value with a key that is not already present in the table. __index is called in every other situation (when reading from or writing to the table) EDIT: Ninja'd. However, the guy before me is slightly wrong, since __newindex doesn't work as you'd expect. It isn't called when writing a key that already exists.[/QUOTE] I'm struggling to understand from the reference documentation, could you give me a basic example? bear in mind I'm very low level coding. Am I right in thinking that the function is called through hook.Add but then it waits for a change before continuing? Where does this __newindex go exactly?
[QUOTE=Bilsta1000;39341137]I'm struggling to understand from the reference documentation, could you give me a basic example? bear in mind I'm very low level coding. Am I right in thinking that the function is called through hook.Add but then it waits for a change before continuing? Where does this __newindex go exactly?[/QUOTE] It's not a hook, you apply the __methods to the table you want to monitor.
In my case I'm trying to monitor how many players are within a specific box. So it needs to look like this? or am I just not getting it. [lua]PVPPlayers.__newindex = ents.FindInBox( Vector(9004.761719, -3845.509277, 5487.840332), Vector(16267.462891, -9213.438477, 2983.771729))[/lua]
[lua]local metatable = { __newindex = function( tbl, key, value ) print("something has been added to " .. tostring(tbl) .. " at " .. tostring(key) .. " with value " .. tostring(value)) rawset( tbl, key, value ) -- set the value end, __index = function( tbl, key ) print("something has been accessed from " .. tostring(tbl) .. " at " .. tostring(key)) return rawget( tbl, key ) -- return the value end, } local mytable = {} setmetatable(mytable,metatable)[/lua] EDIT: I tested the above code in SciTE, and found the following: [lua]mytable.stuff = "hax" -- will call metatable.__newindex with the table "mytable", key "stuff" and value "hax" print(mytable.stuff) -- won't call any function mytable.stuff = "asdasdasd" -- won't call any function print(mytable.asdsd) -- will call __index[/lua] it's a bit strange, but that's how it works.
[lua]local metatable = { __newindex = function( tbl, key, value ) print("something has been added to " .. tostring(tbl) .. " at " .. tostring(key) .. " with value " .. tostring(value)) GiveNewPlayerGuns() end, __index = function( tbl, key ) print("something has been accessed from " .. tostring(tbl) " at " .. tostring(key)) end, } local PVPPlayers = {} setmetatable(PVPPlayers,metatable) PVPPlayers = ents.FindInBox( Vector(9004.761719, -3845.509277, 5487.840332), Vector(16267.462891, -9213.438477, 2983.771729))[/lua] Tried adding the code to mine. So everytime a new player enters the defined box the value will change and the GiveNewPlayerGuns() function will run....... right?
Quick question, is there a difference between Player.tbl and Player:GetTable().tbl?
[QUOTE=Bilsta1000;39341328]So everytime a new player enters the defined box the value will change and the GiveNewPlayerGuns() function will run....... right?[/QUOTE] Nope, ents.FindInBox is only run once and returns a table. You said you do low-level programming, so if it makes more sense this way: it's not a pointer. ents.FindInBox has to be called each time you want to check entities in a box. [editline]24th January 2013[/editline] [QUOTE=Adult;39341467]Quick question, is there a difference between Player.tbl and Player:GetTable().tbl?[/QUOTE] Yes they're the same, however Entity:GetTable() is now deprecated, it's very much advised you don't use it. It was around before you were able to apply variables directly to Entity objects.
[QUOTE=Matt-;39341681]Nope, ents.FindInBox is only run once and returns a table. You said you do low-level programming, so if it makes more sense this way: it's not a pointer. ents.FindInBox has to be called each time you want to check entities in a box.[/QUOTE] Then what would you advise if I wanted to run a function every time another player entered the box? They teleport in there using the hammer entity if that helps.
[QUOTE=Bilsta1000;39341858]Then what would you advise if I wanted to run a function every time another player entered the box?[/QUOTE] It's quite a heavy function, but hmm. Try the "Tick" hook, unless somebody else can come up with a better hook.
Or timers.
[QUOTE=Adult;39341939]Or timers.[/QUOTE] You lose accuracy there, people could be in and out of the area within a second.
Lets say i had a tunnel. Is there any way of checking which way a person entered/exited the tunnel and the direction they travel in?
[QUOTE=fairy;39321936]function GM:PlayerSpawnVehicle(ply) return end[/QUOTE] Doesn't work, I have a similar problem. I managed to block entities and weapons being spawned like this, but not vehicles. I set the max to 0 but that makes Car Dealer a pointless job, I only want to block that damned creator tool. >.>
[QUOTE=Science;39342094]Lets say i had a tunnel. Is there any way of checking which way a person entered/exited the tunnel and the direction they travel in?[/QUOTE] Check players distance from the center of the tunnel, when they come in range take the starting position and when they're out of range take the end position. Then do a bit of simple math to work out the direction.
You sir. Are a genius
Im looking to bind a command to F1, how would I do so and remove the Help screen?
[QUOTE=Science;39342277]You sir. Are a genius[/QUOTE] Thanks. [editline]24th January 2013[/editline] [QUOTE=nazz;39343674]Im looking to bind a command to F1, how would I do so and remove the Help screen?[/QUOTE] Serverside: [lua] hook.Add("ShowHelp", 0, function(ply) ply:ConCommand("dostuff") return true end) [/lua]
[lua]] lua_run_cl http.Fetch("www.google.com", print, print) unsuccessful [/lua] [lua]] lua_run_cl http.Fetch("http://www.google.com", print, print) ... HTML STUFF ... [/lua] Why is this? [lua]] lua_run_cl http.Fetch("http://www.steamcommunity.com", print, print) unsuccessful [/lua] Is this some sort of fucking puzzle?
-snip no nvm-
Sorry, you need to Log In to post a reply to this thread.