Server Help

ASSS Questions - timer

tcsoccerman - Fri Jul 13, 2007 7:48 pm
Post subject: timer
I was wondering about a timer required in a module i'm creating. In order to make this easier though, i thought i might ask, how long does it take for the "packets"(i don't know if this is right but i think so) to give player location? in the halo_hill module, i don't see a timer, i just see a

Code: Show/Hide
if(true) --seconds remaning


sorda thing(that's not the exact code). if smong could respond to how he did his hill timer that would be great.

My goal:for every second a person is in a location, turn on another image.

My question:how do you find out how long a person is in a location.
tcsoccerman - Fri Jul 13, 2007 9:53 pm
Post subject:
I've found a way, i just don't know what the call back is for when someone is IN the zone. not entering. this is not what i want at all.
k0zy - Sat Jul 14, 2007 4:27 am
Post subject:
tcsoccerman wrote:
I've found a way, i just don't know what the call back is for when someone is IN the zone. not entering. this is not what i want at all.


I never coded for ASSS, but:

If someone enters the zone, he/she is in there until leaving it!?
tcsoccerman - Sat Jul 14, 2007 11:01 am
Post subject:
Lol, sorry. i meant region, not zone.
Animate Dreams - Sat Jul 14, 2007 2:58 pm
Post subject:
I'm pretty sure for that, you'll have to use ASSS Regions. Make the "hill" a region, and use the region callback to see when people enter. Just interrupt the timer if if the player ever leaves the region. You could record their position every second or something, and check to see if it was within a certain boundary, but... I'm sure regions are much easier. Only problem I would see is if regions happen to take a while to respond(if I remember right it does take a second or so).
tcsoccerman - Sat Jul 14, 2007 3:53 pm
Post subject:
How many pixels are in a tile?16?24?
Animate Dreams - Sat Jul 14, 2007 3:56 pm
Post subject:
Hm... I always thought it was seven. But I'm probably thinking this because a standard ship's radius is 14, which is big enough to be blocked by a single tile gap, but it fits in a 2 tile gap.

Edit: I found this in the wiki: http://wiki.minegoboom.com/index.php/Tiles which says tiles are 16x16. I confused radius and diameter, which is why my last statement doesn't make sens. >_<
tcsoccerman - Sat Jul 14, 2007 5:33 pm
Post subject:
I figured that out w/ dcme. Now all i need is coding that pauses the current process for x seconds(preferabbly small and precise), and then resumes the process after x secnods have passed. know how? C language.
k0zy - Sat Jul 14, 2007 5:55 pm
Post subject:
sleep
and
usleep
tcsoccerman - Sat Jul 14, 2007 6:05 pm
Post subject:
Example?
Smong - Sat Jul 14, 2007 6:28 pm
Post subject:
You don't want to use sleep in a module, you could end up freezing the entire server.

Also I doubt you want to use regions if this is for a hill that can move around. If all you can get is enter/exit events just follow k's advice and stop/pause the timer as soon as you get an exit event.

What I did in the original halo_hill module was set an asss timer to trigger on every second. Then inside this timer I checked all the player positions to see if they were inside the hill or not. If one team had more players inside than the other than I decremented that team's timer by 1.

Now about your goal, did you want like a meter than increases the longer you stay in the area? And then this meter resets as soon as you leave it?

Or did you want to display how many players each team currently has inside the hill?
tcsoccerman - Sat Jul 14, 2007 6:43 pm
Post subject:
Ok, i see. i do want to use regions because the hills don't move. What area of code did you trigger the timer every second?I want the idea of a meter that increases every second in the hill, but doesn't reset when you leave it.once they are in the hill for long enough, that players team owns the hill.
tcsoccerman - Sat Jul 14, 2007 6:51 pm
Post subject:
I see it now in mainloop.h . What do the keys and stuff represent? What should i set them to if i want something similiar to you're hill module to occur, every second.

It would be most useful if it waits for 1 second, then continues. The purpose of this coding is to put a second b/w the meter gfx so the meter doesn't fill up in a instant, but instead takes a while.
Animate Dreams - Sat Jul 14, 2007 11:55 pm
Post subject:
Unfortunately there isn't really a way to just pause your module, you have to use timers. :| It WOULD be nice to have a way to delay a module for a few seconds, and it might even be possible to write a Pause() function that took a number of seconds in as a parameter. I might try that some time, but I keep forgetting how timers work.
k0zy - Sun Jul 15, 2007 6:50 am
Post subject:
The problem with that is that while the module is in the Pause() function the module is unable to handle any other events that might occur.
And if you use a timer with a callback you're not able to jump back to where you called Pause().

You could start a different thread that does whatever you want and where it is safe to sleep in, though.
The manpage of sleep and usleep say that sleep suspends a process, however I remember using sleep in a threaded program without a problem.
Smong - Sun Jul 15, 2007 6:57 am
Post subject:
The key in SetTimer is so you can cancel a specific timer. You might want to do this when the module detaches, to clean up neatly. In this case setting the key to be the arena is a good idea. You don't have to use a key if you don't need to, but if your module detaches/unloads and any running timers are not stopped could crash the server.

To make the timer get called ever second set the interval to 100 ticks. The initial delay can be anything small, maybe 500 if you are calling it in MM_ATTACH or set it to 0 if the game starts on command.

You'll want to set the "param" parameter to the arena, so you can access the arena data inside the timer.

Also don't forget to make the timer return 1 so it repeats.

Code: Show/Hide
local int timer(void *arena_)
{
   Arena *arena = arena_;
   struct adata *ad = P_ARENA_DATA(arena, adkey);

   //count players here, etc

   return 1;
}

EXPORT int MM_halo_hill(int action, Imodman *mm_, Arena *arena)
{
...
   else if (action == MM_ATTACH)
   {
      ml->SetTimer(timer, 500, 100, arena, arena);
   }
   else if (action == MM_DETACH)
   {
      ml->ClearTimer(timer, arena);
   }

Dr Brain - Sun Jul 15, 2007 10:39 am
Post subject:
Smong wrote:
The key in SetTimer is so you can cancel a specific timer. You might want to do this when the module detaches, to clean up neatly. In this case setting the key to be the arena is a good idea. You don't have to use a key if you don't need to, but if your module detaches/unloads and any running timers are not stopped could crash the server.


You can use use ml->ClearTimer(timer, NULL) to clear without keys.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group