Skip to content

Instantly share code, notes, and snippets.

@oscar-broman
Created July 17, 2012 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oscar-broman/3128950 to your computer and use it in GitHub Desktop.
Save oscar-broman/3128950 to your computer and use it in GitHub Desktop.

Built-in modules

PBP comes with a few modules by default. These are not mandatory in any way, you can simply remove those you don't need.

Core module 

The core module doesn't do much.. yet.

StaticGroups module 

You can declare groups as global variables with the following syntax:

  new StaticGroup<MY_GROUP> = "My Group";
  
  // In functions and such:
  Group_SetPlayer(MY_GROUP, playerid, true); // Add "playerid" to the group

Commands module 

The commands module provides information about commands, as well as /help and /commands (soon).

Creating commands exclusively for static groups

Here's how you'd create a command only accessible for players in the ADMIN and VIP groups:

  // In your module's header.inc
  new StaticGroup<ADMIN> = "Administrator";
  new StaticGroup<VIP>   = "VIPs";
  
  // In your module's commands.inc
  YCMD(ADMIN, VIP):kick(playerid, params[], help) {
  	// ...
  }

Specifying descriptions with CommandDescription

Commands can have information attached to them using the CommandDescription macro. Example:

CommandDescription<setlevel> = "Set a player's admin level.";

YCMD(GROUP_MANAGEMENT):setlevel(playerid, params[], help) {
    // code..
}

The above code will cause /setlevel to get a description in /commands, without any extra effort!

Config module 

The config module allows automatic loading and saving of configuration variables. All you need to do is put this in your header file (after you declared the variable):

new this.SomeInt = 50;
new Float:this.SomeFloat = 123.456;
new this.SomeString[64] = "hello world";
new this.SomeArray[20];

RegisterConfigVariable: this.SomeInt;
RegisterConfigVariable: this.SomeFloat;
RegisterConfigVariable: this.SomeString;
// Special case for arrays (RegisterConfigArray)
RegisterConfigArray: this.SomeArray;

The data will be easily accessible from scriptfiles/config.db, and it can be refreshed at any time by using the RCON command config_reload.

There is also an RCON command that allows you to change the value of any config variable, usage:

/rcon config_set Module.VariableName "new value"

Users module 

The user module seamlessly provides a user system and, similar to the config system, global variables that can be registered as user variables.

User variables

User variables are essentially arrays having the size MAX_PLAYERS. When you register them using a macro (see below), the user system will automatically load and save these variables in the user database.

To make use of these user variables, simply register them with the RegisterUserVariable macro:

// File: modules/TestModule/header.inc
new
	      this.PlayerInt[MAX_PLAYERS],
	Float:this.PlayerFloat[MAX_PLAYERS],
	      this.PlayerString[MAX_PLAYERS][50]
;

RegisterUserVariable: this.PlayerInt;    // Will be called "TestModule.PlayerInt" in the database
RegisterUserVariable: this.PlayerFloat;  // Will be called "TestModule.PlayerFloat" in the database
RegisterUserVariable: "my-string" => this.PlayerString; // Will be called "my-string" in the database

Callbacks

  • OnPlayerLogIn(playerid, bool:autologin) - Called when a player logs in. The value of autologin is true if the user was automatically logged in.
  • OnPlayerAccountBeingSaved(playerid) - Called right before all user variables will be read from and saved into the database.

ClassSelection module 

Currently, this module contains only the essential things; however, by using the module, you will be able to do much more with your classes in future versions.

Provides easy class selection setups. Instead of defining each class with all the info, the system is split up into 3 pieces:

  • Weapon sets
  • Spawn locations
  • Classes

Weapon sets and spawn locations are then used when adding classes.

Creating a weapon set

Simply use CreateWeaponSet, such as this:

// Weapon, ammo, weapon, ammo, etc.
new weapon_set = CreateWeaponSet(
	WEAPON_DEAGLE,  307,
	WEAPON_SHOTGUN, 200,
	WEAPON_M4,      400,
	WEAPON_SNIPER,  150,
	WEAPON_ARMOUR,  50
);

Creating a spawn location

Use CreateSpawnLocation for this. The function can take many optional arguments, so it's best declaring like this to keep things organized:

new spawn = CreateSpawnLocation(
	.interior   = 0,
	.world      = 0,
	.x          = 1958.3783,
	.y          = 1343.1572,
	.z          = 15.3746,
	.rot        = 269.1425,
	.weapon_set = weapon_set
);

Possible arguments are:

  • interior - The interior. Default is 0.
  • world - The virtual world. Default is 0.
  • x - X coord.
  • y - Y coord.
  • z - Z coord.
  • rot - Facing angle.
  • group - Group to put player in on spawn (y_groups). Default is no group.
  • team - Team to set player as on spawn. Default is NO_TEAM.
  • weapon_set - Weapon set to use. Default is no weapon set.

Creating a class

Now that we can create weapon sets and spawn locations, the only thing left is to create a class.

The minimal requirement is a spawn location, so this would work just fine:

// "spawn" is what we created above
CreateClass(123, spawn);

// All arguments:
CreateClass(
	.skin = 123,
	.spawn_location = spawn,
	.weapon_set = some_other_weapon_set,
	.world = 1336,
	.group = GROUP_COPS,
	.team = TEAM_COPS
);

Text module 

formatex integration

The text module adds formatex to most native functions. See this topic for some more information.

Some examples:

SendClientMessageToAll(COLOR_RED, "Test %d %f", 20, 45.11); // Output: Test 20 45.11
SendClientMessageToAll(COLOR_RED, "Welcome, %p", playerid); // Welcome, <player name>
SendClientMessageToAll(COLOR_RED, "You were killed by %w.", WEAPON_M4); // You were killed by an M4

Translations

You can make your gamemode easily translatable with PBP. The only thing you need to do, really, is add an @-sign in front of strings that you want to be able to translate.

Brief tutorial

Add this line in OnPlayerSpawn.inc inside some module:

SendClientMessage(playerid, color, @"Hello!");

By default, that will send a message saying Hello to playerid.

Now, let's create this file: scriptfiles/es.lang.inc. After you created the file, run the compiler.

The file should now contain this line:

"Hello" = "Hello"

Change the right side to Hola, like this:

"Hello" = "Hola"

Save the file and restart the server. If you select Spanish in the language selection, you should see Hola in the chat when you spawn.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment