Author Topic: Delaying Meteors?  (Read 7876 times)

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Delaying Meteors?
« on: November 02, 2005, 03:18:49 PM »
well I have some code I found and have been using but there seems to be no way I can set when to have it hit. Is there a way? do I have to use another code or put it somewere else?
Code: [Select]
TethysGame::SetMeteor(40,40,5);
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Delaying Meteors?
« Reply #1 on: November 03, 2005, 12:07:01 PM »
looks like your ready for some more coding input from us! :D

To start a meteor ,or any other disaster, you need to define a TimeTrigger:

Code: [Select]
CreateTimerTrigger( 1, 1, time, "function" );
...

SCRIPT_API void function()
{
   TethysGame::SetMeteor(40,40,5);
}
where time is the number of game-ticks, and there are 100 ticks in 1 timemark. The timer starts counting from the moment you define it.
So if you want it to have a meteor at mark 30, then use 3000 for time.
Then if you want a tornade to come just 20 marks after the meteor; change it liek this:
Code: [Select]
CreateTimerTrigger( 1, 1, 3000, "meteor" );
...

SCRIPT_API void meteor()
{
   TethysGame::SetMeteor(40,40,5);
   CreateTimerTrigger( 1, 1, 2000, "quake" );
}

SCRIPT_API void quake()
{
   TethysGame::SetQuake(40,40,1);
}
Please read the file TethysGame.h to look at all possible triggers. i think there's also some help available on the wiki (if it ever comes back online  <_< )
 
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Delaying Meteors?
« Reply #2 on: November 03, 2005, 12:14:30 PM »
Quote
Please read the file TethysGame.h to look at all possible triggers. i think there's also some help available on the wiki (if it ever comes back onlineĀ  )

yea I headed over there the other day and could not get to it  <_<

Edit: I  ended up with 6 compile errors when I tried to use it

 
« Last Edit: November 03, 2005, 01:00:06 PM by spirit1flyer »
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Delaying Meteors?
« Reply #3 on: November 03, 2005, 01:02:47 PM »
okay I managed to rid myself of all the errors but this one.

Main.cpp(90) : error C2143: syntax error : missing ';' before '...'


Please note, I don't know that much at all about C++ I am learning on the job. and without all the code posted or the help that has been given to me I would not know were to begin coding or how to make a multi game into a colony game

Edit:  I tried adding ;  before the three dots but it did not work
« Last Edit: November 03, 2005, 01:03:39 PM by spirit1flyer »
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Delaying Meteors?
« Reply #4 on: November 03, 2005, 05:16:33 PM »
oh the ... means: "put your other code here"

that 1 line CreateTimerTrigger goes in your InitProc
The other functions (with SCRIPT_API) are outside InitProc, like above it, or somewhere below it. It doesnt really matter much right now where u put them.
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline BlackBox

  • Administrator
  • Hero Member
  • *****
  • Posts: 3093
Delaying Meteors?
« Reply #5 on: November 03, 2005, 07:44:20 PM »
Correction: CreateTimeTrigger (not Timer)

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Delaying Meteors?
« Reply #6 on: November 03, 2005, 09:10:40 PM »
well it compiles now but I get whenever I try to use the DLL file. The colony game still runs it just does not have the meteor ever come. anyone know why?
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Delaying Meteors?
« Reply #7 on: November 03, 2005, 09:21:56 PM »
The last parameter to the trigger creation function is the name of an exported function from your DLL. That message box pops up if (when OP2 requests your function's address) the Windows API can't find an exported function from your DLL with the name.

You have to make sure you have a function that's properly exported from your DLL with the name you've given to OP2 in the create trigger call.

Code: [Select]
CreateTimerTrigger( 1, 1, time, "function" );

SCRIPT_API void function()
In those two lines Eddy gave, note the last parameter to CreateTimeTrigger is "function". This MUST match up with the exported function name seen in the second line. The "SCRIPT_API" part tells the compiler this function is to be exported from your DLL (so it can be found when the lookup is done). It is exported using the undecorated function name. In this case it was "function". If you wanted to have a callback named "Meteor", you use this:
Code: [Select]
SCRIPT_API void Meteor()

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Delaying Meteors?
« Reply #8 on: November 03, 2005, 09:33:26 PM »
Code: [Select]
CreateTimeTrigger( 1, 1, 300, "Meteor" ); 

Trigger population = CreateResourceTrigger(1, 1, resColonists, 400, 0, mpGreaterEqual, "NoResponseToTrigger");

CreateVictoryCondition(1, 0, population, "Have 400 Colonists.");


return 1; // return 1 if OK; 0 on failure
}
SCRIPT_API void Meteor()
{
  TethysGame::SetMeteor(40,40,5);
  
}

