The 'QuakeC lessons' thread[prev. help with script teleport]

Have questions about CoD/UO mapping that aren't covered in the tutorials section? Post here!

Moderator: Core Staff

Ryan
CJ Newbie
CJ Newbie
Posts: 64
Joined: March 2nd, 2008, 1:18 am
Location: Germany

The 'QuakeC lessons' thread[prev. help with script teleport]

Post by Ryan » April 29th, 2011, 10:08 am

hey guys

i'd like to learn how to script in CoD1 but i've got absolutely no idea how to start or how do achieve what i want. i read through the tutorial posted by Drofder so i understand the basics of it but i dont see any way of starting from scratch and getting to a fully working script.

what i'd like to do is create a script for teleport. you should be able to specify certain points in the map by putting coordinates and if a player is there and presses F he teleports.

i've got a script here but i dont understand as to why these commands are there exactly in this row exactly like that and why they cant be different... this script was created by megazoR whos been my jumping mate for years...

Code: Select all

tigertown_jump_expansion()
{
	srv_tig1 = (-2345, -2275, 348);
	srv_tigtele1 = (124, -27, 402);

	srv_tig2 = (-298, 403, 231);
	srv_tigtele2 = (-1495, -998, 648);

	for (i = 0; i < level.awe_allplayers.size; i++)
	{
		if (isDefined(level.awe_allplayers[i]) && level.awe_allplayers[i].sessionstate == "playing" && level.awe_allplayers[i] useButtonPressed()) //player? playing? pressed Use?
		{
			if (distance (level.awe_allplayers[i].origin, srv_tig1) < 30)
			level.awe_allplayers[i] setOrigin(srv_tigtele1);
			else if (distance (level.awe_allplayers[i].origin, srv_tig2) < 30)
			level.awe_allplayers[i] setOrigin(srv_tigtele2);
		}
	wait .05;
	}
	thread tigertown_jump_expansion();
}
he explained it to me before only vaguely to make me able to modify the script and set individual teleports. what i dont understand is everything after the coordinates.

i do not want to learn other programming languages first before doing this so i hope we'll be able to sort this out without knowing hundreds of other programming language Quake C is based on...

thanks for your help in advance guys

Edit by Rezil: code tags

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: help with script teleport

Post by Rezil » April 29th, 2011, 10:33 am

The code works fine at first glance, although if the array of players is not constantly updated you might miss some players(disconnecting and connecting). This is the relevant bit:

Code: Select all

         if (distance (level.awe_allplayers[i].origin, srv_tig1) < 30)
         level.awe_allplayers[i] setOrigin(srv_tigtele1);
So, in pseudo:

IF distance from level.awe_allplayers' origin and coordinate srv_tig1 is less than 30,
THEN set origin of level.awe_allplayers to coordinate srv_tigtele1.

You have to alter/add origins of where you want the F button to be pressed and where you want to be teleported once that happens. To find your origin, use this function:

Code: Select all

printOrg()
{
	for(;;)
	{
		p = getEntArray("player","classname");
		for(i=0;i<p.size;i++)
			p[i] iPrintLn("X: "+p[i].origin[0]+"Y: "+p[i].origin[1]+"Z: "+p[i].origin[2]);
			
		wait 0.5;
	}
}
Call it somewhere either from your gametype script or your map script.
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

megazor
CJ Worshipper
CJ Worshipper
Posts: 414
Joined: July 22nd, 2009, 3:02 am
Location: Russia, Vladivostok

Re: help with script teleport

Post by megazor » April 29th, 2011, 10:41 am

Code: Select all

tigertown_jump_expansion()
{
   	srv_tig1 = (-2345, -2275, 348);
   	srv_tigtele1 = (124, -27, 402);

   	srv_tig2 = (-298, 403, 231);
   	srv_tigtele2 = (-1495, -998, 648);

	players = getEntArray("player", "classname");

   	for (i = 0; i < players.size; i++)
      		if (players[i].sessionstate == "playing" && players[i] useButtonPressed()) //player? playing? pressed Use?
      		{
         			if (distance(players[i].origin, srv_tig1) < 30)
         				players[i] setOrigin(srv_tigtele1);
         			else if (distance(players[i].origin, srv_tig2) < 30)
         				players[i] setOrigin(srv_tigtele2);
      		}

   	wait .05;
   	thread tigertown_jump_expansion();
}

