Can someone tell me, why this Entity doesnt collide with the player?
[CODE]
AddCSLuaFile()
ENT.Type = "anim"
ENT.Model = Model("models/props/cs_italy/bananna.mdl")
AccessorFunc( ENT, "thrower", "Thrower")
local planted = false
local plantingTime = 0
function ENT:Initialize()
self:SetModel(self.Model)
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_BBOX)
self:SetCollisionGroup(COLLISION_GROUP_NONE)
plantingTime = CurTime()+1
end
function ENT:SetDetonateExact(t)
end
function ENT:Think()
if plantingTime < CurTime() then
if planted == false then
print("A Banana has been planted")
end
planted = true
end
end
function ENT:SetThrower(ply)
end
function ENT:PhysicsCollide( coldata, collider)
if planted then
if IsValid(collider:GetEntity()) then
local entity = collider:GetEntity()
print("Touch")
if entity:IsPlayer() then
print("Touch is Player")
local playerdir = entity:GetVelocity()
local nvelocity = Vector( playerdir.x * 10 , playerdir.y * 10 , 1)
entity:SetVelocity(nvelocity)
self:Remove()
end
end
end
end
[/CODE]
Try this
[lua]
AddCSLuaFile()
ENT.Type = "anim"
ENT.Model = Model("models/props/cs_italy/bananna.mdl")
AccessorFunc( ENT, "thrower", "Thrower")
local planted = false
local plantingTime = 0
function ENT:Initialize()
self:SetModel(self.Model)
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid( SOLID_VPHYSICS )
local phys = self:GetPhysicsObject()
if phys:IsValid() then
phys:Wake()
end
plantingTime = CurTime()+1
end
function ENT:SetDetonateExact(t)
end
function ENT:Think()
if plantingTime < CurTime() then
if planted == false then
print("A Banana has been planted")
end
planted = true
end
end
function ENT:SetThrower(ply)
end
function ENT:PhysicsCollide( coldata, collider)
if planted then
if IsValid(collider:GetEntity()) then
local entity = collider:GetEntity()
print("Touch")
if entity:IsPlayer() then
print("Touch is Player")
local playerdir = entity:GetVelocity()
local nvelocity = Vector( playerdir.x * 10 , playerdir.y * 10 , 1)
entity:SetVelocity(nvelocity)
self:Remove()
end
end
end
end
[/lua]
Well physics work. It falls down, can be picked up and collides with other objects. With the exception of the player.
[editline]28th September 2016[/editline]
Tried anyway. Didn't work. Made it act very strange.
By the way: The entity is being thrown by a SWEP.
Via ttt_base_grenade.lua
[editline]28th September 2016[/editline]
I meant weapon_tttbasegrenade.lua (gamemode/terrortown/entities/weapons)
Do you have CSS mounted?
yes
[editline]28th September 2016[/editline]
The only thing that doesnt work is the collision with the player. Everything else works.
did you try the code given above? Does it print anything?
I tried it. But it just made the physics a bit glitchy.
Keep in mind, that this entity is generated( Thrown ) by ttt's "weapon_ttt_basegrenadelua".
[editline]29th September 2016[/editline]
Just in case: Here is the code from weapon_ttt_basegrenade.lua
[CODE]
function SWEP:CreateGrenade(src, ang, vel, angimp, ply)
local gren = ents.Create(self:GetGrenadeName())
if not IsValid(gren) then return end
gren:SetPos(src)
gren:SetAngles(ang)
-- gren:SetVelocity(vel)
gren:SetOwner(ply)
gren:SetThrower(ply)
gren:SetGravity(0.4)
gren:SetFriction(0.2)
gren:SetElasticity(0.45)
gren:Spawn()
gren:PhysWake()
local phys = gren:GetPhysicsObject()
if IsValid(phys) then
phys:SetVelocity(vel)
phys:AddAngleVelocity(angimp)
end
-- This has to happen AFTER Spawn() calls gren's Initialize()
gren:SetDetonateExact(self:GetDetTime())
return gren
end
[/CODE]
[editline]29th September 2016[/editline]
Got the Problem. Seems like SetThrower(...) by ttt_weapon_basegrenade makes it uncollidable to the thrower.
gren:SetOwner(ply) does.
Sorry, you need to Log In to post a reply to this thread.