Thanks Donkie. Next issue.
The Touch function does not output anything, no matter what i touch on my prop.
[lua] local Tank = ents.Create("prop_physics")
Tank:SetPos(Vector(-3000,654,100))
Tank:SetAngles(Angle(0,90,0))
Tank:SetModel("models/props_wasteland/laundry_washer003.mdl")
Tank:Spawn()
Tank:SetSolid(SOLID_VPHYSICS)
Tank:GetPhysicsObject():EnableMotion(false)
Tank:SetNWBool("IsGasTank", true)
Tank.Touch = function(gas)
print("Here we are")
if ent:GetModel() == "models/props_junk/PropaneCanister001a.mdl" then
print("Here")
AddTankFill(gas)
end
end[/lua]
[QUOTE=Science;39329652]Thanks Donkie. Next issue.
The Touch function does not output anything, no matter what i touch on my prop.
[lua] local Tank = ents.Create("prop_physics")
Tank:SetPos(Vector(-3000,654,100))
Tank:SetAngles(Angle(0,90,0))
Tank:SetModel("models/props_wasteland/laundry_washer003.mdl")
Tank:Spawn()
Tank:SetSolid(SOLID_VPHYSICS)
Tank:GetPhysicsObject():EnableMotion(false)
Tank:SetNWBool("IsGasTank", true)
Tank.Touch = function(gas)
print("Here we are")
if ent:GetModel() == "models/props_junk/PropaneCanister001a.mdl" then
print("Here")
AddTankFill(gas)
end
end[/lua][/QUOTE]
You can't do like that, Touch only exists on custom SENTs (you could do some magic with ShouldCollide but thats unneccesary). You'd be better off using a custom sent instead!
Where should I start if I want to check if a player is touching a specific entity class?
Basically I added an entity in my map that covers an entire area and then I'd like to be able to give players weapons on the first time they're within it then once they leave it then remove them again.
Litterally don't know where to start with this one.
[QUOTE=Bilsta1000;39331122]Where should I start if I want to check if a player is touching a specific entity class?
Basically I added an entity in my map that covers an entire area and then I'd like to be able to give players weapons on the first time they're within it then once they leave it then remove them again.
Litterally don't know where to start with this one.[/QUOTE]
I don't really think you'd need to use an entity for that. You could just see if their position was within a certain y and x vector position of the map.
[CODE]hook.Add("PlayerDeath", "PS_PlayerDeath", function(victim, inflictor, attacker)
if attacker:IsPlayer() and attacker:IsValid() and not victim != attacker then
attacker:PS_GivePoints(10, "killed " .. victim:Nick())
end
end)[/CODE]
it's Not work...
What need ?
What's wrong?
Please...
Hello. I really need help on something real quick. If someone can help me with this , i'll be grateful.
There is this swep , fists , and i want to make that , on a random value , it will ragdoll the player it hitted for a random time (preferably 2-3) if only someone could PM or post there the LUA or teach me how to do it , man i would be happy o-<l:3 <3
[QUOTE=fairy;39331198]I don't really think you'd need to use an entity for that. You could just see if their position was within a certain y and x vector position of the map.[/QUOTE]
But which hook would I use. I'd use think but I don't want to continually give the players weapons/ammo.
[lua]local PlayersInBox = ents.FindInBox( Vector(9163.880859, -4275.777344, 4827.812012), Vector(16288.849609 -8663.266602 4747.246582) )
for k,v in pairs (PlayersInBox)
do
if v:IsPlayer()
then
v:give("weapon_crowbar")
end
end
[/lua]
that's all I have.
[QUOTE=Bilsta1000;39331743]But which hook would I use. I don't want to continually give the players weapons/ammo.
[lua]local PlayersInBox = ents.FindInBox( Vector(9163.880859, -4275.777344, 4827.812012), Vector(16288.849609 -8663.266602 4747.246582) )
for k,v in pairs (PlayersInBox)
do
if v:IsPlayer()
then
v:give("weapon_crowbar")
end
end
[/lua]
that's all I have.[/QUOTE]
Maybe set a networked int on them once you give it to them, and remove it when you take it away? So only give them a weapon if they don't have the NW int.
[editline]23rd January 2013[/editline]
[url]http://puu.sh/1RFmo[/url]
How can I change the color of the "16000" in the DNumSlider?
[QUOTE=Donkie;39329272]
[editline]23rd January 2013[/editline]
Looked through the sourcecode for creating the ball. Looks like there needs to be a bind to "CPropCombineBall.SetRadius", which doesn't exist in garrysmod. However, it looks like the physics model is made using a simple sphere [url]http://wiki.garrysmod.com/page/Classes/Entity/PhysicsInitSphere[/url]. If you do that, then use [url]http://wiki.garrysmod.com/page/Classes/Entity/SetModelScale[/url] to scale it, you can probably get something accurate.
However, things like explosion effects and such will not get changed, so it won't be perfect.[/QUOTE]
No. 1: They don't even bounce! 2: That doesn't scale them. I'm using the real source entity, by the way.
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=moonk0821;39331585][CODE]hook.Add("PlayerDeath", "PS_PlayerDeath", function(victim, inflictor, attacker)
if attacker:IsPlayer() and attacker:IsValid() and not victim != attacker then
attacker:PS_GivePoints(10, "killed " .. victim:Nick())
end
end)[/CODE]
it's Not work...
What need ?
What's wrong?
Please...[/QUOTE]
Would of helped if you actually gave us the error it returns, whoever made this clearly has no idea what he's doing.
[lua]
hook.Add("PlayerDeath", "PS_PlayerDeath", function(victim, inflictor, attacker)
if attacker:IsValid() and attacker:IsPlayer() and ( victim != attacker ) then
attacker:PS_GivePoints(10)
end
end)
[/lua]
Anyone know any good entity tutorial? (Specifically vehicles)
Anyone have working code for a bare-bones SNPC? I have to make a simple one for my gamemode that's able to toggle following you on use.
[CODE]function GM:OnRoundResult( result, resulttext )
for k,v in pairs(player.GetAll()) do
if v:Team() == TEAM_RUNNER and v:Alive() then
v:PS_GivePoints(20)
end
end
function GM:OnRoundResult( result, resulttext )
for k,v in pairs(player.GetAll()) do
if v:Team() == TEAM_DEATH and v:Alive() then
v:PS_GivePoints(10)
end
end[/CODE]
were do i put it in the deathrun or pointshop?
-sleep-
[QUOTE=Ozhar;39333566][CODE]function GM:OnRoundResult( result, resulttext )
for k,v in pairs(player.GetAll()) do
if v:Team() == TEAM_RUNNER and v:Alive() then
v:PS_GivePoints(20)
end
end
function GM:OnRoundResult( result, resulttext )
for k,v in pairs(player.GetAll()) do
if v:Team() == TEAM_DEATH and v:Alive() then
v:PS_GivePoints(10)
end
end[/CODE]
were do i put it in the deathrun or pointshop?[/QUOTE]
Urgh. Make a file in lua/autorun/server called deathrun_points.lua with this in it:
[lua]
hook.Add('OnRoundResult', 'DeathRun_PointShop', function(result, resulttext)
for k, ply in pairs(player.GetAll()) do
if not ply:Alive() then continue end
if ply:Team() == TEAM_DEATH then
ply:PS_GivePoints(10)
elseif ply:Team() == TEAM_RUNNER then
ply:PS_GivePoints(20)
end
end
end)
[/lua]
[QUOTE=brandonj4;39333911]It would be:
[lua]
TableOfNames = {
"John",
"Tom",
"David"
}
function CheckTblForName(ply)
if !ply or !IsValid(ply) then return end
local name = TableOfNames[ply:Nick()]
if name then
--do stuff
end
end
[/lua][/QUOTE]
Fixed
[lua]TableOfNames = {
["John"] = true,
["Tom"] = true,
["David"] = true
}
function CheckTblForName(ply)
if !IsValid(ply) then return end
if TableOfNames[ply:Nick()] then
--do stuff
end
end[/lua]
[QUOTE=_Undefined;39334026]Urgh. Make a file in lua/autorun/server called deathrun_points.lua with this in it:
[lua]
hook.Add('OnRoundResult', 'DeathRun_PointShop', function(result, resulttext)
for k, ply in pairs(player.GetAll()) do
if not ply:Alive() then continue end
if ply:Team() == TEAM_DEATH then
ply:PS_GivePoints(10)
elseif ply:Team() == TEAM_RUNNER then
ply:PS_GivePoints(20)
end
end
end)
[/lua][/QUOTE]
it didn't work ? in less it doesn't show the points when you get it
[QUOTE=Ozhar;39334589]it didn't work ? in less it doesn't show the points when you get it[/QUOTE]
Even though you really don't deserve this help after [URL="http://www.facepunch.com/showthread.php?t=1228438&p=39333470&viewfull=1#post39333470"]this[/URL], using Player.PS_GivePoints will not notify the player that they received them, do that yourself using ChatPrint or something.
[editline]24th January 2013[/editline]
and he's banned, okay.
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.
end
hook.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 =P
concommand.Add("****hud_toggle","Hide Combine Hud",hud.hideme) -- Create the console command that hides this HUD. Format: "CommandName", "Description", function to use.
-- Maybe a 5-year-old can't understand that, but why are they trying to program, And how are they doing it???
-- A 9-year-old might not understand that, either, and a new programmer might have some questions about it, but since I had a traumatic brain injury, I doubt it.[/lua]
Of course, my ending comments make no sense since it doesn't work...
Shouldn't that be lua_openscript, not lua_run?
Oh, and also, how do I make a combine ball that is owned by the player, and actually bounces???
In regards to a question previously answered, I am now receiving the following error;
attempt to index global 'surface' <a nil value>
It's in cl_init.lua, outside of all functions. Why is it returnign such an error?
[lua]surface.CreateFont( "cam_door_test_font", { font = "Arial", size = 105, weight = 800, antialias = true})
[/lua]
It means you are including it in a file that is being included on the server.
I thought cl_init.lua would be the practical place to put it, where should I instead?
No, I mean to make sure you don't have a serverside file with:
include( "cl_init.lua" )
Ahhh, cheers Kogitsune.
Where do you find the smartsnap lua stuff in the gmod gcf?
I want to make some changes myself personally and I can't cause I can't find where all the code for it is located.
thanks
put?
[editline]24th January 2013[/editline]
not work
[QUOTE=343N;39339332]Where do you find the smartsnap lua stuff in the gmod gcf?
I want to make some changes myself personally and I can't cause I can't find where all the code for it is located.
thanks[/QUOTE]
What do you mean by smartsnap? Do you mean the thing that makes grid lines appear on props/entities? If so that's an addon, it doesn't ship with GMod.
Sorry, you need to Log In to post a reply to this thread.