How do you make custom map scripts?

Post Reply
JOTR
Posts: 19
Joined: Mon Jun 01, 2015 5:37 pm

How do you make custom map scripts?

Post by JOTR »

Hi my lovely community,

I wanted to show you my method how I create custommapscripts and ask you if there is a faster way to make those scripts

How do I get the X,Y,Z-Coords

Because I'm too lazy to run a decicated server or load the correct mod, I just connect to the TWC etjump or 999 etjump Server and load my favourite map in the console with "/map name".

I use this commands to show the coords :
"etj_CHS1Info 44" (use /chs to show all possibilities) and
"/etj_drawCHS1 1"

I use those commands for noclip (I mention this because I had strange bugs trying just to noclip):
/sv_cheats 1
/etj_noclipScale 1
/cmd noclip <-- toggle on/off /noclip will bug you

Create scripts with this small javscript

Open a new tab with about:blank and open the developer console (F12-Console), just copy paste the code below and press enter, the rest ist userfriendly. If you want to see an example or if you are too lazy to setup your own script per about:blank, use this one:

https://jsfiddle.net/xpf7q39w/

Code: Select all



// gui elements
var forma = document.createElement("form"),
	
gui = {
	namebox : document.createElement("input"),
	runnrbox : document.createElement("input"),
	startcoordbox : document.createElement("input"),
	colornrbox : document.createElement("input"),
	endcoordbox : document.createElement("input"),
	checkpoints : document.createElement("div"),
	buttonAddCP : document.createElement("button"),
	buttonReset : document.createElement("button"),
	buttonGenerate : document.createElement("button"),
	showbox : document.createElement("textarea")
};

// gui text
gui.namebox.placeholder = "Enter idendification/name of run";
gui.runnrbox.placeholder = 'Enter the "Run Nr"';
gui.startcoordbox.placeholder = "Enter start coords like -5 5 -5";
gui.colornrbox.placeholder = "Enter the color number of Sthe tart/End trigger";
gui.endcoordbox.placeholder="Enter end coords like 200 -5 -2";
var checkpointInputText = "Enter checkpoints coords like 53 22 55",
	removeCPText = "Remove Checkpoint";

gui.buttonAddCP.textContent="Add Checkpoint";
gui.buttonReset.textContent="Reset"
gui.buttonGenerate.textContent="Generate";

// gui fucntions
function buildGui(){
	forma.onsubmit = function(e){  e.preventDefault(); };
	for( let guielement in gui ){
		gui[guielement].style.minWidth = 320;
		forma.appendChild(gui[guielement]);
		forma.appendChild(document.createElement("br"));
	}
	document.body.appendChild(forma);
	
	gui.showbox.style.minHeight = 300;
}


gui.buttonReset.onclick = function(){
	if( confirm("Reset?") ){
		forma.reset();
		gui.checkpoints.textContent = null;
	}
};

gui.buttonAddCP.onclick = function(){
	let checkpointBox = document.createElement("input");
	checkpointBox.placeholder = checkpointInputText;
	
	let removeCP = document.createElement("a");
	let br = document.createElement("br");
	removeCP.text = removeCPText;
	removeCP.onclick = function(){
		gui.checkpoints.removeChild( checkpointBox );
		gui.checkpoints.removeChild( removeCP );
		gui.checkpoints.removeChild( br );
	};
	
	gui.checkpoints.appendChild(checkpointBox);
	gui.checkpoints.appendChild(removeCP);
	gui.checkpoints.appendChild(br);
	
	
};

function writeCheckpointScriptPart(){
	let retCPPart = "";
	let CPposition = 0; // enumerate checkpoints, define position
	for (let i = 0; i < gui.checkpoints.childNodes.length; i++){
		let el = gui.checkpoints.childNodes[i];
		if(el.constructor.name != "HTMLInputElement"){
			continue;
		}
		
		retCPPart += `
		// checkpoint nr <${CPposition +1}> of "${gui.namebox.value}"
		create
		{
			origin "${el.value}"
			mins "-200 -200 -25"
			maxs "200 200 25"
			classname "trigger_multiple"
			target "check${CPposition}"
			contents "1073741824"
		}
		create
		{
			origin "${el.value}"
			classname "target_checkpoint"
			targetname "check${CPposition}"
			name "${gui.namebox.value}"
		}
		`
		CPposition += 1; 
	}
	
	return { text: retCPPart, size: CPposition };
}

gui.buttonGenerate.onclick = function(){
	gui.showbox.textContent = `
		///////////////////////
		// START OF "${gui.namebox.value}"
		///////////////////////
		create
		{
			origin "${gui.startcoordbox.value}"
			mins "-90 -90 -25"
			maxs "90 90 25"
			classname "trigger_multiple"
			target "starttimer${gui.runnrbox.value}"
			contents "1073741824"
		}
		create
		{
			origin "${gui.startcoordbox.value}"
			classname "target_startTimer"
			targetname "starttimer${gui.runnrbox.value}"
			name "${gui.namebox.value}"
		}
		create
		{
			origin "${gui.startcoordbox.value}"
			classname "misc_gamemodel"
			mins "-90 -90 -25"
			maxs "90 90 25"
			model "models/mapobjects/timerun/start_${gui.colornrbox.value}.md3"
			fps "12"
			frames "25"
			start "0"
			spawnflags "2"
		}
		${ writeCheckpointScriptPart().text != "" ? "// checkpoints" : "// no checkpoints"}
		${writeCheckpointScriptPart().text}
		
		
		create
		{
			origin "${gui.endcoordbox.value}"
			mins "-90 -90 -25"
			maxs "90 90 25"
			classname "trigger_multiple"
			target "stoptimer${gui.runnrbox.value}"
			contents "1073741824"
		}
		create
		{
			origin "${gui.endcoordbox.value}"
			classname "target_stopTimer"
			targetname "stoptimer${gui.runnrbox.value}"
			mincheckpoints "${writeCheckpointScriptPart().size}"
			name "${gui.namebox.value}"
		}
		create
		{
			origin "${gui.endcoordbox.value}"
			classname "misc_gamemodel"
			mins "-90 -90 -25"
			maxs "90 90 25"
			model "models/mapobjects/timerun/stop_${gui.colornrbox.value}.md3"
			fps "12"
			frames "25"
			start "0"
			spawnflags "2"
		}
		///////////////////////
		// END OF "${gui.namebox.value}"
		///////////////////////
	`;
};

//main
buildGui();
** update 05.09 I added some new features for making it easier to work with and the output is now in a textarea so it can be edited and its easier to copy.

Don't forget that this script can't handle the widths of the start-, stoptimer and the checkpoint trigger and you are not able to set the same checkpoint on a different position, but you can do it manually...

Is there a faster/easier way?
Attachments
roeltje2_and_xtremetricks_b1.zip
(4.03 KiB) Downloaded 18549 times
Post Reply