Vice Underdogs

Discussion => VC:MP General => Topic started by: GangstaRas on February 15, 2013, 12:03:34 am

Title: VCMP Scripts Manual/Tutorial
Post by: GangstaRas on February 15, 2013, 12:03:34 am
i know, pascal, javascript and html coding, its time I learn this bitch. But I don't see anything on this crap, what language it is, how you make it, none a that shit. So anyone of you that know how to write scripts, gimme a starter link, why don't ya
Title: Re: VCMP Scripts Manual/Tutorial
Post by: MaDKilleR on February 15, 2013, 11:05:43 am
As you know Vice City Multiplayer has currently 3 languages available. Squirrel, Pawn, mIRC ( outdated ). People do use pawn but at the moment, squirrel is the best choice. I'll explain briefly how you can start writing scripts in Squirrel.

(I'm not much good at explaining!)

Learning Squirrel

You need to learn Squirrel first. You can find the online manual here. (http://www.squirrel-lang.org/doc/squirrel3.html)

Basics

As you know, to create a good and attractive server, your script should have:

Besides these, their are vast ideas too but they depend on your imagination and knowledge.

Getting back into squirrel, the best idea is to study some released scripts. They'll give you a complete idea of how they work and you can learn much squirrel but studying them. Some scripts are:

VCMP Base Scripts (VBS) (http://vcmp.liberty-unleashed.co.uk/forum/index.php?topic=693.0)
FBS (http://vcmp.liberty-unleashed.co.uk/forum/index.php?topic=6.0)
MDM-SQ (http://vcmp.liberty-unleashed.co.uk/forum/index.php?topic=605.0)

By studying these scripts, you can know how various systems works.

Firstly, you need to setup a squirrel server. You can download the server by clicking here (http://vcmp.liberty-unleashed.co.uk/forum/index.php?topic=2.0). A Tutorial about setting up the server can be found here (http://vcmp.liberty-unleashed.co.uk/files/tutorials/VCMPServerGuide.pdf).

Examples

I've written some examples below. Hope this helps. Don't forget to check the wiki (http://liberty-unleashed.co.uk/VCWiki/Scripting/squirrel).


First, you need to create a .nut file and have to load it into the server by editing server.conf. Scroll to the bottom and edit the line:

Code: [Select]
<script></script>
[code]

with

[code]
<script>your-script.nut</script>

Now, the script has been loaded into the server. This is where the VCMP server's event onScriptLoad() is called. You can find a list of all VC:MP events here (http://liberty-unleashed.co.uk/VCWiki/Scripting/Squirrel/Events) with examples.

Code: [Select]
function onScriptLoad()
{
  print( "Script loaded!" );
}


Following is the example of working with a class.

Code: [Select]
class Player
{
   Kills = 0;
   Deaths = 0;
   Joins = 0;
}

At the top, we'll create an array to store the details.

Code: [Select]
playerStats <- array( GetMaxPlayers, null );

Let's welcome the player.

Code: [Select]
function onPlayerJoin( pPlayer )
{
    PrivMessage( "Welcome to the server, "+player.Name+"!", player ); //Send a welcome message.
    local id = player.ID;
    playerStats[ id ] = null; //Delete any previous data.
    playerStats[ id ] = Player(); //The class we declared at the top.
}

Stats Example:

Code: [Select]
function onPlayerKill( killer, player, reason, bodypart )
{
    playerStats[ killer.ID ].Kills++;
    playerStats[ player.ID ].Deaths++;
}


Creating a command:


Code: [Select]
function onPlayerCommand( player, command, text )
{
      local
      cmd = command.tolower(),  //To avoid stupid bugs. For Example, the command "stats" will work even if the player types /c StAts or /c STATS etc
id = player.ID;
     
     if ( cmd == "stats" )
     {
           PrivMessage( "Your Kills:<"+playerStats[player.ID].Kills+"> Deaths:<"+playerStats[player.ID].Deaths+"> Joins:<"+playerStats[player.ID].Joins+">", player );
     }
}


You can find a list of all VCMP Squirrel Server functions here (http://liberty-unleashed.co.uk/VCWiki/Scripting/Squirrel/Functions) with examples. You've to just use different functions at different places according to what you're building.

Title: Re: VCMP Scripts Manual/Tutorial
Post by: GangstaRas on February 15, 2013, 01:37:28 pm
ah thanks madkiller, some of these examples look javascripty, so atleast I don't have a huge learning curve to go through. I'll definitely be using all of this
Title: Re: VCMP Scripts Manual/Tutorial
Post by: [xTr]FastShooter on December 14, 2013, 08:25:19 am
can you add hashes example too in this ....