• Need some advice for this code:
    11 replies, posted
Hey guys, A friend of mine made this custom TTT weapon (Flashbang) For traitors for me, but it dont seem to work. By question is, maybe you guys can advice me what is wrong with this code. BKU (Made TTT) Posted this tutorial: [QUOTE]TTT grenades consist of two parts: a SWEP and a projectile. For example, the incendiary grenade SWEP is in: /terrortown/entities/weapons/weapon_zm_molotov/shared.lua It uses weapon_tttbasegrenade as its SWEP.Base, and that base does most of the work. The incendiary weapon really just sets its model and stuff, as well as SWEP:GetGrenadeName(), which specifies what projectile the SWEP should throw. When a grenade SWEP is "fired", it creates the SENT named by GetGrenadeName and propels it forward. All grenades do this, so if you look at the SWEPs for the discomb or smoke grenade, they only differ in the model stuff and which SENT they throw. The grenade base takes care of all the throwing and stuff. If you checked the incendiary SWEP, you will have noted its projectile is set as "ttt_firegrenade_proj", which is here: /terrortown/entities/entities/ttt_firegrenade_proj/shared.lua Again, most of the work is done in the entity's base class, in this case ttt_basegrenade_proj. All a grenade projectile SENT does is specify how it looks and how it should explode. The explosion is created in ENT:Explode(tr), where "tr" is a trace towards the ground that the grenade is lying on (for effects). The incendiary projectile checks some things, creates some effects, and creates fire entities. So, to create or port a new grenade, you can copy one of the existing grenade SWEPs and just change the name/model/etc. Then you put the name of the grenade projectile entity you're about to make in the GetGrenadeName function. That's it for the SWEP. You then copy one of the existing grenade projectile SENTs and again change name, model, the works. Lastly, you change ENT:Explode to create the explosion you want. If you're porting a grenade, this will hopefully just be a copy/paste job. That should be it. It should be as easy as creating bog standard TTT guns, only the explosion part requires some Lua work.[/QUOTE] My friend told me he downloaded the flashbang from here: [url]http://www.garrysmod.org/downloads/?a=view&id=62657[/url] Then he sended me this Shared.lua what comes in /terrortown/entities/weapons/weapon_ttt_flashbang/shared.lua [lua] if SERVER then AddCSLuaFile( "shared.lua" ) end SWEP.HoldType = "grenade" if CLIENT then SWEP.PrintName = "Flashbang" SWEP.Slot = 2 SWEP.Icon = "VGUI/ttt/icon_nades" end SWEP.Base = "weapon_tttbasegrenade" SWEP.Spawnable = true SWEP.AdminSpawnable = true SWEP.ViewModel = "models/weapons/v_eq_flashbang.mdl" SWEP.WorldModel = "models/weapons/w_eq_flashbang.mdl" SWEP.Weight = 5 SWEP.AutoSpawnable = true -- really the only difference between grenade weapons: the model and the thrown -- ent. function SWEP:GetGrenadeName() return "ttt_flashbang" end [/lua] Then in: /terrortown/entities/entities/ttt_flashbang There is a Init.lua and a Shared.lua He merged the Shared + Init together like this: [lua] if SERVER then AddCSLuaFile( "shared.lua" ) include("shared.lua") end ENT.Type = "anim" ENT.Base = "ttt_basegrenade_proj" ENT.Model = Model("models/weapons/w_eq_flashbang_thrown.mdl") local FLASH_INTENSITY = 3000 /*--------------------------------------------------------- Initialize ---------------------------------------------------------*/ function ENT:Initialize() self.Entity:SetModel("models/weapons/w_eq_flashbang_thrown.mdl") self.Entity:PhysicsInit( SOLID_VPHYSICS ) self.Entity:SetMoveType( MOVETYPE_VPHYSICS ) self.Entity:SetSolid( SOLID_VPHYSICS ) self.Entity:DrawShadow( false ) -- Don't collide with the player self.Entity:SetCollisionGroup( COLLISION_GROUP_WEAPON ) self.Entity:SetNetworkedString("Owner", "World") local phys = self.Entity:GetPhysicsObject() if (phys:IsValid()) then phys:Wake() end timer.Simple(2, function() if self.Entity then self:Explode() end end) end /*--------------------------------------------------------- Explode ---------------------------------------------------------*/ function ENT:Explode() self.Entity:EmitSound(Sound("Flashbang.Explode")); for _,pl in pairs(player.GetAll()) do local ang = (self.Entity:GetPos() - pl:GetShootPos()):Normalize():Angle() local tracedata = {}; tracedata.start = pl:GetShootPos(); tracedata.endpos = self.Entity:GetPos(); tracedata.filter = pl; local tr = util.TraceLine(tracedata); if (!tr.HitWorld) then local dist = pl:GetShootPos():Distance( self.Entity:GetPos() ) local endtime = FLASH_INTENSITY / (dist * 2); if (endtime > 6) then endtime = 6; elseif (endtime < 1) then endtime = 0; end simpendtime = math.floor(endtime); tenthendtime = math.floor((endtime - simpendtime) * 10); -- if (pl:GetNetworkedFloat("FLASHED_END") > CurTime()) then -- pl:SetNetworkedFloat("FLASHED_END", endtime + pl:GetNetworkedFloat("FLASHED_END") + CurTime() - pl:GetNetworkedFloat("FLASHED_START")); -- else pl:SetNetworkedFloat("FLASHED_END", endtime + CurTime()); -- end pl:SetNetworkedFloat("FLASHED_END_START", CurTime()); end end self.Entity:Remove(); end /*--------------------------------------------------------- Think ---------------------------------------------------------*/ function ENT:Think() end /*--------------------------------------------------------- OnTakeDamage ---------------------------------------------------------*/ function ENT:OnTakeDamage() end /*--------------------------------------------------------- Use ---------------------------------------------------------*/ function ENT:Use() end /*--------------------------------------------------------- StartTouch ---------------------------------------------------------*/ function ENT:StartTouch() end /*--------------------------------------------------------- EndTouch ---------------------------------------------------------*/ function ENT:EndTouch() end /*--------------------------------------------------------- Touch ---------------------------------------------------------*/ function ENT:Touch() end /*--------------------------------------------------------- Think ---------------------------------------------------------*/ function ENT:Think() end /*--------------------------------------------------------- Draw ---------------------------------------------------------*/ function ENT:Draw() self.Entity:DrawModel() end /*--------------------------------------------------------- IsTranslucent ---------------------------------------------------------*/ function ENT:IsTranslucent() return true end function FlashEffect() if LocalPlayer():GetNetworkedFloat("FLASHED_END") > CurTime() then local pl = LocalPlayer(); local FlashedEnd = pl:GetNetworkedFloat("FLASHED_END") local FlashedStart = pl:GetNetworkedFloat("FLASHED_START") local Alpha if(FlashedEnd - CurTime() > FLASHTIMER) then Alpha = 150; else local FlashAlpha = 1 - (CurTime() - (FlashedEnd - FLASHTIMER)) / (FlashedEnd - (FlashedEnd - FLASHTIMER)); Alpha = FlashAlpha * 150; end surface.SetDrawColor(255, 255, 255, math.Round(Alpha)) surface.DrawRect(0, 0, surface.ScreenWidth(), surface.ScreenHeight()) end end hook.Add("HUDPaint", "FlashEffect", FlashEffect); local function StunEffect() local pl = LocalPlayer(); local FlashedEnd = pl:GetNetworkedFloat("FLASHED_END") local FlashedStart = pl:GetNetworkedFloat("FLASHED_START") if (FlashedEnd > CurTime() and FlashedEnd - EFFECT_DELAY - CurTime() <= FLASHTIMER) then local FlashAlpha = 1 - (CurTime() - (FlashedEnd - FLASHTIMER)) / (FLASHTIMER); DrawMotionBlur( 0, FlashAlpha / ((FLASHTIMER + EFFECT_DELAY) / (FLASHTIMER * 4)), 0); elseif (FlashedEnd > CurTime()) then DrawMotionBlur( 0, 0.01, 0); else DrawMotionBlur( 0, 0, 0); end end hook.Add( "RenderScreenspaceEffects", "StunEffect", StunEffect ) end ENT.Type = "anim" /*--------------------------------------------------------- OnRemove -----------------
Help please? :(
You show us hundreds of lines of code and you don't even have an error or a clue to what's wrong? All I can do in this situation is to rate you optimistic.
[QUOTE=ralle105;28509071]You show us hundreds of lines of code and you don't even have an error or a clue to what's wrong? All I can do in this situation is to rate you optimistic.[/QUOTE] Well it doesnt give a specific error cuz the code is good. You should only look at the first code, the last 3 are the original code's from the file itself. The problem actolly is that it still explodes as incendiary (sorry for the fail spelling) while it should explode as flashbang but for some reason TTT dont see it as a flashbang so thats my question, What is the problem that TTT dont see this nade to explode as a flashbang?
[QUOTE=Ranger1201;28509146]Well it doesnt give a specific error cuz the code is good. You should only look at the first code, the last 3 are the original code's from the file itself. The problem actolly is that it still explodes as incendiary (sorry for the fail spelling) while it should explode as flashbang but for some reason TTT dont see it as a flashbang so thats my question, What is the problem that TTT dont see this nade to explode as a flashbang?[/QUOTE] I really need some help with this code please.. ?
Why did you post all of the code you did if only one section is used?
yeah alright ill change it
Ok changed the code, I hope its more Clear now.
Never mind made it myself working already, Thx anyways :)
Is this flashbang now working, because i want a flashbang for my server too :D
No, it's outdated.
[QUOTE=code_gs;42424904]No, it's outdated.[/QUOTE] Okay :(
Sorry, you need to Log In to post a reply to this thread.