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

Re: help with script teleport

Post by Ryan » May 3rd, 2011, 1:38 pm

no mate i've run teleport scripts before and i also adjusted them so setting new teleports but only by following instructions given by megazor. it was a .gsc file and i always create these like this: i open notepad++ and click on save as and then put ".gsc" as file extension... tell me if you know a better way to create these...

then i put it into the cb_custom.pk3 and with a few changes in the main .gsc file of the .pk3 launching the teleport script when loading the mod, i uploaded it to the ftp, restarted server and it worked...

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 » May 3rd, 2011, 1:41 pm

Try this:

Make three seperate functions. The first function, fA(param) should return the square of the parameter <param>. The second one, fB(param) should return a boolean(true/false) on whether the parameter <param> is divisible by 3(use modulus - %). The third one, fC(param1, param2) returns a string is this format: "<param1>:-:<param2>".

This one sounds really fun now that I've made it up, give it a go. :D

Print all three using iprintln.
In case you missed it above.
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 » May 3rd, 2011, 1:43 pm

given a string, need to convert it to lowercase one.

example: rYaN -> ryan

the making of that script will give you the knowledge of some new things such as size

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: help with script teleport

Post by Drofder2004 » May 3rd, 2011, 1:46 pm

Rezil wrote:In case you missed it above. [...]
I think that may be a small step ahead, without explaining functions and parameters this will be very confusing.
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

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 » May 3rd, 2011, 1:48 pm

But it's all in your tutorial, so there is no excuse. If he needs further explanation than the one given in your tut, he can ask.

In the meantime:

Code: Select all

main()
{
	integer = fA(25);
	trueBool = fB(39);
	falseBool = fB(5);
	stg = fC(3, "A"); //interestingly enough, in quakeC you don't need to define the type of a variable
	iprintln(integer+" "+trueBool+" "+falseBool+" "+stg);
}

fA(param)
{
	return (param*param)
}
fB(param)
{
	if(param%3==0) return true;
	else return false;
}
fC(param1, param2)
{
	return param1+":-:"+param2;
}
[/size]

Solution here, quote my post/zoom in if you want to spoil it for yourself. :)
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.

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: help with script teleport

Post by Drofder2004 » May 3rd, 2011, 1:50 pm

Rezil wrote:But it's all in your tutorial
Its been a while, that could probably do with a revamp.
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

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 » May 3rd, 2011, 1:51 pm

megazor wrote:given a string, need to convert it to lowercase one.

example: rYaN -> ryan

the making of that script will give you the knowledge of some new things such as size

Code: Select all

randomFunction(string)
{
return tolower(string);
}
Why rewrite a built-in function? :P
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 » May 3rd, 2011, 2:11 pm

IzNoGod no offense meant m8 but can you please stop spoiling my exercises i'm sure mega is competent enough to have known this function for years he just wanted to give me a task to do... he created a fucking minecraft mod for cod1 so i'm sure he knows that this command is an actual built-in function...

KS i've given it a try:

Code: Select all

for(i=0;i<21;i++)
{
        var = i * i;
        
        if(var % 2 = 0);
        {
                iprintln(i+"x"+i+" equals "+(i*i). This is EVEN);
        
        else
                iprintln(i+"x"+i+" equals "+(i*i). This is ODD);
        }
}

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 » May 3rd, 2011, 2:21 pm

There we go, actual progress. I hope you understand what modulus does now. :)

You're missing a closing bracket at the end of your if statement and the semi-colon at the end of it shouldn't be there(syntax error). And your if statement is wrong, as you're not comparing, but assigning a value(one '=' instead of two). Also, it would've been more economical to store the odd/even in a seperate string variable and then use only one iprintln, like this:

Code: Select all

for(i=0;i<21;i++)
{
        result = i*i;
        str = "";
        if(result%2==0) str = "EVEN"; 
/*single line if statements reach only until the end of the next statement(str = "EVEN"; in our case) */
        else str = "ODD";
        
        iprintln(i+"x"+i" equals "+result+" which is "+str);
}
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 » May 3rd, 2011, 2:29 pm

we save bits.

two following parts of code behave the same
if (lol == true) return true;
else return false;
if (lol) return 1;
return 0;
-------

regarding a toLower function, yes, i knew it was a built-in function (not in cod1 though).

but why not develop brains? :) so now have a go writing that.

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

Re: help with script teleport

Post by Ryan » May 3rd, 2011, 2:34 pm

Rezil wrote:Make three functions. The first function, fA(param) should return the square of the parameter <param>. The second one, fB(param) should return a boolean(true/false) on whether the parameter <param> is divisible by 3(use modulus - %). The third one, fC(param1, param2) returns a string is this format: "<param1>:-:<param2>".

This one sounds really fun now that I've made it up, give it a go. :D

Print all three using iprintln.
after trying for a few mins i gave up cos this is impossible to do... think before you post whether this is of suitable difficulty...

give me a few mins i've just finished KS thing then i failed at rezils now ill try mega's and ive got other things to do as well ...

... ok after failing at megazor's cos i've got no idea whatsoever since i've never seen any tutorial or instruction how to do this i would like to request considering your posts before you make them since i cba reading through all your highly complicated pseudocodes i dont understand ending up in a task ive never been taught how to make so please show some understanding...

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

