Solved How to get GameObject Entity (C#)

Brain

Member
Member
Dec 29, 2016
71
7
8
45
Parts Unknown
how to get gameobject entity?

Fougerite.Entity go1 = (Fougerite.Entity)World.GetWorld().Spawn(";deploy_wood_storage_large", sPos.x, sPos.y, sPos.z, sRot);
sm.AddStructureComponent(go1.Object.gameObject.GetComponent[test]());

"object" does not contain a definition for "gameObject" and was not found an extension method "gameObject" that takes a type object as the first argument (possibly missing a using Directive or an Assembly reference
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,021
2,534
113
At your house.
github.com
how to get gameobject entity?

Fougerite.Entity go1 = (Fougerite.Entity)World.GetWorld().Spawn(";deploy_wood_storage_large", sPos.x, sPos.y, sPos.z, sRot);
sm.AddStructureComponent(go1.Object.gameObject.GetComponent[test]());

"object" does not contain a definition for "gameObject" and was not found an extension method "gameObject" that takes a type object as the first argument (possibly missing a using Directive or an Assembly reference
C#:
Fougerite.Entity go1 = (Fougerite.Entity)World.GetWorld().Spawn(";deploy_wood_storage_large", sPos.x, sPos.y, sPos.z, sRot);

            if (go1.IsDeployableObject())
            {
                DeployableObject de = (DeployableObject) go1.Object;
            }
            else if (go1.IsStructure())
            {
                StructureComponent de = (StructureComponent)go1.Object;
            }
            else if (go1.IsStructureMaster())
            {
                StructureMaster de = (StructureMaster)go1.Object;
            }
            else if (go1.IsSupplyCrate())
            {
                SupplyCrate de = (SupplyCrate)go1.Object;
            }
            else if (go1.IsResourceTarget())
            {
                ResourceTarget de = (ResourceTarget)go1.Object;
            }
 

Brain

Member
Member
Dec 29, 2016
71
7
8
45
Parts Unknown
C#:
Fougerite.Entity go1 = (Fougerite.Entity)World.GetWorld().Spawn(";deploy_wood_storage_large", sPos.x, sPos.y, sPos.z, sRot);

            if (go1.IsDeployableObject())
            {
                DeployableObject de = (DeployableObject) go1.Object;
            }
            else if (go1.IsStructure())
            {
                StructureComponent de = (StructureComponent)go1.Object;
            }
            else if (go1.IsStructureMaster())
            {
                StructureMaster de = (StructureMaster)go1.Object;
            }
            else if (go1.IsSupplyCrate())
            {
                SupplyCrate de = (SupplyCrate)go1.Object;
            }
            else if (go1.IsResourceTarget())
            {
                ResourceTarget de = (ResourceTarget)go1.Object;
            }
Thank you
 

Brain

Member
Member
Dec 29, 2016
71
7
8
45
Parts Unknown
C#:
Fougerite.Entity go1 = (Fougerite.Entity)World.GetWorld().Spawn(";deploy_wood_storage_large", sPos.x, sPos.y, sPos.z, sRot);

            if (go1.IsDeployableObject())
            {
                DeployableObject de = (DeployableObject) go1.Object;
            }
            else if (go1.IsStructure())
            {
                StructureComponent de = (StructureComponent)go1.Object;
            }
            else if (go1.IsStructureMaster())
            {
                StructureMaster de = (StructureMaster)go1.Object;
            }
            else if (go1.IsSupplyCrate())
            {
                SupplyCrate de = (SupplyCrate)go1.Object;
            }
            else if (go1.IsResourceTarget())
            {
                ResourceTarget de = (ResourceTarget)go1.Object;
            }
why I can not set the player as owner of the buildings?

C#:
Type test = Util.GetUtil().TryFindReturnType("StructureComponent");
                var spawnPos = Util.GetUtil().CreateVector(Convert.ToSingle(player.PlayerClient.lastKnownPosition.x), Convert.ToSingle(player.PlayerClient.lastKnownPosition.y), Convert.ToSingle(player.PlayerClient.lastKnownPosition.z));
                var spawnRot = Util.GetUtil().CreateQuat(Convert.ToSingle(1), Convert.ToSingle(2), Convert.ToSingle(3), Convert.ToSingle(4));
                var sm = World.GetWorld().CreateSM(player, spawnPos.x, spawnPos.y, spawnPos.z, spawnRot);
                Fougerite.Entity go1 = (Fougerite.Entity)World.GetWorld().Spawn(";deploy_wood_storage_large", spawnPos.x, spawnPos.y, spawnPos.z, spawnRot);
                StructureComponent de = (StructureComponent)go1.Object;
                sm.AddStructureComponent(de.gameObject.GetComponent[test]());
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,021
2,534
113
At your house.
github.com
why I can not set the player as owner of the buildings?

C#:
Type test = Util.GetUtil().TryFindReturnType("StructureComponent");
                var spawnPos = Util.GetUtil().CreateVector(Convert.ToSingle(player.PlayerClient.lastKnownPosition.x), Convert.ToSingle(player.PlayerClient.lastKnownPosition.y), Convert.ToSingle(player.PlayerClient.lastKnownPosition.z));
                var spawnRot = Util.GetUtil().CreateQuat(Convert.ToSingle(1), Convert.ToSingle(2), Convert.ToSingle(3), Convert.ToSingle(4));
                var sm = World.GetWorld().CreateSM(player, spawnPos.x, spawnPos.y, spawnPos.z, spawnRot);
                Fougerite.Entity go1 = (Fougerite.Entity)World.GetWorld().Spawn(";deploy_wood_storage_large", spawnPos.x, spawnPos.y, spawnPos.z, spawnRot);
                StructureComponent de = (StructureComponent)go1.Object;
                sm.AddStructureComponent(de.gameObject.GetComponent[test]());
lol

why not use something simpler?


https://github.com/Notulp/Fougerite/blob/master/Fougerite/Fougerite/Entity.cs#L142


Location:

player.Location
 

Brain

Member
Member
Dec 29, 2016
71
7
8
45
Parts Unknown

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,021
2,534
113
At your house.
github.com
C#:
var sm = World.CreateSM(player, location.x, location.y, location.z, spawnRot);
            var ent = new Entity(World.Spawn(";struct_metal_wall", location.x, location.y, location.z, spawnRot));
            if (ent.IsStructure())
            {
                var smn = (StructureComponent)ent.Object;
                sm.AddStructureComponent(smn.GetComponent<StructureComponent>());
            }
 

Brain

Member
Member
Dec 29, 2016
71
7
8
45
Parts Unknown
C#:
var sm = World.CreateSM(player, location.x, location.y, location.z, spawnRot);
            var ent = new Entity(World.Spawn(";struct_metal_wall", location.x, location.y, location.z, spawnRot));
            if (ent.IsStructure())
            {
                var smn = (StructureComponent)ent.Object;
                sm.AddStructureComponent(smn.GetComponent<StructureComponent>());
            }
"StructureMaster.AddStructureComponent(StructureComponent)" is deprecated: ""NOT OBSOLETE BUT.. This should only be called from datablocks or otherwise immediately after the component is instantiated - and only once""
 

Brain

Member
Member
Dec 29, 2016
71
7
8
45
Parts Unknown
Doesn't matter.
The object has no owner...

var sm = World.GetWorld().CreateSM(player, player.Location.x, player.Location.y, player.Location.z);
var ent = new Entity(World.GetWorld().Spawn(";struct_metal_wall", player.Location.x, player.Location.y, player.Location.z));
if (ent.IsStructure())
{
var smn = (StructureComponent)ent.Object;
sm.AddStructureComponent(smn.GetComponent<StructureComponent>());
ent.ChangeOwner(player);
Server.GetServer().Broadcast("Item: " + ent.Name + " Owner: " + ent.CreatorName);
}
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,021
2,534
113
At your house.
github.com
how to get gameobject entity?

Fougerite.Entity go1 = (Fougerite.Entity)World.GetWorld().Spawn(";deploy_wood_storage_large", sPos.x, sPos.y, sPos.z, sRot);
sm.AddStructureComponent(go1.Object.gameObject.GetComponent[test]());

"object" does not contain a definition for "gameObject" and was not found an extension method "gameObject" that takes a type object as the first argument (possibly missing a using Directive or an Assembly reference
In case anyone was wondering like i was right now, cuz i forgot, you need to reference Facepunch.ID.dll in your C# project, then you will see the gameobject variable.