Author Topic: PerroRACE 2.0 - very cool Racing script  (Read 18471 times)

0 Members and 1 Guest are viewing this topic.

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
Re: PerroRACE - very cool Racing script (beta?)
« Reply #20 on: November 04, 2007, 02:08:36 pm »
About the second, yeah, I messed up with the arrows, it's a double checkpoint. Not a problem once you know the circuit.

About the first, were you playing in the server when you attemped to start the race? If there are no players the race will automatically end. Also, the autostart won't start any race if the server is empty.

So, you have to do this:
1. Join the server.
2. Wait for the message "Waiting for all players to be alive and with no movement.".
3. Stay still for a little while (this is to avoid the initial speed after moving all players to the initial position).
4. Wait for th countdown and start running.

If it doesn't work that way it's because of the inestability of ThreadFunc, so try restarting with "/recompile race" until it works.
urraka

Offline chutem

  • Veteran
  • *****
  • Posts: 1119
Re: PerroRACE - very cool Racing script (beta?)
« Reply #21 on: November 06, 2007, 02:23:21 am »
Hmm it seems to be working now, but i don't know why, maybe because I changed the gamestyle to '1', or possibly that i set max grenades to 4000 :)

Anywho its a great script and I might just make some maps for it :D
1NK3FbdNtH6jNH4dc1fzuvd4ruVdMQABvs

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
Re: PerroRACE - very cool Racing script (beta?)
« Reply #22 on: November 06, 2007, 02:24:07 pm »
Cool, if you make more maps post them here :P (remember to include the checkpoints stored in race.ini)
urraka

Offline chutem

  • Veteran
  • *****
  • Posts: 1119
Re: PerroRACE - very cool Racing script (beta?)
« Reply #23 on: November 08, 2007, 09:55:04 pm »
Heres my first map, rc_Blox, I'll make more over weekend.

Checkpoints:


[rc_Blox]
Laps=5
Num=8
checkpoint1=28.87,-745.29
checkpoint2=359.89,-234.46
checkpoint3=83.64,54.95
checkpoint4=-285.95,282.88
checkpoint5=95.62,449.97
checkpoint6=426.46,5.85
checkpoint7=-184.27,-247.64
checkpoint8=-483.7,-235.16


\/ Map \/
1NK3FbdNtH6jNH4dc1fzuvd4ruVdMQABvs

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
Re: PerroRACE - very cool Racing script (beta?)
« Reply #24 on: November 09, 2007, 01:59:32 pm »
Nice man, already added it to my server :P

I'll post tow more maps a friend made.

[rc_HH]
Laps=3
Num=9
checkpoint1=-947.79,-644.57
checkpoint2=-991.79,-457.95
checkpoint3=-921.07,0.23
checkpoint4=-715.9,-260.39
checkpoint5=186.2,227.04
checkpoint6=1049.67,625.89
checkpoint7=1330.51,311.44
checkpoint8=1056.9,18.55
checkpoint9=-40.66,-134.94

[rc_cambodia]
Laps=3
Num=10
checkpoint1=-505.7,-668.35
checkpoint2=-802.82,-179.74
checkpoint3=-233.23,540.54
checkpoint4=-356.85,640.57
checkpoint5=96.2,528.22
checkpoint6=481.43,579.57
checkpoint7=393.61,161.32
checkpoint8=88.97,-4.1
checkpoint9=441.9,-386.66
checkpoint10=268.42,-747.82
urraka

Offline chutem

  • Veteran
  • *****
  • Posts: 1119
Re: PerroRACE - very cool Racing script (beta?)
« Reply #25 on: November 11, 2007, 02:06:39 am »
three more maps, i don't know wat happened to the checkpoints for conquest, but i can't be bothered making another zip file. Or do the checkpoints right now :P

Checkpoints:


[rc_Ash]
Laps=3
Num=11
checkpoint1=-1068.13,177.26
checkpoint2=-421.63,-105.29
checkpoint3=181.66,159.15
checkpoint4=241.36,-105.61
checkpoint5=-181.71,158.24
checkpoint6=-557.91,82.12
checkpoint7=-174.96,367.99
checkpoint8=553.27,82.63
checkpoint9=172.27,-226.36
checkpoint10=-363,-299.94
checkpoint11=-661.17,339.55