Re: The 'QuakeC lessons' thread[prev. help with script telep

Post by megazor » May 3rd, 2011, 4:15 pm

ok, size.

the size of a string variable is the amount of characters that make the string up.
for example, the size of the string "lol" is 3.
to get the string size, use

Code: Select all

rofl.size
in the above code, rofl is a string

another example

Code: Select all

str = "megazor is pro";
iprintln(str.size);
that will print 14. yes, it counts spaces.

now about certain characters:

say we have some string, how do we get the first character of it?
simply:

Code: Select all

str = "ryan";
iprintln(str[0]);
remember that the string index always starts from 0, not from 1. so, to get the second characher of the same string, "y", you will want to use

Code: Select all

iprintln(str[1])
well, the function toLower comes here:

Code: Select all

toLower()
{
	string = "rYaN";	//a string to convert, changeable
	big = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";	//string that contains all latinic letters - uppercase
	correct = "abcdefghijklmnopqrstuvwxyz";		//the same as previous, but lowercase
	correctString = "";	//empty string that will be being filled with correct characters
	for (i = 0; i < string.size; i++)	//for each characher in 'string' (which size is 4, can you see that?), do:
	{
		s = string[i];	//'s' is a new variable which gets the value of 'string[i]'. if 'i' equals 0, string[i] being "r", and when 'i' equals 1, string[i] being "Y", etc
		for (a = 0; a < big.size; a++)	//now check through 'big' if this character ('s') is inside it. if so, then it's uppercase.
			if (s == big[a])	
			{
				s = correct[a];	//change 's' to lowercase. so, if 's' being "Y", it will become "y".	pay attention to the fact that the letters in 'big' and 'correct' are equal, the only difference is being lower/uppercase
				break;	//break 'big' loop, no need to check for that character any longer as it's been corrected.
			}
		correctString += s;	//add the character (which might have been converted to lowercase) to the string 
	}
	//all the characters have been checked out and converted if they were to.
	iprintln(correctString);
}

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

Re: The 'QuakeC lessons' thread[prev. help with script telep

Post by Ryan » May 3rd, 2011, 4:24 pm

after reading through the scripting for dummies thread twice only for your task (not to tell you the other 50 thousand times i've read through it) and reading a whole array topic on a cprogramming site this is the only thing i can come up with and i'm 100 % sure its wrong:

Code: Select all

int callofduty1 = [21]

for(i = 1; i <=20; i++)
	{
		iprintln(callofduty1.size); //forwards here
	}
for(i = 20; i >=1; i--)
	{
		iprintln(callofduty1.size); //backwards here
	}

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

Re: The 'QuakeC lessons' thread[prev. help with script telep

Post by Ryan » May 3rd, 2011, 4:35 pm

megazor wrote:...
and you were seriously expecting me to be able to do that with my shit noob knowledge? i started a few days ago and have done like 3 tasks successfully and you expect me to be able to do that?

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: The 'QuakeC lessons' thread[prev. help with script telep

Post by Drofder2004 » May 3rd, 2011, 5:03 pm

Ryan wrote:after reading through the scripting for dummies thread twice only for your task (not to tell you the other 50 thousand times i've read through it) and reading a whole array topic on a cprogramming site this is the only thing i can come up with and i'm 100 % sure its wrong:

Code: Select all

int callofduty1 = [21]

for(i = 1; i <=20; i++)
	{
		iprintln(callofduty1.size); //forwards here
	}
for(i = 20; i >=1; i--)
	{
		iprintln(callofduty1.size); //backwards here
	}
The idea is there but wrong execution. The for loops are fine however.

Firstly, with CoDScript you do not need to declare the size of an array or require the 'int'.
You can type simply "arrayName = [];"
That is your array created.

Firstly KS, said to store the numbers inside the array.
To store number in an array we use the following syntax:

arrayName[arrayname.size] = <value>;
to explain what is going on:

Firstly "arrayName" is simply the name we called our array. like a variable, call it what you want.
Secondly, we use the value of "size".
Arrays are an index. Indexes start at ZERO.
So, the current SIZE of the array is ZERO.

arrayName[arrayName.size]
is the same as
arrayName[0]

When we add a value to the array, the array size now becomes 1.
So arrayName[arrayName.size] now equals arrayName[1], etc.

So, we can create an array and populate it using a loop.

Code: Select all

/* Create your array outside the loop */
arrayName = [];
 
for(i=0;i<21;i++)
{
   arrayName[arrayName.size] = i;
}
You will now have your array of 20 values.

From here, you were asked to print them out.
Your loops were correct, but your prints were slightly wrong.

Instead of printing the size, you print the value.
iprintln(arrayName);

So, your final code will look like:

Code: Select all

/* Create an array */
callofduty1 = [];
 
/* Populate your array with values */
for(i=1;i<=20;i++)
{
   callofduty1[callofduty1.size] = i;
}
 
/* Print the values from 1 to 20 */
for(i = 1; i <=20; i++)
{
   iprintln(callofduty1[i]); //forwards here
}
 
/* Print the values from 20 to 1 */
for(i = 20; i >=1; i--)
{
   iprintln(callofduty1[i]); //backwards here
}
I urge you to understand the above final piece of code before you try and continue, and do not be confused with Pseudocode, it is just the method of reading code to make it udnerstandable.

When you read your code out loud and make understanding of it, your are essentially thinking Pseudocode.
Also, ignore Megazors exercise, the difficulty level of it was not even amateur let alone beginner...
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests