Thread Rating:
  • 2 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tutorial Basic GSC Coding: Building your first mod and your first code
#1
Hello

This is the first tutorial about making your very first mod, in this first one Ill show how to build a mod, adding gsc files, creating folders, threading to other files and making a quick simple code.

The first thing you need is MW2 Liberation (modloader), inside it, there is a folder called Mods. Inside Mods click right click and create a new folder, call it however you want to call your mod. Inside your Mod folder, create another one called maps. Inside maps, create another one called mp. Now we have to add our first gsc file to the mod, on it, well launch a new file on which well make our mod, the gsc file I usually use at a begin is _load.gsc. Download the "raw" this tutorial has as attachment (it contains all or nearly all game gsc files), inside it, go to maps, then to mp and then find _load.gsc, double click on it and it will open. Click on save as, select your mods mp folder and save it as _load.gsc. Now you have succesfully added the file to your mod.

Now, open the _load.gsc you have extracted to your mods folder and inside it, after this part for example (it can be nearly any):

Code:
    level.requiredMapAspectRatio = getDvarFloat( "scr_RequiredMapAspectratio", 1 );    
    level.createClientFontString_func = maps\mp\gametypes\_hud_util::createFontString;
    level.HUDsetPoint_func = maps\mp\gametypes\_hud_util::setPoint;
    level.leaderDialogOnPlayer_func    = maps\mp\_utility::leaderDialogOnPlayer;

After that well thread our own gsc file by adding a new line, I will call it: _tutorial.gsc. Just do this:

Code:
    level.requiredMapAspectRatio = getDvarFloat( "scr_RequiredMapAspectratio", 1 );    
    level.createClientFontString_func = maps\mp\gametypes\_hud_util::createFontString;
    level.HUDsetPoint_func = maps\mp\gametypes\_hud_util::setPoint;
    level.leaderDialogOnPlayer_func    = maps\mp\_utility::leaderDialogOnPlayer;
    
    thread maps\mp\_tutorial::init();

Now, its time to create our _tutorial file. Save your edited _load.gsc and click on "New" in your notepad, add this on the blank file:

Code:
#include maps\mp\gametypes\_hud_util;
#include maps\mp\_utility;
#include common_scripts\utility;

init()
{
    level thread onPlayerConnect();
}

onPlayerConnect()
{
    for( ; ; )
    {
        level waittill( "connected", player );
        player thread onPlayerSpawned();
    }
}

onPlayerSpawned()
{
    self endon( "disconnect" );
    for( ; ; )
    {
        self waittill( "spawned_player" );
    }
}

The previous code is a simple and good way to start building your mod. Click on "save as" and save it on your mods mp folder as _tutorial.gsc, after doing that there will be 2 files on your mp folder: _load and _tutorial. Now lets make our first code: something that removes all player weapons and perks on spawn, inform your teammates that you have spawned and give a OMA bag.

In _tutorial.gsc file there is a thread called onPlayerSpawned(), inside it there is a self waittill( "spawned_player");, after it well add codes that will play after we have spawned. So lets add the commands that remove our perks and weapons:

Code:
onPlayerSpawned()
{
    self endon( "disconnect" );
    for( ; ; )
    {
        self waittill( "spawned_player" );
        self takeAllWeapons(); //takes all your weapons
        self clearPerks(); //removes all your perks
    }
}

Now, lets add the rest of the code in an own created function, named TutorialThread() for example and place inside the command that will inform our teammates that we have spawned, the full file would look like this:

Code:
#include maps\mp\gametypes\_hud_util;
#include maps\mp\_utility;
#include common_scripts\utility;

init()
{
    level thread onPlayerConnect();
}

onPlayerConnect()
{
    for( ; ; )
    {
        level waittill( "connected", player );
        player thread onPlayerSpawned();
    }
}

onPlayerSpawned()
{
    self endon( "disconnect" );
    for( ; ; )
    {
        self waittill( "spawned_player" );
        self takeAllWeapons(); //takes all your weapons
        self clearPerks(); //removes all your perks
        self thread TutorialThread(); //execute the thread we wanted to make
    }
}

TutorialThread()
{
    self PingPlayer(); // Red ! on radar for your teammates, the effect finishes after a few seconds
}

After this, well give the OMA and switch to it.

Code:
TutorialThread()
{
    self PingPlayer(); //red ! on radar for your teammates, the effect finishes after a few seconds
    wait ( 0.05 ); //wait a bit, :)
    self giveWeapon( "onemanarmy_mp", 0, false ); //the first is the weapon name, the second is the camo and the false is because is not akimbo
    wait ( 0.05 ); //wait to remove bugs
    self switchToWeapon( "onemanarmy_mp", 0, false ); //switch to it
}

Save and load your mod on Liberation. Congratulations You have built your first mod and your first easy code. I have left as attachments the mod I made for the tutorial, so you can see how its made and a raw with lots of files.

Virusscans:

http://virusscan.jotti.org/es/scanresult...af44783734
http://virusscan.jotti.org/es/scanresult...d999648d0d

Thanks to: @Gagarin , @NTAuthority , @Rendflex , @aluigi

Thanks @Yamato ..


Attached Files
.rar   Tutorial.rar (Size: 3.42 KB / Downloads: 167)
.zip   raw.zip (Size: 8.52 MB / Downloads: 252)
Reply

#2
_LOAD.GSC!!! Nyan Cat

OMA wins
[Image: MaEIQ.png]
Reply

#3
Hey, that's pretty good
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tutorial] Basic GSC Coding: Functions Yamato 15 12,284 08-17-2013, 10:17
Last Post: hamza-q99
  [Tutorial] Basic GSC Coding: Making your second code Yamato 9 8,636 12-28-2012, 13:30
Last Post: Yamato
  [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:
1 Guest(s)

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