Page 1 of 17

How to use pick up items in your title packs

Posted: 15 Apr 2013, 19:07
by Eole
Hi everyone,

For those who want to try pickup items (as seen in new Combo mode),
you can download http://files.maniaplanet.com/tools/Samp ... pItems.zip.

Unzip the content of this zip archive into your ManiaPlanet userdir (typically <userdocs>/ManiaPlanet/ , so that, in that case you have the <userdocs>/ManiaPlanet/Items/SMCommon/Pickups folder).

After extraction, restart Maniaplanet.
New items should appear in map editor, object mode (F4).

WARNING: The ManiaScript item API changed drastically. The following code doesn't work anymore with the current version of the game.

To use items in a game mode you have to create a TitlePack with a custom mode script.
First you must load the items you want to use at the beginning of your script.

Code: Select all

ItemList_Begin();
declare ArmorId = ItemList_Add("SMCommon\\Pickups\\Armor.Item.gbx");
declare RocketId = ItemList_Add("SMCommon\\Pickups\\Rocket.Item.gbx");
declare LaserId = ItemList_Add("SMCommon\\Pickups\\Laser.Item.gbx");
declare NucleusId = ItemList_Add("SMCommon\\Pickups\\Nucleus.Item.gbx");
declare ArrowId = ItemList_Add("SMCommon\\Pickups\\Arrow.Item.gbx");
ItemList_End();
ItemList_Add() takes the path to the item as an argument and return the Id of the item model. It's highly recommended to restart your server after adding this bit of code at the start of your script to be sure the server could load it properly.

You can now create an item:

Code: Select all

declare ItemArmor = CreateItem(ArmorId);
CreateItem() uses the model id of the item you want to create. With this you have one item in the script, but it's not spawned on the map already.

If the map creator puts items on the map, and you want to spawn them in your mode (as in Combo):

Code: Select all

foreach (ItemAnchor in ItemAnchors) {
	switch (ItemAnchor.ItemName) {
		case "SMCommon\\Pickups\\Armor.Item.gbx": {
			AttachItemToAnchor(ItemArmor, ItemAnchor);
		}
	}
}
AttachItemToAnchor() takes two parameters:
- The item you want to spawn in the map
- The anchor used to spawn the item
With this you have one item in your map at the position designed by the map maker.

Now you have to manage what happen when a player pick up an item:

Code: Select all

foreach (Event in PendingEvents) {
	if (Event.Type == CSmModeEvent::EType::OnPlayerTouchesItem) {
		if (Event.Player != Null && Event.Player.SpawnStatus == CSmPlayer::ESpawnStatus::Spawned) {
			AttachItemToPlayer(Event.Item, Event.Player);

			// Do something depending on the item
			// ...

			PassOn(Event);
		}
	}
}
AttachItemToPlayer() has two parameters:
- The item to pick up
- The player who'll receive the item


A short list of item related functions:

Code: Select all

// ----------------------------------------------------- //
/**	Create an item
 *
 *	@param	ModelId		The model if of the item to create
 *
 *	@return				The created item
 */
CSmItem CreateItem(Ident ModelId)

// ----------------------------------------------------- //
/**	Destroy an item
 *
 *	@param	Item		The item to destroy
 */
Void DestroyItem(CSmItem Item)

// ----------------------------------------------------- //
/// Destroy all the created items
DestroyAllItems()
You can access all the items created in the script by using the Items array.

Code: Select all

// ----------------------------------------------------- //
/**	Attach an item to an anchor
 *
 *	@param	Item		The item to attach
 *	@param	ItemAnchor	The anchor where to attach the item
 */
Void AttachItemToAnchor(CSmItem Item, CSmItemAnchor ItemAnchor)

// ----------------------------------------------------- //
/**	Attach an item to a player
 *
 *	@param	Item		The item to attach
 *	@param	Player		The player where to attach the item
 */
Void AttachItemToPlayer(CSmItem Item, CSmPlayer Player)
You can access all the item anchors by using the ItemAnchors array.

Code: Select all

// ----------------------------------------------------- //
/**	Detach an item, it will be dropped at the position of the player/anchor carrying the item
 *
 *	@param	Item		The item to drop
 */
Void DetachItem(CSmItem Item)

// ----------------------------------------------------- //
/**	Detach an item and drop it at a given position
 *
 *	@param	Item		The item to drop
 *	@param	Position	The position of the item
 *	@param	Yaw			The orientation of the item
 */
Void DetachItemAndSetPosition(CSmItem Item, Vec3 Position, Real Yaw)

Code: Select all

// ----------------------------------------------------- //
/**	Unspawn an item
 *
 *	@param	Item		The item to unspawn
 */
Void UnspawnItem(CSmItem Item)

Code: Select all

// ----------------------------------------------------- //
/**	Find the player carrying a specific item
 *
 *	@param	Item		The item to search
 *
 *	@return				The player carrying the given item, Null if the item is not carried by a player
 */
CSmPlayer GetPlayerCarryingItem(CSmItem Item)

// ----------------------------------------------------- //
/**	Find the anchor carrying a specific item
 *
 *	@param	Item		The item to search
 *
 *	@return				The anchor carrying the given item, Null if the item is not carried by an anchor
 */
CSmBlock GetBlockCarryingItem(CSmItem Item)

Re: How to use pick up items in your title packs

Posted: 15 Apr 2013, 19:17
by Triseaux
Merciiiiiiii !!!! se soir c'est champagne

Re: How to use pick up items in your title packs

Posted: 15 Apr 2013, 21:25
by TitiShu
Nice Nice nice

Allez allez.... manque plus que l'importer aussi bien pour les item que les bots...

Re: How to use pick up items in your title packs

Posted: 16 Apr 2013, 00:01
by djhubertus
Soo, to run items on my script I need create title pack ?

Re: How to use pick up items in your title packs

Posted: 16 Apr 2013, 08:11
by jonthekiller
djhubertus wrote:Soo, to run items on my script I need create title pack ?
Yes, a title pack is required.

Re: How to use pick up items in your title packs

Posted: 16 Apr 2013, 11:58
by alividerci
pls give us script combo ;)

Re: How to use pick up items in your title packs

Posted: 21 Apr 2013, 14:47
by TGYoshi
Is there yet a way to import items (and character models etc.) yourself?

EDIT: What does a the skin name in ItemList_AddWithSkin refer to? I get "skin not found" but I don't know how to use it too. Slight explaination would be appriciated.

Re: How to use pick up items in your title packs

Posted: 22 Apr 2013, 10:38
by Eole
TGYoshi wrote:Is there yet a way to import items (and character models etc.) yourself?
No, not yet.
TGYoshi wrote:EDIT: What does a the skin name in ItemList_AddWithSkin refer to? I get "skin not found" but I don't know how to use it too. Slight explaination would be appriciated.

Code: Select all

Ident ItemList_AddWithSkin(Text ModelName, Text SkinName)
This function is not yet fully functional. Its goal is to allow the use of skins on items or bots. ModelName will be the path to the model used by the item/bot and SkinName the path to the skin (override the default one).

Re: How to use pick up items in your title packs

Posted: 22 Apr 2013, 12:19
by Gugli
Just so you know : I'm still designing the new Items API. I'll post it here as soon as I have a clear view of what it will be like, to get your invaluable feedback ^_^.

Re: How to use pick up items in your title packs

Posted: 22 Apr 2013, 12:20
by steeffeen
Gugli wrote:Just so you know : I'm still designing the new Items API. I'll post it here as soon as I have a clear view of what it will be like, to get your invaluable feedback ^_^.
can't wait :yes: