Standalone [1.3] tModLoader - A Modding API

Do you mean to a weapon or to the player itself (as in a buff)?
On the weapon it's easy, you can override the ConsumeAmmo function of the ModItem and just check against a random value. As an example:
Code:
public override bool ConsumeAmmo(Player player)
{
    if (Main.rand.Next(0, 2) == 0) // 50% chance not to consume ammo.
        return false;
    return true;
}
If you want it on the player, you'll either need to wait for player hooks (I guess you'll be able to do it then) or use one of the build in booleans from the player, but these are hardcoded at set percentages.
Oh, i need that for the armor...
 
Oh, i need that for the armor...

Well I know at least for throwable items, there's are boolean fields in Player called thrownCost33 and thrownCost50 that you can set to true or false in the UpdateArmorSet method that can give you a 33% or 50% chance to not consume ammo (don't know what happens if you set both to true).

Looking through Player.cs it looks like there are ammoCost75 and ammoCost80 fields too, try changing those and see what happens.
 
Well I know at least for throwable items, there's are boolean fields in Player called thrownCost33 and thrownCost50 that you can set to true or false in the UpdateArmorSet method that can give you a 33% or 50% chance to not consume ammo (don't know what happens if you set both to true).

Looking through Player.cs it looks like there are ammoCost75 and ammoCost80 fields too, try changing those and see what happens.
Yup, you can use those (the ammo ones). The '75' one gives you 25% not to consume ammo, whilst the '80' one gives a 20% chance.
 
It wouldn't hurt to ask the mods; that would also clear up some confusion. On that note, their rules also contain out-of-date information (such as dev armor not being obtainable), so it would be nice for them to update that too.
It seems the rationale for this rule was to prevent players from being envious of players who managed to get unobtainable/unimplemented items, but pretty much any well-made mod item will make others envious since it is a new item. It would be nice for someone in charge to think critically about this, as one of the first things a lot of mod developers do to learn how to mod would be to make those items since the concept and art are already there on their computer.

Although I do understand not wanting modders to use the art, since it's not their place to requisition it for their own purposes.
 
Well I know at least for throwable items, there's are boolean fields in Player called thrownCost33 and thrownCost50 that you can set to true or false in the UpdateArmorSet method that can give you a 33% or 50% chance to not consume ammo (don't know what happens if you set both to true).

Looking through Player.cs it looks like there are ammoCost75 and ammoCost80 fields too, try changing those and see what happens.
Thanks :D
 
Well, if you are trying to do something like the Magic Missile:
item.channel = true;
and in projectile.ai():
if (Main.player[projectile.owner].channel)
it was said like 5 pages back and no one bothered helping thanks.
let me explain once again:
the weapon (knife) works like in Gmod murderer (I forgot the name)
where you can slash or throw the knife while holding the mouse down (charging the "power")
EDIT: I cant seem to find any documentation anywhere (for mouseDown) for C# (they keep showing forms after forms) nor did I find on ModLoader documentation
 
it was said like 5 pages back and no one bothered helping thanks.
let me explain once again:
the weapon (knife) works like in Gmod murderer (I forgot the name)
where you can slash or throw the knife while holding the mouse down (charging the "power")
EDIT: I cant seem to find any documentation anywhere (for mouseDown) for C# (they keep showing forms after forms) nor did I find on ModLoader documentation
"Main.player[projectile.owner].channel" will be true while the mouse is held down and the item selected has "item.channel = true". You should be able to do whatever you want with that, just imagine that "Main.player[projectile.owner].channel" and "LeftMouseButtonDown" are the same. Timing will be your issue, as you'll have to decide how long the button will have to be held down to go into charge mode vs just a swing. I'm not sure about how the knife weapon you are referring to acts, so if there is a Terraria example that comes close, I could help you understand how it works.

You might need your own UseStyle depending on how you want to accomplish what you want.
 
