Author Topic: if Attacked?  (Read 5780 times)

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
if Attacked?
« on: February 02, 2011, 10:04:24 PM »
Is there anything that allows you to check if there is enemies on a certain asteroid?

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: if Attacked?
« Reply #1 on: February 02, 2011, 10:14:34 PM »
Yes there is! :>

For example:

Code: [Select]
if GetAsteroid(0):GetNumSeedlings(2) > 1 then
-- do something cool!
end

That would check Asteroid ID 0, to see if there are more than 1 seedlings belonging to Empire 2.
:>

(so at least TWO seedlings would be required to activate this If... because it's looking for values greater than 1)

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: if Attacked?
« Reply #2 on: February 02, 2011, 10:19:03 PM »
if you have
Code: [Select]
function CheckAttacks()

for i = 0,99 do

local a = GetAsteroid(i)
local b = a.Owner
local c = a.ID

if b == GetEmpire(1) then

if a:GetNumSeedlings(0) > 0 or a:GetNumSeedlings(2) > 0 or a:GetNumSeedlings(3) > 0 then

local timer = GetGameTime() + 0.5

while GetGameTime() < timer do

SetBackdropColor(122,0,0)
coroutine.yield()

end
SetBackdropColor(br,bg,bb)

end

end

end

end

it don't seem to work, any help on fixing the problem? :)

(Trying to add an attack warning for my map, since it is so large :D)

EDIT: maybe the owner thing for "b" should be considered as integer not empire result?

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: if Attacked?
« Reply #3 on: February 02, 2011, 10:21:55 PM »
You are correct.

Code: [Select]
if b == GetEmpire(1) then
Should really be this:

Code: [Select]
if b == 1 then


Bizarelly, a.owner returns a number object, rather than an empire object.  If you wanted an empire object instead you would need to use GetEmpire(b).


Hope this helps :>  I'll see if I can spot anything else as well.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: if Attacked?
« Reply #4 on: February 02, 2011, 10:23:44 PM »
Code: [Select]
if b == GetEmpire(1) then
Should really be this:

Code: [Select]
if b == 1 then


Bizarelly, a.owner returns a number object, rather than an empire object.  If you wanted an empire object instead you would need to use GetEmpire(b).


Hope this helps :>  I'll see if I can spot anything else as well.

Yeah, fixed and working(tried before you posted). Thx, amybe releasing my map soon... Don't know cause my immagination just jumps around atm xD

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: if Attacked?
« Reply #5 on: February 02, 2011, 10:27:45 PM »
I had that problem too, with "Return to Fluffy Land", which is the first level where I tried some proper scripting.  The level got more and more crazy as you went through it (it was linear), as I learned more about the language and tried out all the different commands.  I got a taste of what was to come... it bites you and doesn't let go.. :>

Looking forward to seeing your first release! :>

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: if Attacked?
« Reply #6 on: February 02, 2011, 10:28:56 PM »
I just hope my map wont lag D:

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: if Attacked?
« Reply #7 on: February 02, 2011, 10:31:40 PM »
Lag can be addressed, too.. :>  There's usually some inefficiencies sneak into the algorithm of whatever you are doing, plus there's always options like local variables (which I note you are already using), avoiding expensive operations like math.sqrt (heh, squirt...  actually it stands for square root), etc.
Give it some thorough testing when you're done, and if it's too laggy then we can help with that as well.. :>

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: if Attacked?
« Reply #8 on: February 02, 2011, 10:39:11 PM »
If I want it to have a text flashing in the upper left corner of the screen, how do I do that? (Flashin red and white in a gray box :))

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: if Attacked?
« Reply #9 on: February 03, 2011, 01:00:49 AM »
There's no support for drawing text, as far as I know.  You'd have to carve out the letters yourself using DrawLine commands in function LevelDraw().

If you were going to the trouble of all that, you might as well just make a function that will let you write any series of characters from the whole alphabet.  :>  It's a project...

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: if Attacked?
« Reply #10 on: February 03, 2011, 01:51:38 AM »
I'll might do that after my third map, after thinking of it it will be a big project(atleast for me xD)

Edit: I actually did this o.o


if it is offending: sorry :/
« Last Edit: June 22, 2011, 05:21:17 AM by Aino »