Welcome, Guest. Please login or register.
Did you miss your activation email?
November 25, 2024, 08:15:14 PM
Home Help Login Register
News: Trouble in Terrorist Town? Site here, forum here.

Zombie Master  |  Other  |  Trouble in Terrorist Town  |  Topic: Question about "weapon_tttbasegrenade"
Pages: [1]
Author Topic: Question about "weapon_tttbasegrenade"  (Read 4704 times)
Mr. Wepz.
Poster

Posts: 65


« on: February 28, 2011, 01:02:12 AM »

Hey guys, so I downloaded a css flashbang from gmod.org (http://www.garrysmod.org/downloads/?a=view&id=58283) and the code is fine I think, it dont give a LUA error in my console. But everytime when I toss the FlashBang it explodes as Incendiary Grenade.

First time I make a  "weapon_tttbasegrenade" tho, i always had "weapon_tttbase" that worked correctly always with this kind of stuffs :D

So my question is, Does TTT not support the flashbang? But i dont think thats the problem.. Or was there indeed something wrong in the script?

Thanks!
Mr. Gash
Poster

Posts: 382


www.nonerdsjustgeeks.com


« Reply #1 on: February 28, 2011, 03:31:09 AM »

Paste the code?
Manmax75
Poster

Posts: 254


Programming Guy


« Reply #2 on: February 28, 2011, 06:01:28 AM »

remove something like this from your projectile code(sent)

util.Effect("Explosion", effect, true, true)

Ride Forward and Thrust Your Pelvis In The Dark Void. The One Induced By Pleasure Yet Cast By The Bigger Picture.
Mr. Wepz.
Poster

Posts: 65


« Reply #3 on: February 28, 2011, 12:16:41 PM »

Ok, wait im gonna paste the code, I dont know if it will be to long:

Shared.lua in weapon_ttt_flashbang

if (SERVER) then --the init.lua stuff goes in here
  AddCSLuaFile ("shared.lua")
end

if (CLIENT) then --the cl_init.lua stuff goes in here


SWEP.PrintName = "Flashbang"
SWEP.SlotPos = 6
SWEP.IconLetter = "g"
SWEP.NameOfSWEP = "weapon_ttt_flashbang" --always make this the name of the folder the SWEP is in.
killicon.AddFont( SWEP.NameOfSWEP, "CSKillIcons", SWEP.IconLetter, Color( 255, 80, 0, 255 ) )
       SWEP.Icon = "VGUI/ttt/icon_bw_flashbang"

end

SWEP.Primary.NumNades = 3 --number of throwable grenades at your disposal
SWEP.Grenade = "rcs_thrownflashbang" --self explanitory

local here = true
SWEP.Author = "cheesylard"
SWEP.Category = "RealCS"

SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.Base = "weapon_tttbasegrenade"
SWEP.Kind = WEAPON_EQUIP2
SWEP.CanBuy = { ROLE_TRAITOR }
SWEP.LimitedStock = true

SWEP.EquipMenuData = {
  type = "Weapon",
  desc = "Use for distraction.\nUse it wise, you only\nhave one flashbang."
};

SWEP.AllowDrop = true
SWEP.AutoSpawnable = false


SWEP.ViewModel = "models/weapons/v_eq_flashbang.mdl"
SWEP.WorldModel = "models/weapons/w_eq_flashbang.mdl"

SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = true
SWEP.Primary.Ammo = "none"

SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"

SWEP.IronSightsPos = Vector (7.3161, 0, 0.6718)
SWEP.IronSightsAng = Vector (7.2937, 9.6773, 51.2462)


-----------------------------------------------------------------------------------------------
Shared.lua in entities
---
local DIETIMER = 1.5; --time in seconds, for the grenade to transition from full white to clear
local EFFECT_DELAY = 0.5; --time, in seconds when the effects still are going on, even when the whiteness of the flash is gone (set to -1 for no effects at all =]).




local pos, endflash, endflash2;
if (CLIENT) then
function ENT:Initialize()
pos = self:GetPos()
timer.Simple(2, function()
local beeplight = DynamicLight( self:EntIndex() )
if ( beeplight ) then
beeplight.Pos = pos
beeplight.r = 255
beeplight.g = 255
beeplight.b = 255
beeplight.Brightness = 6
beeplight.Size = 1000
beeplight.Decay = 1000
beeplight.DieTime = CurTime() + 0.15
end
end)
end
function ENT:Think()
pos = self:GetPos()
end
function ENT:Draw()
self.Entity:DrawModel()
end
function ENT:IsTranslucent()
return true
end

--actual white stuff
function SimulateFlash_REALCS_NOT_ANYTHINGELSE() if LocalPlayer():GetNetworkedFloat("RCS_flashed_time") > CurTime()then
local pl = LocalPlayer();
local e = pl:GetNetworkedFloat("RCS_flashed_time"); --when it dies away
local s = pl:GetNetworkedFloat("RCS_flashed_time_start"); --when it started

local alpha;
if(e-CurTime()>DIETIMER)then
alpha = 255;
else
local pf = 1-(CurTime() - (e-DIETIMER))/(e - (e-DIETIMER));
alpha = pf*255;
end

