[QUOTE=bobbleheadbob;47063136]Here's an example to draw a health bar:
[lua]
hook.Add("HUDPaint","Draw Arc Healthbar",function()
local x,y = 200,200
local radius = 100
local thickness = 20
local startAng,endAng = 1, ( LocalPlayer():Health() / 100 ) * 359
draw.Arc(x,y,radius,thickness,startAng,endAng,1,Color(255,0,0))
end)
[/lua][/QUOTE]
Nope, still not working, I'm running on the client and this is the code I'm using: [url]http://pastebin.com/zLLEfHUv[/url]
It only shows the white text with the health value
[QUOTE=GGG KILLER;47064804]Nope, still not working, I'm running on the client and this is the code I'm using: [url]http://pastebin.com/zLLEfHUv[/url]
It only shows the white text with the health value[/QUOTE]
[url]http://steamcommunity.com/sharedfiles/filedetails/?id=386200779[/url]
Works for me.
I have a few files around 100kb, 300kb, etc and they work just fine ( vehicle initialization for lonewolfies = 257kb, another is 108kb for list of vehicles ).
[QUOTE=ROFLBURGER;47062822]I really need help again with trigonometry
[t]http://i.imgur.com/t3ul6FW.png[/t]
[/QUOTE]
I'm pretty sure you already got your answer but here is something to visualize the triangles ( turn on line drawing, etc...: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/hud/simple_hud_radar_system.lua.html[/url]
And that uses players for points, This one keeps players at the edge: simple_hud_radar_system_keep_players_on_radar.lua
I recently wrote a function to help with funding the angle difference between 2 points: [url]http://facepunch.com/showthread.php?t=1440586&p=47046519&viewfull=1#post47046519[/url]
[code]//
// Calculates the 2 unknown angles of a right-triangle so the sum adds up to -180 or 180 - Acecool - See AcecoolDev_Base
//
function math.OmegaAngleDifference( _pos, _pos2 )
local _rad = math.atan( ( _pos.y - _pos2.y ) / ( _pos2.x - _pos.x ) );
local _deg = math.deg( _rad );
local _deg2 = 180 - ( 90 + math.abs( _deg ) );
_deg2 = ( _deg < 0 ) && _deg2 * -1 || _deg2;
return _deg, _deg2, _rad, math.rad( _deg2 );
end[/code]
From that you can turn it into Angle( 0, _deg or _deg2, 0 ):Forward( ) * _dist; for the new position, _deg or _deg2 for the new angle to face when walking, etc...
If it doesn't help you, hopefully it helps someone else; I'm not the best at math so this is one of the helper functions that took me a while to get just right ( some of the others I wrote trying to do this ended up always returning different angles based on points where-as this one gives the same results regardless of the point.
[QUOTE=Acecool;47065010]I have a few files around 100kb, 300kb, etc and they work just fine ( vehicle initialization for lonewolfies = 257kb, another is 108kb for list of vehicles ).[/QUOTE]
It's an undesirable situation. The files are compressed before the 64KB limit is taken in to account.
[QUOTE=bobbleheadbob;47064962][url]http://steamcommunity.com/sharedfiles/filedetails/?id=386200779[/url]
Works for me.[/QUOTE]
Well, I just ran the script with lua_openscript_cl and it didn't gave me anything apart from the white text(I'm using DarkRP, if that changes anything)
Maybe you're using something more that is making the script work...
[QUOTE=GGG KILLER;47065116]Well, I just ran the script with lua_openscript_cl and it didn't gave me anything apart from the white text(I'm using DarkRP, if that changes anything)
Maybe you're using something more that is making the script work...[/QUOTE]
Nah I did the same thing but it was in sandbox.
Maybe you have some conflicts. Try replacing all draw.Arc with DrawArc and surface.PrecacheArc with PrecacheArc.
[QUOTE=bobbleheadbob;47065141]Nah I did the same thing but it was in sandbox.
Maybe you have some conflicts. Try replacing all draw.Arc with DrawArc and surface.PrecacheArc with PrecacheArc.[/QUOTE]
Yeah, I just ran it on sandbox and it worked, I think I'll try doing what you suggested then
[QUOTE=Willox;47065041]It's an undesirable situation. The files are compressed before the 64KB limit is taken in to account.[/QUOTE]
Thanks for the heads up on that! Looks like I'll need to add an oversize warning system to my autoloader just in case someone tries including a file that is oversized ( and it'll network it via my system if oversize but output warning ).
Yeah, I threw those vehicles in there as a quick method ( because my unregistered vehicles system outputs the code to register the vehicles in the new table format ) so that I could set up lighting. But I am going to change the format of my vehicle system before I release it so data will be in txt form and then converted to Lua on the fly; and it'll also have permissions for each component because the client doesn't need to know everything in the table just like the server won't need everything either.
Is there a way to override the Garry's Mod main menu from a serverside sent client lua file? Like a hook or something? I could make my custom main menu pop up over the main menu after pressing Esc, I can't figure out how to close the regular gmod menu afterwards and it's still visible in the background.
[QUOTE=GGG KILLER;47065146]Yeah, I just ran it on sandbox and it worked, I think I'll try doing what you suggested then[/QUOTE]
Might message FPtje on facepunch and ask him if there's something which might conflict with that in DarkRP (assuming that's the issue). He'll know exactly what would.
EDIT:
[QUOTE=swadicalrag;47065282]Is there a way to override the Garry's Mod main menu from a serverside sent client lua file? Like a hook or something? I could make my custom main menu pop up over the main menu after pressing Esc, I can't figure out how to close the regular gmod menu afterwards and it's still visible in the background.[/QUOTE]
Derma draws over the main menu if it's moved to the front. I have had to hide before it whenever the main menu is showing so it didn't cover the real menu.
Add a think hook (not Panel:Think, GM:Think) which checks if the main menu is visible and if so, show the custom main menu and move it to the front.
Use these:
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/gui/ActivateGameUI]gui.ActivateGameUI[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/gui/IsGameUIVisible]gui.IsGameUIVisible[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/gui/HideGameUI]gui.HideGameUI[/url]
I'm trying to export an animated landing gear for a WW2 plane, and i've done the animation in Milkshape. Then, i exported the model as .smd. Here is the .qc file i used to compile it afterwards:
[IMG]http://puu.sh/foiKf/9addf3f8c8.png[/IMG]
Ok, so after compiling it i opened up Gmod and tried to spawn this model, but no mater how many times i clicked the model icon, it just refused to spawn.
This is my first time working with animations, so i have no idea what could be the problem.
[QUOTE=ThrowAwayAcct;47063623][B]Hey everyone, is there some kind of practical limit on the size of a LUA file?[/B]
I'm building a gamemode. Until recently I had all my autorun in three files (client, server and shared), each of which were maybe 2000 lines (~80kb).
Until this point, I've greatly enjoyed the lua autorefresh feature of GMod13, I just make changes to the code and ta-da they're instantly in game. But then things started crashing. I have very few addons enabled (dev mode, I want fast load times), and the game is otherwise very stable, but whenever I make a change to a script file, gmod crashes instantly. It's like it crashes while trying to reload the file.
I broke my autorun out into six files, halving each in size, but it still crashes whenever I try to make changes at runtime. Is it because the files are too big? Has anyone encountered this?[/QUOTE]
Hahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahaha!!!!!!!!!!!!!!! I have scripts that are over [B]16000 [/B]lines long that work with no lag or anything!!!
Post note: I can't really test my scripts online, my internet service, hell be to them, and the routers they've given us, don't entirely allow me to forward my ports. I'm not sure how they'd do then...
If I was gonna guess what's causing the crash, it's probably some of the code you wrote. When lua files refresh, the code needs to run again... initialize doesn't run again on already spawned sweps, so I assume the same concept exists in many other situations.
[highlight](User was banned for this post ("bad post" - Gurant))[/highlight]
[QUOTE=Killstr3aKs;47065569]I'm trying to export an animated landing gear for a WW2 plane, and i've done the animation in Milkshape. Then, i exported the model as .smd. Here is the .qc file i used to compile it afterwards:.[/QUOTE]
You should try to post in in the [URL="http://facepunch.com/forumdisplay.php?f=40"]Modelling[/URL] Section instead of the Developer Section. We discuss here more Lua related stuff then models.
[QUOTE=Tomelyr;47066499]You should try to post in in the [URL="http://facepunch.com/forumdisplay.php?f=40"]Modelling[/URL] Section instead of the Developer Section. We discuss here more Lua related stuff then models.[/QUOTE]
I already tried, but no one answered so far :/
[QUOTE=Killstr3aKs;47065569]I'm trying to export an animated landing gear for a WW2 plane, and i've done the animation in Milkshape. Then, i exported the model as .smd. Here is the .qc file i used to compile it afterwards:
[IMG]http://puu.sh/foiKf/9addf3f8c8.png[/IMG]
Ok, so after compiling it i opened up Gmod and tried to spawn this model, but no mater how many times i clicked the model icon, it just refused to spawn.
This is my first time working with animations, so i have no idea what could be the problem.[/QUOTE]
$inertia is a normal value. That means between 0 and 1.
[url]https://developer.valvesoftware.com/wiki/$collisionmodel[/url]
[QUOTE=bobbleheadbob;47067022]$inertia is a normal value. That means between 0 and 1.
[url]https://developer.valvesoftware.com/wiki/$collisionmodel[/url][/QUOTE]
I've been compiling all the non-animated models with that value for $inertia and they all work fine. I will try with 0 or 1 and see if thats the problem.
EDIT: Nope, it still refuses to spawn.
[QUOTE=Killstr3aKs;47067232]I've been compiling all the non-animated models with that value for $inertia and they all work fine. I will try with 0 or 1 and see if thats the problem.
EDIT: Nope, it still refuses to spawn.[/QUOTE]
I'll add you on steam and I'll try to help you out.
Okay, i've made some progress. I managed to compile the model correctly and it works ingame. The problem is, it's rotated 90º on the x axis, so the tip of the wing is pointing forwards instead of to the left. Like this:
[t]http://i.imgur.com/VSpUa02.png[/t]
So all my script files are well under 64kb, so it's not a size issue. This is also SinglePlayer, so iunno how that affects networking, but in any case I don't think that's the problem.
I cleaned up my addons (subscribed to, like, 10 addons now), wiped out my garrysmod folder (everything deleted, after of course copying out the addon i'm working on, in legacy format), then uninstalled gmod. Then I reinstalled gmod, then restarted my computer, started gmod, let it redownload my ten addons, then put my addon in and restarted gmod.
After all this, it still happens. When I make changes to an autorun file, sometimes it reloads it fine and sometimes the game just crashes instantly. I took a relevant MDMP file to a website to parse it, it got me the console output right before crashing, and I see nothing of interest.
I don't know why the lua auto-refresh is crashing gmod. [b]Can anyone tell me of a way to disable it, perhaps?[/b] Like a console command? In the olden days of GM12, I used lua_reloadents to reload my scripts, and I still have a key bound for that purpose. Perhaps I can fallback to that after disabling lua autorefresh?
[b]EDIT:[/b] Thanks, RobotBoy, for the link. I tried to see if the console would complete any kind of command for autorefresh for me, and it didn't show me anything. That page has some very insteresting info I'll take into account.
[QUOTE=ThrowAwayAcct;47068837]So all my script files are well under 64kb, so it's not a size issue. This is also SinglePlayer, so iunno how that affects networking, but in any case I don't think that's the problem.
I cleaned up my addons (subscribed to, like, 10 addons now), wiped out my garrysmod folder (everything deleted, after of course copying out the addon i'm working on, in legacy format), then uninstalled gmod. Then I reinstalled gmod, then restarted my computer, started gmod, let it redownload my ten addons, then put my addon in and restarted gmod.
After all this, it still happens. When I make changes to an autorun file, sometimes it reloads it fine and sometimes the game just crashes instantly. I took a relevant MDMP file to a website to parse it, it got me the console output right before crashing, and I see nothing of interest.
I don't know why the lua auto-refresh is crashing gmod. [b]Can anyone tell me of a way to disable it, perhaps?[/b] Like a console command? In the olden days of GM12, I used lua_reloadents to reload my scripts, and I still have a key bound for that purpose. Perhaps I can fallback to that after disabling lua autorefresh?[/QUOTE]
[url]http://wiki.garrysmod.com/page/Auto_Refresh[/url]
There once was a mod that allowed to replace all generic bullet impact particle effects with Modern Warfare ones. If anybody knows where it is now, or how one could achieve the same effect , please share your knowledge.
Ok Idk what is going on but team.addscore and team.setscore are refusing to work. I have tried it multiple ways.
[lua]
function GM:PlayerDeath( ply, inflictor, attacker )
//Add points to team for tdm
//if attacker:Team() != ply:Team() and GetConVarNumber( "esp_pointsperkill") == 1 then
local temp = team.GetScore( attacker:Team() ) + 1
team.SetScore( attacker:Team(), temp )
print("Attacker Score: "..team.GetScore( 2))
print("Your Score: "..team.GetScore( 1))
//Send points to the client
umsg.Start( "addpoints" );
umsg.Float( attacker:Team() );
umsg.Long( temp );
umsg.End();
//end
[/lua]
So I decided last Sunday that i'd finally knuckle down and learn Lua. I've gone through a few youtube tutorials/series on the basics of GMod lua and have very (very) basic knowledge of it all. I decided to first try and make some HUD related stuff, so i've got my own dedicated local server and i'm trying to make my own health bar. With some help i've got the HUD side of it down:
[CODE]
hook.Add( "HUDPaint", "MyHudPaint", function()
draw.RoundedBox( 0, 10, 30, 200, 4, Color( 100, 100, 200 ) ) // Back of Armour
draw.RoundedBox( 0, 10, 30, 100, 4, Color( 0, 0, 255 ) ) // Front of Armour
draw.RoundedBox( 0, 10, 10, 200, 20, Color( 255, 0, 0 ) ) //Back of health
draw.RoundedBox( 0, 10, 10, 200, 20, Color( 0, 255, 0 ) ) // Front of Health
draw.SimpleTextOutlined( "Health", "DermaDefaultBold", 90, 14, color_white, 0, 0, 1, Color(0,0,255,255) )
end )
[/CODE]
but I've been looking for the past 4 hours on how to find the current player's health and set that as a local variable. I've been on [URL="https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexd101.html"]https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexd101.html[/URL] to try and find anything related to the player's health and can't find it. I don't really know what I'm looking for to be honest or where it could be.
I'm also running this from my lua folder and using "lua_openscript_cl drawboxes.lua" in the console to run it. (If that's any use for you to know)
[QUOTE=Kamber56;47069322]So I decided last Sunday that i'd finally knuckle down and learn Lua. I've gone through a few youtube tutorials/series on the basics of GMod lua and have very (very) basic knowledge of it all. I decided to first try and make some HUD related stuff, so i've got my own dedicated local server and i'm trying to make my own health bar. With some help i've got the HUD side of it down:
[CODE]
hook.Add( "HUDPaint", "MyHudPaint", function()
draw.RoundedBox( 0, 10, 30, 200, 4, Color( 100, 100, 200 ) ) // Back of Armour
draw.RoundedBox( 0, 10, 30, 100, 4, Color( 0, 0, 255 ) ) // Front of Armour
draw.RoundedBox( 0, 10, 10, 200, 20, Color( 255, 0, 0 ) ) //Back of health
draw.RoundedBox( 0, 10, 10, 200, 20, Color( 0, 255, 0 ) ) // Front of Health
draw.SimpleTextOutlined( "Health", "DermaDefaultBold", 90, 14, color_white, 0, 0, 1, Color(0,0,255,255) )
end )
[/CODE]
but I've been looking for the past 4 hours on how to find the current player's health and set that as a local variable. I've been on [URL="https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexd101.html"]https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexd101.html[/URL] to try and find anything related to the player's health and can't find it. I don't really know what I'm looking for to be honest or where it could be.
I'm also running this from my lua folder and using "lua_openscript_cl drawboxes.lua" in the console to run it. (If that's any use for you to know)[/QUOTE]
local health = LocalPlayer():Health()
[QUOTE=bobbleheadbob;47069373]local health = LocalPlayer():Health()[/QUOTE]
Jesus christ it was that simple? Thanks lol
So does LocalPlayer() Only work clientside? And where would I be able to find other things I can use in place of :Health()? Is there a list somewhere?
[QUOTE=Kamber56;47069421]Jesus christ it was that simple? Thanks lol
So does LocalPlayer() Only work clientside? And where would I be able to find other things I can use in place of :Health()? Is there a list somewhere?[/QUOTE]
Yeah, LocalPlayer() gets the PLAYER object of the current user.
To get a player by other means, you have hooks, [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/player/GetAll]player.GetAll[/url], and other functions. Anything that can be run on LocalPlayer() can be ran on any other player, and vice versa.
Also, because players are just special Entities, you can run code that would work on an entity on a player.
All of these methods work with a player:
[url]http://wiki.garrysmod.com/page/Category:Player[/url]
[url]http://wiki.garrysmod.com/page/Category:Entity[/url]
[QUOTE=bobbleheadbob;47069589]Yeah, LocalPlayer() gets the PLAYER object of the current user.
To get a player by other means, you have hooks, [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/player/GetAll]player.GetAll[/url], and other functions. Anything that can be run on LocalPlayer() can be ran on any other player, and vice versa.
Also, because players are just special Entities, you can run code that would work on an entity on a player.
All of these methods work with a player:
[url]http://wiki.garrysmod.com/page/Category:Player[/url]
[url]http://wiki.garrysmod.com/page/Category:Entity[/url][/QUOTE]
Okay that clears up alot, Thanks!
Just one more question. How would I go about calling the hook (I think that's the right terminology) every time the player takes damage, so it updates the draw.RoudedBox? Am i able to put the hook for drawing all the boxes inside a Think hook? Or does it not work like that?
Here's my current code:
[CODE]local health = LocalPlayer():Health()
hook.Add( "HUDPaint", "MyHudPaint", function()
draw.RoundedBox( 0, 10, 30, 200, 4, Color( 100, 100, 200 ) ) // Back of Armour
draw.RoundedBox( 0, 10, 30, 100, 4, Color( 0, 0, 255 ) ) // Front of Armour
draw.RoundedBox( 0, 10, 10, 200, 20, Color( 255, 0, 0 ) ) //Back of health
draw.RoundedBox( 0, 10, 10, health*2, 20, Color( 0, 255, 0 ) ) // Front of Health
draw.SimpleTextOutlined( "Health", "DermaDefaultBold", 90, 14, color_white, 0, 0, 1, Color(0,0,255,255) )
end )[/CODE]
I've been trying to get my head around hooks and I think i'm still having issues fully understanding them and how the hook.Add Attributes work + making your own hooks..
[QUOTE=Kamber56;47069829]Okay that clears up alot, Thanks!
Just one more question. How would I go about calling the hook (I think that's the right terminology) every time the player takes damage, so it updates the draw.RoudedBox? Am i able to put the hook for drawing all the boxes inside a Think hook? Or does it not work like that?
Here's my current code:
I've been trying to get my head around hooks and I think i'm still having issues fully understanding them and how the hook.Add Attributes work + making your own hooks..[/QUOTE]
To get the updated Health after Damage you need to modify the local health with the new health. An Easy way would be to move the health variable into the paint hook, but so the function got called very often. Otherwise you could hook [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerHurt]GM/PlayerHurt[/url] with an check if victim == localplayer and then reset the health variable.
an good way to start with the hook system is to use the basic [url]http://wiki.garrysmod.com/page/Hook_Library_Usage[/url] guide or summon Acecool
Well here's the reality of just about every program that exists which isn't just a run-one-then-done.
A program is just a BIG infinite loop. This loop runs all the commands, reaches the end, and starts itself again until the user tells the loop to exit, shutting the program down.
Each run of this loop is a "Frame", and these frames are VERY fast. This is where the term Frames Per Second comes in.
During each frame in Garry's Mod, the game does a bunch of things, including checking a bunch of things to see if they have changed and calling "Hooks" if they have changed (or just calling hooks because they are called every frame).
Every frame, the "Think" hook and the "HUDPaint" hook are called on the client (among other hooks). This means that code ran in these hooks are basically ran in real time.
For instance, before "HUDPaint" is called, the HUD is cleared completely, at which point you can draw the new and refreshed hud. So if you had a bar which was very wide at full health, and the health of the player drops between two frames, the width of the bar will be thinner when the old one is cleared and a brand new one is drawn.
This can be confusing, and if you don't understand that's fine. Just know that "HUDPaint" is ran basically every millisecond. Therefore, if the player's health changes, in the next millisecond the HUD will update if you do your code like this:
[lua]
hook.Add( "HUDPaint", "MyHudPaint", function()
local health = LocalPlayer():Health() //Get our health in real time
local percent = health/100 //Get our RATIO of health, or what percent our health is at.
local maxWidth = 200 //The maximum width of our health bar.
local curWidth = maxWidth * percent //Multiply our max width by our ratio of health, so it gets smaller as our health gets lower.
//You can get the player's armor with LocalPlayer():Armor(), just like health.
//Do the same thing as above to use it.
draw.RoundedBox( 0, 10, 30, maxWidth, 4, Color( 100, 100, 200 ) ) // Back of Armour
draw.RoundedBox( 0, 10, 30, 100, 4, Color( 0, 0, 255 ) ) // Front of Armour
draw.RoundedBox( 0, 10, 10, maxWidth, 20, Color( 255, 0, 0 ) ) //Back of health
draw.RoundedBox( 0, 10, 10, curWidth, 20, Color( 0, 255, 0 ) ) // Front of Health
draw.SimpleTextOutlined( "Health", "DermaDefaultBold", 90, 14, color_white, 0, 0, 1, Color(0,0,255,255) )
end )
[/lua]
[editline]HOW DARE YOU[/editline]
[QUOTE=Tomelyr;47070101]or summon Acecool[/QUOTE]
THOU SHALL NOT INVOKE THAT UNHOLY NAME.
Are client-side props possible? Ones with physics interaction?
Sorry, you need to Log In to post a reply to this thread.