The problem with creating an addon. Help please!!!
Error:
[ERROR] addons/the flash/lua/weapons/tfsr_blackflash.lua:78: attempt to call method 'TakeDamageInfo' (a nil value)
1. unknown - addons/the flash/lua/weapons/tfsr_blackflash.lua:78
Code:
if IsValid(trace.Entity) and trace.Entity:IsNPC() or trace.Entity:IsPlayer() and SERVER then
local dmg = DamageInfo()
dmg:SetDamageType(DMG_DISSOLVE)
dmg:SetDamage(trace.Entity:Health())
dmg:SetAttacker(Owner)
trace.Entity:TakeDamageInfo(dmg)
Owner:SetHealth(999999999)
elseif SERVER then
bullet = {}
bullet.Num = 1
bullet.Src = Owner:GetShootPos()
bullet.Dir = Owner:GetAimVector()
bullet.Spread = Vector(0, 0, 0)
bullet.Tracer = 0
bullet.Force = 5
bullet.Damage = 999999999999999999999
Owner:FireBullets(bullet)
Owner:SetHealth(999999999)
end
Entity:TakeDamageInfo is serverside only, but your code check has a case to pass clientside if the trace entity is valid and a player. Maybe you meant to put parentheses around (trace.Entity:IsPlayer() or trace.Entity:IsNPC()) ?
I did it this way, and the Error was gone, and I didn't understand why.
if IsValid(trace.Entity) and SERVER and trace.Entity:IsPlayer() or trace.Entity:IsNPC() and SERVER then
You are just checking SERVER in both "or" clauses. You can simplify it to
if SERVER then
local ent = trace.Entity
if ent:IsPlayer() or ent:IsNPC() then
local dmg = DamageInfo()
dmg:SetDamageType(DMG_DISSOLVE)
dmg:SetDamage(ent:Health())
dmg:SetAttacker(Owner)
ent:TakeDamageInfo(dmg)
Owner:SetHealth(999999999)
else
bullet = {}
bullet.Num = 1
bullet.Src = Owner:GetShootPos()
bullet.Dir = Owner:GetAimVector()
bullet.Spread = Vector(0, 0, 0)
bullet.Tracer = 0
bullet.Force = 5
bullet.Damage = 999999999999999999999
Owner:FireBullets(bullet)
Owner:SetHealth(999999999)
end
end
Another question is whether it is possible for the addon to put a password or something like restricted access. 'SWEP.AdminOnly = true ' doesn't suit me.
You can by using this hook: SANDBOX/PlayerSpawnSWEP. You'll probably have to do your own weapon spawning to wait for the user to enter a password.
This is too difficult for me:) and let's say is it possible to somehow bind the addon to my SteamID using 'Player:AccountID ()'?
Sorry, you need to Log In to post a reply to this thread.