Author Topic: [Solved] Spawning an item at any coordinate  (Read 1992 times)

I was doing some digging on the forums and looking through a few add-ons but I can't seem to get an understanding of spawning items.

How do I spawn an item at a specified position on the map?

Also, thanks for all of the support the forum has been offering.
« Last Edit: October 12, 2015, 12:57:28 PM by Dr.Tyler O. »

%item = new item()
{
   datablock = yourDatablockName;
   canPickup = true;
   scale = "1 1 1";
   position = "x y z";
};


That is the basic structure of spawning an item at a given position.

That is the basic structure of spawning an item at a given position.

Alright, thank you. Is there a website or some sort of documentation that lists all of the variables for new items that I can customize?

Alright, thank you. Is there a website or some sort of documentation that lists all of the variables for new items that I can customize?
You could take a look at the datablocks in-game. Start up a server and write "tree();" in console. This opens a new window that inspects and modifies game information.
« Last Edit: October 12, 2015, 03:53:14 AM by Quartz »

You could take a look at the datablocks in-game. Start up a server and write "tree();" in console. This opens a new window that inspects and modifies game information.
Alright, thanks.

Actually, I was looking at the itemdata for the gun and I can see that it has a maxVelocity variable but no variables to set the velocity when it first spawns like you can with a spawnItem event. How would I do this?


Actually, I was looking at the itemdata for the gun and I can see that it has a maxVelocity variable but no variables to set the velocity when it first spawns like you can with a spawnItem event. How would I do this?

[img]http://i.imgur.com/iWsvVgt.png[/img]
You don't add velocity with a variable. You call the function.
Either call .setVelocity("0 0 0"); or .addVelocity("0 0 0"); on the item after you've spawned it.

Here's the default variables you can have for items.

collideable = false;
dataBlock = someItemDataBlock;
position = "0 0 0";
rotate = false; //If true, the item will rotate around in clockwise circles.
rotation = "1 0 0 0";
scale = "1 1 1";
static = false; //If true, the item will float in the air and won't be affected by gravity or velocity.

canPickUp = true;

bl_id = %client.getBLID();
minigame = %client.minigame;
spawnBrick = -1;

To clarify: GunItem is an ItemData (which is a type of Datablock), which is different to an Item. An Item is an instance of an ItemData, just like a Player is an instance of a PlayerData.
Datablocks are downloaded to the client when they join a server, and so you cannot modify the variables on them (safely). Datablocks determine some base stats of the item, things that should not change, such as its name or its mass. Instances are copies of that datablock, but they can have a position, rotation, velocity, etc. and they are actually visible in-game.

jes00 is talking about an item instance, Quartz is talking about an item datablock.

Do you want to create a new type of item (ItemData), or do you just want to spawn an item (Item)?

Do you want to create a new type of item (ItemData), or do you just want to spawn an item (Item)?
He wants to spawn an item(as plainly clarified in the OP).

Don't know why Quartz was talking about datablocks.

You don't add velocity with a variable. You call the function.
Either call .setVelocity("0 0 0"); or .addVelocity("0 0 0"); on the item after you've spawned it.
I feel ignorant. Thank you

Don't know why Quartz was talking about datablocks.
I think I misread the topic before it got edited.

I've ran into one more issue. The item doesn't want to disappear after it has spawned unless I pick it up and drop it.

Here's one way
%item = new item()
{
   datablock = yourDatablockName;
   canPickup = true;
   scale = "1 1 1";
   position = "x y z";
};

%item.schedule(5000, delete);


If someone picks it up you will get a console error. I would advise finding a method native to Blockland.