C
C#2y ago
KRY_

❔ hook errors and unexpected }

So I’m working on some code for rust as of now and it’s function so far is to spawn a crate at a players position with a offset of 1.5 for the x, I keep getting errors with it though and I can’t seem to fix the issue anyone got a solution? Code:
using Oxide.Core.Libraries.Covalence;
using System;
using System.Collections.Generic;
using UnityEngine;

namespace Oxide.Plugins
{
[Info("hackable", "KRYPT1KZ", "1.0.1")]
public class hackable : CovalencePlugin
{
private const string hackablePrefab = "assets/prefabs/deployable/hackable_crate.prefab";

[Command("hackable")]
private void CommandHackable(IPlayer player, string cmd, string[] args)
{
var spawnPosition = new Vector3(player.Position().x + 1.5f, player.Position().y, player.Position().z);
var entity = GameManager.server.CreateEntity(hackablePrefab, spawnPosition);

entity.Spawn();

Puts($"{player.Name} spawned a hackable at {spawnPosition}.");
}

private void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitinfo)
{
if (hitinfo.Initiator != null && hitinfo.Initiator is BasePlayer && entity.ShortPrefabName == "hackable_crate")
{
var player = hitinfo.Initiator as BasePlayer;
Puts($"Player {player.displayName} has opened hackable crate {entity.net.ID}");
}
}

protected override void LoadDefaultConfig()
{
// Subscribe to the entity take damage event
this.HookEvent(Rust.Event.OnEntityTakeDamage, OnEntityTakeDamage);
}
}
}
using Oxide.Core.Libraries.Covalence;
using System;
using System.Collections.Generic;
using UnityEngine;

namespace Oxide.Plugins
{
[Info("hackable", "KRYPT1KZ", "1.0.1")]
public class hackable : CovalencePlugin
{
private const string hackablePrefab = "assets/prefabs/deployable/hackable_crate.prefab";

[Command("hackable")]
private void CommandHackable(IPlayer player, string cmd, string[] args)
{
var spawnPosition = new Vector3(player.Position().x + 1.5f, player.Position().y, player.Position().z);
var entity = GameManager.server.CreateEntity(hackablePrefab, spawnPosition);

entity.Spawn();

Puts($"{player.Name} spawned a hackable at {spawnPosition}.");
}

private void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitinfo)
{
if (hitinfo.Initiator != null && hitinfo.Initiator is BasePlayer && entity.ShortPrefabName == "hackable_crate")
{
var player = hitinfo.Initiator as BasePlayer;
Puts($"Player {player.displayName} has opened hackable crate {entity.net.ID}");
}
}

protected override void LoadDefaultConfig()
{
// Subscribe to the entity take damage event
this.HookEvent(Rust.Event.OnEntityTakeDamage, OnEntityTakeDamage);
}
}
}
40 Replies
TheBoxyBear
TheBoxyBear2y ago
What line has the error?
KRY_
KRY_2y ago
didn’t specify, my RCON only gave me an error when compiling saying it’s got a hook error
TheBoxyBear
TheBoxyBear2y ago
Code seems fine Maybe it's tripping up at the interpolated string?
KRY_
KRY_2y ago
Possible i wouldn’t really know, not very good at C# just yet What could I do to fix the string issue if that is what it is?
TheBoxyBear
TheBoxyBear2y ago
string.Format
KRY_
KRY_2y ago
I’ll test it out, which line would it be?
TheBoxyBear
TheBoxyBear2y ago
Replacing the $"" strings string.Format("Hello, my name is {0}", name) for example The number is the index of the parameter, you can have as many as you want
KRY_
KRY_2y ago
I see
TheBoxyBear
TheBoxyBear2y ago
Though I never heard of RCON
KRY_
KRY_2y ago
Haha RCON is a CMD basically It’s for rust rust uses C# plugins running under the mod manager oxidemod many other games use it too, minecraft is a good example of one
TheBoxyBear
TheBoxyBear2y ago
Remote Console I see
KRY_
KRY_2y ago
Yes
TheBoxyBear
TheBoxyBear2y ago
So it has its own compiler to make sure it can run alongside the game? Then maybe it's just outdated and doesn't support string interpolation, but then it would be tripping up on the $ before the string
KRY_
KRY_2y ago
Yes and that’s pretty understandable So what would I do for the $?
TheBoxyBear
TheBoxyBear2y ago
string.Format
KRY_
KRY_2y ago
Hm Puts string.Format(“”); or Puts (string.Format “”);
TheBoxyBear
TheBoxyBear2y ago
latter Format becomes the final string
KRY_
KRY_2y ago
? Sorry I’m a little slow
TheBoxyBear
TheBoxyBear2y ago
Puts(string.Format())
KRY_
KRY_2y ago
Oh New error
KRY_
KRY_2y ago
KRY_
KRY_2y ago
it’s calling a plugin I don’t have I think Or exist Nvm What would I do for this
TheBoxyBear
TheBoxyBear2y ago
this.HookEvent(Rust.Event.OnEntityTakeDamage, OnEntityTakeDamage); It's here Does the base class have it?
KRY_
KRY_2y ago
? base class? I don’t follow
TheBoxyBear
TheBoxyBear2y ago
The CovalencePlugin class
KRY_
KRY_2y ago
probably not? I’m not 100% sure
TheBoxyBear
TheBoxyBear2y ago
Ctrl-click CovalencePlugin to check
KRY_
KRY_2y ago
Like a permission or something?
KRY_
KRY_2y ago
Still don’t follow-
TheBoxyBear
TheBoxyBear2y ago
hackable derives from CovalencePlugin For HookEvent to exist, it needs to be defined in hackable or its base class or somewhere higher on the hierarchy of classes
KRY_
KRY_2y ago
What could I add to the code which will make it exist then
TheBoxyBear
TheBoxyBear2y ago
Check the docs
KRY_
KRY_2y ago
which part
TheBoxyBear
TheBoxyBear2y ago
The page on HookEvent
KRY_
KRY_2y ago
Okay let me see here New issue
KRY_
KRY_2y ago
TheBoxyBear
TheBoxyBear2y ago
Check the class definition
KRY_
KRY_2y ago
I’ll keep trying in a little I have to do something for now Alright I’m back
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts