Jump to content

Recommended Posts

Posted (edited)

Hi everyone, I’m currently working on a project for Rust modding. I’ve created some test elements in 3D using Blender, imported them into Unity, and generated the prefab. I’ve placed the prefab in a directory within the server’s folder, but unfortunately, I haven’t been able to spawn the object in the server. I’ve tried changing the directory path multiple times without success. Below, I’ll share the code I’m using to spawn the GameObject.

The idea revolves around a hot air balloon, but it’s different from the existing one. It’s a balloon that will rise on its own, similar to the Sky Lantern, but it will also launch fireworks and display custom flags with images from URLs (similar to how some plugins allow images on picture frames).

I’m already a developer, but I’ve never worked with games before—this is my first project. I couldn’t find any tutorials on how to add prefabs to the server. (I’ve seen that it’s possible to add them via RustEdit, but my idea isn’t for a static object. It’s an item that players can carry in their inventory and use with a mechanic similar to the Sky Lantern or the Hot Air Balloon.)

Here’s the code I’m using to spawn the object:

using Oxide.Core.Plugins;
using UnityEngine;

namespace Oxide.Plugins
{
    [Info("SpawnPrefab", "SeuNome", "1.0.0")]
    [Description("Spawna um prefab existente no Rust")]

    public class SpawnPrefab : RustPlugin
    {
        [ChatCommand("spawncubo")]
        private void SpawnPrefabCommand(BasePlayer player, string command, string[] args)
        {
            string prefabPath = "server/servidor_modded/assets/cubaoo";

            Vector3 spawnPosition = player.transform.position + (player.transform.forward * 3);

            var entity = GameManager.server.CreateEntity(prefabPath, spawnPosition, Quaternion.identity);
            if (entity != null)
            {
                entity.Spawn();
                SendReply(player, "Prefab spawnado com sucesso!");
            }
            else
            {
                SendReply(player, "Erro ao spawnar o prefab.");
            }
        }
    }
}


Error I receive when using the "/spawncubo" command in the game.

image.png.73993c43d4d077edcd4988e8345ae872.png

--------------------------------------------------------------------------

Directory of the prefabs I’ve already tested, including the "Small Rocket," which I downloaded here from the forum, and I also can’t spawn it in the world without RustEdit. It shows the same error in the console. I’ve tried adding ".prefab" at the end of the path, but the same error persists.

image.png.1f750df171046de716dee106155cde94.png

--------------------------------------------------------------

One of the balloon models that will be added.

image.png.9b9876de417ba4408851980c087189d0.png

------------------------------------

Edit.

The error lies in the way I’m exporting from Unity. Rust is not recognizing it, as even RustEdit couldn’t identify the .prefab. However, it did identify the prefab I downloaded here, the "Small Rocket."

 

image.png.72c66b14ae35849a982a13b2922024db.png

I would greatly appreciate any guidance or suggestions on how to get this working. Thank you in advance!

Edited by MillerDias
Posted

afaik this is not possible. You can only spawn existing prefabs, as they have to exist on both the server and client (we can not modify the client). Furthermore only prefabs that have a BaseEntity component on them can be spawned. Everything else is only instantiated on the server and not networked to the client.

  • Love 1
Posted
10 minutes ago, The_Kiiiing said:

afaik this is not possible. You can only spawn existing prefabs, as they have to exist on both the server and client (we can not modify the client). Furthermore only prefabs that have a BaseEntity component on them can be spawned. Everything else is only instantiated on the server and not networked to the client.

Even in 100% modded servers? Also, how are static items created? For example, during events like Halloween, many new assets, such as skeletons, are added. There are thousands of structures that are not part of the original Rust, including the example I sent in the attachment, which worked in RustEdit, but I believe it doesn’t exist in Rust.

image.png.0457978ed4562a7f50d4c90f70cd57bb.png

Posted
On 11/16/2024 at 1:17 AM, MillerDias said:

Even in 100% modded servers? Also, how are static items created? For example, during events like Halloween, many new assets, such as skeletons, are added. There are thousands of structures that are not part of the original Rust, including the example I sent in the attachment, which worked in RustEdit, but I believe it doesn’t exist in Rust.

image.png.0457978ed4562a7f50d4c90f70cd57bb.png

As I see it, you're right that the object doesn't exist in Rust, but it was assembled from existing parts that exist in Rust so that it creates a coherent object that is then available in the game, since every part used for this exist in the game. Like the string of lights on the side of the rocket that definitely exists in the game.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
1.4m

Downloads

Total number of downloads.

6.9k

Customers

Total customers served.

102.2k

Files Sold

Total number of files sold.

2m

Payments Processed

Total payments processed.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.