Jump to content

Recommended Posts

Posted

Just trying to understand using functions between Scripts.

 

Code is taken from Darkness Awaits but cut down a bit.

 

self:AttackEnemy() is called in the goblin Script.

 

but I get attempt to index local 'Newplayer' (a nil value)

 

 

In Newplayer Script I have

function Script:TakeDamage(damage)
if self.Health>0 then
 self.Health = self.Health - damage
end
end

 

in Goblin Script I have

function Script:AttackEnemy(Newplayer)
local entitypos = Newplayer.entity:GetPosition(true)
local pos = Transform:Point(entitypos.x,entitypos.y,entitypos.z,nil,self.entity)
pos = pos * self.entity:GetScale()
pos.z = pos.z * -1
if pos.z>0 and pos.z<self.attackRange then
 if pos.z>math.abs(pos.x) then
  Newplayer:TakeDamage(10)
end  end
end

Elite Cobra Squad

Posted

Sorted, studied the code bit by bit and and read the the explanation of the

EnemyAttackForEachEntityInAABBDoCallback(entity,extra)

by Chris Vossen in a past thread, another hurdle is overcome.

  • Upvote 1

Elite Cobra Squad

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...