IzNoGoD
CJ Worshipper
CJ Worshipper
Posts: 343
Joined: January 6th, 2009, 8:39 pm
Location: Netherlands/Holland

Re: help with script teleport

Post by IzNoGoD » April 29th, 2011, 12:28 pm

Code: Select all

tigertown_jump_expansion()
{
	thread tigertown_jump_expansion_triggers(); //use this instead of calling a thread within the function, it prevents buffer overflows
}
tigertown_jump_expansion_triggers()
{
	srv_tig[0]=spawnstruct(); //just to create a structure here, so the code below doesnt error
	srv_tig[0].origin=(-2345, -2275, 348); //arrays start from zero, not from one
	srv_tig[0].target=(124, -27, 402);

	srv_tig[1]=spawnstruct();
	srv_tig[1].origin=(-298, 403, 231);
	srv_tig[1].target=(-1495, -998, 648);

	//add more teleports by copy-pasting above code, upping the index by one and changing the coordinates, example:

	//srv_tig[2]=spawnstruct();
	//srv_tig[2].origin=(0,0,0);
	//srv_tig[2].target=(1,1,1);

	//as above code is commented, it wont execute. Start with the [2] index to add more (the [2] is not yet in use, as above code is commented)

	for(;;) //keep looping the code below this
	{
		players=getentarray("player","classname");

		for(i=0;i<players.size;i++)	//execute the code below on every player
		{
			if(isdefined(players[i].sessionstate)&&players[i].sessionstate=="playing"&&players[i] usebuttonpressed()) //check if player is playing (added the isdefined to prevent developer 1 crashes), and if he is pressing the usebutton
			{
				for(j=0;j<srv_tig.size;j++) //this auto-detects how many teleports you have, and loops the code for every teleport, so adding teleports is very easy
				{
					if(distancesquared(players[i].origin,srv_tig[j].origin)<30*30) //distancesquared is lighter for the server than distance
					{
						players[i] setorigin(srv_tig[j].target); //the code that actually does the teleporting
						players[i] iprintlnbold("You have been teleported");
					}
				}
			}
		}
		wait 0.05;
	}
}
Fixed, rewrote the whole code for you. Should be easier to add more teleports, and lighter for the server, without any buffer overflow crashes
LMGTFY!

Its not a glitch... Its the future!

Ryan
CJ Newbie
CJ Newbie
Posts: 64
Joined: March 2nd, 2008, 1:18 am
Location: Germany

Re: help with script teleport

Post by Ryan » April 29th, 2011, 1:33 pm

i appreciate that you help me but i dont really understand what all of this means for example level.awe_allplayers what does level and awe_allplayers and i do and why is there a period between level and awe_allplayers and why is i in box brackets...

i'd like to learn about this and not just insert it into a ftp and use it...

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: help with script teleport

Post by Rezil » April 29th, 2011, 1:40 pm

i'd like to learn about this and not just insert it into a ftp and use it...
:roll:

Well then learn. Coding is logic in it's most basic form. You can start with C and then move to QuakeC or you can start with QuakeC from the get go. Another thing is that you can't really understand how things work without actually applying them yourself. So practice, practice, practice.

Homework:
Store a value of 0 in a variable, then loop for ten cycles, incrementing the value every cycle and printing it out to the player.

When you're able to do this(a very basic task), you should be able to understand megazors code a bit more.

Unrelated, but for the coders here: QuakeC is a fucking shitty language in terms of coding habits. Variables don't have a type defined, no new type declarations, no file handling(other than writing a simple text file) etc. If you start at QuakeC and then move on to something else(like Java), you better be good at changing habits. :P
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

Ryan
CJ Newbie
CJ Newbie
Posts: 64
Joined: March 2nd, 2008, 1:18 am
Location: Germany

Re: help with script teleport

Post by Ryan » April 29th, 2011, 2:42 pm

Rezil wrote:
Homework:
Store a value of 0 in a variable, then loop for ten cycles, incrementing the value every cycle and printing it out to the player.
havent i just said that ive got no idea how to start? i could look up drofders tutorial and just copy+paste what you want but wheres the learning effect? you know just to give you an idea of my level of scripting you could ask me to open notepad cos thats the only thing i can do so far... what has to be typed in it i dont know...

SubGunner
CJ Wannabe
CJ Wannabe
Posts: 17
Joined: February 16th, 2011, 10:41 pm

