[QUOTE=Ari_Draconia;48130592]Can you give some more info? like how you called the GetColor() function.[/QUOTE]
I am calling them on the player hud to color the team and such.
Code:
[lua]
local FTeam = {}
local STeam = {}
if LocalPlayer():Team() == 1 then
FTeam[1] = team.GetPlayers( 1 )
STeam[1] = team.GetPlayers( 2 )
FTeam.color = team.GetColor(1)
STeam.color = team.GetColor(2)
else
FTeam[1] = team.GetPlayers( 2 )
STeam[1] = team.GetPlayers( 1 )
FTeam.color = team.GetColor(2)
STeam.color = team.GetColor(1)
end
//First team
for i=1,4 do
draw.RoundedBox( 3, ScrW()*(.288 + (i *.037)), 40, 25, 20, Color(0,0,0,80) )
if (FTeam[1][i] != nil) and (FTeam[1][i]:Alive() )then
draw.RoundedBox( 3, ScrW()*(.29 + (i *.037)) , 20, 20, 40, FTeam.color )
else
draw.RoundedBox( 3, ScrW()*(.29 + (i *.037)) , 20, 20, 40, Color(80,80,80,255) )
draw.DrawText( "X", "SmallText", ScrW()*(.29 + (i *.037)), 20, Color( 255, 255, 255, 255 ), TEXT_ALIGN_LEFT )
end
end
[/lua]
Where would I run a command on a player who joins my sandbox server? We have a ulx command called !build which basically disables pvp dmg. How would I have this enabled when they join? Thanks
[QUOTE=bran92don;48131576]I am calling them on the player hud to color the team and such.
Code:
[lua]
local FTeam = {}
local STeam = {}
if LocalPlayer():Team() == 1 then
FTeam[1] = team.GetPlayers( 1 )
STeam[1] = team.GetPlayers( 2 )
FTeam.color = team.GetColor(1)
STeam.color = team.GetColor(2)
else
FTeam[1] = team.GetPlayers( 2 )
STeam[1] = team.GetPlayers( 1 )
FTeam.color = team.GetColor(2)
STeam.color = team.GetColor(1)
end
//First team
for i=1,4 do
draw.RoundedBox( 3, ScrW()*(.288 + (i *.037)), 40, 25, 20, Color(0,0,0,80) )
if (FTeam[1][i] != nil) and (FTeam[1][i]:Alive() )then
draw.RoundedBox( 3, ScrW()*(.29 + (i *.037)) , 20, 20, 40, FTeam.color )
else
draw.RoundedBox( 3, ScrW()*(.29 + (i *.037)) , 20, 20, 40, Color(80,80,80,255) )
draw.DrawText( "X", "SmallText", ScrW()*(.29 + (i *.037)), 20, Color( 255, 255, 255, 255 ), TEXT_ALIGN_LEFT )
end
end
[/lua][/QUOTE]
I set up teams like this. (might not be the best but it worked better for me.)
[CODE]
local teams = {}
teams[0] = {name = "Team0", color = Vector( .1 .0, .0 )
teams[1] = {name = "Team1", color = Vector( .0, .1, .0 )
teams[2] = {name = "Team2", color = Vector( .0, .0, .1 )
[/CODE]
Can I use 3D2D in a SWEP:DrawHUD() function? I don't want to use any 3D2D HUD library's I just want to know if I can or not. If I can't, how would I use render targets to place drawn shapes onto a certain part of an entity? Basically I want to attach a drawn circle object to a certain part of my weapon's viewmodel. I figured 3D2D would work for this.
How can I write tables to a text file and read them, never tackled saving before and been having troubles with file.Write and is it better to use JSON conversion?
[QUOTE=_Entity;48135695]How can I write tables to a text file and read them, never tackled saving before and been having troubles with file.Write and is it better to use JSON conversion?[/QUOTE]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/util/TableToJSON]util.TableToJSON[/url] takes a table and returns a string.
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/file/Write]file.Write[/url] takes a string and writes it to the .txt file.
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/file/Read]file.Read[/url] takes the name and path of the .txt file and returns the JSON string of the table.
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/util/JSONToTable]util.JSONToTable[/url] converts the JSON string to a Lua table and returns it.
Be aware that you cannot write some types, such as functions, entities, etc. You said you're having trouble with file.Write, so I'll provide you with an example that writes "hello world" to garrysmod/data.
[lua]file.Write("example.txt", "hello world")[/lua]
You can only write files to the garrysmod/data folder, but file.Read isn't restricted to the data folder.
[QUOTE=man with hat;48135758][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/util/TableToJSON]util.TableToJSON[/url] takes a table and returns a string.
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/file/Write]file.Write[/url] takes a string and writes it to the .txt file.
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/file/Read]file.Read[/url] takes the name and path of the .txt file and returns the JSON string of the table.
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/util/JSONToTable]util.JSONToTable[/url] converts the JSON string to a Lua table and returns it.
Be aware that you cannot write some types, such as functions, entities, etc. You said you're having trouble with file.Write, so I'll provide you with an example that writes "hello world" to garrysmod/data.
[lua]file.Write("example.txt", "hello world")[/lua]
You can only write files to the garrysmod/data folder, but file.Read isn't restricted to the data folder.[/QUOTE]
Thank you, so also if I may ask: if I am saving player data every few seconds file.Write will erase the previous data saved in that file... Will file.Append update already existing data + additions or just add onto the text file for example:
[code]
tbl = { name = "John", items = {"hat", "shoes"}
[/code]
[B]Save[/B]
[B]Then the table is updated: [/B]
[code]
tbl = { name = "John", items = {"hat", "shoes", "case"}
[/code]
[B]Save[/B]
Will the text file containing the table be updated or will a new table be added on with file.Append?
UPDATE: Okay, so I'm trying to create a HUD that uses 3D2D elements, and in the wiki's words: [quote=The Gmod Wiki;43689236]Sets up a new 3D2D rendering context. If you are trying to use this in a GM:HUDPaint or similar hook for huds, you'll need to use cam.Start3D or cam.Start first.[/quote]
So does this mean I would need to do something like:
[lua]hook.Add( "HUDPaint", "example", function()
cam.Start3D()
cam.Start3D2D()
--Code
cam.End3D2D()
cam.End3D()
end)[/lua]
? I don't know what they mean but I assume it's like this... Is this what they mean?
[QUOTE=_Entity;48135871]Thank you, so also if I may ask: if I am saving player data every few seconds file.Write will erase the previous data saved in that file... Will file.Append update already existing data + additions or just add onto the text file for example:
[code]
tbl = { name = "John", items = {"hat", "shoes"}
[/code]
[B]Save[/B]
[B]Then the table is updated: [/B]
[code]
tbl = { name = "John", items = {"hat", "shoes", "case"}
[/code]
[B]Save[/B]
Will the text file containing the table be updated or will a new table be added on with file.Append?[/QUOTE]
A new table will be added if you use file.Append. file.Write removes everything in the file before writing it, so file.Write is what you're looking for. I don't recommend writing files every few seconds, though. You should save at higher intervals and when the player disconnects. You may even want to look into using SQL.
[url]http://wiki.garrysmod.com/page/Category:sql[/url]
<snip>
Anyone who is familiar with Lexi's sourcebans module, can you help me out here?
I've been using her sourcebans module since day 1 and everything works but I can't seem to figure out how to setup another script alongside it using the functions it offers.
So the thing is, I want to run a script that bans family shared accounts of players that are already banned on my servers.
The script runs off of ULib's ban database, and I need to change it to query the sourcebans database to check if the player has any relation to a banned account.
Here is the code:
[CODE]
local APIKey = "api key here" -- See http://steamcommunity.com/dev/apikey
local function HandleSharedPlayer(ply, lenderSteamID)
print(string.format("FamilySharing: %s | %s has been lent Garry's Mod by %s",
ply:Nick(),
ply:SteamID(),
lenderSteamID
))
if not (ULib and ULib.bans) then return end
if ULib.bans[lenderSteamID] then
RunConsoleCommand("ulx sbanid "..ply:SteamID().."0 The account that lent you Garry's Mod is banned on this server")
end
end
local function CheckFamilySharing(ply)
http.Fetch(
string.format("http://api.steampowered.com/IPlayerService/IsPlayingSharedGame/v0001/?key=%s&format=json&steamid=%s&appid_playing=4000",
APIKey,
ply:SteamID64()
),
function(body)
body = util.JSONToTable(body)
if not body or not body.response or not body.response.lender_steamid then
error(string.format("FamilySharing: Invalid Steam API response for %s | %s\n", ply:Nick(), ply:SteamID()))
end
local lender = body.response.lender_steamid
if lender ~= "0" then
HandleSharedPlayer(ply, util.SteamIDFrom64(lender))
end
end,
function(code)
error(string.format("FamilySharing: Failed API call for %s | %s (Error: %s)\n", ply:Nick(), ply:SteamID(), code))
end
)
end
hook.Add("PlayerAuthed", "CheckFamilySharing", CheckFamilySharing)
[/CODE]
And here is a paste of lexi's module:
[url]http://pastebin.com/CzCE1qQC[/url]
There are about 6 different bancheckers in that module, and I just can't figure out which one to use, or how to implement it.
Any ideas?
-snip-
Sorry for the late reply to your answer, thank you but I was wondering if there was a way I can
recreate the targeting system in a game like World of Warcraft. Like where you press TAB and
it targets a player in front of you, then when you press tab again it basically cycles through the players in front of you.
[CODE]me.SelectedTarget = targets[i+1][/CODE]
I had the above originally because I thought it would basically cycle through to the next player/npc entity
in front of me, but it only does that when I put something like:
[CODE]me.SelectedTarget = targets[i/#targets+1][/CODE]
And it doesn't always work. I think because i has to be a whole number, and that only occurs when there are
5 targets or more within the table. Because at 5 it goes to 2. I'm explaining this very badly I apologize.
Is it possible to hide gunsounds on other people's clients without changing Player:EmitSound to something else (using net library to target specific people)?
This is sort of dumb since I asked this in a thread already, but as a last resort, I'm just gonna ask it here:
Okay. So, I'm trying to create a clientside model and parent it to my weapon's viewmodel. This is my current code:
[code]local pso = ClientsideModel( "models/cw2/attachments/pso.mdl", RENDERGROUP_OPAQUE )
pso:FollowBone( player.GetByID(1):GetViewModel(), player.GetByID(1):GetViewModel():LookupBone( "v_weapon.m4_Parent" ) )
pso:SetPos( player.GetByID(1):GetPos() + Vector( 0.516, 3.866, -2.719))[/code]
But, this doesn't work. Thing is, with a SWEP model placer and bone merger tool I have, the model is positioned fine and where I want it to be on the viewmodel. But, for some reason, when creating the model [I]here[/I], the model isn't placed correctly and isn't anywhere to be seen. Help! Note that I'm not using the SWEP construction kit because I only want to create the models when an NW Bool is set.
[QUOTE=MegaTronJohn;48141653]This is sort of dumb since I asked this in a thread already, but as a last resort, I'm just gonna ask it here:
Okay. So, I'm trying to create a clientside model and parent it to my weapon's viewmodel. This is my current code:
[code]local pso = ClientsideModel( "models/cw2/attachments/pso.mdl", RENDERGROUP_OPAQUE )
pso:FollowBone( player.GetByID(1):GetViewModel(), player.GetByID(1):GetViewModel():LookupBone( "v_weapon.m4_Parent" ) )
pso:SetPos( player.GetByID(1):GetPos() + Vector( 0.516, 3.866, -2.719))[/code]
But, this doesn't work. Thing is, with a SWEP model placer and bone merger tool I have, the model is positioned fine and where I want it to be on the viewmodel. But, for some reason, when creating the model [I]here[/I], the model isn't placed correctly and isn't anywhere to be seen. Help! Note that I'm not using the SWEP construction kit because I only want to create the models when an NW Bool is set.[/QUOTE]
You are doing it wrong. Dont use FollowBone or SetPos. Use SetParent and SetLocalPos and SetLocalAngles. Then do NoDraw(true) and do self.myawesomemodel:DrawModel() in the post view model draw SWEP hook. That should do it.
Workshop is being a pain and refuses to put out any updates I do on an addon. I'm using GMOSH 2.2.1. Any ideas on what might be keeping it from updating? (Note: GUI claims that the addon was updated successfully.)
(Wasn't sure if I should put this here or in it's own thread.)
Edit: I've also tried straight command line and Garrys Mod Publishing Utility (I stopped using that though because IIRC it's outdated/doesn't work anymore).
how does one resize the default primary view model entity, in the shared Lua script of a weapon?
[QUOTE=cynaraos;48142944]how does one resize the default primary view model entity, in the shared Lua script of a weapon?[/QUOTE]
If you are trying to shrink the view model to hide it, you're better off setting its material. If you're just trying to resize it to make it bigger or still have it visible, then maybe play around with the PostDrawViewModel function?
Okay, I'm [b]STILL[/b] having trouble creating a clientside model for my viewmodel, please help...
[lua]
function SWEP:Initialize()
self:CreateAimPoint()
self:SetHoldType( "smg" )
end
function SWEP:ViewModelDrawn()
self.aimpoint:DrawModel()
self.aimpoint:SetLocalPos( Vector(-0.527, -4.816, -4.615) )
self.aimpoint:SetLocalAngles( Angle(0, 1.5, 0) )
end
if CLIENT then
function SWEP:CreateAimPoint()
self.aimpoint = ClientsideModel( "models/wystan/attachments/aimpoint.mdl", RENDER_GROUP_VIEW_MODEL_OPAQUE )
self.aimpoint:SetNoDraw( true )
self.aimpoint:SetParent( self )
end
end
[/lua]
If the model should exist but I may have set its' position off so I can't see it, please let me know. But for now I don't know what's wrong...
SRCDS is crashing on me and I'm not quite sure what is could be causing the issue, if anyone has any clue, it would be greatly appreciated.
"The thread tried to read from or write to a virtual address for which it does not have the appropriate access."
Would there be any way to trace the stack to see what's making the call to an invalid memory address?
Hey, how do I redraw a single VGUI element in a derma menu on command? I have a DModelPanel that I want to automatically change in the same function as when a variable is changed.
Also, is there a way to restrict spawning weapons from certain categories?
How would I go about capturing a key press from an F-key on an entity in order to open a derma menu?
Eg: User presses F2 while looking at a printer and it opens a derma panel.
[QUOTE=JRODISME;48147714]How would I go about capturing a key press from an F-key on an entity in order to open a derma menu?
Eg: User presses F2 while looking at a printer and it opens a derma panel.[/QUOTE]Use [url]http://wiki.garrysmod.com/page/ENTITY/AcceptInput[/url].
Im not sure if it works with key enums but if it does then use
KEY_F2.
[QUOTE=JRODISME;48147714]How would I go about capturing a key press from an F-key on an entity in order to open a derma menu?
Eg: User presses F2 while looking at a printer and it opens a derma panel.[/QUOTE]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/input/IsKeyDown]input.IsKeyDown[/url] in a think hook, and do an eye trace to get the entity.
[QUOTE=JRODISME;48147714]How would I go about capturing a key press from an F-key on an entity in order to open a derma menu?
Eg: User presses F2 while looking at a printer and it opens a derma panel.[/QUOTE]
Just fire a trace when the hook ShowTeam is called (F2). If it hits a printer, send the client a net message that will open the derma menu.
I'm trying to make the RGB(Alpha) fade away real smooth and fast but nothing is working :(
How could I make Alpha go down from 255 to 0 smoothly so it dosent disappear instantly?
[QUOTE=Invule;48148549]I'm trying to make the RGB(Alpha) fade away real smooth and fast but nothing is working :(
How could I make Alpha go down from 255 to 0 smoothly so it dosent disappear instantly?[/QUOTE]
math.approach? Or maybe some calculations with CurTime?
Hey, got a question, if I wanted to make a weapon that uses ironsights only if secondary attack is held down, would I hook.Add GM:PlayerBindPress? Or because that isn't predicted is it a bad idea to do it that way?
[QUOTE=MegaTronJohn;48150441]Hey, got a question, if I wanted to make a weapon that uses ironsights only if secondary attack is held down, would I hook.Add GM:PlayerBindPress? Or because that isn't predicted is it a bad idea to do it that way?[/QUOTE]
Since you are doing a SWEP, you are better off by simply using SWEP:SecondaryAttack
[QUOTE=Robotboy655;48150478]Since you are doing a SWEP, you are better off by simply using SWEP:SecondaryAttack[/QUOTE]
Well yeah, but I only want the ironsights to be activated if Secondary attack is [i]held down[/i]. When you hold it down you ironsight, but when you release the key you stop ironsighting. I don't know how I'd do that with SecondaryAttack.
Sorry, you need to Log In to post a reply to this thread.