You can find the Target Name, I'm sure, but how do you do that?
As for other entities, most don't even have a target name flag.
[editline]20th January 2013[/editline]
For all ents in map, Keyvalue "Targetname" == "Blah" then there you go. Just, how do you write that??
[editline]20th January 2013[/editline]
Now can someone PLEASE help me with my problem? D:
And stop rating me dumb, even if you are all ass holes from the internet... I got a brain injury, and I am trying to return to how I was before the accident that caused it.
[QUOTE=luavirusfree;39295292]You can find the Target Name, I'm sure, but how do you do that?
As for other entities, most don't even have a target name flag.
[editline]20th January 2013[/editline]
For all ents in map, Keyvalue "Targetname" == "Blah" then there you go. Just, how do you write that??
[editline]20th January 2013[/editline]
Now can someone PLEASE help me with my problem? D:
And stop rating me dumb, even if you are all ass holes from the internet... I got a brain injury, and I am trying to return to how I was before the accident that caused it.[/QUOTE]
Can you be a little more specific? Are you talking about GetClass()?
Is it possible to add a sound each step you take?
Like how the Combine, CCA walk it sounds like their equipment is jiggling around, anyway to do this?
Hello. I am having trouble with a Lua error, and I know nothing when it comes to Lua.
I am trying to add Bows (TES:III Bow Sweps V2.0) to my server, and I get this error in the console:
[QUOTE][TES:III Bow Sweps Version 2.0] lua/weapons/weapon_mor_base_bow/shared.lua:72: invalid escape sequence near '"sound'
1. unknown - lua/weapons/weapon_mor_base_bow/shared.lua:0
[/QUOTE]
This is the weapon's [B]shared.lua[/B]:
[CODE]if( SERVER ) then
AddCSLuaFile( "shared.lua" )
end
if( CLIENT ) then
SWEP.PrintName = "Morrowind Bow"
SWEP.Slot = 0
SWEP.SlotPos = 1
SWEP.DrawAmmo = true
SWEP.DrawCrosshair = false
function SWEP:DrawHUD()
local scrx = ScrW()/2
local scry = ScrH()/2
if self.Crosshair == true then
surface.SetDrawColor(255, 255, 255, 255)
surface.DrawRect(scrx - 5 - 15, scry - 1, 15, 2)
surface.DrawRect(scrx + 5, scry - 1, 15, 2)
surface.DrawRect(scrx - 1, scry + 5, 2, 15)
surface.DrawRect(scrx -1 , scry - 5 - 15, 2, 15)
end
local scrx = ScrW()
local scry = ScrH()
surface.SetDrawColor(255, 255, 255, 100)
surface.DrawRect(scrx - 175, scry - 105, 108, 16)
if self:GetDTFloat(0) != 0 then
local ratio = math.Clamp((self.MaxHoldTime + CurTime() - self:GetDTFloat(0))/(self.MaxHoldTime * .5), .5, 1)
ratio = 2 * (ratio - .5)
surface.SetDrawColor(255, 0, 0, 180)
surface.DrawRect(scrx - 171, scry - 103, 100 * ratio, 12)
end
end
end
SWEP.Category = "Morrowind Bows"
SWEP.Author = ""
SWEP.Instructions = ""
SWEP.Contact = ""
SWEP.Purpose = ""
SWEP.ViewModelFOV = 72
SWEP.ViewModelFlip = true
SWEP.Spawnable = false
SWEP.AdminSpawnable = false
SWEP.ViewModel = "models/morrowind/steel/shortbow/v_steel_shortbow.mdl"
SWEP.WorldModel = "models/morrowind/steel/shortbow/w_steel_shortbow.mdl"
SWEP.Primary.Damage = 50
SWEP.Primary.Delay = 2
SWEP.Primary.ClipSize = -1 // Size of a clip
SWEP.Primary.DefaultClip = 9 // Default number of bullets in a clip
SWEP.Primary.Velocity = 1800 // Arrow speed.
SWEP.Primary.Automatic = false // Automatic/Semi Auto
SWEP.Primary.Ammo = "XBowBolt"
SWEP.Crosshair = true
SWEP.Secondary.ClipSize = -1 // Size of a clip
SWEP.Secondary.DefaultClip = -1 // Default number of bullets in a clip
SWEP.Secondary.Automatic = false // Automatic/Semi Auto
SWEP.Secondary.Ammo = "none"
SWEP.QuickFireRatio = .6 // Changes quickfire damage/velocity, a ratio of normal damage/velocity.
SWEP.MaxHoldTime = 5 // Must let go after this time. Determines damage/velocity based on time held.
//Do not touch.
//SWEP.FiredArrow = false
SWEP.DelayTime = 0
function SWEP:Precache()
util.PrecacheSound("sound\weapons\bow\OUT.wav")
util.PrecacheSound("sound\weapons\bow\PULL.wav")
util.PrecacheSound("sound\weapons\bow\SHOOT.wav")
end
function SWEP:Initialize()
self:SetWeaponHoldType("pistol")
end
function SWEP:Equip()
self:Deploy()
end
function SWEP:SetupDataTables()
self:DTVar("Bool", 0, "FiredArrow")
self:DTVar("Float", 0, "HoldTimer")
end
function SWEP:Deploy()
self:EmitSound("weapons/bow/OUT.wav")
self.Weapon:SetNextPrimaryFire(CurTime() + 1)
self.Weapon:SetNextSecondaryFire(CurTime() + 1)
self.DelayTime = CurTime() + 1
// local anim = self:LookupSequence("draw")
self.Weapon:SendWeaponAnim(ACT_VM_DRAW)
self:SetDTBool(0, false)
self:SetDTFloat(0, 0)
return true
end
function SWEP:Holster()
if self:GetNextPrimaryFire() > CurTime() then return end
return true
end
/*---------------------------------------------------------
Name: SWEP:PrimaryAttack()
Desc: +attack1 has been pressed.
---------------------------------------------------------*/
function SWEP:PrimaryAttack()
if self:Ammo1() < 1 then return end
if self:GetDTFloat(0) != 0 then return end
if self.Owner:KeyDown(IN_SPEED) then return end
local anim = self.Owner:GetViewModel():LookupSequence("reload"..math.random(1,3))
self.Weapon:SendWeaponAnim(ACT_VM_RELOAD)
self.Weapon:EmitSound("weapons/bow/PULL.wav")
self.DelayTime = CurTime() + .5
self:SetDTFloat(0, CurTime() + self.MaxHoldTime)
self:SetNextPrimaryFire(self:GetDTFloat(0))
self:SetNextSecondaryFire(self:GetDTFloat(0))
end
/*---------------------------------------------------------
Name: SWEP:Think()
Desc: Called every frame.
---------------------------------------------------------*/
function SWEP:Think()
if !self.Owner:IsValid() or !self.Owner:IsPlayer() then return end
if self.Owner:KeyDown(IN_SPEED) then
self:SetWeaponHoldType("normal")
else
self:SetWeaponHoldType(self.HoldType)
end
if self:GetDTFloat(0) != 0 and self.DelayTime < CurTime() and self:GetDTBool(0) == false then
if !self.Owner:KeyDown(IN_ATTACK) or self:GetDTFloat(0) < CurTime() then
if SERVER then
self:ShootArrow()
end
self:SetDTBool(0, true)
self:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
self:SetNextSecondaryFire(CurTime() + self.Primary.Delay)
end
end
end
/*---------------------------------------------------------
Name: SWEP:ShootArrow()
Desc: Hot Potato.
---------------------------------------------------------*/
function SWEP:ShootArrow()
if self.DelayTime > CurTime() then return end
local anim = self.Owner:GetViewModel():LookupSequence("shoot"..math.random(4,6))
self.Owner:GetViewModel():SetSequence(anim)
timer.Simple(self.Owner:GetViewModel():SequenceDuration(), function()
if !self.Owner then return end
local anim = self.Owner:GetViewModel():LookupSequence("idle")
self.Owner:GetViewModel():ResetSequence(anim)
// self.Owner:GetViewModel():SetCycle(10)
end)
timer.Simple(.2, function()
if !self.Owner then return end
local ratio = math.Clamp((self.MaxHoldTime + CurTime() - self:GetDTFloat(0))/(self.MaxHoldTime * .5), .5, 1)
self.Weapon:EmitSound("weapons/bow/SHOOT.wav")
local arrow = ents.Create("ent_mor_arrow")
if SERVER then
arrow:SetAngles(self.Owner:EyeAngles())
local pos = self.Owner:GetShootPos()
pos = pos + self.Owner:GetUp() * -3
arrow:SetPos(pos)
arrow:SetOwner(self.Owner)
arrow.Weapon = self // Used to set the arrow's killicon.
arrow.Damage = self.Primary.Damage * ratio
arrow:SetAngles(self.Owner:EyeAngles() + Angle(0, 180, 0))
local trail = util.SpriteTrail(arrow, 0, Color(255, 255, 255, 100), false, 5, 5, 4, 1/(15+1)*0.5, "trails/plasma.vmt")
arrow.Trail = trail
arrow:Spawn()
arrow:Activate()
end
// self.Weapon:SendWeaponAnim(ACT_VM_IDLE)
self.Owner:SetAnimation(PLAYER_ATTACK1)
self:SetDTFloat(0, 0)
self:SetDTBool(0, false)
if SERVER then
local phys = arrow:GetPhysicsObject()
phys:SetVelocity(self.Owner:GetAimVector() * self.Primary.Velocity * ratio)
end
self:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
self:SetNextSecondaryFire(CurTime() + self.Primary.Delay)
self:TakePrimaryAmmo(1)
end)
end
/*---------------------------------------------------------
Name: SWEP:SecondaryAttack()
Desc: +attack1 has been pressed.
---------------------------------------------------------*/
function SWEP:SecondaryAttack()
if !self.Zoomed then -- The player is not zoomed in.
self.Zoomed = true -- Now he is
if SERVER then
self.Owner:SetFOV( 35, 0.3 ) -- SetFOV is serverside only
end
else
self.Zoomed = fal
[QUOTE=Morpheel;39296749]function SWEP:Precache()
util.PrecacheSound("sound\weapons\bow\OUT.wav")
util.PrecacheSound("sound\weapons\bow\PULL.wav")
util.PrecacheSound("sound\weapons\bow\SHOOT.wav")
end[/CODE][/QUOTE]
Use / instead of \
If I were to put this:
[CODE]for k,ply in pairs(player.GetAll()) do
ply:SetMuted( true );
end[/CODE]
Simple script inside lua/autorun would it mute all mic's for all players?
[QUOTE=pilot;39297288]If I were to put this:
[CODE]for k,ply in pairs(player.GetAll()) do
ply:SetMuted( true );
end[/CODE]
Simple script inside lua/autorun would it mute all mic's for all players?[/QUOTE]
No, anyone that joins after that player will not be muted. Use [url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index1bc4.html]this[/url]
[QUOTE=Hyper Iguana;39297427]No, anyone that joins after that player will not be muted. Use [url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index1bc4.html]this[/url][/QUOTE]
Doesn't that just make admins not hear other players and vise versa? What about this:
[CODE]function FirstSpawn( ply )
ply:SetMuted( true )
end
hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", FirstSpawn )[/CODE]
Thanks for the help! All the weapons load correctly now. Now there is another problem:
[QUOTE][TES:III Bow Sweps Version 2.0] gamemodes/base/entities/weapons/weapon_base/sh_anim.lua:30: bad argument #1 to 'lower' (string expected, got nil)
1. lower - [C]:-1
2. SetWeaponHoldType - gamemodes/base/entities/weapons/weapon_base/sh_anim.lua:30
3. unknown - lua/weapons/weapon_mor_base_bow/shared.lua:136
[/QUOTE]
On a SRCDS server that a develop for, spawning any NPC with ent_create crashes the server. No errors are output or logged, and I cannot reproduce the issue on my local Listen server.
[QUOTE=YoshieMaster;39297673]On a SRCDS server that a develop for, spawning any NPC with ent_create crashes the server. No errors are output or logged, and I cannot reproduce the issue on my local Listen server.[/QUOTE]
Spawn it in the InitPostEntity hook.
@ OldFusion i already checked the wiki, that only returns what the engine can use, not what a player had mounted.
i need something exactly like engine.getGames() but for players
[QUOTE=Pandaman09;39298339]@ OldFusion i already checked the wiki, that only returns what the engine can use, not what a player had mounted.
i need something exactly like engine.getGames() but for players[/QUOTE]
You could run the function clientside and send results to the server
[lua]for k, v in pairs( engine.GetGames() ) do
if v.title == "Portal" then
RunConsoleCommand( "gamemounted", v.title, v.mounted and 1 or 0 )
end
end[/lua]
and on server
[lua]concommand.Add( "gamemounted", function( Player, Command, Args )
if not Args[1] or not Args[2] then return end
if Args[2] == "1" then
Msg( "Player: " .. Player:Nick() .. " has " .. Args[1] .. " mounted.\n" )
else
Msg( "Player: " .. Player:Nick() .. " does not have " .. Args[1] .. " mounted.\n" )
end
end )[/lua]
This is how the table should look for engine.GetGames()
[lua]] lua_run_cl PrintTable( engine.GetGames() )
1:
depot = 220
installed = true
title = Half-Life 2
folder = hl2
mounted = true
owned = true
2:
depot = 240
installed = true
title = Counter-Strike
folder = cstrike
mounted = true
owned = true
3:
depot = 300
installed = true
title = Day of Defeat
folder = dod
mounted = true
owned = true
4:
depot = 440
installed = true
title = Team Fortress 2
folder = tf
mounted = true
owned = true
5:
depot = 420
installed = true
title = Half-Life 2: Episode 2
folder = ep2
mounted = true
owned = true
6:
depot = 380
installed = true
title = Half-Life 2: Episode 1
folder = episodic
mounted = true
owned = true
7:
depot = 320
installed = true
title = Half-Life 2: Deathmatch
folder = hl2mp
mounted = true
owned = true
8:
depot = 340
installed = true
title = Half-Life 2: Lost Coast
folder = lostcoast
mounted = false
owned = true
9:
depot = 280
installed = false
title = Half-Life: Source
folder = hl1
mounted = false
owned = false
10:
depot = 360
installed = false
title = Half-life Deathmatch: Source
folder = hl1mp
mounted = false
owned = false
11:
depot = 22208
installed = false
title = Zeno Clash
folder = zeno_clash
mounted = false
owned = false
12:
depot = 400
installed = true
title = Portal
folder = portal
mounted = true
owned = true
13:
depot = 17530
installed = true
title = D.I.P.R.I.P.
folder = diprip
mounted = false
owned = true
14:
depot = 17500
installed = true
title = Zombie Panic! Source
folder = zps
mounted = false
owned = true
15:
depot = 17570
installed = true
title = Pirates, Vikings and Knights II
folder = pvkii
mounted = false
owned = true
16:
depot = 17580
installed = true
title = Dystopia
folder = dystopia
mounted = false
owned = true
17:
depot = 17700
installed = false
title = Insurgency
folder = insurgency
mounted = false
owned = true
18:
depot = 17510
installed = true
title = Age of Chivalry
folder = ageofchivalry
mounted = false
owned = true
19:
depot = 500
installed = true
title = Left 4 Dead
folder = left4dead
mounted = true
owned = true
[/lua]
Still need help with this
[QUOTE=Robertbrownlo;39286125][B]PEOPLE, I NEED HELP![/B]
How can I allow certain steam ids in a txt file be able to have access to donator privelages, without being in the donator group? (Because some admins on the server i work on are donators and some are not)
I made a txt file in the data folder, so in game I could add steam ids to it using a derma menu and the file.Write function. I just need to know how a Lua file can read that txt file (using file.read) and then give those steam ids permissions.
Perhaps I could make a ulx donator group which nobody is in, and then let the steam ids inherit from that (but let them still be in anotherulx group in game)
Another method could be this method:
[lua] local a = CTeam.admin
if a > 0 and not ply:IsAdmin()
or a > 1 and not ply:IsSuperAdmin()
or a > 3 and not ply:SteamID() == file.read("file.txt")
then
Notify(ply, 1, 4, string.format(LANGUAGE.need_admin, CTeam.name))
return ""
end
[/lua]
Would this even work?[/QUOTE]
How can i make TTT custom weapons in GMOD 13? Badkings guide dosn't work anymore.
Could somebody explain to me how to set up a 3D2D panel that will accept mouse / clicking input? So far i've only been able to do simple surface.Draw stuff. Do i just make normal derma stuff?
Getting weird error with this keyboard derma menu I'm trying to make. Basically it only includes keys 1-9 and all the the alphabet. For some reason, it looks like [URL="http://i50.tinypic.com/2yjqx07.jpg"]this[/URL]
[lua]
local function showKeyboardMenu()
local ply = LocalPlayer()
local btnHover
local btnActive
local btnWidth = 50
local btnHeight = 50
local btnBarSize = 10
local cellspacing = 5
DKey = {}
local counterX = 1
local w,h = ( btnWidth * 10 ) + ( cellspacing * 11 ), ( btnHeight * 4 ) + ( cellspacing * 5 )
local x,y = (ScrW() * .5) - (w * .5), (ScrH() * .5) - (h * .5)
local Frame = vgui.Create("DFrame")
Frame:SetSize(w,h)
Frame:SetPos(x,y)
Frame:SetDraggable( true )
Frame:ShowCloseButton( true )
Frame:SetTitle( "" )
Frame:SetVisible( true )
/*Frame.Paint = function()
surface.SetDrawColor( 100,100,100,100 )
surface.DrawRect(x,y,w,h)
end*/
local function makeKeyBtn( i, btnY )
local x, y = ( btnWidth * counterX ) + ( cellspacing * i ), ( btnHeight * btnY ) + ( cellspacing * btnY )
local txt = string.sub( keyStrings[i], 5 ) -- just KEY_"X"
counterX = counterX + 1
local background
DKey[i] = vgui.Create("DButton")
DKey[i]:SetSize(btnWidth, btnHeight)
DKey[i]:SetPos( x, y )
DKey[i]:SetParent(Frame)
DKey[i]:SetText( "" )
DKey[i].OnCursorEntered = function() btnHover = i end
DKey[i].OnCursorExited = function() btnHover = false end
DKey[i].DoClick = function( btn )
btnActive = DKey[i]
ply:ChatPrint(i)
end
DKey[i].Paint = function(w,h)
if btnActive == DKey[i] then
background = Color( 121, 121, 121, 255 )
else
background = Color( 29, 31, 33, 255 )
end
surface.SetDrawColor( background )
surface.DrawRect( x,y, btnWidth, btnHeight )
if btnHover == DKey[i] && btnActive != DKey[i] then
surface.SetDrawColor( 217, 217, 217, 255 )
surface.DrawRect( x, y, btnWidth, btnBarSize )
end
surface.SetFont( "keyboardBtnFont" )
local sfc_w, sfc_h = surface.GetTextSize( txt )
local txt_x, txt_y = ( x * .5 ) - ( sfc_w * .5 ), ( y * .5 ) - ( sfc_h * .5 )
surface.SetTextPos( txt_x, txt_y )
surface.SetTextColor( 255, 255, 255, 255 )
surface.DrawText( txt )
end
end
-- KEYBOARD ROWS --
for i=1, 36 do
if i == 1 then counterX = 1 end
makeKeyBtn( i, 1 )
end
for i=11, 20 do
if i == 11 then counterX = 1 end
makeKeyBtn( i, 2 )
end
for i=21, 29 do
if 1 == 21 then counterX = 1 end
makeKeyBtn( i, 3 )
end
for i=30, 36 do
if i == 30 then counterX = 1 end
makeKeyBtn( i, 4 )
end
end
concommand.Add("gmwc_keyboardmenu", showKeyboardMenu)
[/lua]
It makes several buttons, but only number one is visible (which is the first index of the table).
How would i go about using lua to do the equivilent of picking up a prop_physics, and also, what would be the best way to block the use command and general use of players using anything.
(This is for the DarkRP gamemode)
In init.lua, I have:
[lua]GM.Hits = {}
include("server/main.lua")[/lua]
In main.lua, I refer to GM.Hits and it thinks that GM is a nil value/table.
Why is it doing that if it's all put into one script?
[QUOTE=Science;39301916]what would be the best way to block the use command and general use of players using anything.[/QUOTE]
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index5f71.html[/url]
[QUOTE=fairy;39302493](This is for the DarkRP gamemode)
In init.lua, I have:
[lua]GM.Hits = {}
include("server/main.lua")[/lua]
In main.lua, I refer to GM.Hits and it thinks that GM is a nil value/table.
Why is it doing that if it's all put into one script?[/QUOTE]
I THINK (could be wrong) but the GM variable is only available once at runtime. After that you should use the GAMEMODE variable instead (which does the same?)
[QUOTE=Ruzza;39298701]You could run the function clientside and send results to the server
[lua]for k, v in pairs( engine.GetGames() ) do
if v.title == "Portal" then
RunConsoleCommand( "gamemounted", v.title, v.mounted and 1 or 0 )
end
end[/lua]
and on server
[lua]concommand.Add( "gamemounted", function( Player, Command, Args )
if not Args[1] or not Args[2] then return end
if Args[2] == "1" then
Msg( "Player: " .. Player:Nick() .. " has " .. Args[1] .. " mounted.\n" )
else
Msg( "Player: " .. Player:Nick() .. " does not have " .. Args[1] .. " mounted.\n" )
end
end )[/lua]
This is how the table should look for engine.GetGames()
-snip-[/QUOTE]
Thanks for clarifying that :)
Hello,
I need help with a jailbreak script I found laying around on my PC somewhere.
Anyway, the script below should normally restart the round, but it doesn't.
It plays the 5 countdown seconds sounds etc. But the timer itself fails.
Also I believe line 16 triggers an error (self (nil value))
[LUA]
--[[
File: "sv_rounds.lua".
Mod: "JailMod".
]]--
ROUND_NO = 0
ROUND_START = 1
ROUND_PLAY = 2
ROUND_END = 3
GM.Round = ROUND_NO
-- Restart the round when it's over.
function GM:NewRound()
self.Round = ROUND_START
timer.Simple(25, function() self.Round = ROUND_PLAY end)
-- Cleanup
for _, ent in pairs( ents.FindByClass( "weapon_*" ) ) do
if ent:IsValid() then
ent:Remove()
end
end
for _, ent in pairs( ents.FindByClass( "prop_ragdoll" ) ) do
if ent:IsValid() then
ent:Remove()
end
end
-- Reload
if self.MapFile then
for _, entt in pairs(self.MapFile.weapons) do
entt = string.Explode(" ", entt)
local ent = ents.Create(entt[1])
ent:SetPos(Vector(entt[2], entt[3], entt[4]))
ent:Spawn()
ent:Activate()
end
end
for _,pl in pairs(player.GetAll()) do
if pl:Team() == TEAM_GUARD_DEAD then
pl:SetTeam(TEAM_GUARD)
elseif pl:Team() == TEAM_PRISONER_DEAD then
pl:SetTeam(TEAM_PRISONER)
end
end
-- AutoSwap
local G = team.NumPlayers(TEAM_GUARD)
local P = team.NumPlayers(TEAM_PRISONER)
if P > 2*G then
for k,v in pairs(self.PSwap) do
if v and v:IsValid() then
v:SetTeam(TEAM_GUARD)
P = P - 1
G = G + 1
local rp = RecipientFilter()
rp:AddPlayer(v)
umsg.Start("WishSwap", rp)
umsg.Bool(false)
umsg.End()
end
table.remove(self.PSwap, k)
if not ( P > 2*G ) then break end
end
while P > 2*G+1 do
local pl = team.GetPlayers(TEAM_PRISONER)[math.random(1, P)]
pl:SetTeam(TEAM_GUARD)
P = P - 1
G = G + 1
end
elseif P < 2*G then
for k,v in pairs(self.GSwap) do
if v and v:IsValid() then
v:SetTeam(TEAM_PRISONER)
P = P + 1
G = G - 1
local rp = RecipientFilter()
rp:AddPlayer(v)
umsg.Start("WishSwap", rp)
umsg.Bool(false)
umsg.End()
end
table.remove(self.GSwap, k)
if not ( P < 2*G ) then break end
end
while P+1 < 2*G do
local pl = team.GetPlayers(TEAM_GUARD)[math.random(1, G)]
pl:SetTeam(TEAM_PRISONER)
P = P + 1
G = G - 1
end
end
for k,plP in pairs(self.PSwap) do
if #(self.GSwap) == 0 then break end
if plP and plP:IsValid() then
local plG = nil
for k,pl in pairs(self.GSwap) do
if pl and pl:IsValid() then
plG = pl
break
else
table.remove(self.GSwap, k)
end
end
if plG then
plP:SetTeam(TEAM_GUARD)
plG:SetTeam(TEAM_PRISONER)
local rp = RecipientFilter()
rp:AddPlayer(plP)
rp:AddPlayer(plG)
umsg.Start("WishSwap", rp)
umsg.Bool(false)
umsg.End()
end
else
table.remove(self.PSwap, k)
end
end
-- Respawn
for _, pl in pairs( player.GetAll() ) do
if pl:IsValid() and pl:Team() != TEAM_SPECTATOR then
pl:Spawn()
end
end
end
function OpenDoors( pl )
if self.MapFile then
for entname, trigger in pairs(self.MapFile.auto) do
for _,ent in pairs(ents.FindByName(entname)) do
ent:Fire(trigger)
end
end
end
end
function GM:EndRound(win)
self.Round = ROUND_END
GMName = "JailBreak"
Event = false
TTT = false
EventWaitTime = 0
game.CleanUpMap()
if not win then
for _, pl in pairs(player.GetAll()) do
pl:ChatPrint( "Guards - "..team.GetScore(TEAM_GUARD).." | Prisoners - "..team.GetScore(TEAM_PRISONER) )
pl:ChatPrint( "Next round in 5 seconds." )
pl:EmitSound( "vo/k_lab/kl_initializing02.wav" )
end
timer.Simple(5, self.NewRound, self)
return
end
if win > 0 then
team.AddScore(win, 1) end
local txt = ""
if win == TEAM_GUARD then
txt = "The Guards won the round."
else
txt = "The Prisoners won the round."
end
local txt2 = "Guards - "..team.GetScore(TEAM_GUARD).." | Prisoners - "..team.GetScore(TEAM_PRISONER)
for _, pl in pairs(player.GetAll()) do
pl:PrintMessage( HUD_PRINTCENTER, txt )
pl:ChatPrint( txt )
pl:ChatPrint( txt2 )
pl:ChatPrint( "Next round in 5 seconds." )
pl:EmitSound( "vo/k_lab/kl_initializing02.wav" )
end
timer.Simple(5, self.NewRound, self)
return
end
function PlayerDeath()
local GM = gmod.GetGamemode()
if GM.Round == ROUND_END then return end
local G = team.NumPlayers(TEAM_GUARD)
local GG = team.NumPlayers(TEAM_GUARD_DEAD)
local P = team.NumPlayers(TEAM_PRISONER)
local PP = team.NumPlayers(TEAM_PRISONER_DEAD)
if G + GG + P + PP >= 2 then
if G > 0 and P == 0 then
GM:EndRound(TEAM_GUARD)
elseif G == 0 and P > 0 then
GM:EndRound(TEAM_PRISONER)
elseif G == 0 and P == 0 then
GM:EndRound()
end
end
end
hook.Add( "Think", "PlayerDeath", PlayerDeath )
[/LUA]
Can someone point me in the direction of how to use net messages. For example say a situation where when a player shoots an NPC it shows prints the damage done to the player. I don't really understand how to use them.
[QUOTE=Gaming_Unlim;39304228]Can someone point me in the direction of how to use net messages. For example say a situation where when a player shoots an NPC it shows prints the damage done to the player. I don't really understand how to use them.[/QUOTE]
try this (untested):
[lua]
if SERVER then
util.AddNetworkString( "netNPCDamage" )
function netDmgNPC( ent, dmginfo )
local attacker = dmginfo:GetAttacker()
if IsValid(ent) && IsValid(attacker) && attacker:IsNPC() then
net.Start( "netNPCDamage" )
net.WriteUInt( dmginfo:GetDamage(), 16 )
net.Send( ent )
end
hook.Add("EntityTakeDamage", "netDmgNPC", netDmgNPC)
end
if CLIENT then
net.Receive( "netNPCDamage", function( length, client )
local dmg = tostring( net.ReadUInt( 16 ) )
chat.AddText( LocalPlayer(), Color( 232, 106, 106, 255 ), "You took "..dmg.." damage from an NPC!" )
end)
end
[/lua]
just save that as anything.lua and put it into garrysmod/lua/autorun
[QUOTE=M0dSe7en;39304662]try this (untested):
[lua]
if SERVER then
util.AddNetworkString( "netNPCDamage" )
function netDmgNPC( ent, dmginfo )
local attacker = dmginfo:GetAttacker()
if IsValid(ent) && IsValid(attacker) && attacker:IsNPC() then
net.Start( "netNPCDamage" )
net.WriteUInt( dmginfo:GetDamage(), 16 )
net.Send( ent )
end
hook.Add("EntityTakeDamage", "netDmgNPC", netDmgNPC)
end
if CLIENT then
net.Receive( "netNPCDamage", function( length, client )
local dmg = tostring( net.ReadUInt( 16 ) )
chat.AddText( LocalPlayer(), Color( 232, 106, 106, 255 ), "You took "..dmg.." damage from an NPC!" )
end)
end
[/lua]
just save that as anything.lua and put it into garrysmod/lua/autorun[/QUOTE]
Thanks alot, It does work and if I were to later put that in a gamemode I could just put that in a shared file or just put everything under the Client in the client file and put the Server in the init?
Is there any way that I could get this code to remove the entity 5 seconds after the original countdown has finished?:
[CODE]if ignite then
v:Ignite( 10, 10 )
timer.Simple( 9, function() if v:IsValid() then v:SetMaterial( "models/props_debris/plasterwall009d.vmt" ) end end )
end[/CODE]
[QUOTE=Gaming_Unlim;39305070]Thanks alot, It does work and if I were to later put that in a gamemode I could just put that in a shared file or just put everything under the Client in the client file and put the Server in the init?[/QUOTE]
just put it in shared.lua or you can make a new file called "sh_net.lua" or something. Then just add these lines in init.lua
[lua]
include( 'sh_net.lua' )
AddCSLuaFile( "sh_net.lua" )
[/lua]
Lastly, put this in cl_init.lua
[lua]
include( 'sh_net.lua' )
[/lua]
Where I put "if SERVER" that means it's serverside code so it goes into init.lua, and obviously client is client side code so it goes in cl_init.lua. If you see "cl_" in a filename it means that the code is only client side. "sv_" means server side. Lastly, "sh_" means shared, or both of them.
Can anyone give me an example of how to use CUserCmd:GetMouseX() and CUserCmd:GetMouseY()? When I try to use those two methods in a CreateMove hook it always returns 0 even after moving the mouse quite a bit.
e.g.:
[lua]
function Foo(cmd)
print(cmd:GetMouseY())
print(cmd:GetMouseX())
end
hook.Add("CreateMove", "Foo", Foo)
[/lua]
I am trying to make a script that takes the damage you do to an entity and gives it back to you. Here is what I have I right now and it is probably off by a lot, but if someone could help me that would be great!
init
[lua]
util.AddNetworkString( "LifeStealer" )
function LifeSteal( ent, dmginfo )
local attacker = dmginfo:GetAttacker()
local life = dmginfo:GetDamage()
if IsValid(attacker) && attacker:IsPlayer() then
net.Start("LifeSteal")
net.WriteUInt( life, 2 )
net.Send( ent )
end
end
hook.Add( "EntityTakeDamage", "LifeSteal", LifeSteal )[/lua]
cl_init
[lua]
net.Receive( "LifeStealer", function( len, ply )
local life = ( net.ReadUInt( 2 ) )
local health = LocalPlayer():Health()
health = health + life
end)
[/lua]
Right now I am getting an error for [B]calling net.Start with unpooled message name[/B], but I am calling [B]util.AddNetworkString( "LifeStealer" )[/B] at the beginning of my init file.
Sorry, you need to Log In to post a reply to this thread.