Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tutorial Basic GSC Coding: Making your second code
#1
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():

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
Reply

#2
Awesome very usefull ,)
Reply

#3
wow ty dude i learning alot of them
Reply

#4
Dude , i dont know what this do and how they know the geometruy of each funct , see :

Example:
toggle()
{
self endon("death");
vec = anglestoforward(self getPlayerAngles());
center = BulletTrace( self gettagorigin("tag_eye"), self gettagorigin("tag_eye")+(vec[0] * 200000, vec[1] * 200000, vec[2] * 200000), 0, self)[ "position" ]; //wtf that means and how i can know the bullettrace that im looking for...
level.center = spawn("script_origin", center);
level.lift = [];
h=0;k=0;
origin = level.center.origin;
for(i=0;i<404;i++)
{
if(i<=100)
level.lift[k] = spawn("script_model", origin+(-42,42,h)); //how i can make an object spawn in front of me without laggin me out?
else if(i<=201 && i>100)
level.lift[k] = spawn("script_model", origin+(42,42,h-2777.5*2));
else if(i<=302 && i>201)
level.lift[k] = spawn("script_model", origin+(-42,-42,h-5555*2));
else if(i<=404 && i>301)
level.lift[k] = spawn("script_model", origin+(42,-42,h-8332.5*2));
level.lift[i].angles = (90,90,0);
h+=55;
k++;
}
Reply

#5
What?
Reply

#6
l2[ code ]
Reply

#7
sorry dudes , i was saying :
how i can make a care package shot something?
how i can make that when the care package shot 3 times the care package get delete?

Can someone help me plis?
Reply

#8
(12-27-2012, 09:17)Bloodfocus Wrote: sorry dudes , i was saying :
how i can make a care package shot something?
how i can make that when the care package shot 3 times the care package get delete?

Can someone help me plis?

Make it shot a magicbullet from its position to the thing you want to shot
Reply

#9
No se como se hace eso , no me lo podes hacer vos porfavos dude?
Reply

#10
(12-27-2012, 21:33)Bloodfocus Wrote: No se como se hace eso , no me lo podes hacer vos porfavos dude?

http://www.itsmods.com/forum/Thread-Tuto...mages.html
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tutorial] Basic GSC Coding: Building your first mod and your first code Yamato 2 11,205 06-07-2016, 21:49
Last Post: FrostbytePG
  [Tutorial] Basic GSC Coding: Functions Yamato 15 12,284 08-17-2013, 10:17
Last Post: hamza-q99
  [Tutorial] Basic GSC Coding: Operations Yamato 0 8,004 04-04-2012, 13:07
Last Post: Yamato
  [Tutorial] Basic GSC Coding: Foreach, Continue and Return Yamato 6 7,574 04-04-2012, 08:33
Last Post: Yamato
  [Tutorial] Basic GSC Coding: Switch Yamato 6 6,035 04-03-2012, 18:32
Last Post: tsoPANos
  [Tutorial] Basic GSC Coding: If, Else and Else If Yamato 2 5,795 03-30-2012, 10:47
Last Post: alvarogt95
  [Tutorial] Basic GSC Coding: Downloading and Installing a mod Yamato 1 5,195 03-30-2012, 10:42
Last Post: alvarogt95
  [Tutorial] Basic GSC Coding: For Yamato 4 5,925 03-26-2012, 18:39
Last Post: tsoPANos
  [Tutorial] Basic GSC Coding: While, Break and Wait Yamato 6 7,516 03-06-2012, 13:48
Last Post: Yamato

Forum Jump:


Users browsing this thread:
2 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2024 Melroy van den Berg.