How do I build an addon that is a derma with a client and server file, I am looking for the file structure,
somehow my lua doesnt seem to work at all.
[IMG]https://i.gyazo.com/a406a3505de376b6a6d09f0486000384.png[/IMG]
[QUOTE=MGFear;51920860]How do I build an addon that is a derma with a client and server file, I am looking for the file structure,
somehow my lua doesnt seem to work at all.
[IMG]https://i.gyazo.com/a406a3505de376b6a6d09f0486000384.png[/IMG][/QUOTE]
Normally on Garrysmods addons, lua files dont load by default, only the lua files located at the "autorun" folder are loaded automatically. If you wanted to keep that current structure you have, you could make a file inside the "autorun" folder and include those shop files you have, but you would have to include them depending if the lua file is running on the server instance or on the client instance, AND you should also [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/AddCSLuaFile]AddCSLuaFile[/url] them, so the files get sent to the clients and they can include them.
What is a cleaner / optimized way to write key-value tables, like the one below?
The key must be a string.
[code]
local check_options = {}
check_options["foo"] = {}
check_options["bar"] = {}
check_options["foo"]["bar"] = "Hello"
check_options["foo"]["foo"] = "World"
check_options["bar"]["tender"] = "Goodbye"
[/code]
The idea is a table, who's key's contain value -table-, which contains strings.
So, if I was to do something like room_contents["bedroom"]["wood"] then it would return "table", since it's a wooden item in the bedroom (just an example to explain what I'm talking about)
The above code looks very sloppy and I'd like it to be cleaner / more optimized, but tables are my weak spot.
Anyone know of some optimized, well written, and properly predicted weapon base I could use? Nothing too fancy but even if it is I could strip it down myself.
[QUOTE=YourStalker;51922445]Anyone know of some optimized, well written, and properly predicted weapon base I could use? Nothing too fancy but even if it is I could strip it down myself.[/QUOTE]
TFA's and mine are the only two I've seen out there that have even attempted proper prediction support -- it's no easy feat to implement, meaning you're not going to find anything small or simple.
[QUOTE=code_gs;51922671]TFA's and mine are the only two I've seen out there that have even attempted proper prediction support -- it's no easy feat to implement, meaning you're not going to find anything small or simple.[/QUOTE]
How completed is yours? What is left for you to do with it.
[QUOTE=rtm516;51920754]Will do when I get home, I'll post screenshots of what I have and annotate with what I want[/QUOTE]
[t]https://share.rtm516.co.uk/2017-03-06_20-52-41.jpg[/t]
So like on this move the avatar to the otherside of the curve
[LUA]
local iconPos = {}
iconPos.x = math.Clamp(pos.x, 100, ScrW()-100)
iconPos.y = math.Clamp(pos.y, 100, ScrH()-100)
[/LUA]
I want the clamps to create curved corners
[QUOTE=Rory;51921953]What is a cleaner / optimized way to write key-value tables, like the one below?
The key must be a string.
[code]
local check_options = {}
check_options["foo"] = {}
check_options["bar"] = {}
check_options["foo"]["bar"] = "Hello"
check_options["foo"]["foo"] = "World"
check_options["bar"]["tender"] = "Goodbye"
[/code]
The idea is a table, who's key's contain value -table-, which contains strings.
So, if I was to do something like room_contents["bedroom"]["wood"] then it would return "table", since it's a wooden item in the bedroom (just an example to explain what I'm talking about)
The above code looks very sloppy and I'd like it to be cleaner / more optimized, but tables are my weak spot.[/QUOTE]
Your code is fine. Don't get hung up on minor things like that. :)
[editline]7th March 2017[/editline]
[QUOTE=rtm516;51922692][t]https://share.rtm516.co.uk/2017-03-06_20-52-41.jpg[/t]
So like on this move the avatar to the otherside of the curve
[LUA]
local iconPos = {}
iconPos.x = math.Clamp(pos.x, 100, ScrW()-100)
iconPos.y = math.Clamp(pos.y, 100, ScrH()-100)
[/LUA]
I want the clamps to create curved corners[/QUOTE]
Ah, I understand now. I'm going to type some code but I'm on mobile and not testing anything so if it doesn't work you'll have to fix it yourself:
[lua]local distfromedge = 100 -- this is the 100 you already have in your code
local cornerradius = 200
if iconPos.x < distfromedge+cornerradius
and iconPos.y < distfromedge+cornerradius
then
local dx = distfromedge+cornerradius-iconPos.x
local dy = distfromedge+cornerradius-iconPos.y
local dist = math.sqrt(dx*dx + dy*dy)
if dist > cornerradius then
dx = dx * (cornerradius/dist)
dy = dy * (cornerradius/dist)
iconPos.x = distfromedge+cornerradius - dx
iconPos.y = distfromedge+cornerradius - dy
end
end[/lua]
This should have the top left corner. I'll leave the other 3 corners to you ;)
[QUOTE=Rory;51921953]What is a cleaner / optimized way to write key-value tables, like the one below?
The key must be a string.
[code]
local check_options = {}
check_options["foo"] = {}
check_options["bar"] = {}
check_options["foo"]["bar"] = "Hello"
check_options["foo"]["foo"] = "World"
check_options["bar"]["tender"] = "Goodbye"
[/code]
The idea is a table, who's key's contain value -table-, which contains strings.
So, if I was to do something like room_contents["bedroom"]["wood"] then it would return "table", since it's a wooden item in the bedroom (just an example to explain what I'm talking about)
The above code looks very sloppy and I'd like it to be cleaner / more optimized, but tables are my weak spot.[/QUOTE]
[lua]local check_options = {
foo = {
bar = "Hello",
foo = "World",
},
bar = {
tender = "Goodbye",
},
}[/lua]
[QUOTE=Zelerity;51918124]Heya!
I consider my 'issue' minor and therefore Im chosing to post it here. Guessing this questions might have been asked before, maybe once, a thousand times. You are allowed to consider me stupid or ignorant, but here goes;
[B]I would like to [U]disable the billboard somehow[/U] since my server will function better with previous /advert [Advert] or not containing the 'advert' feature at all.[/B]
Already tried;
[URL="http://forum.darkrp.com/threads/classic-advert.8022/"]http://forum.darkrp.com/threads/classic-advert.8022/[/URL] - Fillipuster's Classic Advert
[I]It does not really disable the billboard feature, only adds an command for the previous /advert[/I]
[I]Disclaimer: I do not dislike the advert billboard in any way, it's just that it doesn't fit in how I want my server to work out.[/I][/QUOTE]
[url]http://forum.darkrp.com/threads/revert-advert.8056/[/url] does that.
[QUOTE=NeatNit;51922932]Ah, I understand now. I'm going to type some code but I'm on mobile and not testing anything so if it doesn't work you'll have to fix it yourself:
[lua]*snip*[/lua]
This should have the top left corner. I'll leave the other 3 corners to you ;)[/QUOTE]
[url]https://hastebin.com/mobiyocumu.lua[/url]
This is what I have in the end, it works is it the most efficient way? It feels like the icon gets stuck slightly in the corners, but that might just be me.
The icon will have a tendency to be in the corners because it's more likely to be there in a diagonal from you instead of straight up/down/left/right from you. There are ways around this but they require fancier math that, personally, I wouldn't bother with.
Don't worry about efficiency. If you disable this code (leave only math.clamp), does your FPS get noticably better? if not then it's perfectly fine.
Happy to have helped!
Who can help me with render targets? I can't understand how to use this.
[QUOTE=LisyFOX;51930903]Who can help me with render targets? I can't understand how to use this.[/QUOTE]
Just ask your question. Asking to ask just wastes time. ;)
How to disable render.Clear? If I don't use his, then my blend has black color on edges.
If I don't use render.Clear:
[img]http://i.imgur.com/hBtepeE.jpg[/img]
If I use render.Clear:
[img]http://i.imgur.com/ajv9E3f.png[/img]
code?
[QUOTE=NeatNit;51931417]code?[/QUOTE]
[CODE]hook.Add( "HUDPaint", "minimap", function()
local oldW, oldH = ScrW(), ScrH()
local oldRT = render.GetRenderTarget()
render.SetRenderTarget( minimapRT )
render.SetViewPort( 50, 791, 350, 233 )
--render.Clear( 255, 255, 255, 0, true, true )
local map = Material( "lfservers/map.png", "noclamp smooth" )
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial( map )
angs = LocalPlayer():GetAngles()
rot = angs.z
surface.DrawTexturedRectRotatedPoint( -1000, -1000, 8000, 8000, rot, 1000, 1000 )
-- srcBlend, destBlend, srcBlendAlpha, destBlendAlpha
render.OverrideBlendFunc( true, BLEND_ONE_MINUS_SRC_COLOR, BLEND_SRC_ALPHA, BLEND_ONE, BLEND_ONE )
local mask_map = Material( "lfservers/radar_mask.png", "noclamp smooth" )
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial( mask_map )
surface.DrawTexturedRect( 0, 0, oldW, oldH )
render.SetRenderTarget( oldRT )
render.OverrideBlendFunc( false )
render.SetViewPort( 0, 0, oldW, oldH )
end)[/CODE] Just need remove black color on borders. I'm tried edit blend args, but this args must be right.
-snip- Had to create a SENT.
[QUOTE=LisyFOX;51931434][CODE]hook.Add( "HUDPaint", "minimap", function()
local oldW, oldH = ScrW(), ScrH()
local oldRT = render.GetRenderTarget()
render.SetRenderTarget( minimapRT )
render.SetViewPort( 50, 791, 350, 233 )
--render.Clear( 255, 255, 255, 0, true, true )
local map = Material( "lfservers/map.png", "noclamp smooth" )
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial( map )
angs = LocalPlayer():GetAngles()
rot = angs.z
surface.DrawTexturedRectRotatedPoint( -1000, -1000, 8000, 8000, rot, 1000, 1000 )
-- srcBlend, destBlend, srcBlendAlpha, destBlendAlpha
render.OverrideBlendFunc( true, BLEND_ONE_MINUS_SRC_COLOR, BLEND_SRC_ALPHA, BLEND_ONE, BLEND_ONE )
local mask_map = Material( "lfservers/radar_mask.png", "noclamp smooth" )
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial( mask_map )
surface.DrawTexturedRect( 0, 0, oldW, oldH )
render.SetRenderTarget( oldRT )
render.OverrideBlendFunc( false )
render.SetViewPort( 0, 0, oldW, oldH )
end)[/CODE] Just need remove black color on borders. I'm tried edit blend args, but this args must be right.[/QUOTE]
Why are you using an undocumented function that I'm not even sure is released yet?
[editline]9th March 2017[/editline]
But uh, sorry, I guess handling transparency correctly it a bit out of my depth. When do you draw the minimap to the screen though?
[editline]9th March 2017[/editline]
By the way, best to have the Material lines outside of the hook:
[lua]local map = Material( "lfservers/map.png", "noclamp smooth" )
local mask_map = Material( "lfservers/radar_mask.png", "noclamp smooth" )
hook.Add( "HUDPaint", "minimap", function()
-- use map and mask_map
end)[/lua]
Problem...
[code]
local npc = ents.Create("npc_combine_s")
npc:SetPos(self:GetPos() + Vector(math.random(0, self.radius), math.random(0, self.radius), 0))
npc:SetAngles(Angle(0,math.random(1,360),0))
npc:SetKeyValue("spawnflags","8192")
npc:SetKeyValue("spawnflags","512")
npc:Spawn()
npc:Give("weapon_ar2")
[/code]
Main Issue:
Combine will not attack. He just aims, and butts you if you get too close. He will not chase, move, or fight, but rather just stare at you.
*Fixed, see reply on next page*
Secondary Issue:
The spawnflags I set were fade corpse and don't drop weapon. When the combine dies, he drops his weapon and doesn't fade. The problem above is the biggest issue though.
*Not fixed*
Changing "npc_combine_s" to any melee NPC (headcrab, antlion, etc) works just fine. It just happens to entities that use guns.
I've tried to search this issue but it seems I'm the only one having it.
Don't know about the main issue, but you should be setting the spawn flags after spawn and only setting them once. You can do tostring (bit.bor (8192,512)) to get the proper compilative flag.
[QUOTE=code_gs;51933940]Don't know about the main issue, but you should be setting the spawn flags after spawn and only setting them once. You can do tostring (bit.bor (8192,512)) to get the proper compilative flag.[/QUOTE]
That didn't seem to make any difference. Here's the code:
[code]npc:SetKeyValue("spawnflags",tostring (bit.bor (8192,512)))[/code]
[QUOTE=Rory;51933799]
Main Issue:
Combine will not attack. He just aims, and butts you if you get too close. He will not chase, move, or fight, but rather just stare at you.
[/QUOTE]
Fixed.
[code]npc:SetKeyValue("additionalequipment", "weapon_ar2")[/code]
So I am probably coming back to gmod coding for a bit and want to rewrite my rp gamemode from scratch and I have some questions about networked variables:
-I have read some time ago that using :SetNWInt for storing things like money or other kind of numbers is not a good practice because since other players can fetch these numbers. Should I worry about this?
-What would be other ways to store data safely? Would using the net library better than using say :SetPData?
Thank you
[QUOTE=bilbasio;51935460]
-I have read some time ago that using :SetNWInt for storing things like money or other kind of numbers is not a good practice because since other players can fetch these numbers. Should I worry about this?[/quote]
Yes can they get those values, though unless you've done something wrong else where, they can't modify them.
[quote]
-What would be other ways to store data safely? Would using the net library better than using say :SetPData?
[/QUOTE]
The net library is for sending data between the client and server, it doesn't store anything.
As for what you should use to store data, it really depends on what you're storing and what you're doing with it. For example if you want cross server support, you'll probably want to use MySQL, if not then you can still use MySQL, though your options have extended to flat files or the built in SQLite library. PData uses the SQLite library, though it uses it just to store strings relating to a player, so its efficient use cases are limited.
[QUOTE=bigdogmat;51935486]Yes can they get those values, though unless you've done something wrong else where, they can't modify them.
The net library is for sending data between the client and server, it doesn't store anything.
As for what you should use to store data, it really depends on what you're storing and what you're doing with it. For example if you want cross server support, you'll probably want to use MySQL, if not then you can still use MySQL, though your options have extended to flat files or the built in SQLite library. PData uses the SQLite library, though it uses it just to store strings relating to a player, so its efficient use cases are limited.[/QUOTE]
After reading my post my questions don't make much sense. A better question would be : Should I use pdata to store data for use while the player is connected and then send said data with the Net library for use on the clientside? Or should I not worry about it and just use NWVars?
[QUOTE=bilbasio;51935519]After reading my post my questions don't make much sense. A better question would be : Should I use pdata to store data for use while the player is connected and then send said data with the Net library for use on the clientside? Or should I not worry about it and just use NWVars?[/QUOTE]
You shouldn't be using pdata to store temporary values while the player is connected, that's what tables are for. As for networking the data, it depends on the data. If it's a single integer such as money, it's easier and cleaner to just network it using NWVars, however if it's a players inventory then of course you'll probably want to use the net library.
I'm trying to make a round type within TTT that will make it like The Hidden the script runs serverside and prints the HIDDEN Loaded line. Nothing else happens. Am I overlooking something simple?
[CODE]local randomply = table.Random(player.GetAll())
PrintMessage( HUD_PRINTTALK, "HIDDEN LOADED")
PrintMessage( HUD_PRINTTALK, randomply)
RunConsoleCommand ("ulx csay"..randomply.."Has been chosen as the hidden he will be cloaked shortly PREPARE....")
RunConsoleCommand ("ulx cloak"..randomply.."105")
RunConsoleCommand (randomply.."Now wears a cloak as dense as the night")
RunConsoleCommand ("ulx strip"..randomply)
RunConsoleCommand ("ulx give"..randomply.."weapon_zm_improvised")
RunConsoleCommand ("ulx hp"..randomply.."250")[/CODE]
Thanks
[QUOTE=Scu11y;51937431]I'm trying to make a round type within TTT that will make it like The Hidden the script runs serverside and prints the HIDDEN Loaded line. Nothing else happens. Am I overlooking something simple?
[CODE]local randomply = table.Random(player.GetAll())
PrintMessage( HUD_PRINTTALK, "HIDDEN LOADED")
PrintMessage( HUD_PRINTTALK, randomply)
RunConsoleCommand ("ulx csay"..randomply.."Has been chosen as the hidden he will be cloaked shortly PREPARE....")
RunConsoleCommand ("ulx cloak"..randomply.."105")
RunConsoleCommand (randomply.."Now wears a cloak as dense as the night")
RunConsoleCommand ("ulx strip"..randomply)
RunConsoleCommand ("ulx give"..randomply.."weapon_zm_improvised")
RunConsoleCommand ("ulx hp"..randomply.."250")[/CODE]
Thanks[/QUOTE]
What exactly is the error? Are you trying to print it in every player's chat in the server? or just the server console?
[QUOTE=bilbasio;51937487]What exactly is the error? Are you trying to print it in every player's chat in the server? or just the server console?[/QUOTE]
There arent any errors being output. The printmessage lines were just to determine if the script was actually executing. The problem is that none of the runconsolecommands are executing.
You have to pass extra arguments as extra arguments to the function, e.g.
[code]
RunConsoleCommand("ulx", "cloak", randomply, "105")
[/code]
Also, `randomply` when converted to a string won't work, considering it's ulx you'll probably have to do something like
[code]
RunConsoleCommand("ulx", "cloak", '$' .. randomply:UserID(), "105")
[/code]
Though it'd be preferred that you just call the function to do this on a player.
Edit: Also also, just use
[code]
local tab = player.GetAll()
local randomPly = tab[math.random(#tab)]
[/code]
Considering that table is always sequential
Edit edit: Seems the code block doesn't want to show the $ in my second example, but it's
'$' .. randomply:UserID()
Sorry, you need to Log In to post a reply to this thread.