Code:void OnPlayerLoot(PlayerLoot inventory, BasePlayer target) { if (TeamData.ContainsKey(target)) inventory.Clear(); }Code:[Error] Failed to call hook 'OnPlayerLoot' (InvalidCastException: Cannot cast from source type to destination type.)
Solved Stop looting of other players? (C#)
Discussion in 'Rust Development' started by PsychoTea, Nov 15, 2015.
-
What's the TeamData dict? I mean, is it Dictionary<BasePlayer, string>?
-
yes yes yes
-
Code:
void OnPlayerLoot(PlayerLoot inventory, BasePlayer target) { if(TeamData.ContainsKey(target)) target.inventory.Strip(); } -
It to clear inventory of the player (target)
May be I try:
Code:inventory.entitySource.ToPlayer().EndLooting();
-
Didn't help
(
May be BasePlayer not BasePlayer? or i'm don't know in what's problem -
I haven't read the whole conversation but instead of:
try this:Code:inventory.entitySource.ToPlayer().EndLooting();
Code:BasePlayer player = inventory.GetComponent<BasePlayer>();if (player == null) return;player.EndLooting();
-
I don't understand in what a problem.Code:
[Error] Failed to call hook 'OnPlayerLoot' (InvalidCastException: Cannot cast from source type to destination type.)
EDIT: I rename hook toErrors weren'tCode:void OnPlayerLoot(PlayerLoot inventory, BaseEntity entity)
Last edited by a moderator: Dec 21, 2015 -
the message shows, and Loot not to stopCode:
void OnPlayerLoot(PlayerLoot inventory, BaseEntity entity) { if (entity is BasePlayer) { BasePlayer target = entity.ToPlayer(); if (TeamData.ContainsKey(target)) { target.EndLooting(); inventory.Clear(); PrintToChat(target, "Your inventory grabbed"); } } } -
entity isn't the player! It's the thing you are looting. To get the player who is looting you have to write the following:
Code:BasePlayer target = inventory.GetComponent<BasePlayer>();