[rc_Cobra]
Laps=3
Num=9
checkpoint1=-18.87,420.57
checkpoint2=-811.33,-59.88
checkpoint3=-216.57,204.99
checkpoint4=-576.68,-60.92
checkpoint5=-392.31,-257.41
checkpoint6=375.21,-245.38
checkpoint7=582.77,-60.9
checkpoint8=196.56,203.88
checkpoint9=813.72,-60.9
1NK3FbdNtH6jNH4dc1fzuvd4ruVdMQABvs

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
Re: PerroRACE - very cool Racing script (beta?)
« Reply #26 on: November 11, 2007, 07:15:17 pm »
I made the checkpoints for rc_Conquest

[rc_Conquest]
Laps=3
Num=12
checkpoint1=-2019.18,155.06
checkpoint2=-1375.49,536.11
checkpoint3=-17.39,521
checkpoint4=20.32,-91.89
checkpoint5=444.28,199.34
checkpoint6=1058.35,369.19
checkpoint7=2159.59,284.29
checkpoint8=767.23,531.06
checkpoint9=456.3,-28.91
checkpoint10=20.32,-91.89
checkpoint11=-451.71,-30.42
checkpoint12=-1904.73,384.15


By the way, I really liked how you made those 3 maps :)
« Last Edit: November 11, 2007, 07:20:54 pm by PerroAZUL »
urraka

Offline Leo

  • Soldat Beta Team
  • Veteran
  • ******
  • Posts: 1011
Re: PerroRACE - very cool Racing script (beta?)
« Reply #27 on: November 12, 2007, 08:20:33 am »
Nice script but when I tested it at my linux server it was jumping to 54% of CPU usage with 2 players. Any idea why ?

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
Re: PerroRACE - very cool Racing script (beta?)
« Reply #28 on: November 12, 2007, 11:31:54 pm »
Hmm I never took a look at the CPU usage, but I used Sleep(1) in the thread loop. Should I use Sleep(x) with x > 1? Anyway, I'll update the script soon, I have a couple of ideas to handle the threadfunc bugs. But keep in mind that it's not a stable script.

Date Posted: 12/11/2007 - 11:07:08
Well I updated the script.

I changed the Sleep(1) in the loops to Sleep(20), that might help with the performance. Please test it and tell me how it goes.

I also implemented a way to handle the bugs but I'm not so sure if it works because I couldn't test it since the ThreadFunc didn't want to crash this time ¬¬. Maybe having Sleep(20) reduced the probability of crashing. (I've just made that up :P)
So the thread should be recovered every second if it crashed, in theory.

Let me know if something goes wrong, I'll test it more carefully later.

The new package contains all the maps posted here so far.

Download

edit: tested it for a while and nothing worked as expected ¬¬... working on it...
« Last Edit: November 13, 2007, 09:49:26 am by PerroAZUL »
urraka

Offline sai`ke

  • Camper
  • ***
  • Posts: 318
  • Can't be arsed to remove christmas avatar
Re: PerroRACE - very cool Racing script (beta?)
« Reply #29 on: November 13, 2007, 01:45:14 pm »
You can do something like this in AppOnIdle: the checkpoints should be made of 2 points - the points will create a line segment. 2 player positions, from previous AppOnIdle and current AppOnIdle, will create the second line segment. Check if the line segments intersect, if true, the player passed the checkpoint. Though I dunno if it won't be to slow.
I'm afraid that is not a solution to the time resolution problem as shown in this picture:


Let's assume the player moves from position one to two between two consecutive calls of AppOnIdle. Due to the large timestep it would miss the checkpoint in that case. Let me know if I misunderstood your idea.

PerroAZUL, you can increase the time resolution if you don't need weapons! If you drop a weapon at each checkpoint, you can do the distance checking and whatnot in onWeaponChange. Also, immediately Forceweapon fists again in the routine to make sure it gets called again the next checkpoint. Of course, you also need to drop a new weapon, but this shouldn't be much of a problem. To be on the safe side you could drop multiple weapons just in case players arrive at a checkpoint at the same time. If I'm right about this, this would eliminate the need for threadfunc and get rid of your problems. :)

Another (less elegant) option would be to have a bot on an offscreen section of the map on hurtpoly's and doing the distance checking in onplayerkill. You can then set your desired time resolution by changing the amount of damage done by the hurt poly's. Of course, respawntime should be zero then and I'm not sure if that is possible. I reckon this option could induce quite some lag on your server though, so I'd try the former first.
« Last Edit: November 13, 2007, 02:25:01 pm by sai`ke »
#soldat.ttw #ttw.gather --- Quakenet!
http://ttwforums.com

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
Re: PerroRACE - very cool Racing script (beta?)
« Reply #30 on: November 13, 2007, 02:42:53 pm »
Well right now I'm rewriting the code, making it clean cause it was a mess. I'll try how it works doing the loop in AppOnIdle without considering the time resolution. Maybe it's not so bad, the problem comes when 2 or more players go together, the one with lower ID will win I guess. And also I made this script having in mind making it save the best lap times, and 1 second resolution would suck for that.

