Standalone [1.3] tModLoader - A Modding API

You can set 'item.shootSpeed = 10;' or something of the sorts in the SetDefaults method of your item.
Yes, it works.
By the way, I'm tryna add some recipes about vanilla items. So I create a .cs file just like the "RecipeHelper.cs" in ExampleMod:
Code:
    public static class RecipeHelper
    {
        public static void AddRecipes(Mod mod)
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.IceBlock, 10);
            recipe.SetResult(ItemID.IceBlade);
            recipe.AddRecipe();
        }
    }
But as usual, it ain't working anyway.
 
Yes, it works.
By the way, I'm tryna add some recipes about vanilla items. So I create a .cs file just like the "RecipeHelper.cs" in ExampleMod:
Code:
    public static class RecipeHelper
    {
        public static void AddRecipes(Mod mod)
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.IceBlock, 10);
            recipe.SetResult(ItemID.IceBlade);
            recipe.AddRecipe();
        }
    }
But as usual, it ain't working anyway.
Do you have a class that derives from 'Mod'? (probably in the root folder of your project).
If you do, you'll need to override the AddRecipes function in there and call 'RecipeHelper.AddRecipes(this);'.
Your RecipeHelper alone won't do anything, you need to actually call a function in there to make it fire.
 
Do you have a class that derives from 'Mod'? (probably in the root folder of your project).
If you do, you'll need to override the AddRecipes function in there and call 'RecipeHelper.AddRecipes(this);'.
Your RecipeHelper alone won't do anything, you need to actually call a function in there to make it fire.
So I create a little main .cs file for myself:
Code:
public class wch : Mod
    {
        public override void SetModInfo(out string name, ref ModProperties properties)
        {
            name = "wch";
            properties.Autoload = true;
            properties.AutoloadGores = true;
            properties.AutoloadSounds = true;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(this);
            recipe.AddIngredient(ItemID.IceBlock, 10);
            recipe.SetResult(ItemID.IceBlade);
            recipe.AddRecipe();
        }

    }
Now it works, although I got little idea about why.
 
How to prescribe and in what folder there should be a chain for the weapon ball o chain?

How to create those damn balls on a chain :indifferent:
 
Last edited:
So I create a little main .cs file for myself:
Code:
public class wch : Mod
    {
        public override void SetModInfo(out string name, ref ModProperties properties)
        {
            name = "wch";
            properties.Autoload = true;
            properties.AutoloadGores = true;
            properties.AutoloadSounds = true;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(this);
            recipe.AddIngredient(ItemID.IceBlock, 10);
            recipe.SetResult(ItemID.IceBlade);
            recipe.AddRecipe();
        }

    }
Now it works, although I got little idea about why.
It's all got to to with overriding and how things are handled in the source code.
Your RecipeHelper class was not deriving from any class (like you have your new class deriving from 'Mod') and thus not overriding anything. If a function is not overriden, you can safely assume that that function will not get called, unless you do it manually. You can read up on this subject right here, if you're interested (it's a good read if you want to understand how tModLoader works a bit more).
 
Uhm, and how do I do that?
You can override the PreAI function and increment an ai value there, before checking if that value has reached a certain point:
Code:
public override bool PreAI()
{ 
    projectile.ai[3]++;
    if(projectile.ai[3] >= 60)        
        projectile.hide = true;
    return true;
}
Note that this will fire after 1 second (60 ticks = 1 second).
 
You can override the PreAI function and increment an ai value there, before checking if that value has reached a certain point:
Code:
public override bool PreAI()
{
    projectile.ai[3]++;
    if(projectile.ai[3] >= 60)       
        projectile.hide = true;
    return true;
}
Note that this will fire after 1 second (60 ticks = 1 second).
What does the '3' in the brackets mean? And why would you increase it by 1 (++)?
[DOUBLEPOST=1450008740,1450008326][/DOUBLEPOST]
You can override the PreAI function and increment an ai value there, before checking if that value has reached a certain point:
Code:
public override bool PreAI()
{
    projectile.ai[3]++;
    if(projectile.ai[3] >= 60)       
        projectile.hide = true;
    return true;
}
Note that this will fire after 1 second (60 ticks = 1 second).
Oh, and something is causing a bug, the projectiles dont appear, they are constantly invisible
 
