Author Topic: New scripters ask advanced peeps how to script something  (Read 8002 times)

BC wins

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 39
New scripters ask advanced peeps how to script something
« on: August 13, 2010, 09:36:41 PM »
I made this topic so that I and other new lvl makers can ask you experts (like anik) how to do something in lua

BC wins

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 39
Re: New scripters ask advanced peeps how to script something
« Reply #1 on: August 13, 2010, 09:40:23 PM »
i am trying to make 100 seedlings appear at the moment i scout a planet using the
 OnAsteroidRevealed function
(click to show/hide)


can someone tell me what i am doing wrong

BC wins    

Sniped50

  • Sapling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 97
Re: New scripters ask advanced peeps how to script something
« Reply #2 on: August 14, 2010, 05:40:05 AM »
I don't think you need that 'return' bit. OnAsteroidRevealed(id,owner) is always automatically called every time an asteroid is discovered, no matter how many times it's been called before.

I'm not sure whether that will work, but try it out. There doesn't seem to be anything else wrong with your code on it's own. If it doesn't work, then it's probably a piece of code elsewhere that's the problem (for instance, if you have 3 asteroids, and, like here, you want to add seedlings to asteroid 3, then in fact you should put GetAsteroid(2), because asteroid numbers start at 0, not 1, and go up from there).

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: New scripters ask advanced peeps how to script something
« Reply #3 on: August 15, 2010, 08:15:10 AM »
Did Sniped's suggestion work?

I also think you don't need the Return bit.

Also, if you still can't get it working, the solution (somewhat involved) is to simply switch a variable from false to true when the asteroid is revealed, then catch that in a While loop in the LevelLogic and add the seedlings that way.  You would need to set the value to false again as well to prevent looping and infinite seeds appearing.

...yea, hopefully just removing Return and double-checking the asteroid ID numbers will sort it :>

BC wins

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 39
Re: New scripters ask advanced peeps how to script something
« Reply #4 on: August 16, 2010, 08:18:22 AM »
this is about how to get the 400 seedlings from your test lvl to move properly with the timer
first my whole lvl
(click to show/hide)

and here's the timer bit
(click to show/hide)

Terrial

  • Sapling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 66
Re: New scripters ask advanced peeps how to script something
« Reply #5 on: August 16, 2010, 12:38:16 PM »
An alternative way to write that is:

(click to show/hide)

BC wins

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 39
Re: New scripters ask advanced peeps how to script something
« Reply #6 on: August 16, 2010, 10:03:32 PM »
thanks :)
i'll go see if it works
don't understand the
 Timer = Timer + 15
bit

BC wins

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 39
Re: New scripters ask advanced peeps how to script something
« Reply #7 on: August 16, 2010, 10:12:43 PM »
i had to change the caps in the If
but it says they expect then near =

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: New scripters ask advanced peeps how to script something
« Reply #8 on: August 16, 2010, 10:30:53 PM »
The Timer = Timer + 15 means that the timer will be set to 15 seconds past its previous value.

BC wins

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 39
Re: New scripters ask advanced peeps how to script something
« Reply #9 on: August 17, 2010, 03:36:18 AM »
k thx :)

BC wins

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 39
Re: New scripters ask advanced peeps how to script something
« Reply #10 on: August 17, 2010, 04:23:56 AM »
i have another question
about the function OnAsteroidTaken
I want something to happen with a certain planet when taken over by a certain player regardless of the owner.
Something like
if id == 7 and aggressor == 1 then
   GetAsteroid(7)SendDistance = 5000   
      return
   end

can someone help ? :) 

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: New scripters ask advanced peeps how to script something
« Reply #11 on: August 17, 2010, 05:06:17 AM »
You don't need the return line in any of the Eufloria functions, I think, but definitely not that one. Anyway

Code: [Select]
function OnAsteroidTaken(id, owner)
   if id == 7 and owner == 1 then
      GetAsteroid(7)SendDistance = 5000   
   end
end
should work, yeah.

BC wins

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 39
Re: New scripters ask advanced peeps how to script something
« Reply #12 on: August 17, 2010, 05:22:52 AM »
ok thanks :)

but I want something to happen with a certain planet when taken over by a certain player regardless of the owner.

Terrial

  • Sapling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 66
Re: New scripters ask advanced peeps how to script something
« Reply #13 on: August 17, 2010, 08:19:18 AM »
use this:

(click to show/hide)

This will go into effect every time a new player takes the asteroid

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: New scripters ask advanced peeps how to script something
« Reply #14 on: August 17, 2010, 05:19:53 PM »
"owner" means the NEW owner, as far as I know...

BC wins

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 39
Re: New scripters ask advanced peeps how to script something
« Reply #15 on: August 17, 2010, 05:43:10 PM »
thx terrial
i tried it but the game crashes when i take the asteroid :(
plus i really need it to be player specific as in (Challenger(1))

and i really am confused now is the owner in
function OnAsteroidTaken (id, owner)
the new owner or old owner ?
it would explain why my function are going wrong :D


annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: New scripters ask advanced peeps how to script something
« Reply #16 on: August 17, 2010, 10:44:49 PM »
BC,

Can you clarify what you want to happen.  Using words like "owner" is no good unless you also specify whether they are the owner before or after the asteroid is taken.

Remember that OnAsteroidTaken is run immedietely after the asteroid is taken, therefore it will return the asteroid's owner as being the aggressor, not the empire that lost the asteroid.




Depending on how you want this to work, try one of these:



Code: [Select]
function OnAsteroidTaken(id,owner)

  if id == 7 then

    Pause()
    MessageBox("Asteroid 7 was taken by Empire" .. owner)
    WaitDialog()
    Unpause()

  end

end
This code will display a message box anytime asteroid 7 gets a new owner.




Code: [Select]
function LevelLogic()

  runonce = false
  specificowner = 3  --change as you like, doesn't have to be empire 3

  while GameRunning() do



    if runonce == false and GetAsteroid(7).Owner == specificowner then

      Pause()
      MessageBox("Asteroid 7 was taken by Empire" .. specificowner)
      WaitDialog()
      Unpause()

      runonce = true

    end


    if GetAsteroid(7).Owner ~= 3 then

      runonce = false

    end

  coroutine.yield()
  end

end
This code will display a message box anytime the empire mentioned in "specificowner" captures asteroid 7 - but it won't display a message if a different empire captures it.



Hope this halps.  :>

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: New scripters ask advanced peeps how to script something
« Reply #17 on: August 17, 2010, 11:11:09 PM »
BC's code: (direct copy-paste)
Code: [Select]
if id == 7 and aggressor == 1 then
   GetAsteroid(7)SendDistance = 5000  
      return
   end

I'd guess that s/he wants Asteroid 7 to have a SendDistance of 5000 when captured by by the player.

I'd suggest:
Code: [Select]
OnAsteroidTaken(id, aggressor)
   if id == 7 and aggressor == 1 then
      GetAsteroid(7):SendDistance = 5000  
   end
end

BC, you need a colon ( : ) between the GetAsteroid(7) and SendDistance. I forgot it in the last code I gave you, which might explain why it doesn't work.

EDIT: Stupid smileys.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: New scripters ask advanced peeps how to script something
« Reply #18 on: August 17, 2010, 11:25:05 PM »
I might be wrong, but I think that probably won't work; "aggressor" isn't naturally contained in OnAsteroidTaken.  You would need to use "owner".

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: New scripters ask advanced peeps how to script something
« Reply #19 on: August 17, 2010, 11:38:47 PM »
I know, but that confused BC. Just wondered if aggressor would work if you treated it like owner.

BC, just replace aggressor with owner. Should work then.