Hi, I'm trying to code something called a magic melon as a request from somebody on the server I code for. I'm having trouble finishing this coding, and would love if anyone could help/point out what's wrong. If you don't have interest in helping, this would be the time to exit the post; Otherwise, here's what my request was to make - I'm supposed to code something called a "Magic Melon" which is thrown down as the melon prop (For TTT) and when damaged to 0, then it erupts a ton of dildos (Which I've successfully managed to do) and then explode like a tripmine/c4. The issue I'm having isn't with the actual prop/or getting the dildos to explode from the melon, it's getting the explosion to damage players around. The idea would to make it do 200 damage to anyone in the near vicinity, but the issue right now is getting the explosion to kill the players around, and give credit to the traitor who placed down the melon. Here's the code I've got so far -
Swep (entities\weapons\weapon_ttt_magic_melon\shared.lua):
if SERVER then
AddCSLuaFile( "shared.lua" )
end
SWEP.HoldType = "normal"
if CLIENT then
SWEP.PrintName = "Magic Melon"
SWEP.Slot = 6
SWEP.Author = "Strelok"
SWEP.ViewModelFOV = 10
SWEP.EquipMenuData = {
type = "item_weapon",
name = "Magic melon",
desc = "It will shock your very soul"
};
SWEP.Icon = "VGUI/ttt/icon_health"
end
SWEP.Base = "weapon_tttbase"
SWEP.Kind = WEAPON_EQUIP
SWEP.CanBuy = {ROLE_TRAITOR} -- only detectives can buy
SWEP.LimitedStock = false
SWEP.ViewModel = "models/weapons/v_crowbar.mdl"
SWEP.WorldModel = "models/props_junk/watermelon01.mdl"
SWEP.DrawCrosshair = false
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = true
SWEP.Primary.Ammo = "none"
SWEP.Primary.Delay = 1.0
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = true
SWEP.Secondary.Ammo = "none"
SWEP.Secondary.Delay = 1.0
SWEP.AllowDrop = false
SWEP.NoSights = true
function SWEP:Reload()
end
function SWEP:Initialize()
end
function SWEP:Think()
end
function SWEP:OnDrop()
self:Remove()
end
function SWEP:PrimaryAttack()
self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
self:BombDrop()
end
function SWEP:SecondaryAttack()
self.Weapon:SetNextSecondaryFire( CurTime() + self.Secondary.Delay )
self:BombDrop()
end
local throwsound = Sound( "Weapon_SLAM.SatchelThrow" )
function SWEP:BombDrop()
if SERVER then
local ply = self.Owner
if not IsValid(ply) then return end
local vsrc = ply:GetShootPos()
local vang = ply:GetAimVector()
local vvel = ply:GetVelocity()
local vthrow = vvel + vang * 200
local mbomb = ents.Create("ttt_melonp")
if IsValid(mbomb) then
mbomb:SetPos(vsrc + vang * 10)
mbomb:Spawn()
mbomb:PhysWake()
local phys = mbomb:GetPhysicsObject()
if IsValid(phys) then
phys:SetVelocity(vthrow)
end
self:Remove()
self.Planted = true
end
end
self.Weapon:EmitSound(throwsound)
end
function SWEP:Deploy()
if SERVER and IsValid(self.Owner) then
self.Owner:DrawViewModel(false)
end
return true
end
function SWEP:DrawWorldModel()
end
function SWEP:DrawWorldModelTranslucent()
end
--------------------------------------------------------------------------------------------------------------------------------------------
Entity Code(entities\entities\ttt_melonp\shared.lua) :
if SERVER then
AddCSLuaFile("shared.lua")
end
ENT.Type = "anim"
ENT.Model = Model("models/props_junk/watermelon01.mdl")
ENT.Stuck = false
ENT.Weaponised = false
ENT.PunchMax = 6
ENT.PunchRemaining = 6
function SWEP:Reload()
end
function ENT:Initialize()
if SERVER then
self.Entity:SetHealth(50)
self.Entity:SetModel("models/props_junk/watermelon01.mdl")
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
self.Entity:DrawShadow(false)
self.Entity:SetCollisionGroup(COLLISION_GROUP_WORLD)
--local phys = self.Entity:GetPhysicsObject():EnableMotion(false)
self:StartEffects()
self:Explosive()
end
end
function SWEP:Think()
end
ENT.OurHealth = 50
function ENT:OnTakeDamage(dmg)
self:TakePhysicsDamage(dmg)
if(self.OurHealth <= 0) then return; end
self.OurHealth = self.OurHealth - dmg:GetDamage()
if(self.OurHealth <= 0) then
self:Explosive()
self:Remove()
end
end
function ENT:SetDamage()
self:SetDamage(500)
end
local model = "models/jaanus/dildo.mdl"
function ENT:Explosive()
if SERVER then
for i=1, 50 do
local dildo = ents.Create ("prop_physics")
dildo:SetModel (model)
dildo:SetPos(self:GetPos())
dildo:Spawn()
end
local phexp = ents.Create("env_explosion")
if IsValid(phexp) then
phexp:SetPos(self:GetPos())
phexp:SetKeyValue("magnitude", 3000)
phexp:SetKeyValue("radius", 3000)
phexp:SetKeyValue("spawnflags", 1 + 2)
phexp:Spawn()
phexp:Fire("Explode", "", 0)
end
local phyexp = ents.Create("env_physexplosion")
phyexp:SetPos(self:GetPos())
phyexp:SetKeyValue("magnitude", 100)
phyexp:SetKeyValue("radius", 128)
phyexp:SetKeyValue("spawnflags", 1 + 2)
phyexp:Spawn()
phyexp:Fire("Explode", "", 0)
local norm = self:GetAngles():Up() * -1
local position = self:GetPos()
local damage = 80
local radius = 1024
local attacker = self:GetOwner()
local inflictor = self.Entity
util.BlastDamage(position, damage, radius, attacker, inflictor)
local effect = EffectData()
effect:SetStart(self:GetPos())
effect:SetOrigin(self:GetPos())
effect:SetNormal(norm * -1)
effect:SetRadius(16)
effect:SetScale(1)
util.Effect("ManhackSparks", effect, true, true)
end
end
That's it. Hopefully somebody could help me with the coding, and fix it to where the explosions do damage to players nearby. Thanks so much for reading and I look forward to seeing some of the responses I get. :) Have a nice day
First off everything about this thread is fishy. Although I will help you.
Future reference, lua tags are friendly.
[lua]
local phexp = ents.Create("env_explosion")
if IsValid(phexp) then
phexp:SetPos(self:GetPos())
phexp:SetKeyValue("magnitude", 3000)
phexp:SetKeyValue("radius", 3000)
phexp:SetKeyValue("spawnflags", 1 + 2)
phexp:Spawn()
phexp:Fire("Explode", "", 0)
end
local phyexp = ents.Create("env_physexplosion")
phyexp:SetPos(self:GetPos())
phyexp:SetKeyValue("magnitude", 100)
phyexp:SetKeyValue("radius", 128)
phyexp:SetKeyValue("spawnflags", 1 + 2)
phyexp:Spawn()
phyexp:Fire("Explode", "", 0)
[/lua]
Look up env_explosion on google, it will tell you what the flags you have set mean. You have flags 1 and 2 set.
Anyways the fix to this all, delete those lines above, and replace them with this.
[lua]
local phyexp = ents.Create("env_physexplosion")
phyexp:SetPos(self:GetPos())
phyexp:SetKeyValue("magnitude", 200)
phyexp:SetKeyValue("radius", 256)
phyexp:SetKeyValue("spawnflags", 2)
phyexp:Spawn()
phyexp:Fire("Explode", "", 0)
[/lua]
I strongly urge you to read the page on env_explosions. This will also help with fine tuning your explosion and adding unique flags.
[QUOTE=find me;41912412]First off everything about this thread is fishy. Although I will help you.
Future reference, lua tags are friendly.
[lua]
local phexp = ents.Create("env_explosion")
if IsValid(phexp) then
phexp:SetPos(self:GetPos())
phexp:SetKeyValue("magnitude", 3000)
phexp:SetKeyValue("radius", 3000)
phexp:SetKeyValue("spawnflags", 1 + 2)
phexp:Spawn()
phexp:Fire("Explode", "", 0)
end
local phyexp = ents.Create("env_physexplosion")
phyexp:SetPos(self:GetPos())
phyexp:SetKeyValue("magnitude", 100)
phyexp:SetKeyValue("radius", 128)
phyexp:SetKeyValue("spawnflags", 1 + 2)
phyexp:Spawn()
phyexp:Fire("Explode", "", 0)
[/lua]
Look up env_explosion on google, it will tell you what the flags you have set mean. You have flags 1 and 2 set.
Anyways the fix to this all, delete those lines above, and replace them with this.
[lua]
local phyexp = ents.Create("env_physexplosion")
phyexp:SetPos(self:GetPos())
phyexp:SetKeyValue("magnitude", 200)
phyexp:SetKeyValue("radius", 256)
phyexp:SetKeyValue("spawnflags", 2)
phyexp:Spawn()
phyexp:Fire("Explode", "", 0)
[/lua]
I strongly urge you to read the page on env_explosions. This will also help with fine tuning your explosion and adding unique flags.[/QUOTE]
Wow, didn't expect for that much help, thank you so much; Don't know what was fishy about it (Prob my post count=1) but I don't use facepunch much and wanted to get some help with this issue. Thanks a ton! :)
Sorry, you need to Log In to post a reply to this thread.