[QUOTE=Chessnut;34863758]Yes, it's also how most STools handle their properties.[/QUOTE]
I tried that and the only way it updates is if I reload the script.
Is the position of the HUD being updated based on the convar?
[QUOTE=Chessnut;34864440]Is the position of the HUD being updated based on the convar?[/QUOTE]
[lua]
CreateClientConVar("xpos", "0", true, false)
CreateClientConVar("ypos", "0", true, false)
local xpos = GetConVarNumber("xpos")
concommand.Add("menu", function()
local DermaPanel = vgui.Create( "DFrame" )
DermaPanel:SetPos( 50,50 )
DermaPanel:SetSize( 200, 250 )
DermaPanel:SetTitle( "Testing Derma Stuff" )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:ShowCloseButton( true )
DermaPanel:MakePopup()
local NumSlider = vgui.Create( "DNumSlider", DermaPanel )
NumSlider:SetPos( 25,50 )
NumSlider:SetWide( 150 )
NumSlider:SetText( "Max Props" )
NumSlider:SetMin( 0 ) -- Minimum number of the slider
NumSlider:SetMax( ScrH() ) -- Maximum number of the slider
NumSlider:SetDecimals( 0 ) -- Sets a decimal. Zero means it's a whole number
NumSlider:SetConVar( "xpos" ) -- Set the convar
end)
function HUDPAINT()
if POINTSHOP.Config.DisplayPoints then
hook.Add("HUDPaint", "PointShop_HUDPaint", function()
local text = "Points: " .. LocalPlayer():PS_GetPoints()
if LocalPlayer():Alive() then
draw.WordBox( 4, xpos,100, text, "ScoreboardText", Color(0,0,0,b), Color(255,255,255,a))
draw.WordBox( 4, 10,10, "Shop[F4]", "ScoreboardText", Color(0,0,0,shopalpha), Color(255,255,255,shoptxtalpha))
end
points = LocalPlayer():PS_GetPoints()
end)
end
end
[/lua]
that sets it to xpos when it's created, use GetConVarNumber( "xpos" ) in the draw code
How am I able to tell whether or not the player is looking at a door ?
[QUOTE=joyenusi;34865425]How am I able to tell whether or not the player is looking at a door ?[/QUOTE]
[lua]
function _R.Player:LookingAtDoor()
local door=self:GetEyeTraceNoCursor().Entity
return door:GetClass()=="prop_door_rotating" -- Something like this
end
[/lua]
Get the door entity and check what class it is.
[code]lua_run print( string.find(player.GetByID(1):GetEyeTrace().Entity:GetClass(), "door") )[/code]
[QUOTE=Banana Lord.;34864980]that sets it to xpos when it's created, use GetConVarNumber( "xpos" ) in the draw code[/QUOTE]
local xpos = GetConVarNumber("xpos")
isnt that the same thing?
How do I spawn an entity in a function, say I want to have an NPC drop an entity item when killed ?
Use GM:OnNPCKilled() and ents.Create() for spawning the weapon.
[QUOTE=brandonj4;34867683]local xpos = GetConVarNumber("xpos")
isnt that the same thing?[/QUOTE]
You're only setting xpos when the script first runs. You have to set it every time your HUD is drawn.
[QUOTE=Nerdeboy;34869739]You're only setting xpos when the script first runs. You have to set it every time your HUD is drawn.[/QUOTE]
Care to explain how?
[lua]
CreateClientConVar("xpos", "0", true, false)
CreateClientConVar("ypos", "0", true, false)
concommand.Add("menu", function()
local DermaPanel = vgui.Create( "DFrame" )
DermaPanel:SetPos( 50,50 )
DermaPanel:SetSize( 200, 250 )
DermaPanel:SetTitle( "Testing Derma Stuff" )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:ShowCloseButton( true )
DermaPanel:MakePopup()
local NumSlider = vgui.Create( "DNumSlider", DermaPanel )
NumSlider:SetPos( 25,50 )
NumSlider:SetWide( 150 )
NumSlider:SetText( "Max Props" )
NumSlider:SetMin( 0 ) -- Minimum number of the slider
NumSlider:SetMax( ScrH() ) -- Maximum number of the slider
NumSlider:SetDecimals( 0 ) -- Sets a decimal. Zero means it's a whole number
NumSlider:SetConVar( "xpos" ) -- Set the convar
end)
function HUDPAINT()
if POINTSHOP.Config.DisplayPoints then
hook.Add("HUDPaint", "PointShop_HUDPaint", function()
local text = "Points: " .. LocalPlayer():PS_GetPoints()
local xpos = GetConVarNumber("xpos") -- by moving it here
if LocalPlayer():Alive() then
draw.WordBox( 4, xpos,100, text, "ScoreboardText", Color(0,0,0,b), Color(255,255,255,a))
draw.WordBox( 4, 10,10, "Shop[F4]", "ScoreboardText", Color(0,0,0,shopalpha), Color(255,255,255,shoptxtalpha))
end
points = LocalPlayer():PS_GetPoints()
end)
end
end
[/lua]
Since you're opening the script, it will seem like the HUD is working. It's only being called one.
You have to hook the function to the HUDPaint hook.
Is there a list of methods available for various things?
Like a list of things you can do to a player in your code, and variables of a player you can change?
Also, when i'm writing scripts for darkrp, how do i know where to put them? Like, if i wanted to make a script execute when a player types a command, where would i put that code?
[QUOTE=ralle105;34861507][lua]
function _R.Entity:IsOnFire()
for k,v in pairs(ents.FindByClass("entityflame")) do
if (v:GetParent() == self) then
return true
end
end
return false
end
[/lua][/QUOTE]
[lua]
function _R.Entity:IsOnFire()
for _, v in pairs(ents.FindByClass("entityflame")) do
return (v:GetParent() == self);
end
end
[/lua]
How can you fix the problem where a DModelPanel's entity's bones are contorted oddly? Like, where the head is looking way behind the body for no reason whatsoever?
[editline]25th February 2012[/editline]
[QUOTE=JustSoFaded;34872946][lua]
function _R.Entity:IsOnFire()
for _, v in pairs(ents.FindByClass("entityflame")) do
return (v:GetParent() == self);
end
end
[/lua][/QUOTE]
That would only return correctly for the first entityflame
-snip-
[QUOTE=Chessnut;34863389]Use Entity.FindInSphere and EmitSound. You should probably use a timer or the Think hook along with setting some sort of next play time kind of variable for the player to know when to emit the sound.[/QUOTE]Thanks, gave me a nice head start. Should I use tables for the different sounds?
[QUOTE=RCRad;34872497]Is there a list of methods available for various things?
Like a list of things you can do to a player in your code, and variables of a player you can change?
Also, when i'm writing scripts for darkrp, how do i know where to put them? Like, if i wanted to make a script execute when a player types a command, where would i put that code?[/QUOTE]
The GMod wiki is the place you're looking for, it's currently being moved so it's empty, however a mirror of the old one can be found here:
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index4875.html?title=Main_Page[/url]
As for DarkRP, every Lua file in DarkRP/gamemode/modules is automatically loaded with DarkRP, just put your code in a file in there and it should work. DarkRP isn't well documented, so I'll save you some time and tell you that AddChatCommand( "/command", func ) is the syntax for adding a chat command. func is the function to call when the player types the command - two arguments are passed to it, the player who typed it and anything else they typed after it.
-snip I did this a retarded way, DMultiChoice needs to return something we can set values on-
-snippity snip snip. Just realized there is a subforum for questions. Sorry.-
Is it possible to directly control NPC's with LUA? By that I mean the target of the NPC's, if that target doesn't exist (The target will be a breakable wall) then go for the nearest player. Ill be spawning NPC's a far bit back from the building the player is in and Ill need to spawn the NPC's (about 7 different spawner's to go to different breakable walls all around the building for them to then break it and enter through that hole).
This sound ultimately confusing but basically controlling NPC's as a whole.
Basically, how do I control a npc_maker with LUA?
[QUOTE=Mrkrabz;34881555]Is it possible to directly control NPC's with LUA? By that I mean the target of the NPC's, if that target doesn't exist (The target will be a breakable wall) then go for the nearest player. Ill be spawning NPC's a far bit back from the building the player is in and Ill need to spawn the NPC's (about 7 different spawner's to go to different breakable walls all around the building for them to then break it and enter through that hole).
This sound ultimately confusing but basically controlling NPC's as a whole.
Basically, how do I control a npc_maker with LUA?[/QUOTE]
I'm not sure what you mean by control, you want to make them spawn somewhere if I understand correctly?
[QUOTE=_NewBee;34882754]I'm not sure what you mean by control, you want to make them spawn somewhere if I understand correctly?[/QUOTE]
[img]http://img7.imagebanana.com/img/m24kq9x3/Untitled.png[/img]
Where the red dots are is where a npc_maker will be. I want to be able to control these with LUA to spawn say 5 each. The NPC's will then head towards the green line which will be a wooden barricade as such, once that's destroyed they look for the nearest player. Basically waves of NPC's will be coming while the player can repair barricades etc.
If you name the controllers in hammer you will be able to find and control them them with lua.
You could make some spawnpoints in Hammer that are not used by players to spawn (or create an entire new point entity for this), get the positions of them with lua and let some npcs spawn there.
[QUOTE=Drakehawke;34876520]The GMod wiki is the place you're looking for, it's currently being moved so it's empty, however a mirror of the old one can be found here:
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index4875.html?title=Main_Page[/url]
As for DarkRP, every Lua file in DarkRP/gamemode/modules is automatically loaded with DarkRP, just put your code in a file in there and it should work. DarkRP isn't well documented, so I'll save you some time and tell you that AddChatCommand( "/command", func ) is the syntax for adding a chat command. func is the function to call when the player types the command - two arguments are passed to it, the player who typed it and anything else they typed after it.[/QUOTE]
So would this work if i just dropped it in modules? (Its making a chat command for the mayor job that makes the player they are looking at into a secret service agent.)
[CODE]local function AppSS( ply, args )
if ply:Team() == TEAM_MAYOR then
local LookingAt = ply:GetEyeTrace().Entity
if not ValidEntity(LookingAt) or not LookingAt:IsPlayer() or LookingAt:GetPos():Distance(ply:GetPos()) > 100 then
Notify(ply, 1, 4, string.format(LANGUAGE.must_be_looking_at, "player"))
return ""
end
LookingAt:ChangeTeam( TEAM_MG, true )
ply:PrintMessage(HUD_PRINTTALK, "You have made "..LookingAt.." a secret service agent!"
end
return ""
end
AddChatCommand( "/makess", AppSS )[/CODE]
What is the mean of self ? What is the purpose of self ?
[QUOTE=LuaGuy;34895090]What is the mean of self ? What is the purpose of self ?[/QUOTE]
Read [url=http://www.lua.org/pil/16.html]this[/url]
Sorry, you need to Log In to post a reply to this thread.