The weapons idea would screw up the race because sometimes you have to stop in order to take the weapon, and also there are some checkpoints in the air.

Thinking about that line thing, another idea came to my mind. I make a line from the player position to the next checkpoint in one call to AppOnIdle, in the next I do the same. Then I calculate the angle between those 2 lines, if it's greater than 90° it means you crossed the checkpoint. I still have to think about it, I'm not so sure about this :P

PD: Is there even a way to calculate the angle... sh*t!
« Last Edit: November 13, 2007, 02:45:34 pm by PerroAZUL »
urraka

Offline sai`ke

  • Camper
  • ***
  • Posts: 318
  • Can't be arsed to remove christmas avatar
Re: PerroRACE - very cool Racing script (beta?)
« Reply #31 on: November 13, 2007, 03:05:36 pm »
Quote
Well right now I'm rewriting the code, making it clean cause it was a mess. I'll try how it works doing the loop in AppOnIdle without considering the time resolution.
Looping in appOnIdle will pause your server and probably cause a truckload of other problems. I'll assume you mean just checking in apponidle. Furthermore, a time resolution of a second is pretty bad for racing.

Quote
Maybe it's not so bad, the problem comes when 2 or more players go together, the one with lower ID will win I guess.
Why would this be a problem? You just loop through all players and check whether they are close enough.

Quote
And also I made this script having in mind making it save the best lap times, and 1 second resolution would suck for that.
Yeah.

Quote
The weapons idea would screw up the race because sometimes you have to stop in order to take the weapon, and also there are some checkpoints in the air.
I don't think you need to stop to pick up a weapon if you currently have no weapons. It wouldn't solve the in air checkpoint problem though but can't you move these, or change the maps a little so that there is a plateau for the weapons to fall on?

Quote
Then I calculate the angle between those 2 lines, if it's greater than 90° it means you crossed the checkpoint. I still have to think about it, I'm not so sure about this
Nope. That won't hold. It's not very hard to come up with a counterexample.

There is no substitute for time resolution when it comes to racing I'm afraid.

Also, ok, if the weapons thing isn't an option, consider putting a bot somewhere, spawn bullets above him at different heights and doing the distance checking in OnPlayerDamage. I'm not sure if there's a built-in time routine that gives you the current time with a resolution of less than a second but if it's a big problem you could always set up a secondary program that continuously writes the current time including milliseconds to a file and read it on passing a checkpoint. Even without that, you'd still know who is first tho'.

P.S. If you still need angles, you can calculate the angle between two vectors by means of the dot product.
Consider two vectors v1 and v2 then
v1x * v2x + v1y * v2y = cos( angle between them ) * length( v1 ) * length( v2 )
with length I mean geometric length and not number of elements.


Date Posted: November 13, 2007, 02:55:54 pm
Here you go:
Code: [Select]
function angle( v1x, v1y, v2x, v2y: single ): single;
var
cosangle: single;
dist: single;
begin
dist := ( distance( 0, 0, v1x, v1y ) * distance( 0, 0, v2x, v2y ) );
cosangle := ( v1x * v2x + v1y * v2y ) / dist;
if dist = 0 then
begin
result := -1;
exit;
end
result := 90 - 720 * ( arctan( cosangle / ( 1 + sqrt( 1 - cosangle * cosangle ) ) ) ) / (2 * pi);
end;

PS. Note that this will always give you the smallest angle between two vectors!
« Last Edit: November 13, 2007, 04:08:54 pm by sai`ke »
#soldat.ttw #ttw.gather --- Quakenet!
http://ttwforums.com

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
Re: PerroRACE - very cool Racing script (beta?)
« Reply #32 on: November 13, 2007, 03:31:16 pm »
1. Yes I meant just checking in AppOnIdle :P

2. I meant that considering using the time resolution of 1 second. If both player are too close and reach the final checkpoint, the server will think they reached it at the same time. So as that's checked looping through all players, the one looped first will be the winner.

3. Yep.

4. I don't say you need to stop every time, but many times I've have the problem that I want to pick up a weapon and it takes a little while to pick it up. Usually with the knife, maybe because it's small (?). Anyway, making all the checkpoints in ground limits the map layouts and that sucks too :P

5. So far I couldn't think of a counter example. The only problem I found is for example if you are going straight down to a checkpoint in the ground and then need to turn 90°, if the point is too close to the ground and the player never gets to cross it the angle won't be greater than 90°. But that can be solved not placing the point too close to the ground. And also the same checking the script does right now would be done apart from this. In the worst case you'll have to stay 1 second in the checkpoint. I know it sucks, but I'd like to make a stable script and see how bad it is. I will also make the threaded version, which works perfectly for me, with some exceptions :P

6. About the angle calculating, yeah I knew there was some formula for that, what I was thinking was whether I would have the needed functions, in this case arctan. I just don't know if it exists in the engine, it doesn't appear in EnEsCe manual.

He should really implement those timers :P

PD: :P
urraka

Offline sai`ke

  • Camper
  • ***
  • Posts: 318
  • Can't be arsed to remove christmas avatar
Re: PerroRACE - very cool Racing script (beta?)
« Reply #33 on: November 13, 2007, 03:35:16 pm »
note I made a typo in the previous version of that angle thing, so you might wanna c/p it again ;)
#soldat.ttw #ttw.gather --- Quakenet!
http://ttwforums.com

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
Re: PerroRACE - very cool Racing script (beta?)
« Reply #34 on: November 13, 2007, 03:37:44 pm »
No problem, I'm not coding that part yet :P
urraka

Offline sai`ke

  • Camper
  • ***
  • Posts: 318
  • Can't be arsed to remove christmas avatar
Re: PerroRACE - very cool Racing script (beta?)
« Reply #35 on: November 14, 2007, 07:02:04 am »
The problem with a small checking range is that if people need to wait they need to wait unequal amounts of time, which makes it unfair.  The problem with a large checking range is that people can short circuit the 'race track'.
#soldat.ttw #ttw.gather --- Quakenet!
http://ttwforums.com

Offline D!m000n

  • Major(1)
  • Posts: 11
Re: PerroRACE - very cool Racing script (beta?)
« Reply #36 on: November 16, 2007, 08:19:19 am »
How do i start the race in my own server?
after i open some of race maps ;o

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
Re: PerroRACE - very cool Racing script (beta?)
« Reply #37 on: November 16, 2007, 12:23:46 pm »
First of all you must download the dedicated server, which you can downlaod >here< (it's not the one that comes with soldat)

Then, you unzip that somewhere and unzip PerroRACE.zip in the same somewhere.

You can edit the file soldat.ini to set the server options, but it's not really necessary.

If the race won't start use the command "/recompile race". That will reload the script. Other than that use the commands I posted in the first post. Remember that you have to use some of the maps I included (rc_Airpirates, rc_Bigfalls, rc_Arena) or set the checkpoints on your own if you want to play in another map.
urraka

Offline chutem

  • Veteran
  • *****
  • Posts: 1119
Re: PerroRACE - very cool Racing script (beta?)
« Reply #38 on: November 16, 2007, 06:50:24 pm »
in the server.ini, mke sure the gamemode is 0 or 1 and there is no bots, double click dedicated server.

then open up normal soldat > join game and request the local servers, yours should appear join al voila
1NK3FbdNtH6jNH4dc1fzuvd4ruVdMQABvs

Offline Eclipse

  • Soldier
  • **
  • Posts: 210
  • :D
Re: PerroRACE - very cool Racing script (beta?)
« Reply #39 on: November 17, 2007, 02:58:53 am »
I went in, Its okay. Maps are awesome
All teh Piezors Shall beh Minezors!