MoHAAS.net scripts

From MoHAAS.net Wiki
Jump to: navigation, search

On this page you can read about game server side scripts that can be necessary or helpful to get the most out of the MoHAAS.net administration panel.


Preliminaries

Go through all your mods of your game server. Search for the file global/ambient.scr in your pk3 files. If you cannot find this file, you can directly jump to the download section below and integrate the file with your existing mods. Scroll down to the very bottom of this page to find the download.

If you already have an ambient.scr in your game pk3 mods, you will need to follow the instructions below in order to make our scripts work with your existing mods. If you ignore the instructions, you might get complications and either our or your scripts may stop working.


Necessary scripts for full functionality on MoHAAS.net

You should add two custom rcon commands to the server if you would like to get all MoHAAS.net functionality. Here you can read further how to do that.

The commands

Forcing fullscreen on clients

Some users have gray screens when you try to screenshot using the MoHAAS.net administration panel. You can avoid that by forcing them to windowed mode by the panel or by rcon directly before you screenshot them.

If you implement the code on the bottom of this page, you will be able to call rcon clientfullscreen 2|0. This will set the fullscreen state to 0 for client 2. Fullscreen state 0 is windowed mode, which will prevent that you get a gray screen when screenshotting the player.

Moving clients to another server

When correctly configured, you can force some (or all) players to be thrown out of your server when they are not using the MoHAAS.net tool. When you implement the code on the bottom of this page, these players will not get kicked, but moved to the MoHAAS.net redirect server. This server is unplayable, but shows a message to them that they should download the MoHAAS.net tool.

If the script is working, you can also use it by calling rcon clientconnect 3|192.168.1.1:12204. This will force the player client 3 to connect to the server 192.168.1.1:12204.

Setup

Open your file global/ambient.scr and add the line

exec global/rconcommands.scr

to the very top, but after waittill spawn.

The script

Copy the following code into a file rconcommands.scr. Put this file into the global folder of your mod pk3 file.

// The main method. Gets executed when you call the file by "exec rconcommands.scr"
main:

// Infinite loop
while(1) {

	// Check if the current command has been called
	if(getcvar(clientfullscreen) != "") {
		
		// Get the entered clientnumber
		local.data = getcvar clientfullscreen
			
		// Reset the cvar to empty
		setcvar clientfullscreen ""
			
		// Launch the execute command
		thread clientfullscreen local.data
	}
		
	// Wait just an instant
	waitframe
	
	// Check if the current command has been called
	if(getcvar(clientconnect) != "") {
		
		// Get the entered clientnumber
		local.data = getcvar clientconnect
			
		// Reset the cvar to empty
		setcvar clientconnect ""
			
		// Launch the execute command
		thread clientconnect local.data
	}

	// Check for rcon commands every second
	wait 0.25
	
}


//


// Gets the player id by the client number
getIdByClientNr local.cvar:

for(local.i=1;local.i<=$player.size;local.i++) {
	if($player[local.i].entnum == local.cvar) end local.i
}

end 0


//


// Changes the fullscreen state
clientfullscreen local.cvar:

// local.var looks like this: "nr|nr"
local.nr = ""
local.value = ""

local.stringSize = int(local.cvar.size)

local.count = 1

for(local.i=0; local.i<local.stringSize; local.i++) {
	if(local.cvar[local.i]=="|") {
		local.count++
	} else {
		if(local.count==1) local.nr = local.nr + local.cvar[local.i]
		if(local.count==2) local.value = local.value + local.cvar[local.i]
	}
}

// If we dont have 1 | then end
if(local.count!=2) end

// Make integers
local.nr = int(local.nr)
local.value = int(local.value)

// Get player ID
local.who = thread getIdByClientNr local.nr

// Set the screen resolution to the player
local.player = $player[local.who]
local.player stufftext ("set r_fullscreen " + local.value + ";vid_restart")

end


// Connects the client to another server
clientconnect local.cvar:

// local.var looks like this: "nr|ip"
local.nr = ""
local.ip = ""

local.stringSize = int(local.cvar.size)

local.count = 1

for(local.i=0; local.i<local.stringSize; local.i++) {
	if(local.cvar[local.i]=="|") {
		local.count++
	} else {
		if(local.count==1) local.nr = local.nr + local.cvar[local.i]
		if(local.count==2) local.ip = local.ip + local.cvar[local.i]
	}
}

// If we dont have 1 | then end
if(local.count!=2) end

// Make integers
local.nr = int(local.nr)

// Get player ID
local.who = thread getIdByClientNr local.nr

// Set the screen resolution to the player
local.player = $player[local.who]
local.player stufftext ("connect " + local.ip)

end

Additional scripts

If you would like to announce something on your server (for example the introduction of the MoHAAS.net tool, we have the perfect script for you. The following script can be called any time in your code on your game server, for example at the end of a round.

When called, the script draws a black image over the whole screen of the players, so no one can really do anything and all attention is drawn to the message you would like to display. The script can draw up to 5 lines of text to the screen of the players.

Setup the script

Step 1

Initialize the script in your map. The easiest way to achieve is to open the file global/ambient.scr in one of your mods and add the line

exec global/announcement.scr
exec global/announcement.scr::listen // this line is only necessary if you want to be able to announce the message by rcon

to the very top, but after waittill spawn. If you do not have the file ambient.scr in your mods already, you can download our pk3 and simply add it to your game server folder.

Step 2

Create a file anouncement.cfg and place it into your main/ta/tt folder of your game server (depending on your game). Add the following lines to the file:

level.announcement = makeArray
	"IMPORTANT MESSAGE TO ALL PLAYERS"	
	"Our server is protected by our new anti-cheat."	
	"Please download, install and run our tool from mohaas.net!"	
	"Then you can rejoin our server and please play clean."	
	" >>> www.mohaas.net <<< "
endArray

It is very important to make no error in this code. You can edit the 5 lines to your needs, that is how it will be displayed on your game server.

Examples: How to make the announcement appear

There are two ways how to call the announcement script.

Call by rcon

If line 2 above has been added, you can call the announcement by rcon: Type rcon announcementSeconds 10. This will show the announcement for 10 seconds to all users.

Call by code

Instead of using rcon, you can call the script from any point in your script by adding these lines:

// ADDED
waitexec global/announcement.scr::show
wait 10
waitexec global/announcement.scr::hide
// END ADDED

For example, you could add this code to the end of a round. In Countdown, you could add the script into HTR/camera.scr to the top method main local.dmteam before the line where this code is displayed:

local.gt = getcvar "g_gametype"

This would make sure that your announcement is placed before the score table is drawn and a winner is made, but the round has already ended.

The script

Put this script into a file called announcement.scr. Place this file into the folder global of any of your mods.

// Sets up the server message huds
main:

	// Include the config with the data
	waitexec announcement.cfg
					
end 1


// Listener
listen:

	while(1) 
	{
		local.announcementSeconds = int(getcvar "announcementSeconds")
		
		if (local.announcementSeconds > 0)
		{
			setcvar "announcementSeconds" 0
			
			local.seconds = 0
						
			while (local.seconds < local.announcementSeconds) 
			{
				thread show
				local.seconds++
				wait 1
			}
			
			thread hide	
		}	
		
		wait 5
	}

end


// Shows the message
show:

	if (level.announcement.size != 5)
	{
		end 0
	}
	
	// Draw black image
	huddraw_virtualsize 90 1
	huddraw_alpha 90 1
	huddraw_rect 90 0 0 5000 5000
	huddraw_shader 90 "textures/mohmenu/black.tga"
		
	// Draw the text
	huddraw_align 91 center center
	huddraw_rect 91 -370 -100 0 0
	huddraw_font 91 "delima-30"
	huddraw_alpha 91 1
	huddraw_color 91 1 1 1
	huddraw_string 91 level.announcement[1][1]
				
	huddraw_align 92 center center
	huddraw_rect 92 -370 -50 0 0
	huddraw_font 92 "delima-30"
	huddraw_alpha 92 1
	huddraw_color 92 1 1 1
	huddraw_string 92 level.announcement[2][1]
				
	huddraw_align 93 center center
	huddraw_rect 93 -370 -10 0 0
	huddraw_font 93 "delima-30"
	huddraw_alpha 93 1
	huddraw_color 93 1 1 1
	huddraw_string 93 level.announcement[3][1]
				
	huddraw_align 94 center center
	huddraw_rect 94 -370 30 0 0
	huddraw_font 94 "delima-30"
	huddraw_alpha 94 1
	huddraw_color 94 1 1 1
	huddraw_string 94 level.announcement[4][1]
			
	huddraw_align 95 center center
	huddraw_rect 95 -370 70 0 0
	huddraw_font 95 "delima-30"
	huddraw_alpha 95 1
	huddraw_color 95 1 1 1
	huddraw_string 95 level.announcement[5][1]

end


// Hides the message
hide:
	
	for (local.i = 90; local.i <= 95; local.i++)
	{
		huddraw_alpha local.i 0
	}
	
end

Download

If you do not have any file called ambient.scr in your mods (excluding all official pak*.pk3), you can simply download our pre-packed pk3 file and add this file to your game server into the folder mainta (Spearhead). If you would like to use it with MoHAA or Breakthrough, you can proceed by adding the pk3 to main or maintt respectively. Do not forget to add the announcement.cfg to the same folder as the pk3 file.