04-06-2012, 14:03
Hello
This is the second tutorial about making your first codes. In this one Ill show you how to make a code that shows your position ( can be used to make map edits ) and also something that makes you jump when you go into water.
Lets call our first function CoordinateFinder():
Now well add a "while" command to keep the game showing your position, and then well add a command which will print our origin:
Lets improove a bit the code so when we die or disconnect the "while" stops to prevent bugs:
Lets make the other script.
So, in total we have this 2 functions:
To execute them simply add this after the player spawn as I did on the previous tutorial:
I hope you have learnt something new, the next tutorial will be a bit more advanced (in lenght)
@Yamato
This is the second tutorial about making your first codes. In this one Ill show you how to make a code that shows your position ( can be used to make map edits ) and also something that makes you jump when you go into water.
Lets call our first function CoordinateFinder():
Code:
CoordinateFinder()
{
//codes will go here
}
Now well add a "while" command to keep the game showing your position, and then well add a command which will print our origin:
Code:
CoordinateFinder()
{
while( 1 )
{
self iPrintLnBold( self getOrigin() ); //iPrintLnBold prints a text on the center of your screen, getorigin gets your origin
wait 2; //frequency (each 2 seconds it will say your position
}
}
Lets improove a bit the code so when we die or disconnect the "while" stops to prevent bugs:
Code:
CoordinateFinder()
{
self endon( "death" ); //endon(something) makes that the game will stop that function when that event(something) occurs
self endon( "disconnect" );
while( 1 )
{
self iPrintLnBold( self getOrigin() ); //iPrintLnBold prints a text on the center of your screen, getorigin gets your origin
wait 2; //frequency (each 2 seconds it will say your position
}
}
Lets make the other script.
Code:
JumpInWater()
{
self endon( "death" );
self endon( "disconnect" );
self.trace = undefined; //lets add this variable to avoid a unitialized variable error later.
for( ; ; ) //we can also use a "for" instead of a "while"
{
self.trace = bulletTrace( self getEye(), self getOrigin() - ( 0, 0, 60 ), false, self ); //geteye gives the position of your players eye, the - 0, 0, 60 means that I reduce in 60 units the players position in z axis, the rest: check bullettrace tutorial
if( self.trace[ "surfacetype" ] == "water" ) //explained in bullettrace tutorial
self setVelocity( ( 0, 0, 600 ) ); //setvelocity pushes a player with the vector we define
wait 0.5;
}
}
So, in total we have this 2 functions:
Code:
CoordinateFinder()
{
self endon( "death" ); //endon(something) makes that the game will stop that function when that event(something) occurs
self endon( "disconnect" );
while( 1 )
{
self iPrintLnBold( self getOrigin() ); //iPrintLnBold prints a text on the center of your screen, getorigin gets your origin
wait 2; //frequency (each 2 seconds it will say your position
}
}
JumpInWater()
{
self endon( "death" );
self endon( "disconnect" );
self.trace = undefined; //lets add this variable to avoid a unitialized variable error later.
for( ; ; ) //we can also use a "for" instead of a "while"
{
self.trace = bulletTrace( self getEye(), self getOrigin() - ( 0, 0, 60 ), false, self ); //geteye gives the position of your players eye, the - 0, 0, 60 means that I reduce in 60 units the players position in z axis, the rest: check bullettrace tutorial
if( self.trace[ "surfacetype" ] == "water" ) //explained in bullettrace tutorial
self setVelocity( ( 0, 0, 600 ) ); //setvelocity pushes a player with the vector we define
wait 0.5;
}
}
To execute them simply add this after the player spawn as I did on the previous tutorial:
Code:
self thread CoordinateFinder();
self thread JumpInWater();
I hope you have learnt something new, the next tutorial will be a bit more advanced (in lenght)
@Yamato