Useful script for headless hosts

Talk about haxball in here, maps, sides, players, tactics, anything related to the game.

Useful script for headless hosts

Postby Anddy » June 21st, 2018, 8:21 pm

Hey, I made a little script with some interesting features in order to handle rooms
I started javascript 2 months ago so i'd be happy to get a review of my code ^^
If a bug happens, please post it or pm me on ts, i'll try to solve it as quickly as possible
There's a known bug that sometimes the scorer displayed can be the wrong one.

I know other coders have done better than me but nobody posted on fm, so here's the link
https://pastebin.com/e9nxgRQ7

features: version 0: https://pastebin.com/f7AJ5f9G
- if the room is empty, the first player who joins will be admin
- if the last admin leaves, the oldest player in the room will be admin
- a player can get admin by typing a password (here it's !admin Anddyisthebest) can be changed line 131 and can't been seen if written ofc
- an admin is able to mute players (or himself ^^) in the room, he can also unmute them
- an admin is able to reset the bans of the room
- a message is written by the host when a goal has been scored, it says who scored, who assisted (if there is), if it's an og, when it has been scored and against who
- a message is written by the host when a match is finished, it globally sum up the previous point for each goals
- a player can see how much goals he scored/assisted/miserably scored against his team

Added in version 1: https://pastebin.com/UHsbhqa2
- A player keeps his previous stats when he refreshs
- A player is now able to see other player's stats with the command "!stats PlayerName" (note: "!stats" command doesnt work anymore without a nickname in argument)
- An admin can unmute himself if he gets muted (pm me on ts if you don't want this feature for your own utility :albino: )

Added in version 1.1: https://pastebin.com/1unKMnk4
- Cleensheet are now implemented, write "!gk" before the first min to be declared as the gk of your team !

Added in version 1.2: https://pastebin.com/DA5JWYRn
- Wins and loses are now implemented !
- Gk will be now determined by saviola's method (the most backward player in the team at the kick off will be set as gk), but the "!gk" command is still working if the bot is wrong.

Added in version 1.3: hhttps://pastebin.com/T7Rz2bJf
- Ranking system based on fm fantasy haxball ! Type "!ranking" to see the best players in the room !
Goal: 5 pts, assist: 3 pts, win: 3 pts, cs: 6 pts, lose: -7 pts, og: -4 pts. (maybe i'll add "!gk" like command to know who is dm, am, st and be more fair about points)
- Fixed a bug where the gk wasn't set if all the red players were behind the ball (near the circle)

Added in version 1.4: https://pastebin.com/fDdsxRmC

- FUCKING BUG FIXED, JAVASCRIPT IS BULLSHIT.
- !swap command (for admins), switch blues and reds when no game are in progress.
- Added points to !stats Player.
- A player with positive points is able to reset his stats with "!resetstats"
- Better ranking display.


Added in version 1.5: https://pastebin.com/ZGmtR5pm

- "!rr" command to restart a game
- "!poss" command, to see the ball possession of the two team in a match. (Don't be scared about NaN% if the ball haven't been touched once)
- New structure for commands, cleaner, easier if you want to remove some features, and a little faster for the machine (thanks saviola)

Fixed a possession bug: https://pastebin.com/e9nxgRQ7

What i'm working on:
- add wins/loses/matchs played/mins played in statistics # just missing mins played, will be added soon
- a player will be able to see other player's stats # Done
- when basro will add private messages in haxball, the host will stop spamming to everyone when someone type a command
- try to fix the sometimes wrong scorer issue # Done


If you have any suggestion, any idea to improve the bot, please don't be shy.
  • 80

Last edited by Anddy on July 27th, 2018, 11:00 am, edited 17 times in total.
Anddy
 
Posts: 245
News Articles: 0
Reputation: 537

Joined: October 4th, 2015, 5:54 pm


Re: Useful script for headless hosts

Postby saviola » June 22nd, 2018, 6:24 am

Good job. Is it necessary to define the room.onTeamGoal event handler inside the room.onGameTick handler? This will be executed on every tick, so you define a new event handler every tick, I think it should be pulled into the global scope.
  • 6

User avatar
saviola
 
Posts: 144
News Articles: 0
Reputation: 660

Joined: December 9th, 2012, 5:08 pm


Re: Useful script for headless hosts

Postby Anddy » June 22nd, 2018, 7:57 am

You're right, it's not necessary, i'll edit the first post, thanks
  • 0

Anddy
 
Posts: 245
News Articles: 0
Reputation: 537

Joined: October 4th, 2015, 5:54 pm


Re: Useful script for headless hosts

Postby DonLokko » June 22nd, 2018, 4:03 pm

:thumbup: First of all, thank you very much for sharing this, very OpenSource I like it!
I was reading through your code and something got my attention:
Are the events implemented? I see some chat commands that can be executed like p and clearing bans.
If these work, I think you made yourself an html 2.0.

Btw: are you the one that made the headless interface?
Anyways good job mon ami :thumbup:
  • 0

User avatar
DonLokko
 
Posts: 5
News Articles: 0
Reputation: 28

Joined: July 19th, 2017, 9:01 am

Position: Goalkeeper

Re: Useful script for headless hosts

Postby jasko » June 22nd, 2018, 6:26 pm

Anddy the real MVP!
  • 0

 
Never argue with an idiot. They will only bring you down to their level and beat you with experience.

Wise men speak because they have something to say, fools because they have to say something.

No one is more hated than he who speaks the truth.

Courage is knowing what not to fear.

Showing off is the fool's idea of glory.
User avatar
jasko
 
Posts: 347
News Articles: 0
Reputation: 582

Joined: April 3rd, 2016, 11:02 pm

Position: Attacking Midfielder

Re: Useful script for headless hosts

Postby Anddy » June 23rd, 2018, 4:43 pm

If you find a bug, and I know there is, particularly with the bot telling the wrong scorer/assister, please send me a rec to analyze why it's bugging, ty ^^
  • 0

Anddy
 
Posts: 245
News Articles: 0
Reputation: 537

Joined: October 4th, 2015, 5:54 pm


Re: Useful script for headless hosts

Postby Anddy » June 24th, 2018, 9:44 am

Update:
- A player keeps his previous stats when he refreshs
- A player is now able to see other player's stats with the command "!stats PlayerName" (note: "!stats" command doesnt work anymore without a nickname in argument)
- An admin can unmute himself if he gets muted (pm me on ts if you don't want this feature for your own utility :albino: )



Since stats are now working with nicknames and not anymore with ids, if 2 players have exactly the same nickname, they will share the same stats.

First message edited with the new version, haven't fully tested it so here's the old one https://pastebin.com/f7AJ5f9G
  • 0

Anddy
 
Posts: 245
News Articles: 0
Reputation: 537

Joined: October 4th, 2015, 5:54 pm


Re: Useful script for headless hosts

Postby Anddy » June 24th, 2018, 9:46 pm

Update:
- Cleensheet are now implemented in stats, i'm hoping users are not idiots to troll so I made this system:
Each GK will have to write "!gk" on chat before the first minute to announce they are gk, the last one who says gk will get the cleensheet (if there is), i'm expecting you won't spam "!gk !gk !gk !gk" :albino:

- I understood why it's sometimes bugging but i can't fix it yet, it's exactly when you kick the ball with this power http://thehax.pl/forum/powtorki.php?nag ... 92808b30ae

https://pastebin.com/1unKMnk4
  • 0

Anddy
 
Posts: 245
News Articles: 0
Reputation: 537

Joined: October 4th, 2015, 5:54 pm


Re: Useful script for headless hosts

Postby lajz » June 24th, 2018, 11:04 pm

Anddy wrote:Update:
- Cleensheet are now implemented in stats, i'm hoping users are not idiots to troll so I made this system:
Each GK will have to write "!gk" on chat before the first minute to announce they are gk, the last one who says gk will get the cleensheet (if there is), i'm expecting you won't spam "!gk !gk !gk !gk" :albino:


What about changing it to making a GK 1st player in each team. Most of the teams are using GK-DM-AM-ST. If they care about it it's about them to make it correct :P
  • 5

lajz
 
Posts: 16
News Articles: 0
Reputation: 103

Joined: March 4th, 2018, 6:54 pm


Re: Useful script for headless hosts

Postby saviola » June 25th, 2018, 7:00 am

How about determining the GK based on the player locations at kickoff? So at kickoff you check all player locations (coordinates on the field) and the ones closest to the respective goal are the GKs. Not perfect, but should cover 95% of cases (you could keep your "!gk" command if people want to manually fix it), maybe you could announce the GKs after kickoff on chat.
  • 1

User avatar
saviola
 
Posts: 144
News Articles: 0
Reputation: 660

Joined: December 9th, 2012, 5:08 pm


Re: Useful script for headless hosts

Postby Anddy » June 25th, 2018, 8:05 am

I'll code your ideas and I'll see which one is the best (rather saviola's in order to make it automatically)
  • 0

Anddy
 
Posts: 245
News Articles: 0
Reputation: 537

Joined: October 4th, 2015, 5:54 pm


Re: Useful script for headless hosts

Postby lajz » June 25th, 2018, 10:11 am

saviola_GK wrote:How about determining the GK based on the player locations at kickoff? So at kickoff you check all player locations (coordinates on the field) and the ones closest to the respective goal are the GKs. Not perfect, but should cover 95% of cases (you could keep your "!gk" command if people want to manually fix it), maybe you could announce the GKs after kickoff on chat.


Why not both? :) Some teams are using diffrent tactics for kick-off (e.g. strat 43 in archNemeses :lol:). If goalkeeper in red team is starting the game or GK and DM are doing some weird rocketshot Saviola's idea sadly won't work. :(
  • 0

lajz
 
Posts: 16
News Articles: 0
Reputation: 103

Joined: March 4th, 2018, 6:54 pm


Re: Useful script for headless hosts

Postby Anddy » June 25th, 2018, 12:51 pm

Update:

- Wins and loses are now implemented !
- Gk will be now determined by saviola's method (the most backward player in the team at the kick off will be set as gk), but the "!gk" command is still working if the bot is wrong.

https://pastebin.com/DA5JWYRn
  • 0

Anddy
 
Posts: 245
News Articles: 0
Reputation: 537

Joined: October 4th, 2015, 5:54 pm


Re: Useful script for headless hosts

Postby Anddy » June 26th, 2018, 9:51 am

Update : https://pastebin.com/T7Rz2bJf
- Ranking system based on fm fantasy haxball ! Type "!ranking" to see the best players in the room !
Goal: 5 pts, assist: 3 pts, win: 3 pts, cs: 6 pts, lose: -7 pts, og: -4 pts. (maybe i'll add "!gk" like command to know who is dm, am, st and be more fair about points)
- Fixed a bug where the gk wasn't set if all the red players were behind the ball (near the circle)
  • 0

Anddy
 
Posts: 245
News Articles: 0
Reputation: 537

Joined: October 4th, 2015, 5:54 pm


Re: Useful script for headless hosts

Postby Anddy » July 1st, 2018, 7:21 pm

Update: https://pastebin.com/fDdsxRmC

- FUCKING BUG FIXED, JAVASCRIPT IS BULLSHIT.
- !swap command (for admins), switch blues and reds when no game are in progress. ( HI JASKO !!!!!!!!!!!!)
- Added points to !stats Player.
- A player with positive points is able to reset his stats with "!resetstats"
- Better ranking display.


My code is becoming shitter and shitter, so maybe i'll stop here or maybe i'll do one last huge surprise update soon, idk yet.
still waiting for basro's pm promise because i see more and more people crying about the bot's spam in chat but i can't do anything atm ^^
  • 0

Anddy
 
Posts: 245
News Articles: 0
Reputation: 537

Joined: October 4th, 2015, 5:54 pm


Re: Useful script for headless hosts

Postby Anddy » July 3rd, 2018, 5:20 pm

Update: https://pastebin.com/ZGmtR5pm

- "!rr" command to restart a game
- "!poss" command, to see the ball possession of the two team in a match. (Don't be scared about NaN% if the ball haven't been touched once)
- New structure for commands, cleaner, easier if you want to remove some features, and a little faster for the machine (thanks saviola)
- A muted player can't unmute himself anymore (sorry if you prefer the previous version :p )

I've made a test to know what's the limit of onGameTick event, it seems that we're able to do more than 100000000 simple operations per tick without crashing. Since this script does like +100 operations per, it represents > 0.00001% before players feel a difference.

Oh btw, new password to be admin, read the code, not hard to find :p
  • 13

Anddy
 
Posts: 245
News Articles: 0
Reputation: 537

Joined: October 4th, 2015, 5:54 pm


Re: Useful script for headless hosts

Postby FrA » July 3rd, 2018, 8:05 pm

nice job brother, rly usefull
  • 0

FrA
 
Posts: 22
News Articles: 0
Reputation: 10

Joined: May 12th, 2013, 5:34 pm


Re: Useful script for headless hosts

Postby Anddy » July 4th, 2018, 9:03 am

Thanks !
  • 0

Anddy
 
Posts: 245
News Articles: 0
Reputation: 537

Joined: October 4th, 2015, 5:54 pm


Re: Useful script for headless hosts

Postby Anddy » July 27th, 2018, 10:59 am

- fixed a really small bug where the ball possession was going crazy if a goal is scored by a team and the ball is touched by the other team. Now it will always finish with red + blue = 100 (+-1)
- added possession display at the end of a match

https://pastebin.com/e9nxgRQ7


edit after fully test: it seems it still bugged
  • 10

Anddy
 
Posts: 245
News Articles: 0
Reputation: 537

Joined: October 4th, 2015, 5:54 pm


Re: Useful script for headless hosts

Postby el tigre » August 14th, 2019, 12:32 am

hello friend,

do you still working on this script? do you add new things? even this version still so useful but you know, im very excited about new things :)
  • 0

el tigre
 
Posts: 2
News Articles: 0
Reputation: 0

Joined: August 14th, 2019, 12:29 am


Next

Return to General Haxball Discussion

Who is online

Users browsing this forum: No registered users and 19 guests