surface.SetDrawColor(255,255,255,math.Round(alpha));
surface.DrawRect(0,0,surface.ScreenWidth(),surface.ScreenHeight());
//draw.SimpleText("alpha: "..alpha,"TargetID",0,0,Color(0,0,0,255),0,0);
//draw.SimpleText("time left: "..(e-CurTime()),"TargetID",0,15,Color(0,0,0,255),0,0);


end end
hook.Add("HUDPaint", "SimulateFlash_REALCS_NOT_ANYTHINGELSE", SimulateFlash_REALCS_NOT_ANYTHINGELSE);

--motion blur and other junk
local function SimulateBlur_REALCS_NOT_ANYTHINGELSE()
local pl = LocalPlayer();
local e = pl:GetNetworkedFloat("RCS_flashed_time") + EFFECT_DELAY; --when it dies away
local s = pl:GetNetworkedFloat("RCS_flashed_time_start"); --when it started
if (e > CurTime()  &&  e-EFFECT_DELAY-CurTime()<=DIETIMER )then
local pf = 1-(CurTime() - (e-DIETIMER))/(DIETIMER);
DrawMotionBlur( 0,pf/((DIETIMER+EFFECT_DELAY)/DIETIMER), 0);
//DrawBloom( 3, pf*5, 6, 6, 12, 0, 255, 255, 255 );
elseif(e > CurTime())then
DrawMotionBlur( 0, 0.01, 0);
else
DrawMotionBlur( 0, 0, 0);
end
end

hook.Add( "RenderScreenspaceEffects", "SimulateBlur_REALCS_NOT_ANYTHINGELSE", SimulateBlur_REALCS_NOT_ANYTHINGELSE )

end

ENT.Type = "anim"
function ENT:OnRemove()
end
function ENT:PhysicsUpdate()
end
function ENT:PhysicsCollide(data,phys)
if data.Speed > 50 then
self.Entity:EmitSound(Sound("weapons/flashbang/grenade_hit1.wav"))
end

local lollol = -data.Speed * data.HitNormal * .1 + (data.OurOldVelocity * -0.6)
phys:ApplyForceCenter(lollol)
end


-----------------------------------------------------------------------------------------------

And init in entities

--

local FLASH_INTENSITY = 2250; --the higher the number, the longer the flash will be whitening your screen




AddCSLuaFile( "shared.lua" )
include("shared.lua")
local function simplifyangle(angle)
while(angle>=180) do
angle = angle - 360;
end
while(angle <= -180) do
angle = angle + 360;
end
return angle;
end
/*useless
local function pos_to_ang(pos1, pos2) --takes the angle from the first argument to the second argument and returns it for use with the flashbang. (function made by chee/syla/rd)
local xR,yR; --initialize variables
if(pos1.y == pos2.y) then--if your dividing by zero OSHI-
xR = 90; --what it WOULD return, but dividing by zero obviously creates a rip in the space time continuum, let's not do that.
else
xR = math.atan((pos2.z-pos1.z)/(pos2.y-pos1.y)); --gets tangent of slope
end

if (pos1.z > pos2.z || pos1.y > pos2.y) && !(pos1.z > pos2.z || pos1.y > pos2.y) then --angles are switched around
xR = -1*xR; --inverse it
end

if(pos1.x == pos2.x)then
yR = 90;
else
yR = math.atan((pos2.y-pos1.y)/(pos2.x-pos1.x));
end

if (pos1.y > pos2.y || pos1.x > pos2.x) && !(pos1.y > pos2.y || pos1.x > pos2.x) then
yR = -1*yR;
end
return Angle(xR, yR, 0);
end*/

function ENT:Explode()
self.Entity:EmitSound(Sound("weapons/flashbang/flashbang_explode"..math.random(1,2)..".wav"));
for _,pl in pairs(player.GetAll()) do
//--local ang = pos_to_ang(pl:GetShootPos(), self.Entity:GetPos());
local ang = (self.Entity:GetPos() - pl:GetShootPos()):Normalize():Angle()
//print("Ideal angle: Angle("..ang.p..", "..ang.y..", "..ang.r..")\n");
//print("Player angle: Angle("..pl:EyeAngles().p..", "..pl:EyeAngles().y..", "..pl:EyeAngles().r..")\n");
local tracedata = {};
tracedata.start = pl:GetShootPos();
tracedata.endpos = self.Entity:GetPos();
tracedata.filter = pl;
local tr = util.TraceLine(tracedata);


local pitch = simplifyangle(ang.p - pl:EyeAngles().p);
local yaw = simplifyangle(ang.y - pl:EyeAngles().y);
//print("Relativity to FOV: Angle("..pitch..", "..yaw..", 0)\n");
if (!tr.HitWorld) then
local dist = pl:GetShootPos():Distance( self.Entity:GetPos() )  
local endtime = FLASH_INTENSITY/dist;
if (endtime > 6) then
endtime = 6;
elseif(endtime < 0.4) then
endtime = 0.4;
end
simpendtime = math.floor(endtime);
tenthendtime = math.floor((endtime-simpendtime)*10);
if(  pitch > -45 && pitch < 45 && yaw > -45 && yaw < 45 ) || (pl:GetEyeTrace().Entity && pl:GetEyeTrace().Entity == self.Entity )then --in FOV
//pl:PrintMessage(HUD_PRINTTALK, "In FOV");
else
//pl:PrintMessage(HUD_PRINTTALK, "Not in FOV");
endtime = endtime/2;
end
if (pl:GetNetworkedFloat("RCS_flashed_time") > CurTime()) then --if you're already flashed
pl:SetNetworkedFloat("RCS_flashed_time", endtime+pl:GetNetworkedFloat("RCS_flashed_time")+CurTime()-pl:GetNetworkedFloat("RCS_flashed_time_start")); --add more to it
else --not flashed
pl:SetNetworkedFloat("RCS_flashed_time", endtime+CurTime());
end
pl:SetNetworkedFloat("RCS_flashed_time_start", CurTime());
end
end
self.Entity:Remove();
end
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 )
self.Entity:SetCollisionGroup( COLLISION_GROUP_WEAPON )

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

function ENT:Think()
end
function ENT:OnTakeDamage()
self:Explode()
end
function ENT:Use()
end
function ENT:StartTouch()
end
function ENT:EndTouch()
end
function ENT:Touch()
end




« Last Edit: February 28, 2011, 02:54:47 PM by Mr. Wepz. »
Cush
Poster

Posts: 79


« Reply #4 on: February 28, 2011, 02:43:40 PM »

Might wanna put  [ code] [ /code] tags around it (Without the spaces in the tags), its hard to read otherwise.
Mr. Wepz.
Poster

Posts: 65


« Reply #5 on: February 28, 2011, 02:55:13 PM »

Done
Mr. Wepz.
Poster

Posts: 65


« Reply #6 on: March 02, 2011, 05:42:36 PM »

Help pls? :3
Bad King Urgrain
Administrator
*****
Posts: 12276



« Reply #7 on: March 02, 2011, 06:18:23 PM »

The weapon has not been converted to TTT's grenade structure at all. Of course it doesn't work properly.

http://www.zombiemaster.org/smf/index.php?topic=10682.msg424997#msg424997

Before you ask: no, I'm not going to walk you through the things you would have to change.
Mr. Wepz.
Poster

Posts: 65


« Reply #8 on: March 02, 2011, 08:22:31 PM »

Hmm maybe somebody else who can tell me what i did wrong? Because weapon_tttbase always worked
Mr. Wepz.
Poster

Posts: 65


« Reply #9 on: March 03, 2011, 02:23:23 PM »

Bad king that tutorial dint help, it still explodes as incend.

This is the code at the moment:

Shared.lua in weapon_ttt_flashbang


if SERVER then
  AddCSLuaFile( "shared.lua" )
 
end

SWEP.HoldType = "grenade"

if CLIENT then
  SWEP.PrintName = "Flashbang"
  SWEP.Slot = 3

  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


Shared.lua in entries

if SERVER then
  AddCSLuaFile("shared.lua")
end

ENT.Type = "anim"
ENT.Base = "ttt_basegrenade_proj"
ENT.Model = Model("models/weapons/w_eq_smokegrenade_thrown.mdl")


AccessorFunc( ENT, "radius", "Radius", FORCE_NUMBER )

function ENT:Initialize()
  if not self:GetRadius() then self:SetRadius(20) end

  return self.BaseClass.Initialize(self)
end

if (CLIENT) then

/*---------------------------------------------------------
Initialize
---------------------------------------------------------*/
function ENT:Initialize()

local Pos = self:GetPos()

timer.Simple(2, function()
local dynamicflash = DynamicLight( self:EntIndex() )

if ( dynamicflash ) then
dynamicflash.Pos = Pos
dynamicflash.r = 255
dynamicflash.g = 255
dynamicflash.b = 255
dynamicflash.Brightness = 5
dynamicflash.Size = 1000
dynamicflash.Decay = 1000
dynamicflash.DieTime = CurTime() + 0.5
end
end)
end

      em:Finish()
  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
---------------------------------------------------------*/
function ENT:OnRemove()
end

/*---------------------------------------------------------
PhysicsUpdate
---------------------------------------------------------*/
function ENT:PhysicsUpdate()
end

/*---------------------------------------------------------
PhysicsCollide
---------------------------------------------------------*/
function ENT:PhysicsCollide(data,phys)
if data.Speed > 50 then
self.Entity:EmitSound(Sound("Flashbang.Bounce"))
end

local impulse = -data.Speed * data.HitNormal * .4 + (data.OurOldVelocity * -.6)
phys:ApplyForceCenter(impulse)
end

function ENT:Explode(tr)
  if SERVER then
    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
Pages: [1]
Zombie Master  |  Other  |  Trouble in Terrorist Town  |  Topic: Question about "weapon_tttbasegrenade" « previous next »
Jump to:  


Login with username, password and session length

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines
Page created in 0.01 seconds with 18 queries.