Confirmedusers, editor, Administrators
886
edits
CreativeMD (talk | contribs) No edit summary |
CreativeMD (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
This tutorial should introduce you into the basics of custom interactions. We will create a magic wand which should spawn particles when holding right click. | |||
== Preparations == | == Preparations == | ||
Line 6: | Line 5: | ||
I highly recommend to read about [[Advanced Items|The Item Class]] first. Additionally you can download the assets [http://wiki.vintagestory.at/images/4/4d/MagicWand_-_No_CS_File.zip here]. | I highly recommend to read about [[Advanced Items|The Item Class]] first. Additionally you can download the assets [http://wiki.vintagestory.at/images/4/4d/MagicWand_-_No_CS_File.zip here]. | ||
All of this should be familiar to you, creating and registering the item class ... | |||
<syntaxhighlight lang="c#"> | <syntaxhighlight lang="c#"> | ||
Line 28: | Line 27: | ||
== Adding particles == | == Adding particles == | ||
Now we need to implement the | Now we need to implement the interact function. First of all we need to specify that the player can "use" this tool, therefore we need to return <code>true</code> ... | ||
<syntaxhighlight lang="c#"> | <syntaxhighlight lang="c#"> | ||
Line 37: | Line 36: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
The <code>OnInteracting</code> allows | The method <code>OnInteracting</code> allows us to spawn particles per tick while the player is using the item, but it would be better to implement an animation first. Particles should spawn after the animation is done ... | ||
<syntaxhighlight lang="c#"> | <syntaxhighlight lang="c#"> | ||
Line 64: | Line 63: | ||
[[File:Magic Stick Interact.gif|300px]] | [[File:Magic Stick Interact.gif|300px]] | ||
So let's mess around with particles | So let's start to mess around with particles, therefore we need a static particle type ... | ||
<syntaxhighlight lang="c#"> | <syntaxhighlight lang="c#"> | ||
Line 82: | Line 81: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Particles should spawn once the | Particles should spawn once the animation is completed. This will be the case after <code>0.6</code> seconds ... | ||
<syntaxhighlight lang="c#"> | <syntaxhighlight lang="c#"> | ||
if (secondsUsed > 0.6) | if (secondsUsed > 0.6) | ||
{ | { | ||
//Spawn particles | |||
} | |||
</syntaxhighlight> | |||
I suggest to read the tutorial about [[Simple Particles]] first. This code will spawn particles in front of the player with a randomized color and a sinus evolving size ... | |||
<syntaxhighlight lang="c#"> | |||
Vec3d pos = | Vec3d pos = | ||
byEntity.Pos.XYZ.Add(0, byEntity.EyeHeight(), 0) | byEntity.Pos.XYZ.Add(0, byEntity.EyeHeight(), 0) | ||
Line 101: | Line 107: | ||
particles.SizeEvolve = EvolvingNatFloat.create(EnumTransformFunction.SINUS, 10); | particles.SizeEvolve = EvolvingNatFloat.create(EnumTransformFunction.SINUS, 10); | ||
byEntity.World.SpawnParticles(particles); | byEntity.World.SpawnParticles(particles); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 146: | Line 151: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Testing == | |||
Now we can run our first test, doesn't it look beautiful? | |||
<youtube>bTPXL97Gfns</youtube> | <youtube>bTPXL97Gfns</youtube> | ||
== Download == | == Download == | ||
Feel free to try it out yourself: | |||
[http://wiki.vintagestory.at/images/3/38/MagicWand.zip MagicWand.zip] |