"Main.player[projectile.owner].channel" will be true while the mouse is held down and the item selected has "item.channel = true". You should be able to do whatever you want with that, just imagine that "Main.player[projectile.owner].channel" and "LeftMouseButtonDown" are the same. Timing will be your issue, as you'll have to decide how long the button will have to be held down to go into charge mode vs just a swing. I'm not sure about how the knife weapon you are referring to acts, so if there is a Terraria example that comes close, I could help you understand how it works.

You might need your own UseStyle depending on how you want to accomplish what you want.
thanks alot. I think I can try to manage that since I'm still learning
EDIT: Damn. how to change into projectile and etc. I dont get what you mean.
I'm using the if statement and nothing is making any sense
 
Last edited:
thanks alot. I think I can try to manage that since I'm still learning
EDIT: Damn. how to change into projectile and etc. I dont get what you mean.
I'm using the if statement and nothing is making any sense
change into? what do you mean? Are you swinging a weapon with a UseStyle? Or are you shooting a projectile? If you could explain a bit more your desired behavior, I can help better.
 
change into? what do you mean? Are you swinging a weapon with a UseStyle? Or are you shooting a projectile? If you could explain a bit more your desired behavior, I can help better.
ok my bad.
so what happens is that.
slashing with useStyle = 1 (clicking only)
throwing with hands upwards (like the knife is held up, charging with holding left mouse button) and then releases (when releases the mouse button) in a spinning projectile (flies straight with gravity pull)
 
ok my bad.
so what happens is that.
slashing with useStyle = 1 (clicking only)
throwing with hands upwards (like the knife is held up, charging with holding left mouse button) and then releases (when releases the mouse button) in a spinning projectile (flies straight with gravity pull)
Ok, well since a click is just a quick down up, you'll have to do some clever things to get this to work.....
Basically your useStyle code might be something like this:
int counter = 0;
item.useStyle = 0;
useStyle(){
if(counter >10 && channel){
// position the itemlocation over the head
} else if (counter >10 && !channel){
// spawn the projectile
} else if (channel){
counter++
} else {
// copy in the code for useStyle of 1 for the swing
}
}

Obviously I haven't done anything like this, and you may need to mess with UseTime and UseAnimation too, not sure. You'll need to do UseItemFrame as well for the arms. You'll have problems that come up.

I'd say make things work step by step. Make 2 items, one that does the first action, a second that does the charged projectile. Once you get them both working, try to combine their functionality.
 
How can I make a weapon that shoots 4 or 5 shots? like the vampire knives
You'll need to override the Shoot function on a weapon. In there, you can just make a for loop (to loop for 4 to 5 projectiles) and spawn one each loop. I'd also change the speedX and speedY values when you shoot the projectile, as this influences the eventual velocity (and thus move direction) of the projectile you're shooting.
 
I'm trying to make some Robes using the setMatch(); function to call the leg piece but I'm having trouble overriding the function. Anyone can explain me how the setMatch works?
 
I'm trying to make some Robes using the setMatch(); function to call the leg piece but I'm having trouble overriding the function. Anyone can explain me how the setMatch works?

I may be wrong but I don't think that you can do that in the current version (0.6). If it's on the wiki then its probably preemptively updated for the 0.7 version.
 
greetings;
how do i revert to vanilla Terraria without uninstalling? i already tried the Restore vanilla anc Choose File options, but i allways end up with Tmod opening up, not normal Terraria.
 
greetings;
how do i revert to vanilla Terraria without uninstalling? i already tried the Restore vanilla anc Choose File options, but i allways end up with Tmod opening up, not normal Terraria.
If everything is allright, you should have two .exe files in your Terraria folder. One that is called 'Terraria.exe' (which is, in this case, the tModLoader one) and one that is called 'Terraria_versionNumber' where 'versionNumber' is of course the number of the version...
You'll want to rename the Terraria.exe to tMod.exe (for example) and the other one (with the version number) to Terraria.exe.
If everything is allright, it should start the vanilla one. This worked for me at least ;)
 
Back
Top Bottom