[COD4] Adding a timer to codjumper mod
Moderator: Core Staff
[COD4] Adding a timer to codjumper mod
Hi all,
I want to add a timer to the codjumper mod, i already pointed it out here but i think it's easier if i add it locally to my mod...
I made a little search on the board and i found some results but i don't understand very well script, how do they work and where to place them.
Can someone help me please?
I want to add a timer to the codjumper mod, i already pointed it out here but i think it's easier if i add it locally to my mod...
I made a little search on the board and i found some results but i don't understand very well script, how do they work and where to place them.
Can someone help me please?
Re: [COD4] Adding a timer to codjumper mod
If you want to add scripts to the cj mod, without editing existing scripts, I'd overwrite the file _clientids.gsc, since I think its not being used by cj mod
you could add the file to any .iwd file in the mod under maps\mp\gametypes
so:
maps\mp\gametypes\_clientids.gsc
i just modified rezils script a bit, so credit goes to him:
by typing "/openscriptmenu cj stopwatchstart" the counter will start
and "/ openscriptmenu cj stopwatchstop" will stop it.
you could add the file to any .iwd file in the mod under maps\mp\gametypes
so:
maps\mp\gametypes\_clientids.gsc
i just modified rezils script a bit, so credit goes to him:
Code: Select all
init()
{
    precachestring(&":");
    precachestring(&" ");
   Â
    level.clientid = 0;
    level thread onPlayerConnect();
}
Â
onPlayerConnect()
{
    while( true )
    {
        level waittill("connecting", player);
       Â
        player.clientid = level.clientid;
        level.clientid++;
       Â
        player.stopwatchrunning = false;
       Â
        player thread onPlayerSpawned();
    }
}
Â
onPlayerSpawned()
{
    self endon("disconnect");
   Â
    while( true )
    {
        self waittill( "menuresponse", menu, response );
        if( menu == "cj" )
        {
            if( response == "stopwatchstart" )
                self thread start();
            if( response == "stopwatchstop" )
                self thread stop();
        }
        wait 0.5;
    }
}
Â
Â
Â
start()
{
    if(!self.stopwatchrunning)
    {
        self thread make_secondswatch();
        self thread make_minuteswatch();
        self thread dots_inbetween();
        self.stopwatchrunning = true;
    }
    else
        self iprintlnbold("The stopwatch is already running!");
}
Â
make_secondswatch()
{
    self endon( "stopwatch_destroy" );
    self.secondwatch = newclienthudelem(self);
    self.secondwatch.x = 322; //max 650
    self.secondwatch.y = 450; //max 475
    self.secondwatch.alignX = "left";
    self.secondwatch.alignY = "bottom";
    self.secondwatch.font = "default";
    self.secondwatch.fontScale = 2;
    self.secondwatch.archived = false;
    self.secondwatch.color = (1, 1, 1);
    for(;;)
    {
        secondtime = 0;
        secondtime = secondtime * 10;
        seconds = 0;
        for(i=seconds;i<=59;i++)
        {
            self.secondtime = i ;
            self.secondwatch setValue(self.secondtime);
            wait 1;
        }
        wait 0.05;
    }
}
Â
make_minuteswatch()
{
    self endon( "stopwatch_destroy" );
    self.minutewatch = newclienthudelem(self);
    self.minutewatch.x = 311; //max 650
    self.minutewatch.y = 450; //max 475
    self.minutewatch.alignX = "right";
    self.minutewatch.alignY = "bottom";
    self.minutewatch.font = "default";
    self.minutewatch.fontScale = 2;
    self.minutewatch.archived = false;
    self.minutewatch.color = (1, 1, 1);
    self.minutetime = 0;
    minutes = 0; //And no I don't know why I used this instead of just putting i=0;
    for(i=minutes;i>=0;i++)
    {
        self.minutewatch setValue(self.minutetime);
        if(self.secondtime == 599/10) self.minutetime++;
            wait 0.1;
    }
}
Â
dots_inbetween()
{
    self endon( "stopwatch_destroy" );
    self.dots = newclienthudelem(self);
    self.dots.x = 318; //max 650
    self.dots.y = 450; //max 475
    self.dots.alignX = "right";
    self.dots.alignY = "bottom";
    self.dots.font = "default";
    self.dots.fontScale = 2;
    self.dots.archived = false;
    self.dots.color = (1, 1, 1);
    for(;;)
    {
        self.dots.label = &":";
        wait 0.7;
        self.dots.label = &" ";
        wait 0.7;
    }
}
Â
Â
stop()
{
    if(self.stopwatchrunning)
    {
        self notify( "stopwatch_destroy" );
        self iprintlnbold( self.minutetime + " minutes " + self.secondtime + " seconds" );
        self.secondtime = 0;
        self.minutetime = 0;
        self.minutewatch destroy();
        self.secondwatch destroy();
        self.dots destroy();
        self.stopwatchrunning = false;
    }
    else
        self iprintlnbold("You didn't start the stopwatch!");
}
and "/ openscriptmenu cj stopwatchstop" will stop it.
-
- Core Staff
- Posts: 13313
- Joined: April 13th, 2005, 8:22 pm
- Location: UK, London
Re: [COD4] Adding a timer to codjumper mod
Or you could use the "addons.gsc" file that already exists for this very purpose.Nekoneko wrote:If you want to add scripts to the cj mod, without editing existing scripts, I'd overwrite the file _clientids.gsc, since I think its not being used by cj mod
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010
-
- Core Staff
- Posts: 2030
- Joined: July 24th, 2006, 11:21 am
- Location: Cramped in a small cubicle/making another jump map
Re: [COD4] Adding a timer to codjumper mod
This is why I like this community.i just modified rezils script a bit, so credit goes to him:
Feel free to use this script if you find it useful. Truth be told, Drofder came up with the basic idea, I just expanded on it. And do use addons.gsc, it was created for that specific purpose.
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.
Re: [COD4] Adding a timer to codjumper mod
many thanks, worked like a charm
P.S. i used addon.gsc as suggested
P.S. i used addon.gsc as suggested
Re: [COD4] Adding a timer to codjumper mod
Ah, i didn't know about that ^^
Good idea for addons
Good idea for addons
Re: [COD4] Adding a timer to codjumper mod
After a month i realize that there is something wrong in this timer :S when seconds reach 59 it doesn't turn to 1 minute and it resets seconds to 0...
can someone fix it please?
can someone fix it please?
-
- Core Staff
- Posts: 13313
- Joined: April 13th, 2005, 8:22 pm
- Location: UK, London
Re: [COD4] Adding a timer to codjumper mod
The seconds timer counts 0,1,2,3,etc (each second)
But the minutes timer counts 0,0.1,0.2,0.3 (each tenth of a second)
The "minutetime" is incremented when the secondtime = 59.9 but the second time will never equal 59.9
This whole code is bad practice, it would be a lot easier to simply count in seconds and then ever "wait 1" do a quick calculation to work out minutes and seconds.
too tired to fix your code, but I am sure someone can be arsed with the above explanation.
But the minutes timer counts 0,0.1,0.2,0.3 (each tenth of a second)
The "minutetime" is incremented when the secondtime = 59.9 but the second time will never equal 59.9
This whole code is bad practice, it would be a lot easier to simply count in seconds and then ever "wait 1" do a quick calculation to work out minutes and seconds.
Code: Select all
seconds = totalSeconds % 60;
minutes = (totalSeconds - seconds) / 60;
hours = minutes / 60;
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010
-
- Core Staff
- Posts: 2030
- Joined: July 24th, 2006, 11:21 am
- Location: Cramped in a small cubicle/making another jump map
Re: [COD4] Adding a timer to codjumper mod
Code: Select all
/*
- Call playerInit(), stopwatchInit(x, y, offset) and miscHUDinit(offset) on a player
                (eg. stopWatchInit(100, 0, 30);, miscHUDinit(35); )
Â
- When you're ready to start the stopwatch, set isTiming to true and thread monitorTime()
- When you're done with the timing, simply set isTiming to false
*/
Â
playerInit()
{
    self.counter_sec = 0;
    self.counter_min = 0;
    self.counter_hrs = 0;
    self.isTiming = false;
   Â
    if(!isdefined(self.stopwatch))
        self.stopwatch = [];
Â
    if(!isdefined(self.misc))
        self.misc = [];
   Â
    for(i=0;i<3;i++)
    {
        self.stopwatch[i] = newclientHUDelem(self);
        if(i<2) self.misc[i] = newclientHUDelem(self);
    }
}
/*x and y are self explanatory, offset is the length between each element(sec, min, hr) */
stopwatchInit(x_v, y_v, offset)
{
    for(i=0;i<self.stopwatch.size;i++)
    {
        if(i==0) self.stopwatch[i].alignX = "left";
        else self.stopwatch[i].alignX = "center";
        self.stopwatch[i].alignY = "middle";
        self.stopwatch[i].horzAlign = "left";
        self.stopwatch[i].vertAlign = "middle";
        if(i==0)
        {
            self.stopwatch[i].x = x_v;
            self.stopwatch[i].y = y_v;
        }
        else
        {
            self.stopwatch[i].x = self.stopwatch[i-1].x-offset;
            self.stopwatch[i].y = self.stopwatch[i-1].y;
        }
        self.stopwatch[i].foreground = 1;
        self.stopwatch[i].color = (1, 1, 1);
        self.stopwatch[i].alpha = 1;
        self.stopwatch[i].font = "default";
        self.stopwatch[i].fontScale = 2;
    }
    self.stopwatch[0] setValue(self.counter_sec);
    self.stopwatch[1] setValue(self.counter_min);
    self.stopwatch[2] setValue(self.counter_hrs);
   Â
}
miscHUDinit(offset) /*[0] is the : in between hours and minutes, [1] is the : inbetween minutes and seconds*/
{
    for(i=0;i<self.misc.size;i++)
    {
        self.misc[i].alignY = "middle";
        self.misc[i].alignX = "left";
        self.misc[i].horzAlign = "left";
        self.misc[i].vertAlign = "middle";
        self.misc[i].font = "default";
        self.misc[i].fontScale = 2;
        self.misc[i].foreground = 1;
        self.misc[i].color = (1, 1, 1);
        self.misc[i].alpha = 0;
       Â
        self.misc[i].x = self.stopwatch[i].x - (offset/2);
        self.misc[i].y = self.stopwatch[i].y;
        self.misc[i] setText(&":");
    }
}
monitorTime()
{
    self thread stopWatchColon();
    while(self.isTiming)
    {
        for(h=0;h<24;h++)
        {
            self.counter_hrs = h;
            for(i=0;i<60;i++)
            {
                self.counter_min = i;
                for(j=0;j<600;j++)
                {
                    self.counter_sec = j/10;
                    self updateStopwatchHUD();
                    wait 0.1;
                    if(!self.isTiming)
                        break;
                }
                if(!self.isTiming)
                    break;
            }
            if(!self.isTiming) //no 'goto' keyword to break out of all loops :(
                break;
        }
        self iprintlnbold("You've been going for a day now, don't you think it's time to quit already?");
        wait 0.05;
    }
}
stopwatchColon()
{
    while(self.isTiming)
    {
        if(self.misc[0].alpha==1)
            self.misc[0].alpha = 0;
        else self.misc[0].alpha = 1;
       Â
        if(self.misc[1].alpha==1)
            self.misc[1].alpha = 0;
        else self.misc[1].alpha = 1;
       Â
        wait 0.5;
    }
}
updateStopwatchHUD()
{
    if(isdefined(self.stopwatch))
    {
        self.stopwatch[0] setValue(self.counter_sec);
        self.stopwatch[1] setValue(self.counter_min);
        self.stopwatch[2] setValue(self.counter_hrs);
    }
}
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.
-
- Core Staff
- Posts: 13313
- Joined: April 13th, 2005, 8:22 pm
- Location: UK, London
Re: [COD4] Adding a timer to codjumper mod
Rez, that is some awful loop calculating going on there
Also, are the "if(!self.timing) break;" stuff needed, when you are while-looping on the assumption it is alway 1?
Gotta love the flashing colon stuff though, eye for detail
Also, are the "if(!self.timing) break;" stuff needed, when you are while-looping on the assumption it is alway 1?
Gotta love the flashing colon stuff though, eye for detail
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010
-
- Core Staff
- Posts: 2030
- Joined: July 24th, 2006, 11:21 am
- Location: Cramped in a small cubicle/making another jump map
Re: [COD4] Adding a timer to codjumper mod
The break statements are needed because you're in a nested loop and have no clue when the player will stop timing. The while loop condition is checked only after an iteration completes(once per day in our case )
And yeah, I could've written this much more efficiently but in my defence I was planning on optimizing this code next week. :p
And yeah, I could've written this much more efficiently but in my defence I was planning on optimizing this code next week. :p
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.
Re: [COD4] Adding a timer to codjumper mod
Can someone please explain me how to use the code posted by rezil? I tried to copy paste it into addon.gsc but if i launch the server i have a script compile error
-
- Core Staff
- Posts: 2030
- Joined: July 24th, 2006, 11:21 am
- Location: Cramped in a small cubicle/making another jump map
Re: [COD4] Adding a timer to codjumper mod
I am not going to code the entire thing for you, I have only provided you with the framework. If you need any help debugging you can post here, just don't expect ready-made solutions that you can simply copy-paste into a .gsc file and it will magically work.Rezil wrote:Code: Select all
/* - Call playerInit(), stopwatchInit(x, y, offset) and miscHUDinit(offset) on a player                 (eg. stopWatchInit(100, 0, 30);, miscHUDinit(35); )  - When you're ready to start the stopwatch, set isTiming to true and thread monitorTime() - When you're done with the timing, simply set isTiming to false */
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.
Re: [COD4] Adding a timer to codjumper mod
Thanks anyway... since i don't have any basis of coding and i don't know where to start from i was looking for a "ready-made" solution like you said.
Who is online
Users browsing this forum: No registered users and 0 guests