• I need small help with LUA. Please help only if you are good at LUA.
    13 replies, posted
Can anyone help me with LUA? I need simple melee weapon code on weapon_base base. I need SIMPLE melee weapon not on GDCW base or M9K base no on TTT Base but on default (weapon_base)! It needs to have already set damage, because i always had problem with setting damage. If i said something wrong, sorry, i am from Poland and i am bad at english.
[url]https://github.com/garrynewman/garrysmod/tree/master/garrysmod/lua/weapons[/url]
O-ookay, i will try it. [editline]27th February 2015[/editline] Man, i mean MELEE WEAPON like crowbar, knife or anything like that, i am lua noob and i can't change fists into crowbar.
[QUOTE=xgdg;47225641]O-ookay, i will try it. [editline]27th February 2015[/editline] Man, i mean MELEE WEAPON like crowbar, knife or anything like that, i am lua noob and i can't change fists into crowbar.[/QUOTE] Just inherit the weapon_base and change the [URL="http://wiki.garrysmod.com/page/Hold_Types"]hold type[/URL]. That will make a simple melee weapon.
But it has fists animations. I need crowbar anims.
-snip, understood incorrectly-
I don't understand you, i don't understand internet! I just wanted weapon code, or even a attack function, i understand nothing from your reply. If you are experienced LUA scripter, making primary attack function wouldn't be so hard or be waste of time.
Sorry that this took a while, had to test some of the trace stuff. [code]local swingsound = "whatever.wav" local hitsound = "whatever2.wav" function SWEP:PrimaryAttack() self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) -- No spam pls self.Weapon:EmitSound( swingsound ) timer.Simple( 0.2, function() -- Gives a grace period between the swing and the actual hit if IsValid( self ) and IsValid( self.Owner ) then -- Time has passed; always check for validity after a timer self:Hit() -- Here's where the magic happens end end ) self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER ) -- Dummy animation for what the weapon does in third person, act enums here: http://wiki.garrysmod.com/page/Enums/ACT self.Owner:SetAnimation( PLAYER_ATTACK1 ) -- Animation for first person end function SWEP:Hit() -- Separate function for readability and code cleanliness if SERVER then -- For multiplayer; especially without lag compensation, traces will differ from client to server resulting in hits that should(n't) have passed pos = self.Owner:GetShootPos() ang = self.Owner:GetAimVector() me = self.Owner local hit = {} -- Sets up tracing table to create range and position for hitting the entity. Angle and vector values good ranges, but definitely are configurable hit.start = pos hit.endpos = pos + ( ang * 70 ) hit.filter = me hit.mins = Vector( -5, -5, 0 ) hit.maxs = Vector(5, 5, 5) local trace = util.TraceHull( hit ) -- Do not use clientside, serverside will provide the hull trace of the weapon hit if trace.Hit then -- If the weapon hits an object targ = trace.Entity -- What did the weapon hit? if targ:IsPlayer() or targ:IsNPC() then -- If it hit a player or NPC (living entities) ... self.Owner:EmitSound( hitsound ) paininfo = DamageInfo() -- Calculates damage dealt and how it will be handled paininfo:SetDamage( self.Primary.Damage ) paininfo:SetDamageType( DMG_CLUB ) -- or DMG_SLASH if you're making some kind of sharp weapon paininfo:SetAttacker( me ) -- I merely attacked the man... paininfo:SetInflictor( self.Weapon ) -- The weapon is who killed him paininfo:SetDamageForce( trace.Normal * 10000 ) -- Scales up normal (perpendicular) vector of the hit to create a realistic force targ:ViewPunch( Angle( -10, -20, 0 ) ) -- Shakes the swing, hitting people is hard work (optional, comment this line out if you don't want the shake) end end end end[/code]
Thanks! I wanted reply like this! Now i can make my very creative melee weapon! :D :D [editline]27th February 2015[/editline] But... same problem! weapon doesn't take any damage! [editline]27th February 2015[/editline] I would write .exe file with notepad easier than setting damage for lua melee weapon!!!
Gee, do you want a cookie or something?
[QUOTE=eligrand1;47227922]Gee, do you want a cookie or something?[/QUOTE] Did you set the SWEP.Primary.Damage variable?
Sure. I also had the same problem with my other abandoned SWEPs.
lol why'd you reply to me?
[QUOTE=xgdg;47233145]Sure. I also had the same problem with my other abandoned SWEPs.[/QUOTE] Post your whole file in [code] tags. [editline]28th February 2015[/editline] [QUOTE=eligrand1;47233725]lol why'd you reply to me?[/QUOTE] Wrong button
Sorry, you need to Log In to post a reply to this thread.