i can spawn the fireball but how do i attack it so when a player moves it moves with them.
Code:BasePlayer npc, BasePlayer player) { if (!npcData.NpcTP.ContainsKey(npc.UserIDString)) return; // Check if this NPC is registered Effect.server.Run("assets/bundled/prefabs/fx/weapons/landmine/landmine_explosion.prefab", player.transform.position); BaseEntity FireBombArrow = GameManager.server.CreateEntity("assets/bundled/prefabs/oilfireballsmall.prefab", player.transform.position); FireBombArrow?.Spawn(); timer.Once(10, () => FireBombArrow.Kill()); SendReply(player, "Get away from me you are not MVP"); }
Attaching entity to player?
Discussion in 'Rust Development' started by Ts3hosting, Feb 12, 2017.
-
If setting the parent doesn't work. Then maybe create a class, and with Update or whatever the function is within a class set the entity as the player position. HeliRide has a fair example of how you could do it I suppose.
-
i seem to be missing somthing still as it will not follow the player.
Code:class FireBall : MonoBehaviour { public BasePlayer player; void Awake() { var player = GetComponent<BasePlayer>(); var PlayerPOS = player.transform.position; BaseEntity FireBurn = GameManager.server.CreateEntity("assets/bundled/prefabs/oilfireballsmall.prefab", new Vector3(), new Quaternion(), true); FireBurn.transform.localPosition = PlayerPOS; FireBurn?.Spawn(); } } void OnEnterNPC(BasePlayer npc, BasePlayer player) { if (!npcData.NpcTP.ContainsKey(npc.UserIDString)) return; // Check if this NPC is registered Effect.server.Run("assets/bundled/prefabs/fx/weapons/landmine/landmine_explosion.prefab", player.transform.position); player.gameObject.AddComponent<FireBall>(); SendReply(player, "Get away from me you are not MVP"); }
-
FireBurn.SetParent(player); the local position is what you would use to offset the childs transform to the parents transform. But beware, attaching that entity to a player will kill them from fire damage
-
Thanks im aware that its going to kill them.... im still not having any luck.
Code:class FireBall : MonoBehaviour { public BasePlayer player; public Vector3 PlayerPOS; public BaseEntity FireBurn; void Awake() { var player = GetComponent<BasePlayer>(); PlayerPOS = player.transform.position; FireBurn = GameManager.server.CreateEntity("assets/bundled/prefabs/oilfireballsmall.prefab", new Vector3(), new Quaternion(), true); FireBurn.transform.localPosition = PlayerPOS; FireBurn?.Spawn(); FireBurn.SetParent(player); } } void OnEnterNPC(BasePlayer npc, BasePlayer player) { if (!npcData.NpcTP.ContainsKey(npc.UserIDString)) return; // Check if this NPC is registered Effect.server.Run("assets/bundled/prefabs/fx/weapons/landmine/landmine_explosion.prefab", player.transform.position); player.gameObject.AddComponent<FireBall>(); SendReply(player, "Get away from me you are not MVP"); }
Last edited by a moderator: Feb 12, 2017 -
Got it thanks.
Not to clean it all upLast edited by a moderator: Feb 12, 2017 -
Guess one more problem. i half to have this. for it to work but throwing error. if ido not have the 2 lines fire will not display.
Can't add component 'Rigidbody' to assets/bundled/prefabs/oilfireballsmall.prefab because such a component is already added to the game object! How do i destroy that object?
Code:FireBurn.gameObject.AddComponent(typeof(Rigidbody)); ((Rigidbody)FireBurn.gameObject.GetComponent(typeof(Rigidbody))).isKinematic = true;
Code:readonly Dictionary<ulong, Timer> timers = new Dictionary<ulong, Timer>(); void OnEnterNPC(BasePlayer npc, BasePlayer player) { ulong playerId = player.userID; string npcId = npc.UserIDString; string Perms = npcData.NpcTP[npcId].permission; var NoPermDie = npcData.NpcTP[npcId].NoPermKill; if (player is BaseNPC || player.IsDestroyed || permission.UserHasPermission(player.userID.ToString(), Perms)) return; if (!npcData.NpcTP.ContainsKey(npc.UserIDString)) return; // Check if this NPC is registered if (NoPermDie == false) return; SendReply(player, "Get away from me you are not MVP"); PlayerPOS = player.transform.position; var playerPos = player.transform.position; var playerRot = player.transform.rotation; BaseEntity FireBurn = GameManager.server.CreateEntity("assets/bundled/prefabs/oilfireballsmall.prefab", playerPos, playerRot); FireBurn.SetParent(player); FireBurn.Spawn(); FireBurn.SetParent(player); FireBurn.transform.localPosition = new Vector3(0f, 0f, 0f); timer.Once(30, () => FireBurn.Kill()); player.SendConsoleCommand($"say this is a test"); FireBurn.gameObject.AddComponent(typeof(Rigidbody)); ((Rigidbody)FireBurn.gameObject.GetComponent(typeof(Rigidbody))).isKinematic = true; applyBlastDamage(player); } void OnLeaveNPC(BasePlayer npc, BasePlayer player) { if (player is BaseNPC || player.IsDestroyed || !timers.ContainsKey(player.userID)) return; if (!npcData.NpcTP.ContainsKey(npc.UserIDString)) return; // Check if this NPC is registered timers[player.userID].Destroy(); return; } void applyBlastDamage(BasePlayer player) { if (player != null || !timers.ContainsKey(player.userID)) timers[player.userID] = timer.Every(3, () => { if (player.IsDead() && timers.ContainsKey(player.userID)) timers[player.userID].Destroy(); else player.Hurt(5); }); return; }
Last edited by a moderator: Feb 12, 2017