Implemented OnPlayerRightClickingEntity() hook
Fixes FS 425
This commit is contained in:
parent
f481865c35
commit
3531bdb60b
@ -21,6 +21,7 @@ function Initialize(Plugin)
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_TAKE_DAMAGE);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_TICK);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHAT);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_RIGHT_CLICKING_ENTITY);
|
||||
|
||||
PluginManager:BindCommand("/le", "debuggers", HandleListEntitiesCmd, "Shows a list of all the loaded entities");
|
||||
PluginManager:BindCommand("/ke", "debuggers", HandleKillEntitiesCmd, "Kills all the loaded entities");
|
||||
@ -484,6 +485,15 @@ end
|
||||
|
||||
|
||||
|
||||
function OnPlayerRightClickingEntity(a_Player, a_Entity)
|
||||
LOG("Player " .. a_Player:GetName() .. " right-clicking entity ID " .. a_Entity:GetUniqueID() .. ", a " .. a_Entity:GetClass());
|
||||
return false;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- Function "round" copied from http://lua-users.org/wiki/SimpleRound
|
||||
function round(num, idp)
|
||||
local mult = 10^(idp or 0)
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
** Lua binding: AllToLua
|
||||
** Generated automatically by tolua++-1.0.92 on 07/29/13 19:22:49.
|
||||
** Generated automatically by tolua++-1.0.92 on 08/02/13 08:41:18.
|
||||
*/
|
||||
|
||||
#ifndef __cplusplus
|
||||
@ -29459,6 +29459,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
|
||||
tolua_constant(tolua_S,"HOOK_PLAYER_PLACED_BLOCK",cPluginManager::HOOK_PLAYER_PLACED_BLOCK);
|
||||
tolua_constant(tolua_S,"HOOK_PLAYER_PLACING_BLOCK",cPluginManager::HOOK_PLAYER_PLACING_BLOCK);
|
||||
tolua_constant(tolua_S,"HOOK_PLAYER_RIGHT_CLICK",cPluginManager::HOOK_PLAYER_RIGHT_CLICK);
|
||||
tolua_constant(tolua_S,"HOOK_PLAYER_RIGHT_CLICKING_ENTITY",cPluginManager::HOOK_PLAYER_RIGHT_CLICKING_ENTITY);
|
||||
tolua_constant(tolua_S,"HOOK_PLAYER_SHOOTING",cPluginManager::HOOK_PLAYER_SHOOTING);
|
||||
tolua_constant(tolua_S,"HOOK_PLAYER_SPAWNED",cPluginManager::HOOK_PLAYER_SPAWNED);
|
||||
tolua_constant(tolua_S,"HOOK_PLAYER_TOSSING_ITEM",cPluginManager::HOOK_PLAYER_TOSSING_ITEM);
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
** Lua binding: AllToLua
|
||||
** Generated automatically by tolua++-1.0.92 on 07/29/13 19:22:49.
|
||||
** Generated automatically by tolua++-1.0.92 on 08/02/13 08:41:19.
|
||||
*/
|
||||
|
||||
/* Exported function */
|
||||
|
@ -1070,6 +1070,10 @@ void cClientHandle::HandleUseEntity(int a_TargetEntityID, bool a_IsLeftClick)
|
||||
cPlayer & m_Player;
|
||||
virtual bool Item(cEntity * a_Entity) override
|
||||
{
|
||||
if (cPluginManager::Get()->CallHookPlayerRightClickingEntity(m_Player, *a_Entity))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
a_Entity->OnRightClicked(m_Player);
|
||||
return false;
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
||||
|
||||
#include "Plugin.h"
|
||||
// #include "Pawn.h"
|
||||
#include "Player.h"
|
||||
#include "World.h"
|
||||
#include "CommandOutput.h"
|
||||
@ -342,6 +341,17 @@ bool cPlugin::OnPlayerRightClick(cPlayer & a_Player, int a_BlockX, int a_BlockY,
|
||||
|
||||
|
||||
|
||||
bool cPlugin::OnPlayerRightClickingEntity(cPlayer & a_Player, cEntity & a_Entity)
|
||||
{
|
||||
UNUSED(a_Player);
|
||||
UNUSED(a_Entity);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPlugin::OnPlayerShooting(cPlayer & a_Player)
|
||||
{
|
||||
UNUSED(a_Player);
|
||||
|
@ -61,7 +61,7 @@ public:
|
||||
virtual bool OnHandshake (cClientHandle * a_Client, const AString & a_Username);
|
||||
virtual bool OnKilling (cEntity & a_Victim, cEntity * a_Killer);
|
||||
virtual bool OnLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username);
|
||||
virtual bool OnPlayerBreakingBlock(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
|
||||
virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
|
||||
virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
|
||||
virtual bool OnPlayerEating (cPlayer & a_Player);
|
||||
virtual bool OnPlayerJoined (cPlayer & a_Player);
|
||||
@ -70,6 +70,7 @@ public:
|
||||
virtual bool OnPlayerPlacedBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
|
||||
virtual bool OnPlayerPlacingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
|
||||
virtual bool OnPlayerRightClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ);
|
||||
virtual bool OnPlayerRightClickingEntity(cPlayer & a_Player, cEntity & a_Entity);
|
||||
virtual bool OnPlayerShooting (cPlayer & a_Player);
|
||||
virtual bool OnPlayerSpawned (cPlayer & a_Player);
|
||||
virtual bool OnPlayerTossingItem (cPlayer & a_Player);
|
||||
|
@ -678,6 +678,27 @@ bool cPluginManager::CallHookPlayerRightClick(cPlayer & a_Player, int a_BlockX,
|
||||
|
||||
|
||||
|
||||
bool cPluginManager::CallHookPlayerRightClickingEntity(cPlayer & a_Player, cEntity & a_Entity)
|
||||
{
|
||||
HookMap::iterator Plugins = m_Hooks.find(HOOK_PLAYER_RIGHT_CLICKING_ENTITY);
|
||||
if (Plugins == m_Hooks.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
|
||||
{
|
||||
if ((*itr)->OnPlayerRightClickingEntity(a_Player, a_Entity))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPluginManager::CallHookPlayerShooting(cPlayer & a_Player)
|
||||
{
|
||||
HookMap::iterator Plugins = m_Hooks.find(HOOK_PLAYER_SHOOTING);
|
||||
|
@ -15,6 +15,9 @@ class cWorld;
|
||||
// fwd: ChunkDesc.h
|
||||
class cChunkDesc;
|
||||
|
||||
// fwd: Entityes/Entity.h
|
||||
class cEntity;
|
||||
|
||||
// fwd: Player.h
|
||||
class cPlayer;
|
||||
|
||||
@ -69,6 +72,7 @@ public: // tolua_export
|
||||
HOOK_PLAYER_PLACED_BLOCK,
|
||||
HOOK_PLAYER_PLACING_BLOCK,
|
||||
HOOK_PLAYER_RIGHT_CLICK,
|
||||
HOOK_PLAYER_RIGHT_CLICKING_ENTITY,
|
||||
HOOK_PLAYER_SHOOTING,
|
||||
HOOK_PLAYER_SPAWNED,
|
||||
HOOK_PLAYER_TOSSING_ITEM,
|
||||
@ -128,7 +132,7 @@ public: // tolua_export
|
||||
bool CallHookHandshake (cClientHandle * a_ClientHandle, const AString & a_Username);
|
||||
bool CallHookKilling (cEntity & a_Victim, cEntity * a_Killer);
|
||||
bool CallHookLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username);
|
||||
bool CallHookPlayerBreakingBlock(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
|
||||
bool CallHookPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
|
||||
bool CallHookPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
|
||||
bool CallHookPlayerEating (cPlayer & a_Player);
|
||||
bool CallHookPlayerJoined (cPlayer & a_Player);
|
||||
@ -137,6 +141,7 @@ public: // tolua_export
|
||||
bool CallHookPlayerPlacedBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
|
||||
bool CallHookPlayerPlacingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
|
||||
bool CallHookPlayerRightClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ);
|
||||
bool CallHookPlayerRightClickingEntity(cPlayer & a_Player, cEntity & a_Entity);
|
||||
bool CallHookPlayerShooting (cPlayer & a_Player);
|
||||
bool CallHookPlayerSpawned (cPlayer & a_Player);
|
||||
bool CallHookPlayerTossingItem (cPlayer & a_Player);
|
||||
|
@ -880,6 +880,33 @@ bool cPlugin_NewLua::OnPlayerRightClick(cPlayer & a_Player, int a_BlockX, int a_
|
||||
|
||||
|
||||
|
||||
bool cPlugin_NewLua::OnPlayerRightClickingEntity(cPlayer & a_Player, cEntity & a_Entity)
|
||||
{
|
||||
cCSLock Lock(m_CriticalSection);
|
||||
const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_RIGHT_CLICKING_ENTITY);
|
||||
ASSERT(FnName != NULL);
|
||||
if (!PushFunction(FnName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
tolua_pushusertype(m_LuaState, &a_Player, "cPlayer");
|
||||
tolua_pushusertype(m_LuaState, &a_Entity, "cEntity");
|
||||
|
||||
if (!CallFunction(2, 1, FnName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
||||
lua_pop(m_LuaState, 1);
|
||||
return bRetVal;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPlugin_NewLua::OnPlayerShooting(cPlayer & a_Player)
|
||||
{
|
||||
cCSLock Lock(m_CriticalSection);
|
||||
@ -1542,6 +1569,7 @@ const char * cPlugin_NewLua::GetHookFnName(cPluginManager::PluginHook a_Hook)
|
||||
case cPluginManager::HOOK_PLAYER_PLACED_BLOCK: return "OnPlayerPlacedBlock";
|
||||
case cPluginManager::HOOK_PLAYER_PLACING_BLOCK: return "OnPlayerPlacingBlock";
|
||||
case cPluginManager::HOOK_PLAYER_RIGHT_CLICK: return "OnPlayerRightClick";
|
||||
case cPluginManager::HOOK_PLAYER_RIGHT_CLICKING_ENTITY: return "OnPlayerRightClickingEntity";
|
||||
case cPluginManager::HOOK_PLAYER_SHOOTING: return "OnPlayerShooting";
|
||||
case cPluginManager::HOOK_PLAYER_SPAWNED: return "OnPlayerSpawned";
|
||||
case cPluginManager::HOOK_PLAYER_TOSSING_ITEM: return "OnPlayerTossingItem";
|
||||
|
@ -51,7 +51,7 @@ public:
|
||||
virtual bool OnHandshake (cClientHandle * a_Client, const AString & a_Username) override;
|
||||
virtual bool OnKilling (cEntity & a_Victim, cEntity * a_Killer) override;
|
||||
virtual bool OnLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username) override;
|
||||
virtual bool OnPlayerBreakingBlock(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
|
||||
virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
|
||||
virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
|
||||
virtual bool OnPlayerEating (cPlayer & a_Player) override;
|
||||
virtual bool OnPlayerJoined (cPlayer & a_Player) override;
|
||||
@ -60,6 +60,7 @@ public:
|
||||
virtual bool OnPlayerPlacedBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
|
||||
virtual bool OnPlayerPlacingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
|
||||
virtual bool OnPlayerRightClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override;
|
||||
virtual bool OnPlayerRightClickingEntity(cPlayer & a_Player, cEntity & a_Entity) override;
|
||||
virtual bool OnPlayerShooting (cPlayer & a_Player) override;
|
||||
virtual bool OnPlayerSpawned (cPlayer & a_Player) override;
|
||||
virtual bool OnPlayerTossingItem (cPlayer & a_Player) override;
|
||||
|
Loading…
Reference in New Issue
Block a user