I have it that way already. don't I?
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Delaying Meteors?
« Reply #9 on: November 03, 2005, 09:36:38 PM »
It looks good to me. Maybe the problem is from elsewhere? Maybe do a text search for "Meteor". The error message did say "data refernce" after all. (I thought that was a little odd, but it's been a while since I've seen that dialog).
 

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Delaying Meteors?
« Reply #10 on: November 03, 2005, 09:42:33 PM »
its only in those three places  :blink:   maybe Hacker knows?
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter

Offline Betaray

  • Administrator
  • Hero Member
  • *****
  • Posts: 2897
Delaying Meteors?
« Reply #11 on: November 03, 2005, 10:00:33 PM »
you should make a coloney game called turkey shoot, where metiers just keep falling in random places lol

that would keep everyone on their toes!
I am the nincompoop, I eat atomic bombs for breakfest, fusion bombs for lunch, and anti-matter bombs for dinner

I just hope they don't explode

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Delaying Meteors?
« Reply #12 on: November 03, 2005, 10:02:58 PM »
I can do that as soon as I get my current problem fixed  ;)  
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Delaying Meteors?
« Reply #13 on: November 04, 2005, 06:57:34 AM »
If you have installed MSVC6, i assume you also have Dependancy walker with it:  Right-click your mission DLL, and select "View dependancies" - then check on the righthand list, to see if the "Meteor" function is really exported (should show an "e" icon next to it).

Also: keep in mind, that C is a case sensitive language: this means that Meteor differs from meteor. They can be 2 completely different functions.

If that still doesn't solve the problem, it may be necessary to paste the whole C file here (or send to someone thru pm or email)
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Delaying Meteors?
« Reply #14 on: November 04, 2005, 09:33:08 AM »
Quote
If you have installed MSVC6, i assume you also have Dependancy walker with it: Right-click your mission DLL, and select "View dependancies" - then check on the righthand list, to see if the "Meteor" function is really exported (should show an "e" icon next to it).
I don't I just have the free downloaded one hacker put together

Quote
Also: keep in mind, that C is a case sensitive language: this means that Meteor differs from meteor. They can be 2 completely different functions.

If that still doesn't solve the problem, it may be necessary to paste the whole C file here (or send to someone thru pm or email)
I am pretty sure the Meteors are all the same but who knows.   So here is my code

Edit: code taken out.  
Its really strange but it just started working  :blink:  I nearly went crazy when I had the meteor hit my units at the wrong time until I remembered something about the time offset  :P

Thanks for the help

spirit
« Last Edit: November 04, 2005, 09:40:51 AM by spirit1flyer »
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Delaying Meteors?
« Reply #15 on: November 04, 2005, 11:13:12 AM »
Okay I have set 3 meteors to come down with the time triggers but I saw that everytime the time trigger goes off all three meteors come down at the same time  :o

does anyone know how to make it so the meteors will come down one at a time?

oh and I tried using Quake and Earthquake but the earthquake never came? am I using the wrong name?


spirit
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Delaying Meteors?
« Reply #16 on: November 04, 2005, 12:05:09 PM »
Quote
does anyone know how to make it so the meteors will come down one at a time?
2 ways of doing that:
  • Create a repeating trigger. Use param 2 for that. Normally you've got it set to 1 for "1-time". If you set it to 0 it'll run again, and again and again..
    As an added thing, you can use 2 time params with the TimerTirgger: the trigger will fire randomly within the 2 specified params. This will create a trigger to fire over and over every 3 to 5 marks:
    Code: [Select]
    CreateTimeTrigger( 1, 0, 300, 500, "Meteor" ); 
  • The other option is to include a new trigger within the callback-function, like this:
    Code: [Select]
    SCRIPT_API void Meteor()
    {
       TethysGame::SetMeteor(40,40,5);
       CreateTimeTrigger( 1, 1, 300, "Meteor" );
    }
