How to use pick up items in your title packs

Discuss everything related to custom data creation.

Moderator: NADEO

Post Reply
User avatar
Eole
Nadeo
Nadeo
Posts: 1265
Joined: 26 Apr 2011, 21:08

How to use pick up items in your title packs

Post 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)
Contribute to the ManiaPlanet documentation on GitHub
A question about ManiaScript? Ask it here!
Triseaux
Posts: 155
Joined: 28 May 2012, 11:07

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

Post by Triseaux »

Merciiiiiiii !!!! se soir c'est champagne
group leader : "Beniii"
User avatar
TitiShu
Posts: 372
Joined: 27 Feb 2012, 23:31
Location: Belgique

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

Post by TitiShu »

Nice Nice nice

Allez allez.... manque plus que l'importer aussi bien pour les item que les bots...
OS:Windows 8.1 x64
CPU: i5 2500k
RAM: 2x4Go G.Skill Ares
GPU: MSI GTX570
Board: Asus P8Z68-V LX
HDD: WD Green + WD Black
SSD: Crucial M4 64Go
Sound: Realtek (onboard)
Peripherals: Mouse G700 - Keyboard G19 - Headset Roccat Kave
User avatar
djhubertus
Translator
Translator
Posts: 1097
Joined: 09 Jul 2012, 18:30
Location: Poland
Contact:

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

Post by djhubertus »

Soo, to run items on my script I need create title pack ?
My Gamemodes:
MP4 - Countdown, Firefight
MP3 - Reduction, Overload, Flashpoint, Territory, SM Race, Escape
MP2 - Search & Destroy, Oscillation, Instagib
User avatar
jonthekiller
Translator
Translator
Posts: 4629
Joined: 15 Jun 2010, 11:07
Location: In Maniaplanet Alpha
Contact:

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

Post by jonthekiller »

djhubertus wrote:Soo, to run items on my script I need create title pack ?
Yes, a title pack is required.
Image
User avatar
alividerci
Posts: 363
Joined: 11 Feb 2012, 07:03

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

Post by alividerci »

pls give us script combo ;)
User avatar
TGYoshi
Posts: 795
Joined: 15 Mar 2011, 16:59

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

Post 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.
=3
User avatar
Eole
Nadeo
Nadeo
Posts: 1265
Joined: 26 Apr 2011, 21:08

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

Post 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).
Contribute to the ManiaPlanet documentation on GitHub
A question about ManiaScript? Ask it here!
User avatar
Gugli
Nadeo
Nadeo
Posts: 536
Joined: 14 Jun 2010, 17:35
Location: Mon PC est à Paris, mais mon coeur rode dans les forêts de Lozère

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

Post 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 ^_^.
--
(>~_~)> ═╦═ ╔╦╗ <(~_~<)
User avatar
steeffeen
Translator
Translator
Posts: 2463
Joined: 14 Oct 2012, 16:22
Location: Germany

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

Post 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:
    Game Mode and Title Pack Creator, Developer, ShootMania-Player & more

    ManiaControl, FancyManiaLinks
    Post Reply

    Return to “Title Pack & Custom Data Creation”

    Who is online

    Users browsing this forum: No registered users and 4 guests