Is there a Hook similar to Gamemode.PlayerStartVoice, but instead for opening chat? Like, have player as an argument
You could use a console command or use the net library with clientside StartChat and FinishChat.
[QUOTE=Bletotum;39419912][lua]
cam.Start3D( EyePos(), EyeAngles() )
for k, v in pairs(ents.GetAll()) do
if IsValid(v) then v:SetNoDraw(true) end
end
local cd = {}
cd.origin,cd.angles = EyePos(),EyeAngles()
cd.x,cd.y = 0,0
cd.w,cd.h = ScrW()/10,ScrH()/10
render.RenderView(cd)
for k, v in pairs(ents.GetAll()) do
if IsValid(v) then v:SetNoDraw(false) end
end
cam.End3D()
[/lua]
Inside a screen rendering hook, this displays what I see to the top left of my screen, minus all valid entities. How can I also make the world geometry not draw in the renderview?[/QUOTE]
Been looking at the render library but I can't find any function that disables rendering. You could theoretically set it to render to a render target in PreDrawTranslucentRenderables, then you stop the rendering to render target int PostDrawTranslucentRenderables.
Change your render.RenderView with this:
[lua]
DRAWINGRENDERVIEW = true
render.Render...
DRAWINGRENDERVIEW = false
[/lua]
Then you make a check in the Post/PreDrawTranslucentRenderables to make sure its the RenderView thats rendering and not your screen.
Edit:
I just realised that xDrawTranslucentRenderables will also make entities dissapear. No idea how to do this.. (try set NoDraw on the worldspawn?)
[QUOTE=trav0405;39417630]Getting error bad argument #2 to 'Find' (string expected, got nil)
[CODE]for k, v in pairs(file.Find("PERP3/gamemode/sh_modules/*", LUA_PATH)) do include("sh_modules/" .. v); end
Msg("Loading Items...\n");
for k, v in pairs(file.Find("PERP3/gamemode/items/*", LUA_PATH)) do include("items/" .. v); end
Msg("Loading Shops...\n");
for k, v in pairs(file.Find("PERP3/gamemode/shops/*", LUA_PATH)) do include("shops/" .. v); end
Msg("Loading Mixtures...\n");
for k, v in pairs(file.Find("PERP3/gamemode/mixtures/*", LUA_PATH)) do include("mixtures/" .. v); end
Msg("Loading Vehicles...\n");
for k, v in pairs(file.Find("PERP3/gamemode/vehicles/*", LUA_PATH)) do include("vehicles/" .. v); end
local function loadPostInt ( )
Msg("Loading Properties...\n");
for k, v in pairs(file.Find("PERP3/gamemode/properties/*", LUA_PATH)) do include("PERP3/gamemode/properties/" .. v); end
Msg("Loading NPCs...\n");
for k, v in pairs(file.Find("PERP3/gamemode/npcs/*", LUA_PATH)) do include("PERP3/gamemode/npcs/" .. v); end[/CODE]
Any help guys? :/[/QUOTE]
Go into garrysmod/garrysmod/gamemodes and delete PERP3, that SHOULD fix all your errors, and will save about 12 years of your time.
How could I efficiently get the angle of a surface at a position, here is a crappy way I thought of..
The angles are out as I am drawing text onto them.
[lua]
function WhatDirection(vec)
local Dir = {
{"up" , Vector(0,0,1)},
{"down" , Vector(0,0,-1)},
{"leftx" , Vector(-1,0,0)},
{"rightx" , Vector(1,0,0)},
{"lefty" , Vector(0,-1,0)},
{"righty" , Vector(0,1,0)}
}
print(vec)
local Hits = {}
for k,v in pairs(Dir) do
local tracedata = {}
tracedata.start = vec
tracedata.endpos = vec+(v[2]*50)
tracedata.filter = LocalPlayer()
local trace = util.TraceLine(tracedata)
if trace.Hit then
table.insert(Hits, {trace.HitPos, v[1]})
end
end
local Closest = Hits[1]
for k,v in pairs(Hits) do
if vec:Distance(v[1]) < vec:Distance(Closest[1]) then
Closest = v
end
end
print(Closest[2])
if Closest[2] == "up" then return Angle(180,90,0), vec + Vector(0,0,-0.5) end
if Closest[2] == "down" then return Angle(0,-90,0), vec + Vector(0,0,0.5) end
if Closest[2] == "leftx" then return Angle(0,90,90), vec + Vector(0,0.5,0) end
if Closest[2] == "rightx" then return Angle(0,270,90), vec + Vector(0,-0.5,0) end
if Closest[2] == "lefty" then return Angle(0,180,90), vec + Vector(0.5,0,0) end
if Closest[2] == "righty" then return Angle(0,0,90), vec + Vector(-0.5,0,0) end
end
[/lua]
As in the angle the wall is facing.
[url]http://i.imgur.com/XZuTYGB.jpg[/url] -snip
Need some help with a Microwave based health spawner. Gives:
02:13:56 [ERROR] gamemodes/darkrp/entities/entities/health_shop/init.lua:103: attempt to call method 'Setowning_ent' (a nil value)
1. createHealth - gamemodes/darkrp/entities/entities/health_shop/init.lua:103
2. unknown - gamemodes/darkrp/entities/entities/health_shop/init.lua:93
Erroring LUA file:
[CODE]
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
function ENT:Initialize()
self:SetModel("models/Items/HealthKit.mdl")
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
self:SetUseType(SIMPLE_USE)
local phys = self:GetPhysicsObject()
phys:Wake()
self.sparking = false
self.damage = 100
self:Setprice(math.Clamp((GAMEMODE.Config.pricemin ~= 0 and GAMEMODE.Config.pricemin) or 30, (GAMEMODE.Config.pricecap ~= 0 and GAMEMODE.Config.pricecap) or 30))
end
function ENT:OnTakeDamage(dmg)
self.damage = self.damage - dmg:GetDamage()
if (self.damage <= 0) then
self:Destruct()
self:Remove()
end
end
function ENT:Destruct()
local vPoint = self:GetPos()
local effectdata = EffectData()
effectdata:SetStart(vPoint)
effectdata:SetOrigin(vPoint)
effectdata:SetScale(1)
util.Effect("Explosion", effectdata)
end
function ENT:SalePrice(activator)
local owner = self:Getowning_ent()
local discounted = math.ceil(GAMEMODE.Config.dispensercost * 0.82)
if activator == owner then
-- If they are still a medic, sell them the health at the discounted rate
if activator:Team() == TEAM_MEDIC then
return discounted
else -- Otherwise, sell it to them at full price
return math.floor(GAMEMODE.Config.dispensercost)
end
else
return self:Getprice()
end
end
ENT.Once = false
function ENT:Use(activator,caller)
local owner = self:Getowning_ent()
self.user = activator
if not activator:CanAfford(self:SalePrice(activator)) then
GAMEMODE:Notify(activator, 1, 3, "You do not have enough money to purchase health!")
return ""
end
local diff = (self:SalePrice(activator) - self:SalePrice(owner))
if diff < 0 and not owner:CanAfford(math.abs(diff)) then
GAMEMODE:Notify(activator, 2, 3, "Dispenser owner is too poor to subsidize this sale!")
return ""
end
if activator.maxFoods and activator.maxHealths >= GAMEMODE.Config.maxfoods then
GAMEMODE:Notify(activator, 1, 3, "You have reached the health kit limit.")
elseif not self.Once then
self.Once = true
self.sparking = true
local discounted = math.ceil(GAMEMODE.Config.dispensercost * 0.82)
local cash = self:SalePrice(activator)
activator:AddMoney(cash * -1)
GAMEMODE:Notify(activator, 0, 3, "You have purchased health for " .. CUR .. tostring(cash) .. "!")
if activator ~= owner then
local gain = 0
if owner:Team() == TEAM_MEDIC then
gain = math.floor(self:Getprice() - discounted)
else
gain = math.floor(self:Getprice() - GAMEMODE.Config.dispensercost)
end
if gain == 0 then
GAMEMODE:Notify(owner, 2, 3, "You sold some health but made no profit!")
else
owner:AddMoney(gain)
local word = "profit"
if gain < 0 then word = "loss" end
GAMEMODE:Notify(owner, 0, 3, "You made a " .. word .. " of " .. CUR .. tostring(math.abs(gain)) .. " by selling health!")
end
end
timer.Create(self:EntIndex() .. "health", 1, 1, function() self:createHealth() end)
end
end
function ENT:createHealth()
activator = self.user
self.Once = false
local healthPos = self:GetPos()
health = ents.Create("health")
health:SetPos(Vector(healthPos.x,healthPos.y,healthPos.z + 23))
health:Setowning_ent(activator)
health.ShareGravgun = true
health.nodupe = true
health:Spawn()
if not activator.maxhealths then
activator.maxhealths = 0
end
activator.maxhealths = activator.maxhealths + 1
self.sparking = false
end
function ENT:Think()
if self.sparking then
local effectdata = EffectData()
effectdata:SetOrigin(self:GetPos())
effectdata:SetMagnitude(1)
effectdata:SetScale(1)
effectdata:SetRadius(2)
util.Effect("Sparks", effectdata)
end
end
function ENT:OnRemove()
timer.Destroy(self:EntIndex())
local ply = self:Get()
if not IsValid(ply) then return end
end
[/CODE]
What am I doing wrong? It's probably an obvious mistake, I just started LUA. health is an entity named health.
[QUOTE=theVendetta;39423488]How could I efficiently get the angle of a surface at a position, here is a crappy way I thought of..
The angles are out as I am drawing text onto them.
[lua]
function WhatDirection(vec)
local Dir = {
{"up" , Vector(0,0,1)},
{"down" , Vector(0,0,-1)},
{"leftx" , Vector(-1,0,0)},
{"rightx" , Vector(1,0,0)},
{"lefty" , Vector(0,-1,0)},
{"righty" , Vector(0,1,0)}
}
print(vec)
local Hits = {}
for k,v in pairs(Dir) do
local tracedata = {}
tracedata.start = vec
tracedata.endpos = vec+(v[2]*50)
tracedata.filter = LocalPlayer()
local trace = util.TraceLine(tracedata)
if trace.Hit then
table.insert(Hits, {trace.HitPos, v[1]})
end
end
local Closest = Hits[1]
for k,v in pairs(Hits) do
if vec:Distance(v[1]) < vec:Distance(Closest[1]) then
Closest = v
end
end
print(Closest[2])
if Closest[2] == "up" then return Angle(180,90,0), vec + Vector(0,0,-0.5) end
if Closest[2] == "down" then return Angle(0,-90,0), vec + Vector(0,0,0.5) end
if Closest[2] == "leftx" then return Angle(0,90,90), vec + Vector(0,0.5,0) end
if Closest[2] == "rightx" then return Angle(0,270,90), vec + Vector(0,-0.5,0) end
if Closest[2] == "lefty" then return Angle(0,180,90), vec + Vector(0.5,0,0) end
if Closest[2] == "righty" then return Angle(0,0,90), vec + Vector(-0.5,0,0) end
end
[/lua]
As in the angle the wall is facing.
[img]http://i.imgur.com/XZuTYGB.jpg[/img][/QUOTE]
[lua]tracedata.HitNormal:Angle()[/lua]
[QUOTE=havejack;39420838]How come this always gives me errors:
[LUA]
local add1 = (toNumber(ply:GetPData( "JeepOwned" )))
local add = (toNumber(ply:GetPData( "GolfOwned" )))
ply:SetNWInt( "JeepOwned", add1)
ply:SetNWInt( "GolfOwned", add)
[/LUA]
this is the error in the console "attempt to call global 'toNumber' (a nil value)"[/QUOTE]
It's 'tonumber' (lowercased)
[QUOTE=Donkie;39418084]Try it in local-multiplayer instead. Clientside is really unreliable in singleplayer (because it doesn't really exist in source).
self.Owner should always return the player who is carrying the weapon, wether it be spawned by him or not.[/QUOTE]
Thanks for the reply, I've been doing that. I'm asking mainly because I don't want people to think my tool is "shitty and broken" because it doesn't work in SP.
So what happens to the clientside in SP, does it become merged with the server? If that's the case I can patch it by skipping the net messages I'm using in self:TransmitSelection()
I suspect that self.Owner thing might be a glitch with prop protection, I'm looking into it. The symptom was that when a player fired the cannon which I spawned, their shots would originate from my nose :v:
What would be an optimized version to doing a script like this instead of using the think hook. I want their health to never go above 150. I assume I would use a math.Clamp for a better way as problems could propably arise doing it like this?
[lua]
function HealthClamp( ply )
for k,v in pairs (player.GetAll()) do
local health = v:Health()
if health > 150 then
v:SetHealth( 150 )
end
end
end
hook.Add( "Think", "HealthClamp", HealthClamp )
[/lua]
you could always just not let their health go above 150 in whatever script you're setting it in
I'm trying to make a boolean send through network library (no net.WriteBool which is sad) I keep getting this error
[code]bad argument #1 to 'WriteInt' (number expected, got nil)[/code]
Here is the code:
[lua]function meta:SetIronSights( bool )
//self:SetNetworkedBool( "bIronSights", bool );
self.bIronSights = bool;
net.Start( "bs_Ironsights" );
net.WriteInt( tonumber( bool ), 8 );
net.Send( self );
end
[/lua]
[QUOTE=Annoyed Tree;39430674]I'm trying to make a boolean send through network library (no net.WriteBool which is sad) I keep getting this error
[code]bad argument #1 to 'WriteInt' (number expected, got nil)[/code]
Here is the code:
[lua]function meta:SetIronSights( bool )
//self:SetNetworkedBool( "bIronSights", bool );
self.bIronSights = bool;
net.Start( "bs_Ironsights" );
net.WriteInt( tonumber( bool ), 8 );
net.Send( self );
end
[/lua][/QUOTE]
You should use net.Read/WriteBit for sending booleans instead.
How can I take a string like, "{{1,5},{2,5},{3,5}}" and turn it into a table? string.ToTable just explodes every character so that doesn't work too good.
You could be really dirty and just do:
RunString("MyTable = " .. "{{1,5},{2,5},{3,5}}")
Although I'm sure there is a more official way, this is the first that comes to mind.
[QUOTE=Matt-;39431710]You could be really dirty and just do:
RunString("MyTable = " .. "{{1,5},{2,5},{3,5}}")
Although I'm sure there is a more official way, this is the first that comes to mind.[/QUOTE]
Thank you! I got it to work, now I can load a player's inventory via MySQL.
What I did:
[lua]
RunString( "Inventory = "..v.inventory )
ply.Inventory = Inventory
[/lua]
[QUOTE=James0roll;39431900]Thank you! I got it to work, now I can load a player's inventory via MySQL.
What I did:
[lua]
RunString( "Inventory = "..v.inventory )
ply.Inventory = Inventory
[/lua][/QUOTE]
why not just RunString("ply.Inventory = "..v.inventory)
-snip-
Thought he was using SendLua.
[QUOTE=Chessnut;39432018]Because ply would be nil.[/QUOTE]
doesn't RunString() run in the space it's placed in?
How to give custom weapons with sweps to players ?
player:Give("custom_wep")
It says :
"[ERROR] lua/autorun/server/ttt_death_notify.lua:12: attempt to call method 'IsTraitor' (a nil value)
1. fn - lua/autorun/server/ttt_death_notify.lua:12
2. unknown - addons/ulib/lua/ulib/shared/hook.lua:183"
[QUOTE]if ( SERVER ) then
resource.AddFile("lua/autorun/client/ttt_death_notify.lua")
AddCSLuaFile("autorun/client/ttt_death_notify.lua")
hook.Add( "PlayerDeath", "CHIIPPPSS" , function( Pl, Ent, Killer )
umsg.Start( "PlayerDeathCustom", Pl )
umsg.Entity( Killer )
umsg.Bool( Killer:IsTraitor() )
umsg.Bool( Killer:IsDetective() )
umsg.End()
end)
else
usermessage.Hook( "PlayerDeathCustom" , function( um )
local Killer = um:ReadEntity()
local IsT = um:ReadBool()
local IsD = um:ReadBool()
chat.AddText( Color( 255,255,255 ) , "You've been killed by ", Color( 175,175,175 ), Killer:Nick(),
Color( 255,255,255 ), ( ( IsT or IsD ) and ", a " or ", an " ), ( (IsT and Color( 255,99,99)) or (IsD and Color( 52,128, 209)) or Color(161,232,116) ),
( (IsT and "Traitor!") or (IsD and "Detective!") or "Innocent!" ) )
chat.PlaySound()
end)
end[/QUOTE]
ply was nil when using RunString() so I had to use some ingenuity to get it to work.
[QUOTE=hellguy;39432276]It says :
"[ERROR] lua/autorun/server/ttt_death_notify.lua:12: attempt to call method 'IsTraitor' (a nil value)
1. fn - lua/autorun/server/ttt_death_notify.lua:12
2. unknown - addons/ulib/lua/ulib/shared/hook.lua:183"[/QUOTE]
Try:
[lua]
if ( SERVER ) then
resource.AddFile("lua/autorun/client/ttt_death_notify.lua")
AddCSLuaFile("autorun/client/ttt_death_notify.lua")
hook.Add( "PlayerDeath", "CHIIPPPSS" , function( Pl, Ent, Killer )
if !Killer or !Killer:IsValid( ) then return end
umsg.Start( "PlayerDeathCustom", Pl )
umsg.Entity( Killer )
umsg.Bool( Killer:IsTraitor() )
umsg.Bool( Killer:IsDetective() )
umsg.End()
end)
else
usermessage.Hook( "PlayerDeathCustom" , function( um )
local Killer = um:ReadEntity()
local IsT = um:ReadBool()
local IsD = um:ReadBool()
chat.AddText( Color( 255,255,255 ) , "You've been killed by ", Color( 175,175,175 ), Killer:Nick(),
Color( 255,255,255 ), ( ( IsT or IsD ) and ", a " or ", an " ), ( (IsT and Color( 255,99,99)) or (IsD and Color( 52,128, 209)) or Color(161,232,116) ),
( (IsT and "Traitor!") or (IsD and "Detective!") or "Innocent!" ) )
chat.PlaySound()
end)
end
[/lua]
[QUOTE=EthanTheGreat;39432742]Try:
[lua]
if ( SERVER ) then
resource.AddFile("lua/autorun/client/ttt_death_notify.lua")
AddCSLuaFile("autorun/client/ttt_death_notify.lua")
hook.Add( "PlayerDeath", "CHIIPPPSS" , function( Pl, Ent, Killer )
if !Killer or !Killer:IsValid( ) then return end
umsg.Start( "PlayerDeathCustom", Pl )
umsg.Entity( Killer )
umsg.Bool( Killer:IsTraitor() )
umsg.Bool( Killer:IsDetective() )
umsg.End()
end)
else
usermessage.Hook( "PlayerDeathCustom" , function( um )
local Killer = um:ReadEntity()
local IsT = um:ReadBool()
local IsD = um:ReadBool()
chat.AddText( Color( 255,255,255 ) , "You've been killed by ", Color( 175,175,175 ), Killer:Nick(),
Color( 255,255,255 ), ( ( IsT or IsD ) and ", a " or ", an " ), ( (IsT and Color( 255,99,99)) or (IsD and Color( 52,128, 209)) or Color(161,232,116) ),
( (IsT and "Traitor!") or (IsD and "Detective!") or "Innocent!" ) )
chat.PlaySound()
end)
end
[/lua][/QUOTE]
Works like a charm, except for the part that when you suicide, it doesn't say anything, and living players can't still hear you, also your nickname doesn't go to missing players tab..
[QUOTE=hellguy;39432975]Works like a charm, except for the part that when you suicide, it doesn't say anything, and living players can't still hear you, also your nickname doesn't go to missing players tab..[/QUOTE]
what are you even talking about
why would you think that this script does any of those things
[QUOTE=hellguy;39432975]Works like a charm, except for the part that when you suicide, it doesn't say anything, and living players can't still hear you, also your nickname doesn't go to missing players tab..[/QUOTE]
Then, replace line 5 with:
[code]if !Killer or !Killer:IsValid( ) then Killer = Pl end[/code]
[QUOTE=fairy;39432993]what are you even talking about
why would you think that this script does any of those things[/QUOTE]
The script should tell you who killed you and what he was(T, D, or I).. it's almost perfect, but when you are an inno, and you suicide, living players can still hear you, you don't go to "missing players" tab.. only when you suicide as inno, if you suicide as detec or t it's ok.. how do I fix that?
Edit:
You fixed it, thanks A LOT!
Does anyone know what the math function is to find if a number is between two other numbers?
For Example, I want to check if 99939 is between 40 and 10,000
Sorry, you need to Log In to post a reply to this thread.