What does the '3' in the brackets mean? And why would you increase it by 1 (++)?
[DOUBLEPOST=1450008740,1450008326][/DOUBLEPOST]
Oh, and something is causing a bug, the projectiles dont appear, they are constantly invisible
You know what an array is? An array is basically a collection of variables, which is created like this:
Code:
int[] myArray = new int[3];
Here we create an array which allows for 3 entries (hence the 3). Now this is creating it, but how can you call these variables back?
That's done like follows:
Code:
int myArrayEntry = myArray[0];
With this piece of code we can get the value of the first entry in the myArray integer array (the entries always start at 0 and since there are 3 entries, the max value we can access is [2]).
Now if you understand that, you also understand what I'm doing there, getting the 4'th entry of the ai array.
I'm increasing it by one, because that way it will become some sort of timer. Since we can safely assume that there are 60 updates each second (which is done internally), we can check the projectile.ai[3] entry to see how much time has passed.

If you want me to help you with the bug, can you show me your whole code?
 
there got to be a better way then this to make say 25 items to only drop 1 of the 25 not 2 not 0 perfect 1

and not just doing this (i know this here is just 25 coppercoins with 1-25)


if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 1);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 2);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 3);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 4);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 5);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 6);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 7);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 8);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 9);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 10);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 11);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 12);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 13);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 14);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 15);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 16);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 17);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 18);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 19);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 20);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 21);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 22);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 23);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 24);
}
else
{
player.QuickSpawnItem(ItemID.CopperCoin, 25);
}
 
there got to be a better way then this to make say 25 items to only drop 1 of the 25 not 2 not 0 perfect 1

and not just doing this (i know this here is just 25 coppercoins with 1-25)


if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 1);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 2);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 3);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 4);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 5);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 6);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 7);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 8);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 9);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 10);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 11);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 12);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 13);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 14);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 15);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 16);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 17);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 18);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 19);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 20);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 21);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 22);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 23);
}
else if (Main.rand.Next(25) == 0)
{
player.QuickSpawnItem(ItemID.CopperCoin, 24);
}
else
{
player.QuickSpawnItem(ItemID.CopperCoin, 25);
}
You want a random amount of coins to spawn inside the players inventory?
If so:
Code:
player.QuickSpawnItem(ItemID.CopperCoin, Main.rand.Next(1, 26));
 
then let me try this way

moonlord drops 11 items but only 1 at a time its that i want but for like 25 items
Does the moonlord drop his items one by one?
anyway, you'll want to do something like the following:
Code:
for(int i = 0; i < 25; ++i)
{   
    player.QuickSpawnItem(ItemID.CopperCoin);
}
Do note that player.QuickSpawnItem places the item directly in the inventory, rather than spawning it in the world first.
 
Does the moonlord drop his items one by one?
anyway, you'll want to do something like the following:
Code:
for(int i = 0; i < 25; ++i)
{  
    player.QuickSpawnItem(ItemID.CopperCoin);
}
Do note that player.QuickSpawnItem places the item directly in the inventory, rather than spawning it in the world first.

but is this not somewhat the same i had or can i add all items into that one line of code?

for(int i = 0; i < 25; ++i)
{
player.QuickSpawnItem(ItemID.CopperCoin);
player.QuickSpawnItem(ItemID.CopperCoin);
}
 
but is this not somewhat the same i had or can i add all items into that one line of code?

for(int i = 0; i < 25; ++i)
{
player.QuickSpawnItem(ItemID.CopperCoin);
player.QuickSpawnItem(ItemID.CopperCoin);
}
This is a for loop, thus will execute as many times as the values you pass in it.
This executes 25 times, so will basically do the same as you had, but in 3 lines of code instead of... More XD
 
This is a for loop, thus will execute as many times as the values you pass in it.
This executes 25 times, so will basically do the same as you had, but in 3 lines of code instead of... More XD

i se that now but that is only for 1 item not 25 items (example dirt,stone,wood,clay so on)

also u sayd the quickspawn does into inv what does out in world
 
i se that now but that is only for 1 item not 25 items (example dirt,stone,wood,clay so on)

also u sayd the quickspawn does into inv what does out in world
No, this is currently for one item only.
You'll want to use the Item.NewItem function, but the parameters you fill in depend on where you want to call it.
Could I see the part of the code where you want these items to be spawned?
 
Back
Top Bottom