Re: help with script teleport

Post by SubGunner » April 29th, 2011, 3:47 pm

Part of learning how it works is from copy and paste. Disecting parts of coding and making things work.
What type of portal are you after? I have an easy one that i could make a prefab out of. Very simple code to.
You can use as many as you want and even for spawning. We use spawn portals alot in our maps. But placement for exits are very important.

Ryan
CJ Newbie
CJ Newbie
Posts: 64
Joined: March 2nd, 2008, 1:18 am
Location: Germany

Re: help with script teleport

Post by Ryan » April 29th, 2011, 4:01 pm

i dont want a portal... i want a teleport to teleport from one place to another and with only me knowing where these teleports are. they should be able to be used in a normal public server.

i'll try and get me homework done :P

Ryan
CJ Newbie
CJ Newbie
Posts: 64
Joined: March 2nd, 2008, 1:18 am
Location: Germany

Re: help with script teleport

Post by Ryan » April 29th, 2011, 4:16 pm

alright i've done my first attempt and i've got no clue if this is right or not i just guessed from drofder's brilliant tutorial

Code: Select all

for(var=0;var<10;var++)
	{
		iprint1n("var increased");
	}
the iprint1n i just copied since i dont know what the exact cmd is... the things in brackets i found logical so i used it... to me it means: var equals 0 and if its smaller than 10 then increase by 1, once 10 has been reached the loop doesnt proceed anymore, right?

thanks for your help so far guys, hoping for some more XD

Ryan
CJ Newbie
CJ Newbie
Posts: 64
Joined: March 2nd, 2008, 1:18 am
Location: Germany

Re: help with script teleport

Post by Ryan » April 29th, 2011, 5:12 pm

KillerSam wrote:indeed your code says:

Start with var = 0.
check if var is now below 10...if it is, print "var increased" and increase var by 1.
repeat until var is not less than 10.

Small change btw:

iprint1n("var increased");

should be:

iprintln("var increased");

it's a L not a 1, as it means "print a new line" (print line / println).

Btw when you next reply (and have read this) I'll move this topic to the "CoD mapping help" forum, as this is not a tutorial for people to follow.
so is it right then? yeah its obvious i copied it i couldnt see if it was an l or a 1 it looked like a 1 when i briefly looked over it :D

thanks for your help

Rezil you shouldve become a teacher :D so far i've understood it but since this was a very basic script according to what you said i guess thats nothing to be too proud of XD the homework system is cool, they should use this in schools, maybe ppl would then learn more.................................................................. :D

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: help with script teleport

Post by Rezil » April 29th, 2011, 5:41 pm

Homework 2:
Same thing as before, but in your loop, only print that the variable increased IF the value of your variable is either 3 or 8.

Let's see how long it takes you before you get stuck. :)
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

Ryan
CJ Newbie
CJ Newbie
Posts: 64
Joined: March 2nd, 2008, 1:18 am
Location: Germany

Re: help with script teleport

Post by Ryan » April 29th, 2011, 8:53 pm

Code: Select all

for(var=0;var<10;var++)
   {
	if (var == 3)
		{
			iprintln("var increased");
		}
	else if (var == 8)
		{
			iprintln("var increased");
		}
   }

Soviet
Core Staff
Core Staff
Posts: 7760
Joined: April 23rd, 2005, 9:12 pm
Location: Plano, Texas
Contact:

Re: help with script teleport

Post by Soviet » April 29th, 2011, 8:56 pm

Code: Select all

for(var=0;var<10;var++)
   {
	if (var == 3 || var == 8)
		{
			iprintln("var increased");
		}
   }
Slightly more efficient :wink:

|| = or
&& = and
! = not
Image
ImageImageImage
Image
"Zaitsev is a cunt." - Pedsdude

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: help with script teleport

Post by Rezil » April 29th, 2011, 9:05 pm

Soviet's way was what I was looking for. Now for some string manipulation:

Make a variable that contains some random numbers that is 15 letters long, then print out that variable to the player. You can use the built-in function RandomInt(<max>) to get a random value from 0 to <max>-1. Also, you can add to a string by using +("ap"+"ple" would generate a string with the value "apple").

"104576897628576" <- This is what the player should see.




this has turned into a 'learn to script with practice' thread. Also, making up examples is pretty fun. ;)
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests