[QUOTE=luavirusfree;38927870]I can get you one, but I'd need help from an experienced LUA programmer first, on the link above.[/QUOTE]
best way to get no help: be an asshole
I'm creating gun ents (ents.Create("weapon_actualgunentity")).
When I walk over the gun, it will automatically pick it up. How can I change it to only be able to pick it up when you hit USE on it.
I've tried GM:PlayerCanPickupWeapon, but that also affects the lua code's ply:Give("weapon_actualgunentity").
[QUOTE=Hyper Iguana;38928100]I'm creating gun ents (ents.Create("weapon_actualgunentity")).
When I walk over the gun, it will automatically pick it up. How can I change it to only be able to pick it up when you hit USE on it.
I've tried GM:PlayerCanPickupWeapon, but that also affects the lua code's ply:Give("weapon_actualgunentity").[/QUOTE]
The only way I've ever come across of achieving this is the way DarkRP does it - using a dummy entity with the same model as the weapon and then calling ply:Give in it's use function.
Oh, I'm sorry... asking for help, in order to give help. That's apparently being an asshole online....
[editline]22nd December 2012[/editline]
I want help, and I had some help... Until they got banned. Can someone PLEASE help me out? [URL="http://facepunch.com/showthread.php?t=1232367&p=38927296#post38927296"]>_<[/URL]
Hello,
I'm trying to select everything from a table, but for some reason it isn't working
This is a printscreen of my PHPMyadmin table: [url]http://i47.tinypic.com/dmff3q.jpg[/url]
This is the code I'm using. Now, the problem is that it only selects the first entry it finds. This is because of the [i]result = result[1];[/i] line.
But, I'm not a LUA king so I have no idea how to put a loop on the table.
So, how could I make it select every result in the table instead of the first one?
[lua]
-- A function to set the area of a player.
function setArea()
-- Create the tables, and store the variables.
area = {}
player.flux = {}
player.flux.Position = "";
-- Execute the select query.
Query("SELECT * FROM plgn_areaname", function(result)
if (result and type(result) == "table" and #result > 0) then
result = result[1] -- Only selects first result in the table.
-- Get the result and store it in the table.
area.name = result.areaname;
area.vec1 = result.coord1;
area.vec2 = result.coord2;
MySQL("Retreived "..area.name.." from table") -- This only prints 'Lobby'
else
MySQL("No result found in area table")
end
end, 1)
-- This also seems to fail for some reason D;
local tbl1 = string.Explode(" ", player.flux.Vec1)
local tbl2 = string.Explode(" ", player.flux.Vec2)
local full1 = Vector(tbl1[1], tbl1[2], tbl1[3])
local full2 = Vector(tbl2[1], tbl2[2], tbl2[3])
for k, v in pairs(ents.FindInBox( full1, full2 )) do
if v:IsPlayer() then
v.flux.Position = v.flux.AreaName;
Log("Position for "..v:Nick().." updated to "..v.flux.Position)
end
end
end
hook.Add("Think", "setArea", setArea)
[/lua]
[QUOTE=Disseminate;38928034]best way to get no help: be an asshole[/QUOTE]
Yeah don't help this kid, he likes to send hate mail and troll pm's to your inbox. I got him banned for 3 days because he raged over dumb ratings. lolol.
How do you write a ternary statement like:
[PHP]e:SetColor(Color(on and {255, 255, 255, 255} or {255, 0, 0, 255}))[/PHP]
which isn't valid syntax? (a set of variables as one set)
[QUOTE=randomGuest;38928658]How do you write a ternary statement like:
[PHP]e:SetColor(Color(on and {255, 255, 255, 255} or {255, 0, 0, 255}))[/PHP]
which isn't valid syntax? (a set of variables as one set)[/QUOTE]
[lua]SetColor(on and Color(255, 255, 255) or Color(255, 0, 0))[/lua]
[editline]21st December 2012[/editline]
unless you're specifically asking about the tables, which would be
[lua]SetColor(Color(on and unpack({255, 255, 255}) or unpack({255, 0, 0})))[/lua]
[QUOTE=Hyper Iguana;38928100]I'm creating gun ents (ents.Create("weapon_actualgunentity")).
When I walk over the gun, it will automatically pick it up. How can I change it to only be able to pick it up when you hit USE on it.
I've tried GM:PlayerCanPickupWeapon, but that also affects the lua code's ply:Give("weapon_actualgunentity").[/QUOTE]
[lua]hook.Add( "PlayerSpawn", "PickupTimeoutInit", function( ply )
ply.PickupTimeout = CurTime() + 0.5
end )
hook.Add( "PlayerCanPickupWeapon", "PreventPickup", function( ply, wep )
if ( ( ply.PickupTimeout or 0 ) < CurTime() ) then
return false
end
end )
hook.Add( "KeyPress", "PressUse", function( ply, key )
if ( key == IN_USE ) then
ply.PickupTimeout = CurTime() + 0.5
end
end )
[/lua]
When you give a weapon, set the timeout to CurTime() + 0.5 again
[QUOTE=Drakehawke;38928208]The only way I've ever come across of achieving this is the way DarkRP does it - using a dummy entity with the same model as the weapon and then calling ply:Give in it's use function.[/QUOTE]
[lua]
function SWEP:Initialize()
hook.Add( "PlayerCanPickupWeapon", self, self.CanPickup )
hook.Add( "KeyPress", self, self.KeyPress )
end
function SWEP:CanPickup( ply, wep )
if wep==self then return false end
end
function SWEP:KeyPress( ply, key )
if key==IN_USE and ply and IsValid( ply ) then
local tr = ply:GetEyeTrace()
local ent, dist = tr.Entity, tr.StartPos:Distance( tr.HitPos )
if tr.Hit and ent==self and dist<100 then
ply:Give( self:GetClass() )
self:Remove()
end
end
end[/lua]
Wouldn't this work? I know the PlayerUse hook doesn't seem to work on weapons
[QUOTE=my_hat_stinks;38928834][lua]
function SWEP:Initialize()
hook.Add( "PlayerCanPickupWeapon", self, self.CanPickup )
hook.Add( "KeyPress", self, self.KeyPress )
end
function SWEP:CanPickup( ply, wep )
if wep==self then return false end
end
function SWEP:KeyPress( ply, key )
if key==IN_USE and ply and IsValid( ply ) then
local tr = ply:GetEyeTrace()
local ent, dist = tr.Entity, tr.StartPos:Distance( tr.HitPos )
if tr.Hit and ent==self and dist<100 then
ply:Give( self:GetClass() )
self:Remove()
end
end
end[/lua]
Wouldn't this work? I know the PlayerUse hook doesn't seem to work on weapons[/QUOTE]
I think that method would prevent using ply:Give(blah) (though it is more elegant)
[QUOTE=PortalGod;38928769][lua]SetColor(on and Color(255, 255, 255) or Color(255, 0, 0))[/lua]
[editline]21st December 2012[/editline]
unless you're specifically asking about the tables, which would be
[lua]SetColor(Color(on and unpack({255, 255, 255}) or unpack({255, 0, 0})))[/lua][/QUOTE]
I've been using the 1st example but the 2nd unpacking variation doesn't work at all. Damn.
EDIT - Fixed it all, thanks Mech for giving me a hand spotting my blind and dumb coding.
Does anyone have a get_args that works in GM13?
Here's the original that deco wrote:
[lua]
function get_args(f)
local co = coroutine.create(f)
local params = {}
debug.sethook(co, function()
local i, k = 1, debug.getlocal(co, 2, 1)
while k do
if k ~= "(*temporary)" then
table.insert(params, k)
end
i = i+1
k = debug.getlocal(co, 2, i)
end
error("~~end~~")
end, "c")
local res, err = coroutine.resume(co)
if res then
error("The function provided defies the laws of the universe.", 2)
elseif string.sub(tostring(err), -7) ~= "~~end~~" then
error("The function failed with the error: "..tostring(err), 2)
end
return params
end
[/lua]
It just spams:
[ERROR] bad argument #2 to 'getlocal' (level out of range)
Which is line 6 here.
if it possible to (reliably) detect if fall damage is from jumping or walking off something tall?
[QUOTE=Banana Lord.;38932092]if it possible to (reliably) detect if fall damage is from jumping or walking off something tall?[/QUOTE]
You could make a "cooldown" timer for everytime you jump? Haha..
If you die from falldamage within the 5 seconds of you jumping, then it counts as jumping, if not, you walked off?
Not very reliable to be honest.
[QUOTE=Minteh Fresh;38932170]You could make a "cooldown" timer for everytime you jump? Haha..
If you die from falldamage within the 5 seconds of you jumping, then it counts as jumping, if not, you walked off?
Not very reliable to be honest.[/QUOTE]
Yeah what's what I was worried about. Oh well then!
[QUOTE=Banana Lord.;38932092]if it possible to (reliably) detect if fall damage is from jumping or walking off something tall?[/QUOTE]
You should check how TTT does this. He doesn't use the GetFallDamage hook. But he uses:
[lua]
function GM:OnPlayerHitGround(ply, in_water, on_floater, speed)
if in_water or speed < 450 or not IsValid(ply) then return end
-- Everything over a threshold hurts you, rising exponentially with speed
local damage = math.pow(0.05 * (speed - 420), 1.75)
-- I don't know exactly when on_floater is true, but it's probably when
-- landing on something that is in water.
if on_floater then damage = damage / 2 end
-- if we fell on a dude, that hurts (him)
local ground = ply:GetGroundEntity()
if IsValid(ground) and ground:IsPlayer() then
if math.floor(damage) > 0 then
local att = ply
-- if the faller was pushed, that person should get attrib
local push = ply.was_pushed
if push then
-- TODO: move push time checking stuff into fn?
if math.max(push.t or 0, push.hurt or 0) > CurTime() - 4 then
att = push.att
end
end
local dmg = DamageInfo()
if att == ply then
-- hijack physgun damage as a marker of this type of kill
dmg:SetDamageType(DMG_CRUSH + DMG_PHYSGUN)
else
-- if attributing to pusher, show more generic crush msg for now
dmg:SetDamageType(DMG_CRUSH)
end
dmg:SetAttacker(att)
dmg:SetInflictor(att)
dmg:SetDamageForce(Vector(0,0,-1))
dmg:SetDamage(damage)
ground:TakeDamageInfo(dmg)
end
-- our own falling damage is cushioned
damage = damage / 3
end
if math.floor(damage) > 0 then
local dmg = DamageInfo()
dmg:SetDamageType(DMG_FALL)
dmg:SetAttacker(game.GetWorld())
dmg:SetInflictor(game.GetWorld())
dmg:SetDamageForce(Vector(0,0,1))
dmg:SetDamage(damage)
ply:TakeDamageInfo(dmg)
-- play CS:S fall sound if we got somewhat significant damage
if damage > 5 then
sound.Play(table.Random(fallsounds), ply:GetShootPos(), 55 + math.Clamp(damage, 0, 50), 100)
end
end
end
[/lua]
What's wrong?
[CODE]function GM:InitPostEntity ( )
self.GatherInvalidNames();
local GPNP = function()
GAMEMODE.PushNumPlayers
end
timer.Simple(1, GPNP);
end[/CODE]
Error:
[CODE][ERROR] gamemodes/perp3/gamemode/sv_hoocks.lua:114: ´=´ expected near ´end´
1.unknown - gamemodes/perp3/gamemode/sv_hooks.lua:0[/CODE]
I seriouslly don't get it
[QUOTE=Banana Lord.;38932092]if it possible to (reliably) detect if fall damage is from jumping or walking off something tall?[/QUOTE]
Set a boolean to true on jump, set to false on land.
I keep getting the error "Couldn't write type 6".
This is what i'm running serverside:
[lua]
util.AddNetworkString("player_EquipHat")
net.Start("player_EquipHat")
net.WriteEntity(ply)
net.WriteTable(ply.Items)
net.Broadcast()
[/lua]
This returns with:
[QUOTE]Masks:
Items:
1:
Equipped = true
Modify = function: 0x1d403628
Price = 100
Name = Skull
Model = models/props_halloween/jackolantern_01.mdl
Couldn't write type 6[/QUOTE]
This is what i'm running clientside:
[lua]
net.Receive("player_EquipHat", function(length)
local ply = net.ReadEntity()
local tbl = net.ReadTable()
print(ply, tbl)
if (not ply) or (not tbl) then return end
end)
[/lua]
Returns with:
[QUOTE]Player [1][10101 #Survivors#EOTW] table: 0x2ef2cc10[/QUOTE]
Fixed:
Apparently net.WriteTable() can't pass a table with a function for a value.
[QUOTE=Banana Lord.;38932390]Yeah what's what I was worried about. Oh well then![/QUOTE]
Hook, KeyPress.
if player is on the ground and the key is IN_JUMP then
set player.Jumped to true
end
Hook, OnPlayerHitGround
if player.Jumped then
set player.Jumped to false
end
check for player.Jumped in your fall damage hook.
[B][U]For a DarkRP server[/U][/B]
[B]What I need help with: [/B]
Making unique ranks with AssMod.
Making certain jobs VIP only.
Neatening out the shared.lua for jobs.
[B]Payment:[/B] Negotiable over Steam
[B]Payment type:[/B] PayPal
Add me on steam by clicking the steam Icon under my name.
Jeez this fills up FAST... Don't listen to Brandon, he's an asshole. He got me banned for being an asshole to him while he was being an asshole.
[QUOTE=luavirusfree;38932747]Jeez this fills up FAST... Don't listen to Brandon, he's an asshole. He got me banned for being an asshole to him while he was being an asshole.[/QUOTE]
Speaking about others in vulgar terms, because they somehow got you "Banned" doesn't really accomplish anything.
I'm sure you had your own steak in what happened.
[QUOTE=Magenta;38932759]Speaking about others in vulgar terms, because they somehow got you "Banned" doesn't really accomplish anything.
I'm sure you had your own steak in what happened.[/QUOTE]
[QUOTE=brandonj4][QUOTE=luavirusfree][QUOTE=brandonj4][QUOTE=luavirusfree]Fuck. You. Garry can suck my ass/dick/both. And it isn't fixed, yet. Take a chill pill!!! Otherwise, I will find every post made by you, and I will rate them dumb... Unless you can give me a reasonable reason as to why you rated me that way.[/QUOTE]
Calm down buddy, ratings aren't even important it's just a way of replying back to your post without wasting time to type out something. You're rated dumb because what you posted is dumb, it's common sense.
You keep bumping a post that nobody is replying to. If they're not replying to it drop the fucking thread no ones going to help you with it.[/QUOTE]
Fuck. You. Suck my dick, bitch. I almost died twice recently, and I've though of killing myself over rehab. I'm doing as much as I can, and if I need help, I want some god-damned help, so fuck off.[/QUOTE][/QUOTE]
Anyways, back to helping others.
Hey there ppl.
Recently I've been in a dire need of a Derma panel like DTextEntry, but with the ability to use different fonts and colors and selectable text, sort of like the native RichText panel (except it's utter shit). What would be the best way to go about creating one? Can anyone help me out there, please?
Hey, im having some trouble because Im crap at Scripting lua (besides sweps)
I want VIP ranks such as swat and Ninja to fit the ASSMOD vip ranks and above. Could someone help me?
The code i am using for VIP is function(ply) return ply:GetUserGroup() == "vip" or ply:IsAdmin() end)
and the ASSMOD shared.lua is here:
[url]http://pastebin.com/mDExX6Nm[/url]
[QUOTE=Insomnia Array;38932887]Hey there ppl.
Recently I've been in a dire need of a Derma panel like DTextEntry, but with the ability to use different fonts and colors and selectable text, sort of like the native RichText panel (except it's utter shit). What would be the best way to go about creating one? Can anyone help me out there, please?[/QUOTE]
You can do all this with DTextEntry:
[lua]
self.TextEntry = vgui.Create( "DTextEntry", self )
self.TextEntry:SetFont( "SRH_HUD_CHAT" )
self.TextEntry:SetText( "" )
self.TextEntry.Paint = function()
if self.ChatOpen then
draw.RoundedBox( 4, 0, 0, self.TextEntry:GetWide(), self.TextEntry:GetTall(), self.Colors.Black )
draw.RoundedBox( 4, 2, 2, self.TextEntry:GetWide() - 4, self.TextEntry:GetTall() - 4, self.Colors.White )
self.TextEntry:DrawTextEntryText( self.Colors.Black, self.Colors.TextHighlight, self.Colors.Black )
end
end
[/lua]
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index7382.html[/url]
If you don't want the hassle of overriding the paint function, DTextEntry:SetTextColor, DTextEntry:SetHightlightColor and DTextEntry:SetCursorColor work just as well.
[editline]22nd December 2012[/editline]
[QUOTE=Trumple;38928825][lua]hook.Add( "PlayerSpawn", "PickupTimeoutInit", function( ply )
ply.PickupTimeout = CurTime() + 0.5
end )
hook.Add( "PlayerCanPickupWeapon", "PreventPickup", function( ply, wep )
if ( ( ply.PickupTimeout or 0 ) < CurTime() ) then
return false
end
end )
hook.Add( "KeyPress", "PressUse", function( ply, key )
if ( key == IN_USE ) then
ply.PickupTimeout = CurTime() + 0.5
end
end )
[/lua]
When you give a weapon, set the timeout to CurTime() + 0.5 again[/QUOTE]
Surely with this whenever a player presses use they're going to pick up all nearby weapons and not just the one they're looking at?
[QUOTE=Drakehawke;38933225]
Surely with this whenever a player presses use they're going to pick up all nearby weapons and not just the one they're looking at?[/QUOTE]
Oh, if he wants the one the player is looking at then:
[lua]
hook.Add( "PlayerSpawn", "PickupTimeoutInit", function( ply )
ply.PickupTimeout = CurTime() + 0.5
end )
hook.Add( "PlayerCanPickupWeapon", "PreventPickup", function( ply, wep )
if ( ( ply.PickupTimeout or 0 ) < CurTime() ) then
return false
end
end )
hook.Add( "KeyPress", "PressUse", function( ply, key )
if ( key == IN_USE ) then
local tr = ply:GetEyeTrace()
if ( IsValid( tr.Entity ) && tr.Entity:IsWeapon() && tr.Entity:GetPos():Distance( ply:GetShootPos() ) < 96 ) then
ply.PickupTimeout = CurTime() + 0.5
ply:Give( tr.Entity:GetClass() )
tr.Entity:Remove()
end
end
end )
[/lua]
Could probably handle the removing differently but, proof of concept
Sorry, you need to Log In to post a reply to this thread.