Revision Difference
Addons/GettingStarted#551422
<title>Creating a runtime addon.</title>⤶
⤶
# Creating an addon project⤶
Start s&box in "Content Mode".⤶
⤶
<upload src="b4bc4/8db9a1f9d9d8b43.png" size="12387" name="contentmode.png" />⤶
⤶
Once in game, Select "New Project..." under "File" on the menu bar.⤶
⤶
<upload src="b4bc4/8db9a20127ec8df.png" size="9083" name="newproject.png" />⤶
⤶
Select the "Addon" project type and give it a name.⤶
⤶
<upload src="b4bc4/8db9a20822c03f6.png" size="16584" name="image.png" />⤶
⤶
# Coding your runtime addon⤶
⤶
Once created, right-click your addon under the "Addon" list in the "Projects" dock ⤶
and select "Open in Visual Studio". See [Setting up Visual Studio](https://wiki.facepunch.com/sbox/Setting_up_Visual_Studio) for a guide on setting up VS.⤶
⤶
<upload src="b4bc4/8db9a20f111a4a5.png" size="14081" name="image.png" />⤶
⤶
Right click your project and create a new class with Add->New Item... (or press CTRL+SHIFT+A), and then give your new class a name.⤶
⤶
<upload src="b4bc4/8db9a21646b8a36.png" size="23789" name="image.png" />⤶
⤶
The file you just created is where you'll create the class for your runtime addon. You'll probably want one that inherits from some kind of [Entity](https://asset.party/api/Sandbox.Entity), such as [ModelEntity](https://asset.party/api/Sandbox.ModelEntity). ⤶
⤶
The code for the runtime addon in this article is very basic:⤶
⤶
```csharp⤶
namespace Sandbox;⤶
⤶
public partial class MyAddonThing : ModelEntity⤶
{⤶
private TimeSince _lastJump;⤶
⤶
public override void Spawn()⤶
{⤶
base.Spawn();⤶
Model = Cloud.Model( "facepunch.soda_can" );⤶
SetupPhysicsFromModel( PhysicsMotionType.Dynamic );⤶
}⤶
⤶
[GameEvent.Tick.Server]⤶
private void OnTickServer()⤶
{⤶
if ( _lastJump >= 3 )⤶
{⤶
PhysicsGroup?.AddVelocity( Vector3.Up * Game.Random.Next( 80, 120 ) + Rotation.Forward * 60 );⤶
_lastJump = 0;⤶
}⤶
}⤶
}⤶
⤶
```⤶
⤶
This code creates a soda can that'll hop forwards every 3 seconds.⤶
⤶
⤶
# Preparing to upload your addon to asset.party⤶
Once you are ready to upload your addon to [asset party](https://asset.party/) click the cog on your addon in the "Projects" dock. (Or right-click it and select "Project Settings...".)⤶
⤶
<upload src="b4bc4/8db9a23f7a29995.png" size="5002" name="image.png" />⤶
⤶
<upload src="b4bc4/8db9a2447553b2d.png" size="46800" name="image.png" />⤶
⤶
## Assigning your addon to your organisation and tagging⤶
Once here, make sure to set "Organisation Ident" to that of your asset.party organisation.⤶
Make sure to add "runtime" to the "Tags" of your addon.⤶
<upload src="b4bc4/8db9a25c2cc2c0a.png" size="2759" name="tags.png" />⤶
⤶
## Target Game⤶
This guide assumes you are making addons for the "sandbox" gamemode. In this case we set "Target Game" to "facepunch.sandbox". For other gamemodes, it's as simple as: `orgident.gamemodeident`⤶
<upload src="b4bc4/8db9a2483c3c470.png" size="1949" name="image.png" />⤶
⤶
## Primary Type⤶
Find "Runtime Addon" under "Addon"⤶
<upload src="b4bc4/8db9a249afc7739.png" size="1720" name="image.png" />⤶
⤶
Set "Primary Type" to the class we made earlier. The way you do this is by typing the entire namespace the class resides in, and then the class name.⤶
⤶
In our case, it's `Sandbox.MyAddonThing`.⤶
<upload src="b4bc4/8db9a2528c76393.png" size="12750" name="type.png" />⤶
<upload src="b4bc4/8db9a25437118ff.png" size="1979" name="image.png" />⤶
⤶
# Uploading to asset.party⤶
Under "Publishing", click "Upload To Asset Party"⤶
<upload src="b4bc4/8db9a2655cabf40.png" size="2598" name="image.png" />⤶
Select your org like before, click "Next" and follow the upload wizard steps.⤶
⤶
## Tagging and Publish State⤶
After your addon is done uploading, click the "View on asset.party" button on your addon in the "Projects" dock. ⤶
<upload src="b4bc4/8db9a27937a33f3.png" size="2028" name="image.png" />⤶
⤶
Be sure to add "runtime" to the addon's "Tags" if it is not present, and set the "Publish State" to Released, otherwise your addon will not appear in-game. After that's done, click "Save Changes".⤶
<upload src="b4bc4/8db9a26cead73cc.png" size="26680" name="image.png" />⤶