What model path do I use when I am trying to put spawning a vehicle that is from an addon? Do I have to copy it to my gamemode's content or is there a way to point to the addons folder?
[QUOTE=James xX;48307686]I'm using render.RenderView() to render to a render target, but for some reason it draws some things (pictured below) to the screen.
[img_thumb]http://images.akamai.steamusercontent.com/ugc/450709426680523823/4D6B74B5EAD0E515374BF93DD2A6BDB3B90A79E9/[/img_thumb]
[lua]
local oldw, oldh = ScrW(), ScrH()
local oldrt = render.GetRenderTarget( )
render.SetRenderTarget( self.RenderTarget )
render.SetViewPort( 0, 0, ScrW(), ScrH() )
render.Clear( 255, 255, 255, 0 )
cam.Start2D()
self.drawingrenderables = true
render.RenderView({
origin = LocalPlayer( ):EyePos( ),
angles = LocalPlayer( ):EyeAngles( ),
x = 0,
y = 0,
w = ScrW( ),
h = ScrH( ),
dopostprocess = false,
drawhud = false,
drawmonitors = false,
drawviewmodel = false,
ortho = false
})
self.drawingrenderables = false
cam.End2D()
render.SetRenderTarget( oldrt )
render.SetViewPort( 0, 0, oldw, oldh )
[/lua]
That code is only called when self.drawingrenderables is false. Any ides?[/QUOTE]
Does it still happen if you remove render.Clear or try setting with 5th argument (clearDepth) to true or false?
Not a solution to your problem but you can turn your first 4 lines into 1, and the last 2 lines into 1 by using [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/render/PushRenderTarget]render.PushRenderTarget[/url]
[lua] render.PushRenderTarget(self.RenderTarget,0,0,ScrW(),ScrH())
render.Clear( 255, 255, 255, 0 )
cam.Start2D()
--snip
cam.End2D()
render.PopRenderTarget()[/lua]
[QUOTE=MegaTronJohn;48307486]Anyone know how I'd check if a door is locked?[/QUOTE]
exho did an great lib about doors
[url]https://github.com/Exho1/RandomLuaStuff/blob/master/lua/autorun/lib_door.lua[/url]
it saves quite a bit of hastle.
Is there a way to get the damageinfo from PlayerDeath? The Source equivalent, PlayerKilled, passes it as the second argument, and the inflictor and attacker are extracted from there.
[QUOTE=wh1t3rabbit;48309397]Does it still happen if you remove render.Clear or try setting with 5th argument (clearDepth) to true or false?
Not a solution to your problem but you can turn your first 4 lines into 1, and the last 2 lines into 1 by using [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/render/PushRenderTarget]render.PushRenderTarget[/url]
[lua] render.PushRenderTarget(self.RenderTarget,0,0,ScrW(),ScrH())
render.Clear( 255, 255, 255, 0 )
cam.Start2D()
--snip
cam.End2D()
render.PopRenderTarget()[/lua][/QUOTE]
I fixed it last night, no idea what I did, but thanks for trying anyway [IMG]http://www.facepunch.com/fp/ratings/heart.png[/IMG]
Guys, I'm having a problem with numpad.Register and numpad.OnDown that I can't figure out.
The entity is created on a tool with this code:
[CODE]
function CreateEntity( pl, pos, ang, key )
local prop = ents.Create( "prop_test" )
prop:SetPos(pos)
prop:SetAng(ang)
numpad.OnDown( pl, key, "SpawnProp", prop )
end
[/CODE]
Then, on the entity located at "entities/prop_test/init.lua" is like this:
[CODE]
local function PropSpawn( ply, ent )
print( "key pressed" )
ent:Spawn()
ent:Activate()
end
numpad.Register( "SpawnProp", PropSpawn )
[/CODE]
But it don't work, it don't print nothing and keeps telling "Unknown command: +gm_special"
Any tips why or how to make this work ?
I tried making pointshop register the weekday and change the points awarded according to that.
For some reason, it doesn't work, but constantly gives 15 points even on normal weekdays.
(And it isn't due to timezones, it awarded 15 points on a Tuesday)
[code]
if string.lower(os.date("%A")) == "friday" or "saturday" or "sunday" then -- If it's the weekend,
PS.Config.PointsOverTimeAmount = 15 -- Set the points / minute to 15 (50% increase)
else PS.Config.PointsOverTimeAmount = 10 -- else, the normal, 10
end[/code]
EDIT:
Thanks, Author. Used to Python xD
[QUOTE=Legendahkiin;48314768]I tried making pointshop register the weekday and change the points awarded according to that.
For some reason, it doesn't work, but constantly gives 15 points even on normal weekdays.
(And it isn't due to timezones, it awarded 15 points on a Tuesday)
[code]
if string.lower(os.date("%A")) == "friday" or "saturday" or "sunday" then -- If it's the weekend,
PS.Config.PointsOverTimeAmount = 15 -- Set the points / minute to 15 (50% increase)
else PS.Config.PointsOverTimeAmount = 10 -- else, the normal, 10
end[/code][/QUOTE]
That's not how the or statement works in Lua, this is how you would do it,
[lua]local day = string.lower(os.date("%A")) -- localize the day
local happydays = {
["friday"] = true, -- friday should be more points
["saturday"] = true, -- this day as well
["sunday"] = true,
["monday"] = false, -- this shouldnt
}
if happydays[day] then -- If happydays["friday"] is true, then continue
PS.Config.PointsOverTimeAmount = 15 -- Set the points / minute to 15 (50% increase)
else
PS.Config.PointsOverTimeAmount = 10 -- else, the normal, 10
end[/lua]
Rarity system.
I need math help with it.
Currently I'm making a weapon exchange machine, and you get a gun of equal or greater rarity depending on how many guns you put in and what their rarity was. At the moment, rarity is defined by price.
Can I get a hint as to what operations I should be doing to a huge number (let's say, 34,000, which comes from around 3 guns) to split it into 4 percentages?
e.g. if it [I]was[/I] 34,000, then something like
a = 10%
b = 15%
c = 25%
d = 50%
I've been out of the loop for a while, I just have a small question, what is the current MySql module that is used these days, last time I used one it was MySqloo iirc. Thanks.
tmysql4 > mysqloo
Hmm, I knew it wouldn't be ez pz, I'm having a hard time even connecting (I think) the DB and doing a simple query, I know the tmysql page has an example, but that doesn't seem to work, I'm unsure of what I'm doing wrong.
[CODE]db = tmysql.initialize("localhost", "root", "uwishm8", "test", 3306)
function test(r)
print("success")
PrintTable(r[1].data)
end
db:Query("SELECT * FROM player_data", test)[/CODE]
edit: shit, it's not because I have to be on the server right?!
edit2: I think it is, I deserve some boxes probably :)
So Robot told me that I need to add an "if CLIENT then end" code to my SWEP to get this error to stop spamming:
[code][ERROR] addons/nutscript 1.1/lua/weapons/nut_sks.lua:21: Tried to use a NULL entity!
1. SetBodygroup - [C]:-1
2. unknown - addons/nutscript 1.1/lua/weapons/nut_sks.lua:21[/code]
Where should I add it, assuming this is the code being used?
[code]
if (CLIENT) then
SWEP.PrintName = "SKS"
SWEP.Author = "Tazmily"
SWEP.SlotPos = 3
SWEP.IconLetter = "i"
SWEP.NameOfSWEP = "nut_SKS" --always make this the name of the folder the SWEP is in.
killicon.AddFont( SWEP.NameOfSWEP, "CSKillIcons", SWEP.IconLetter, Color( 255, 80, 0, 255 ) )
end
function SWEP:Deploy()
self.Owner:GetViewModel():SetBodygroup(1, 0)
self:SendWeaponAnim(ACT_VM_DRAW)
self:SetBodygroup(1, 0)
return true
end
function SWEP:Holster()
self.Owner:GetViewModel():SetBodygroup(1, 0)
self:SetBodygroup(1, 0)
return true
end
function SWEP:Initialize()
self:SetHoldType(self.HoldType)
end
SWEP.Category = "Nutscript 1.1"
SWEP.Base = "rcs_base"
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.ViewModel = "models/tnb/weapons/c_sks.mdl"
SWEP.WorldModel = "models/tnb/weapons/w_sks.mdl"
SWEP.Weight = 5
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
SWEP.Primary.Sound = Sound( "weapons/m249/m249_fire.wav" )
SWEP.Primary.Recoil = 0.1
SWEP.Primary.Damage = 45
SWEP.Primary.NumShots = 1
SWEP.Primary.Cone = 0.001
SWEP.Primary.ClipSize = 10
SWEP.Primary.Delay = .20
SWEP.Primary.DefaultClip = 0
SWEP.Primary.MaxReserve = 90
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "smg1"
SWEP.UseHands = true
SWEP.ViewModelFlip = false
SWEP.ViewModelFOV = 55
SWEP.Primary.MaxSpread = 0.000001 --the maximum amount the spread can go by, best left at 0.20 or lower
SWEP.Primary.Handle = 0.2 --how many seconds you have to wait between each shot before the spread is at its best
SWEP.Primary.SpreadIncrease = 0.21/15 --how much you add to the cone after each shot
SWEP.MoveSpread = 6 --multiplier for spread when you are moving
SWEP.JumpSpread = 8 --multiplier for spread when you are jumping
SWEP.CrouchSpread = 0.5 --multiplier for spread when you are crouching
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = true
SWEP.Secondary.Ammo = "none"
SWEP.Zoom = 0 --pretty self explanitory, don't change this unless if you want the gun to be fucked up
//SWEP.ZoomOutDelay = 0.2 -- this is used for the delay between when you shoot and when it zooms out to pull the bolt
//SWEP.ZoomInDelay = 1.5 --always set this 0.2 higher than SWEP.Primary.Delay
SWEP.Zoom1 = 30 --Field of view for the first zoom
SWEP.Zoom2 = 15 --field of view for the second zoom
SWEP.Zoom0Cone = 0.1 --spread for when not zoomed
SWEP.Zoom1Cone = 0.01 --spread for when zoomed once
SWEP.Zoom2Cone = 0.01 --spread for when zoomed twice
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = true
SWEP.Secondary.Ammo = "none"
SWEP.IronSightsPos = Vector( -6.3496, 0, 4.247 )
SWEP.IronSightsAng = Vector( 0.3449, 0.1386, 0 )
[/code]
Make sure you check the validity of the ViewModel before using it.
[QUOTE=code_gs;48317436]Make sure you check the validity of the ViewModel before using it.[/QUOTE]
If you mean that I'm using the proper view model, yes, the SWEP works fine in single player, but self.Owner:GetViewModel() is only a clientside command, so on a server (which I made the SWEPs for) it spams that error for random users at random intervals The SWEP works exactly as it should otherwise, bodygroups and all. Robotboy said to add "if CLIENT then end" in the code, and I just want to know where exactly I need to put it if that's the case.
[QUOTE=Shadico;48317472]If you mean that I'm using the proper view model, yes, the SWEP works fine in single player, but self.Owner:GetViewModel() is only a clientside command, so on a server (which I made the SWEPs for) it spams that error for random users at random intervals The SWEP works exactly as it should otherwise, bodygroups and all. Robotboy said to add "if CLIENT then end" in the code, and I just want to know where exactly I need to put it if that's the case.[/QUOTE]
No. Set GetViewModel to a variable and check if it is valid with IsValid.
[QUOTE=code_gs;48317645]No. Set GetViewModel to a variable and check if it is valid with IsValid.[/QUOTE]
Something like this...?
[code]function SWEP:Deploy()
if CLIENT and IsValid(self.Owner:GetViewModel()) then
self.Owner:GetViewModel():SetBodygroup(1, 1)
self:SendWeaponAnim(ACT_VM_DRAW)
self:SetBodygroup(1, 1)
return true
end
end
function SWEP:Holster()
if CLIENT and IsValid(self.Owner:GetViewModel()) then
self.Owner:GetViewModel():SetBodygroup(1, 0)
self:SetBodygroup(1, 0)
return true
end
end
[/code]
[QUOTE=Shadico;48317787]Something like this...?
[code]function SWEP:Deploy()
if CLIENT and IsValid(self.Owner:GetViewModel()) then
self.Owner:GetViewModel():SetBodygroup(1, 1)
self:SendWeaponAnim(ACT_VM_DRAW)
self:SetBodygroup(1, 1)
return true
end
end
function SWEP:Holster()
if CLIENT and IsValid(self.Owner:GetViewModel()) then
self.Owner:GetViewModel():SetBodygroup(1, 0)
self:SetBodygroup(1, 0)
return true
end
end
[/code][/QUOTE]
Should work perfectly.
[QUOTE=code_gs;48317869]Should work perfectly.[/QUOTE]
This did pretty much the exact opposite of fix it. Technically, the errors don't appear anymore, but now whenever you draw a SWEP with that code in it, you can't put it away unless you die, and the bodygroups don't appear (which is probably why the errors are gone.)
Any suggestions?
[QUOTE=Z0mb1n3;48315052]Rarity system.
I need math help with it.
Currently I'm making a weapon exchange machine, and you get a gun of equal or greater rarity depending on how many guns you put in and what their rarity was. At the moment, rarity is defined by price.
Can I get a hint as to what operations I should be doing to a huge number (let's say, 34,000, which comes from around 3 guns) to split it into 4 percentages?
e.g. if it [I]was[/I] 34,000, then something like
a = 10%
b = 15%
c = 25%
d = 50%[/QUOTE]
What you are after is probably a "weighted random".
[url=http://stackoverflow.com/questions/1761626/weighted-random-numbers]The first stackoverflow link[/url] ( if you have an account, make sure to upvote helpful answers and good questions! ).
The idea is this:
For each item in your set, sum their combined weight ( rarity ).
Generate a random number between 0 and your sum
Iterate over the set and subtract the weight from the sum until you reach an item that has a weight greater than the sum - that is your item.
[QUOTE=Shadico;48318131]This did pretty much the exact opposite of fix it. Technically, the errors don't appear anymore, but now whenever you draw a SWEP with that code in it, you can't put it away unless you die, and the bodygroups don't appear (which is probably why the errors are gone.)
Any suggestions?[/QUOTE]
Make sure you are returning OUTSIDE of the if statement.
[QUOTE=code_gs;48318487]Make sure you are returning OUTSIDE of the if statement.[/QUOTE]
Made sure of that, now the weapon functions normally but the bodygroups don't show up on the v_model.
Are you sure that's the right bodygroup number?
[QUOTE=Kogitsune;48318163]What you are after is probably a "weighted random".
[url=http://stackoverflow.com/questions/1761626/weighted-random-numbers]The first stackoverflow link[/url] ( if you have an account, make sure to upvote helpful answers and good questions! ).
The idea is this:
For each item in your set, sum their combined weight ( rarity ).
Generate a random number between 0 and your sum
Iterate over the set and subtract the weight from the sum until you reach an item that has a weight greater than the sum - that is your item.[/QUOTE]
I love you. Thank you so much.
EDIT:
Would there be a better way to decide the percentages other than
[code]
if amt >= 30000 then
garbage = 0
common = 50
exotic = 30
legendary = 20
elseif amt >= 20000 then
garbage = ...
-- continue large elif block
[/code]
(amt being the amount of money put in my machine)
Hey dudes, I'm trying to put some decals on my playermodel.
But it renders white on the player, I don't know what could cause that, any tips please?
[lua]local decal = Material("glow_xp_gain.png", "nocull smooth")
function Test()
local mat = Material("models/kleiner/players_sheet")
local matWidth = 512
local matHeight = 512
local xName = "vehicle_decal1"
local newRT = GetRenderTarget("rt_" .. xName, 512, 512, false)
hook.Add("HUDPaint", "BuildVehicleDecals", function()
local oldRT = render.GetRenderTarget()
local oldWidth = ScrW()
local oldHeight = ScrH()
render.PushRenderTarget(newRT)
render.SetViewPort(0, 0, matWidth, matHeight)
cam.Start2D()
render.Clear(0, 0, 0, 255)
surface.SetDrawColor(255, 0, 0, 0)
surface.DrawRect(0, 0, 128, 128)
render.SetLightingMode(2)
render.SetMaterial(mat)
render.DrawScreenQuad(0, 0, matWidth, matHeight)
render.SetMaterial(decal)
render.DrawScreenQuadEx(50, 70, 128, 128)
render.SetLightingMode(0)
cam.End2D()
render.SetViewPort(0, 0, oldWidth, oldHeight)
render.PopRenderTarget()
hook.Remove("HUDPaint", "BuildVehicleDecals")
end)
local newMat = CreateMaterial(xName, "VertexLitGeneric", {
["$basetexture"] = newRT,
["$bumpmap"] = "models/kleiner/players_sheet",
["$model"] = "1"
})
local ply = LocalPlayer()
local matIdx
for idx, mat in next, ply:GetMaterials() do
if mat:find("players_sheet") then
matIdx = idx -1
break
end
end
ply:SetSubMaterial(matIdx, "!" .. xName)
print(xName)
end
Test()[/lua]
How do I scale a C_ClientRagdoll? I've tried SetModelScale, EnableMatrix, and also combining them with SetLegacyTransform. I've tried delaying the
I really would like my scaled npcs to remain the same scale when they die.
Is there any way I can check if the nav file exists on map spawn ? (on any map)
[QUOTE=Kogitsune;48328340]How do I scale a C_ClientRagdoll? I've tried SetModelScale, EnableMatrix, and also combining them with SetLegacyTransform. I've tried delaying the
I really would like my scaled npcs to remain the same scale when they die.[/QUOTE]
I don't think you can. What you'd need to do is resize the ragdoll's physics objects. Otherwise, if you just scaled the bones down visually, like you're trying to do with SetModelScale and that sort of thing, they'd still collide with everything and be spaced apart from each other as if they were still normal-sized, like you just used the inflator tool on them.
The [URL="http://steamcommunity.com/sharedfiles/filedetails/?id=470366741"]Ragdoll Resizer tool[/URL] on the workshop pulls this off by creating entirely new physics objects with Entity:PhysicsInitConvex() and then constraining them together with [URL="https://developer.valvesoftware.com/wiki/Phys_ragdollconstraint"]phys_ragdollconstraint[/URL] entities (also known as ball socket constraints), but this can't be done with clientside ragdolls, because as far as I can tell, there's no way to create a clientside constraint using Lua.
How do I get the IP of a player and not the port part ?
I made this but I don't know if it works :
[CODE]
local IPAddress = string.Explode(":", ply:IPAddress())
IPAdress = [1]IPAddress
[/CODE]
Sorry, you need to Log In to post a reply to this thread.