I would sugguest you go with the first method, coz the 2nd one could (=will) cause a lot of trouble, when you create a lot of triggers. This is because the trigger-system as created by Dynamix is capable of handling upto 127 triggers and/or groups. Once you've created 128 triggers, the game will horribly crash! Trust me - you don't want this to happen: i had it happen with one of my missions,. and it took me days to figure out what was causing it, and several weeks to correct the problem!
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Delaying Meteors?
« Reply #17 on: November 04, 2005, 12:50:52 PM »
thats not what I was asking about.  I have 2 meteors coming down.  I want both meteors to come down but not at the same time.  I would like to make it so the meteors come at multiple spots. but with time between each meteor.
Thats great to know how to make them come a second time and I would have probly asked about that later.
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Delaying Meteors?
« Reply #18 on: November 04, 2005, 04:48:56 PM »
Make a repeating time trigger. Disable it once it's fired 3 times.

You can use a static variable declared in your trigger function if you need to count there (or a global variable, but that's kinda gross). You can use a global variable for the Trigger.

To make a global variable, move the declaration (eg. Trigger myTrigger;) outside of any function (preferably at the top of your source file, after the #includes, but before your first defined function. To make a static variable, declare it inside a function like you would any other variable, but add static in front, and be sure to include an initializer.
Code: [Select]
static int count = 0;

I'd recommend that you disable the trigger once it's fired 3 times rather than simply stop executing the body of your callback function. Otherwise, the trigger will still be taking processing power every cycle to cehck if it fires, and will keep calling the callback to do nothing.



Edit: ... or just create three seperate triggers with three seperate callback functions (actually you can probably use the same callback for all of them), and change the time associated with each trigger slightly. Easier, but less flexible.
« Last Edit: November 04, 2005, 04:51:25 PM by Hooman »

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Delaying Meteors?
« Reply #19 on: November 04, 2005, 07:10:14 PM »
I am more of a copy and past type of guy  :P

I learn how to code things but I always need to know exactly what to put in and were to put it. After I get that I will be able to do it anyday.

I tried what you said and I must have done something wrong because I did not get meteors coming down  :unsure:  
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Delaying Meteors?
« Reply #20 on: November 04, 2005, 09:33:38 PM »
Code: [Select]
CreateTimeTrigger( 1, 0, 300, "Meteor" );  
CreateTimeTrigger( 1, 0, 500, "Meteor" );  
CreateTimeTrigger( 1, 0, 800, "Meteor" );  

Code: [Select]
SCRIPT_API void Meteor()
{
  TethysGame::SetMeteor(40,40,5);
}

That will create 3 meteors, at location (40, 40), at ticks 300, 500, and 800.

The only thing left to do, might be to customize the x and y coordinates? Oh, and I think the last parameter is only really valid for a range of 0-3 or so? (I don't remember exactly). A value outside that range just makes the game randomly select a value within range for you.
 

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Delaying Meteors?
« Reply #21 on: November 04, 2005, 09:40:06 PM »
thank you but I would like to have them at mutiple locations but each one at a Tick of its own.  How would I go about doing so?  
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Delaying Meteors?
« Reply #22 on: November 05, 2005, 01:54:51 AM »
The easy way:

Code: [Select]
CreateTimeTrigger( 1, 0, 300, "Meteor1" );  
CreateTimeTrigger( 1, 0, 500, "Meteor2" );  
CreateTimeTrigger( 1, 0, 800, "Meteor3" );  


Code: [Select]
SCRIPT_API void Meteor1()
{
 TethysGame::SetMeteor(40,40,1);
}  
SCRIPT_API void Meteor2()
{
 TethysGame::SetMeteor(50,50,1);
}  
SCRIPT_API void Meteor3()
{
 TethysGame::SetMeteor(60,60,1);
}  

Or you could just use random numbers instead of hardcoded locations? Probably better if you use a bit of randomization. How complicated do you want to make this?
 

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Delaying Meteors?
« Reply #23 on: November 05, 2005, 09:24:16 AM »
Thank you

I think this code will do everything I want right now it works just like I wanted.


Thanks again


spirit
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Delaying Meteors?
« Reply #24 on: November 05, 2005, 03:24:46 PM »
Be advised: hooman's code works fine, but creates repeating triggers!
Param 2 (the zero) means: repeat indefinatly...
set it to 1 for a 1-time trigger (or use the counting as he suggested: each MeteorX function should have its own static counter btw, like count1 in Meteor1, count2 in Meteor2 and count3 in Meteor3)
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz