Home » Renegade Discussions » Mod Forum » Timer_Expired
Timer_Expired [message #371542] |
Wed, 11 February 2009 04:18 |
|
Omar007
Messages: 1711 Registered: December 2007 Location: Amsterdam
Karma: 0
|
General (1 Star) |
|
|
Is there a way to use the Timer_Expired inside the Enter part of a script??
small sample of what i mean:
void MyScript::Enter
{
Commands->Start_Timer();
Timer_Expired //want to call it here
{
//rest of code
}
}
Instead of
void MyScript::Enter
{
Commands->Start_Timer();
}
void MyScript::Timer_Expired
{
//rest of code
}
EDIT: Now im already asking would this:
Kill_Enemy_Buildings_By_Team(0)
Be a better solution than:
Guess this would also work if you don't run a Dedicated Server
[Updated on: Wed, 11 February 2009 04:21] Report message to a moderator
|
|
|
Re: Timer_Expired [message #371554 is a reply to message #371542] |
Wed, 11 February 2009 06:13 |
|
jnz
Messages: 3396 Registered: July 2006 Location: 30th century
Karma: 0
|
General (3 Stars) |
|
|
Quote: |
void MyScript::Enter(GameObject *o, GameObject *e)
{
Commands->Start_Timer();
Timer_Expired //want to call it here
{
//rest of code
}
}
|
No, not possible.
You can do this, however:
Quote: |
void MyScript::Enter(GameObject *o, GameObject *e)
{
Commands->Start_Timer(o, this, 123.123, 10);
}
void MyScript::Timer_Expired(GameObject *o, int number)
{
if(number == 10)
{
//do your stuff here
}
}
|
As for the other thing;
Kill_Enemy_Buildings_By_Team(0)
Is much better, if your server is setup for it.
|
|
|
Re: Timer_Expired [message #371565 is a reply to message #371554] |
Wed, 11 February 2009 06:58 |
|
Omar007
Messages: 1711 Registered: December 2007 Location: Amsterdam
Karma: 0
|
General (1 Star) |
|
|
RoShamBo wrote on Wed, 11 February 2009 14:13 |
You can do this, however:
Quote: |
void MyScript::Enter(GameObject *o, GameObject *e)
{
Commands->Start_Timer(o, this, 123.123, 10);
}
void MyScript::Timer_Expired(GameObject *o, int number)
{
if(number == 10)
{
//rest of code
}
}
|
|
Yea the problem of this is that after the Timer_Start i use receive info of the user that entered the zone. Can i call this in this part like this than??:
void MyScript::Timer_Expired(GameObject *obj, GameObject *enter, int number)
{
if(number == Get_Int_Parameter("TimerNumber"))
{
playerid = Get_ID(enter)
//rest of code
}
}
[Updated on: Wed, 11 February 2009 07:01] Report message to a moderator
|
|
|
Re: Timer_Expired [message #371572 is a reply to message #371565] |
Wed, 11 February 2009 07:32 |
|
Jerad2142
Messages: 3812 Registered: July 2006 Location: USA
Karma: 6
|
General (3 Stars) |
|
|
void MyScript::Enter(GameObject *o, GameObject *e)
{
Commands->Start_Timer(o, this, 123.123, 10);
playerid = Get_ID(enter)
}
void MyScript::Timer_Expired(GameObject *obj, GameObject *enter, int number)
{
if(number == Get_Int_Parameter("TimerNumber"))
{
GameObject *enterer = Commands->Find_Object(playerid);
//rest of code
}
}
void MyScript::Register_Auto_Save_Variables()
{
Auto_Save_Variable(1,5,&playerid);
}
You'll have to investigate into arrays if you want the zone to ever be able to handle more then one person, because if thats a 60 second timer, the last id will be overridden before it is put to use if someone hops in.
Visit Jerad's deer sweat shop
[Updated on: Wed, 11 February 2009 07:32] Report message to a moderator
|
|
|
Re: Timer_Expired [message #371576 is a reply to message #371542] |
Wed, 11 February 2009 07:58 |
|
Omar007
Messages: 1711 Registered: December 2007 Location: Amsterdam
Karma: 0
|
General (1 Star) |
|
|
When im home i'll paste some more of the code because it's going to be pritty complicated to get Enter into the Timer_Expired part.
Also soon (this afternoon) i'll have a showoff on the ModDB on the Tiberium Redux page of the code so far. Everything is working except this second timer (yes this script uses 2 timers xD )
Seems i have to rewrite the code for a big part if i have to move my proccesing of data from the void MyScript::Enter to void MyScript::Timer_Expired
[Updated on: Wed, 11 February 2009 07:59] Report message to a moderator
|
|
|
Re: Timer_Expired [message #371579 is a reply to message #371576] |
Wed, 11 February 2009 08:14 |
|
Jerad2142
Messages: 3812 Registered: July 2006 Location: USA
Karma: 6
|
General (3 Stars) |
|
|
Here, I actually put a minute into this example, it will be a lot more helpful to you I'm sure.
class MyScript : public ScriptImpClass {
int playerid[127];
int lastid;
void Created(GameObject *o);
void Enter(GameObject *o, GameObject *e);
void Timer_Expired(GameObject *obj,int number);
void Register_Auto_Save_Variables();
};
void MyScript::Created(GameObject *o)
{
lastid = 0;
for (int x = 0;x < 127;x++)
{
playerid[x] = 0;
}
}
void MyScript::Enter(GameObject *o, GameObject *e)
{
int end = 0;
for (int x = 0;x < 128;x++)
{
if (playerid[x] == Commands->Get_ID(e);
{
end = 1;
}
}
for (int x = lastid;x < 128 && end == 0;x++)
{
if (playerid[x] == 0)
{
playerid[x] = Get_ID(e);
lastid = x;
end = 1;
Commands->Start_Timer(o, this, 123, 10);
}
if (x == 127)
{
x = 0;
}
}
}
void MyScript::Timer_Expired(GameObject *obj,int number)
{
if(number == 123)
{
int startarray = lastid + 1;
if (startarray > 127)
{
startarray = 0;
}
for (int x = startarray,end = 0;x < 128 && end == 0;x++)
{
if (playerid[x] != 0)
{
GameObject *enterer = Commands->Find_Object(playerid[x]);
playerid[x] = 0;
end = 1;
}
if (x == lastid)
{
end = 1;
}
if (x == 127)
{
x = 0;
}
}
}
}
void MyScript::Register_Auto_Save_Variables()
{
Auto_Save_Variable(1,4,&playerid);
Auto_Save_Variable(1,4,&lastid);
}
Lol, forgot the whole point of all my code, make it check if there is already a timer running for your soldier, lol, with out that check you may as well make the timer send the ID of the soldier as the number and then just have it get the id's when expired by the number lol.
Visit Jerad's deer sweat shop
[Updated on: Wed, 11 February 2009 10:14] Report message to a moderator
|
|
|
Re: Timer_Expired [message #371598 is a reply to message #371542] |
Wed, 11 February 2009 09:33 |
|
Omar007
Messages: 1711 Registered: December 2007 Location: Amsterdam
Karma: 0
|
General (1 Star) |
|
|
Part of my Enter script:
Toggle Spoiler
void O_Conquest::Entered(GameObject *obj, GameObject *enter)
{
if (teamid == 0 || teamid == 1)
{
char pick[256];
const char *c = Get_Player_Name(enter);
sprintf(pick,"msg %s Is contesting a zone!",c);
delete[] c;
Console_Input(pick);
}
else if (Commands->Get_Player_Type(enter) == 0)
{
if (currentcontrol == 0)
{
char pick[256];
const char *c = Get_Player_Name(enter);
sprintf(pick,"ppage %s This zone is already under NOD's Control",c);
delete[] c;
Console_Input(pick);
}
else if (currentcontrol == 1)
{
playerid = Commands->Get_ID(enter);
givepoints = false;
teamid = Commands->Get_Player_Type(enter); // Get the id of the team that entered the zone
Commands->Start_Timer(obj,this,Get_Float_Parameter("Time_Before_Takeover[secs]"),Get_Int_Parameter("TimerNumber"));
givepoints = true;
currentcontrol = Commands->Get_Player_Type(enter);
nod++;
gdi--;
char pick[256];
const char *c = Get_Player_Name(enter);
sprintf(pick,"msg %s has taken over a zone for NOD!",c);
delete[] c;
Console_Input(pick);
}
else
{
playerid = Commands->Get_ID(enter);
givepoints = false;
teamid = Commands->Get_Player_Type(enter); // Get the id of the team that entered the zone
Commands->Start_Timer(obj,this,Get_Float_Parameter("Time_Before_Takeover[secs]"),Get_Int_Parameter("TimerNumber"));
givepoints = true;
currentcontrol = Commands->Get_Player_Type(enter);
nod++;
char pick[256];
const char *c = Get_Player_Name(enter);
sprintf(pick,"msg %s has taken over a zone for NOD!",c);
delete[] c;
Console_Input(pick);
}
}
My Timer_Expired part:
Toggle Spoiler
void O_Conquest::Timer_Expired(GameObject *obj, int number)
{
if (nod == Get_Int_Parameter("Number_Of_Zones"))
{
Console_Input("win 0");
}
else if (gdi == Get_Int_Parameter("Number_Of_Zones"))
{
Console_Input("win 1");
}
else
{
if (number == 776600)
{
Commands->Start_Timer(obj,this,01.00,776600);
if (givepoints)
{
Commands->Give_Points(Commands->Find_Object(playerid),Get_Float_Parameter("Points_Per_Sec"),1);
}
}
}
}
This is now.
EDIT: Kill_All_Building_By_Team is no option when it is a map without buildings... (duhu) Anyone who could tell me an alternative for ConsoleInput so it will also work when not running a dedicated server??
EDIT2: Sorry if some things are really n00bish. This is my first script
[Updated on: Wed, 11 February 2009 11:41] Report message to a moderator
|
|
|
|
|
|
Re: Timer_Expired [message #371858 is a reply to message #371856] |
Thu, 12 February 2009 16:17 |
|
danpaul88
Messages: 5795 Registered: June 2004 Location: England
Karma: 0
|
General (5 Stars) |
|
|
Jerad Gray wrote on Thu, 12 February 2009 23:06 |
danpaul88 wrote on Thu, 12 February 2009 10:40 | Just use the Custom system instead, make it send a custom to itself with an x second delay and put the players ID as the parameter to the custom. Easy.
|
Kind of removes the whole delay part though...
|
Quote: | typedef void (*_Send_Custom_Event) (GameObject *Sender,GameObject *Reciever,int Message,int Param,float Delay);
|
Highlighting added for emphasis. Why else do you think the Send_Custom_Event takes a delay parameter if not to delay the delivery of the custom?
Example;
float delay = 10.0f; // delay in seconds
int message = 12345; // unique message code to identify this from other customs
int param = Get_Player_ID( enter ); // ID of player (use Commands->Get_ID(obj) to get the player object ID, which is probably what you really need)
Commands->Send_Custom_Event ( obj, obj, message, param, delay );
No need to create the variables, you can condense it into a single line statement, I added them for clarity only. You need to decide if you want to send the player ID (as seen from FDS) or the player's object ID (which also makes it work for AI units and makes it easy to cancel triggering if the player died before the delay was triggered)
[Updated on: Thu, 12 February 2009 16:30] Report message to a moderator
|
|
|
|
Re: Timer_Expired [message #371969 is a reply to message #371965] |
Fri, 13 February 2009 12:00 |
Genesis2001
Messages: 1397 Registered: August 2006
Karma: 0
|
General (1 Star) |
|
|
Omar007 wrote on Fri, 13 February 2009 11:48 | Seems to be a very good option
Only one thing... (kinda stupid xD) What do i call to receive the custom??
|
in the class defintion, add:
void Custom(GameObject *o, int msg, int param, GameObject *s);
where,
GameObject *o -> the game object that the script is attached to.
GameObject *s -> the game object that sent the custom
int msg -> the message that was sent
int param -> the parameter that was sent with 'msg'
|
|
|
|
Re: Timer_Expired [message #372653 is a reply to message #371858] |
Thu, 19 February 2009 16:02 |
|
Jerad2142
Messages: 3812 Registered: July 2006 Location: USA
Karma: 6
|
General (3 Stars) |
|
|
danpaul88 wrote on Thu, 12 February 2009 16:17 |
Jerad Gray wrote on Thu, 12 February 2009 23:06 |
danpaul88 wrote on Thu, 12 February 2009 10:40 | Just use the Custom system instead, make it send a custom to itself with an x second delay and put the players ID as the parameter to the custom. Easy.
|
Kind of removes the whole delay part though...
|
Quote: | typedef void (*_Send_Custom_Event) (GameObject *Sender,GameObject *Reciever,int Message,int Param,float Delay);
|
Highlighting added for emphasis. Why else do you think the Send_Custom_Event takes a delay parameter if not to delay the delivery of the custom?
Example;
float delay = 10.0f; // delay in seconds
int message = 12345; // unique message code to identify this from other customs
int param = Get_Player_ID( enter ); // ID of player (use Commands->Get_ID(obj) to get the player object ID, which is probably what you really need)
Commands->Send_Custom_Event ( obj, obj, message, param, delay );
No need to create the variables, you can condense it into a single line statement, I added them for clarity only. You need to decide if you want to send the player ID (as seen from FDS) or the player's object ID (which also makes it work for AI units and makes it easy to cancel triggering if the player died before the delay was triggered)
|
Either way you still have the same possible issue as you would with a timer, which my code is designed to go around, as in, you walk in the zone, out of the zone, back in, back out, back in, and then you get hit by 3 customs because you weren't checking to make sure there wasn't a custom delayed/timer running.
Visit Jerad's deer sweat shop
|
|
|
|
Re: Timer_Expired [message #372740 is a reply to message #372660] |
Fri, 20 February 2009 10:17 |
|
jnz
Messages: 3396 Registered: July 2006 Location: 30th century
Karma: 0
|
General (3 Stars) |
|
|
danpaul88 wrote on Fri, 20 February 2009 00:16 | Depending on the effect of the custom, that might not matter.
PS: What *does* that Auto_Save_Variable thing actually DO anyway? I have yet to find anything that actually explains it's function. How is it different to just having a variable inside the scripts class to store the value?
|
I imagine it's to preserve the values if ever the script is deleted and recreated by the server. I can't think of any reason why the server would do this though.
[Updated on: Fri, 20 February 2009 10:20] Report message to a moderator
|
|
|
Re: Timer_Expired [message #372741 is a reply to message #372660] |
Fri, 20 February 2009 10:24 |
|
saberhawk
Messages: 1068 Registered: January 2006 Location: ::1
Karma: 0
|
General (1 Star) |
|
|
danpaul88 wrote on Thu, 19 February 2009 19:16 | Depending on the effect of the custom, that might not matter.
PS: What *does* that Auto_Save_Variable thing actually DO anyway? I have yet to find anything that actually explains it's function. How is it different to just having a variable inside the scripts class to store the value?
|
It's used to automatically save and restore certain variables should the script instance ever end up being saved or loaded.
|
|
|
|
Goto Forum:
Current Time: Thu Dec 19 10:57:28 MST 2024
Total time taken to generate the page: 0.01651 seconds
|