Is it possible to tell a ragdoll to perform an animation or at least spawn in a position of that animation?
Trying to create serverside ragdolls with special effects on death, but the problem is that it always spawns in tpose. (I don't want to use SetShouldServerRagdoll because I don't want the ragdoll to despawn)
[QUOTE=Z0mb1n3;49386151]I found a way around this!
Play all sounds [b]clientside[/b]. So tell all clients to emit the sound from the gun, or something like that.[/QUOTE]
I already have it play clientside. The problem was to get the sound to stop properly, which I figured out after reading a bit of the wiki.
If anyone is curious
[code]
net.Receive( "CSSCustomSound", function( len )
local ply = LocalPlayer()
local Pos = net.ReadVector()
local Weapon = net.ReadEntity()
local GunSound = net.ReadString()
local Level = (net.ReadFloat()*30)^0.1
local Channel = net.ReadFloat()
local Distance = ply:GetPos():Distance(Pos)
local FinalPos = ply:GetPos() + (Pos - ply:GetPos()):Angle():Forward()*256
local FinalVolume = math.Clamp( (1024*Level*1.5) / Distance,0,1)
local FinalPitch = 50 + 50 * FinalVolume
if ply ~= Weapon.Owner and FinalVolume > 0 then
local SoundData = {
name = Weapon:GetClass() .. Weapon:EntIndex(),
channel = Channel,
sound = GunSound,
pitch = FinalPitch,
volume = FinalVolume
}
sound.Add(SoundData)
Weapon:StopSound(Weapon:GetClass() .. Weapon:EntIndex())
sound.Play(Weapon:GetClass() .. Weapon:EntIndex(),FinalPos,75,0,0)
end
end )
[/code]
[QUOTE=ROFLBURGER;49392420]Is it possible to tell a ragdoll to perform an animation or at least spawn in a position of that animation?
Trying to create serverside ragdolls with special effects on death, but the problem is that it always spawns in tpose. (I don't want to use SetShouldServerRagdoll because I don't want the ragdoll to despawn)[/QUOTE]
Would bonemerge work? Assuming the animation is on an exactly identical skeleton, I would think you could bonemerge the ragdoll to play the animation, then set it free for it to fall to a ragdoll from the animation, but I've never personally worked with bonemerge.
Anyone know why my player class init function isn't being called clientside? I have my player class lua file included in shared.
The wiki claims it's a shared function... Relevant code below.
[code]
AddCSLuaFile()
DEFINE_BASECLASS( "player_default" )
local PLAYER = {}
function PLAYER:Init()
if SERVER then self.Player:LoadDB() end
self.Player.LoadoutTable = { {[1] = false}, {[1] = false}, {[1] = 3, [2] = 2, [3] = 1, [4] = 5}}
self.Player.ClassTable = {[TEAM_SURV] = 1, [TEAM_ZOMB] = 1}
end
player_manager.RegisterClass( "player_zh_default", PLAYER, "player_default" )[/code]
I'd just like to have these tables ready on the clientside, is all.
[QUOTE=ThreeDog;49393351]Anyone know why my player class init function isn't being called clientside? I have my player class lua file included in shared.
The wiki claims it's a shared function... Relevant code below.
[code]
AddCSLuaFile()
DEFINE_BASECLASS( "player_default" )
local PLAYER = {}
function PLAYER:Init()
if SERVER then self.Player:LoadDB() end
self.Player.LoadoutTable = { {[1] = false}, {[1] = false}, {[1] = 3, [2] = 2, [3] = 1, [4] = 5}}
self.Player.ClassTable = {[TEAM_SURV] = 1, [TEAM_ZOMB] = 1}
end
player_manager.RegisterClass( "player_zh_default", PLAYER, "player_default" )[/code]
I'd just like to have these tables ready on the clientside, is all.[/QUOTE]
Try adding the csluafile from your serverside init
e.g. AddCSLuaFile("clientsidefile.lua")
Okay, I am probably making a stupid rookie mistake right now, but... Whenever I draw a rounded box before drawing a black circle, it won't draw the circle, it will however draw the box just fine. If I get rid of the code for drawing the box, it will let me draw the circle just fine...
[lua]
local x,y = 225,ScrH()-220
--Draws the rounded box
draw.RoundedBox(8,100,435, 250, 240, Color(0,0,0,230))
--Draws the circle if I don't draw the box first.
local radius = 110
local thickness = 110
local ply = LocalPlayer()
local h = 100
local startAng,endAng = 360, 0
draw.Arc(x,y,radius,thickness,startAng,endAng,1,Color(0,0,0,255))
[/lua]
Incase you need the code for drawing the actual arc
[lua]
function surface.PrecacheArc(cx,cy,radius,thickness,startang,endang,roughness)
local triarc = {}
-- local deg2rad = math.pi / 180
-- Define step
local roughness = math.max(roughness or 1, 1)
local step = roughness
-- Correct start/end ang
local startang,endang = startang or 0, endang or 0
if startang > endang then
step = math.abs(step) * -1
end
-- Create the inner circle's points.
local inner = {}
local r = radius - thickness
for deg=startang, endang, step do
local rad = math.rad(deg)
-- local rad = deg2rad * deg
local ox, oy = cx+(math.cos(rad)*r), cy+(-math.sin(rad)*r)
table.insert(inner, {
x=ox,
y=oy,
u=(ox-cx)/radius + .5,
v=(oy-cy)/radius + .5,
})
end
-- Create the outer circle's points.
local outer = {}
for deg=startang, endang, step do
local rad = math.rad(deg)
-- local rad = deg2rad * deg
local ox, oy = cx+(math.cos(rad)*radius), cy+(-math.sin(rad)*radius)
table.insert(outer, {
x=ox,
y=oy,
u=(ox-cx)/radius + .5,
v=(oy-cy)/radius + .5,
})
end
-- Triangulize the points.
for tri=1,#inner*2 do -- twice as many triangles as there are degrees.
local p1,p2,p3
p1 = outer[math.floor(tri/2)+1]
p3 = inner[math.floor((tri+1)/2)+1]
if tri%2 == 0 then --if the number is even use outer.
p2 = outer[math.floor((tri+1)/2)]
else
p2 = inner[math.floor((tri+1)/2)]
end
table.insert(triarc, {p1,p2,p3})
end
-- Return a table of triangles to draw.
return triarc
end
function surface.DrawArc(arc)
for k,v in ipairs(arc) do
surface.DrawPoly(v)
end
end
function draw.Arc(cx,cy,radius,thickness,startang,endang,roughness,color)
surface.SetDrawColor(color)
surface.DrawArc(surface.PrecacheArc(cx,cy,radius,thickness,startang,endang,roughness))
end
[/lua]
[QUOTE=WalkingZombie;49392462]Would bonemerge work? Assuming the animation is on an exactly identical skeleton, I would think you could bonemerge the ragdoll to play the animation, then set it free for it to fall to a ragdoll from the animation, but I've never personally worked with bonemerge.[/QUOTE]
Bonemerge will probably work but the thing is that there isn't a bonemerge function built in garrysmod.
I've tried it before and I remember there being a keyvalue or something to edit, but I can't find the function anywhere.
How can I use the camera attachment of a viewmodel?
[code]
function SWEP:CalcView(ply, pos, ang, fov)
if self.CameraAttachment and self.CameraAttachment>0 then
vm:SetupBones()
local angpos = vm:GetAttachment(self.CameraAttachment)
local angv = angpos.Ang
angv:Normalize()
ang = angv
end
return pos, ang , fov
end
[/code]
This doesn't work.
I am creating an inventory system that uses separate files for each item, however the lua file limit is affected by these items. I was looking at how to include these files when they are txt files but I'm struggling so far. Is there a way to include a txt file into Lua? Is RunString safe to use in this circumstance?
[QUOTE=TFA;49395645]question[/QUOTE]
That [lua]vm[/lua] variable exists?
[QUOTE=Fruitwesp;49396054]That [lua]vm[/lua] variable exists?[/QUOTE]
Yes, sorry, that was just a snippet of what I thought were the relevant bits. The issue is that the attachment sort of spazzes out, returning the completely wrong angle in one frame and the correct one in another.
[QUOTE=ROFLBURGER;49395477]Bonemerge will probably work but the thing is that there isn't a bonemerge function built in garrysmod.
I've tried it before and I remember there being a keyvalue or something to edit, but I can't find the function anywhere.[/QUOTE]
Yeah, after I wrote that I looked for it on the wiki. If it's still possible, it used to be easier.
[QUOTE=john55223;49394713]Okay, I am probably making a stupid rookie mistake right now, but... Whenever I draw a rounded box before drawing a black circle, it won't draw the circle, it will however draw the box just fine. If I get rid of the code for drawing the box, it will let me draw the circle just fine...
[/QUOTE]
Try reversing your startAng and endAng variables to be 0, 360.
Also, before drawing either of them, use draw.NoTexture()
[QUOTE=mib999;49395934]I am creating an inventory system that uses separate files for each item, however the lua file limit is affected by these items. I was looking at how to include these files when they are txt files but I'm struggling so far. Is there a way to include a txt file into Lua? Is RunString safe to use in this circumstance?[/QUOTE]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/CompileFile]Global.CompileFile[/url]
[QUOTE=mib999;49395934]I am creating an inventory system that uses separate files for each item, however the lua file limit is affected by these items. I was looking at how to include these files when they are txt files but I'm struggling so far. Is there a way to include a txt file into Lua? Is RunString safe to use in this circumstance?[/QUOTE]
yeah, RunString. Here's how Pointshop does it (I believe)
[lua]
ITEM = {}
RunString(file.Read(...))
RegisterItem(ITEM)
ITEM = nil
[/lua]
[QUOTE=man with hat;49396658][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/CompileFile]Global.CompileFile[/url][/QUOTE]
Yes, you could also use this, but this requires the calling of RegisterItem from inside the file.
Nah, it doesn't. Thanks for the help, it works :)
[lua]
ITEM = {}
CompileFile( ... )()
registerItem( ITEM )
ITEM = nil
[/lua]
[QUOTE=Z0mb1n3;49396649]Try reversing your startAng and endAng variables to be 0, 360.
Also, before drawing either of them, use draw.NoTexture()[/QUOTE]
Tried doing both, unfortunately, it didn't work. Thanks for trying to help though.
How would I go about doing a trace on an arc?
(think throwing an object from a cliff and finding the position where it lands)
[QUOTE=mib999;49395934]I am creating an inventory system that uses separate files for each item, however the lua file limit is affected by these items. I was looking at how to include these files when they are txt files but I'm struggling so far. Is there a way to include a txt file into Lua? Is RunString safe to use in this circumstance?[/QUOTE]
You can read text files into lua via [url]http://wiki.garrysmod.com/page/file/Read[/url] but I wouldn't recommend using RunString, as files are read line by line. If were doing it I'd store variables and enums that define certain item behaviours, then define the code in a single item template lua file
[QUOTE=mib999;49395934]I am creating an inventory system that uses separate files for each item, however the lua file limit is affected by these items. I was looking at how to include these files when they are txt files but I'm struggling so far. Is there a way to include a txt file into Lua? Is RunString safe to use in this circumstance?[/QUOTE] I'm not sure why it wouldn't be safe to use, its not like you are accepting the code from a third party source. Its the same exact thing as using a lua file its just loaded into the game differently.
The code is in a shared lua file and it works serverside. But it says "DecompileRewards" is a nil value clientside, I can't figure out what the problem is.
[CODE]
PLAYER = FindMetaTable("Player");
function PLAYER:DecompileRewards(CompiledString)
local InputTable = {}
local itemInfo = string.Explode(":",string.Trim(CompiledString));
for k, v in pairs(itemInfo) do
if v == "" then return end
InputTable[k] = v
end
if CLIENT then
LocalPlayerRewards[#LocalPlayerRewards+1] = InputTable
else
self.Rewards[#self.Rewards+1] = InputTable
end
end
if CLIENT then
local function ReadRewardsInfo()
local CompiledString = net.ReadString()
LocalPlayerRewards = {}
LocalPlayer():DecompileRewards(CompiledString)
end
net.Receive("se_send_rewards", ReadRewardsInfo)
end [/CODE]
[QUOTE=ToBadForYou;49398432]The code is in a shared lua file and it works serverside. But it says "DecompileRewards" is a nil value clientside, I can't figure out what the problem is.
[CODE]
PLAYER = FindMetaTable("Player");
function PLAYER:DecompileRewards(CompiledString)
local InputTable = {}
local itemInfo = string.Explode(":",string.Trim(CompiledString));
for k, v in pairs(itemInfo) do
if v == "" then return end
InputTable[k] = v
end
if CLIENT then
LocalPlayerRewards[#LocalPlayerRewards+1] = InputTable
else
self.Rewards[#self.Rewards+1] = InputTable
end
end
if CLIENT then
local function ReadRewardsInfo()
local CompiledString = net.ReadString()
LocalPlayerRewards = {}
LocalPlayer():DecompileRewards(CompiledString)
end
net.Receive("se_send_rewards", ReadRewardsInfo)
end [/CODE][/QUOTE]
Provide the whole error - I'm fairly certain the error was more related to your CompiledString.
[QUOTE=Netheous;49398682]Provide the whole error - I'm fairly certain the error was more related to your CompiledString.[/QUOTE]
I already checked the value on the string, it returns what it should: 220:224:83:33:194:66:96:70:12:130:261:24:279:224:281:197:87:41:232:243:140:85:280:10:262
(ItemIDs)
Here's the error
[CODE]
[ERROR] gamemodes/serp/gamemode/sh_modules/sh_rewards.lua:24: attempt to call method 'DecompileRewards' (a nil value)
1. func - gamemodes/serp/gamemode/sh_modules/sh_rewards.lua:24
2. unknown - lua/includes/extensions/net.lua:32
[/CODE]
Line 24 is: LocalPlayer():DecompileRewards(CompiledString)
I know it's a long shot - but instead of LocalPlayer() try using player.GetByID() with it returning yourself.
[QUOTE=Shenesis;49399037]When are you sending "se_send_rewards"? If you are doing it on PlayerInitialSpawn, it's possible that you're doing it too early. Try using a timer[/QUOTE]
Yes, thank you that worked! Thanks Netheous for trying to help. :)
Can't get autocomplete for my concommand to work. Seems like the AutoComplete function doesn't return the correct table or something. Any suggestions?
[lua]
local function AutoComplete(cmd,txt)
local tbl = {}
txt = string.Trim( txt )
txt = string.lower( txt )
for k, v in pairs( effects ) do
if string.find(string.lower( v ), txt ) then
table.insert( tbl, "AddEffect ".. v);
end
end
return tbl
end
concommand.Add("AddEffect", AddEffect, AutoComplete)
[/lua]
[QUOTE=kvka;49400738]Can't get autocomplete for my concommand to work. Seems like the AutoComplete function doesn't return the correct table or something. Any suggestions?
[lua]
local function AutoComplete(cmd,txt)
local tbl = {}
txt = string.Trim( txt )
txt = string.lower( txt )
for k, v in pairs( effects ) do
if string.find(string.lower( v ), txt ) then
table.insert( tbl, "AddEffect ".. v);
end
end
return tbl
end
concommand.Add("AddEffect", AddEffect, AutoComplete)
[/lua][/QUOTE]
What do you get when you PrintTable(tbl), your loop for inserting effects might be messed up.
[QUOTE=Revenge282;49397276]How would I go about doing a trace on an arc?
(think throwing an object from a cliff and finding the position where it lands)[/QUOTE]
I'm afraid you're going to have to do some math. Gmod doesn't support curved traces - you can do a hacky workaround by using lots of little traces, but maths is generally your best bet.
[QUOTE=YourStalker;49401698]What do you get when you PrintTable(tbl), your loop for inserting effects might be messed up.[/QUOTE]
i got the correct table, but the function still returned the wrong one.
Dumb question but after reading Lua docs I still don't understand entirely...
Why on most public codes I see (for example Pointshop) they set a table.__index to the table itself if in the lua docs it says that it should be a function or another table (most commonly it's own metatable)?
Example:
[lua]
--[[
pointshop/sh_init.lua
first file included on both states.
]]--
PS = {}
PS.__index = PS
[/lua]
Source: [URL="https://github.com/adamdburton/pointshop/blob/master/lua/pointshop/sh_init.lua#L7"]https://github.com/adamdburton/pointshop/blob/master/lua/pointshop/sh_init.lua#L7[/URL]
Lua docs on __index: [URL="http://www.lua.org/manual/5.1/manual.html#2.8"]http://www.lua.org/manual/5.1/manual.html#2.8[/URL]
[QUOTE=kvka;49405439]i got the correct table, but the function still returned the wrong one.[/QUOTE]
I'm not sure what you're talking about when you say you "got the correct table but the function still returned the wrong one", however that autocomplete function works perfectly fine. Try PrintTable(effects) because that's the only thing I can think of that would cause this to not work.
Using this code
[CODE]local effects =
{
"yEs",
"nO",
"PINEAPPLE",
"jOHn",
"CenA"
}
local function AutoComplete(cmd,txt)
local tbl = {}
txt = string.Trim( txt )
txt = string.lower( txt )
for k, v in pairs( effects ) do
if string.find(string.lower( v ), txt ) then
table.insert( tbl, "AddEffect ".. v);
end
end
return tbl
end
concommand.Add("AddEffect", AddEffect, AutoComplete)[/CODE]
results in
[vid]http://zippy.gfycat.com/RepentantOrdinaryBlackfootedferret.webm[/vid]
Sorry, you need to Log In to post a reply to this thread.