I made a script that make GameObjects locked, with the item you want.
You can add infinite keys.
MANGOS
GM Commands :
Code:
.gobject addkey <guid> <keyid>
.gobject delkey <guid> <keyid>
Code :
Code:
bool ChatHandler::HandleGameObjectAddKeyCommand(const char* args)
{
if (!*args)
return false;
// number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
char* cId = extractKeyFromLink((char*)args,"Hgameobject_entry");
if(!cId)
return false;
uint32 lowguid = atol(cId);
if(!lowguid)
return false;
char* lockid = strtok(NULL, " ");
if(!lockid)
return false;
uint32 keyid = atoi((char*)lockid);
ItemPrototype const *it = objmgr.GetItemPrototype(keyid);
if(!it)
return false;
GameObject* obj = NULL;
// by DB guid
if (GameObjectData const* go_data = objmgr.GetGOData(lowguid))
obj = GetObjectGlobalyWithGuidOrNearWithDbGuid(lowguid,go_data->id);
if(!obj)
{
PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, lowguid);
SetSentErrorMessage(true);
return false;
}
m_session->SendNotification("Key %s added to the object %s.", it->Name1, obj->GetName());
WorldDatabase.PExecute("REPLACE INTO `portelocked` VALUES('%u', '%u');", lowguid, keyid);
return true;
}
bool ChatHandler::HandleGameObjectDelKeyCommand(const char *args)
{
if (!*args)
return false;
// number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
char* cId = extractKeyFromLink((char*)args,"Hgameobject_entry");
if(!cId)
return false;
uint32 lowguid = atol(cId);
if(!lowguid)
return false;
char* lockid = strtok(NULL, " ");
if(!lockid)
return false;
uint32 keyid = atoi((char*)lockid);
ItemPrototype const *it = objmgr.GetItemPrototype(keyid);
if(!it)
return false;
GameObject* obj = NULL;
// by DB guid
if (GameObjectData const* go_data = objmgr.GetGOData(lowguid))
obj = GetObjectGlobalyWithGuidOrNearWithDbGuid(lowguid,go_data->id);
if(!obj)
{
PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, lowguid);
SetSentErrorMessage(true);
return false;
}
WorldDatabase.PExecute("DELETE FROM `portelocked` WHERE keyid = '%u' AND guid = '%u';", keyid, lowguid);
m_session->SendNotification("Key %s deleted from the object %s.", it->Name1, obj->GetName());
return true;
}
ScriptDev2 Code :
Code:
ScriptLoader.cpp
Line 7
//Custom
extern void AddSC_Porte(); // Add this line
//examples etc ...
Line 360
void AddScripts()
{
//Custom
AddSC_Porte(); And this one.
//Examples etc ...
Code:
Custom/Porte.cpp
#include "precompiled.h"
#include "Database/DatabaseEnv.h"
#include "../../system/system.h"
#include "ObjectMgr.h" // Comment it on Windows.
bool GOHello_Porte(Player *player, GameObject* _GO)
{
QueryResult * pResult = SD2Database.PQuery("SELECT keyid FROM mangos.portelocked WHERE guid = '%u'", _GO->GetGUIDLow());
if (pResult)
{
do
{
Field * pFields = pResult->Fetch();
if(!player->HasItemCount(pFields[0].GetUInt32(), 1))
{
ItemPrototype const *pProto = objmgr.GetItemPrototype(pFields[0].GetUInt32()); // Comment it on Windows.
player->GetSession()->SendNotification("You must have the item %s", pProto->Name1); // Comment it on Windows.
delete pResult;
return true;
}
} while(pResult->NextRow());
_GO->UseDoorOrButton();
delete pResult;
return true;
}
else return false;
}
void AddSC_Porte()
{
Script *newscript;
newscript = new Script;
newscript->Name = "PorteLocked";
newscript->pGOHello = &GOHello_Porte;
newscript->RegisterSelf();
}
You must change "mangos" to your world database name
I haven't tested yet the gm commands, but I'll do this as soon as I can.
Other :- On Windows,lines in green won't compile. There will be some links error. If someone has a solution, he's welcome !
- Actually, it works fine on door. I don't test with other GOs.
ARCEMU
Code:
// In misc scripts /GameObjectLockTable.cpp
#include "StdAfx.h"
#include "Setup.h"
class CustomLock: public GameObjectAIScript // Custom Door Locking
{
public:
CustomLock(GameObject* goinstance) : GameObjectAIScript(goinstance)
{
}
~CustomLock()
{
}
void OnActivate(Player * pPlayer)
{
QueryResult *result = NULL;
result = WorldDatabase.Query("SELECT * FROM gameobject_locks WHERE guid = %ld", this->_gameobject->GetGUID());
if(result)
{
do
{
Field * pFields = result->Fetch();
if(!pPlayer->HasItemCount(pFields[1].GetUInt32(), 1))
{
ItemPrototype const *pProto = ItemPrototypeStorage.LookupEntry(pFields[1].GetUInt32());
pPlayer->GetSession()->SendNotification("You must have the item %s", pProto->Name1);
delete result;
return;
}
} while(result->NextRow());
this->_gameobject->Activate(pPlayer->GetMapMgr());
delete result;
return;
}
else return;
}
static GameObjectAIScript *Create(GameObject * GO) { return new CustomLock(GO); }
};
void InitializeGameObjectLockTable(ScriptMgr * mgr)
{
QueryResult *result = NULL;
result = WorldDatabase.Query("SELECT * FROM gameobject_locks");
if(result != NULL)
{
// Check if the SQL table is setup correctly
if (result->GetFieldCount() < 2)
{
sLog.outColor(TRED,"\nError: Custom door locking disabled, invalid 'gameobject_locks' table.");
delete result;
return;
}
do
{
uint32 id = result->Fetch()[0].GetUInt32();
uint32 keyid = result->Fetch()[1].GetUInt32();
mgr->register_gameobject_script(id, &CustomLock::Create);
} while (result->NextRow());
delete result;
}
}
Code:
Setup.h
#ifndef MISC_SCRIPTS_SETUP_H
#define MISC_SCRIPTS_SETUP_H
void SetupGoHandlers(ScriptMgr * mgr);
void SetupRandomScripts(ScriptMgr * mgr);
void SetupMiscCreatures(ScriptMgr * mgr);
void SetupEbonHold(ScriptMgr * mgr);
void SetupWyrmrestTemple(ScriptMgr * mgr);
void SetupGrizzlyHills(ScriptMgr * mgr);
void InitializeGameObjectTeleportTable(ScriptMgr * mgr);
void InitializeGameObjectLockTable(ScriptMgr * mgr); // <-- Add this line
#endif
And the last file :
Code:
Setup.cpp
extern "C" SCRIPT_DECL void _exp_script_register(ScriptMgr* mgr) // Comment any script to disable it
{
SetupGoHandlers(mgr);
SetupRandomScripts(mgr);
SetupMiscCreatures(mgr);
SetupEbonHold(mgr);
SetupWyrmrestTemple(mgr);
SetupGrizzlyHills(mgr);
// Sets up gossip scripts for gameobjects in the (optional)
// gameobject_teleports table. If the table doesn't exist the
// initialization will quietly fail.
InitializeGameObjectTeleportTable(mgr);
InitializeGameObjectLockTable(mgr); <-- Add this line.
}
Arcemu Command ( Same usage as Mangos one) :
Code:
bool ChatHandler::HandleGOAddKey(const char* args, WorldSession *m_session)
{
GameObject *GObj = m_session->GetPlayer()->GetSelectedGo();
if( !GObj )
{
RedSystemMessage(m_session, "No selected GameObject...");
return true;
}
if(!args)
{
RedSystemMessage(m_session, "Invalid syntax. Should be .gobject addkey <keyid>");
return false;
}
uint32 keyid = atol(args);
if(!keyid)
{
RedSystemMessage(m_session, "Invalid syntax. Should be .gobject addkey <keyid>");
return false;
}
ItemPrototype *it = ItemPrototypeStorage.LookupEntry(keyid);
if(!it)
{
RedSystemMessage(m_session, "Item %u doesn't exist.", keyid);
return true;
}
std::stringstream qry;
qry << "REPLACE INTO `gameobject_locks` VALUES('" << GObj->m_spawn->id << "', '" << keyid << "')";
WorldDatabase.Execute( qry.str().c_str( ) );
RedSystemMessage(m_session, "Key %s (%u) added to object %s ( GUID : %u | ID : %u )", it->Name1, it->ItemId, GameObjectNameStorage.LookupEntry( GObj->GetEntry() )->Name, GObj->m_spawn->id, GObj->GetEntry());
return true;
}
bool ChatHandler::HandleGODelKey(const char* args, WorldSession *m_session)
{
GameObject *GObj = m_session->GetPlayer()->GetSelectedGo();
if( !GObj )
{
RedSystemMessage(m_session, "No selected GameObject...");
return true;
}
if(!args)
{
RedSystemMessage(m_session, "Invalid syntax. Should be .gobject addkey <keyid>");
return false;
}
uint32 keyid = atol(args);
if(!keyid)
{
RedSystemMessage(m_session, "Invalid syntax. Should be .gobject addkey <keyid>");
return false;
}
ItemPrototype *it = ItemPrototypeStorage.LookupEntry(keyid);
if(!it)
{
RedSystemMessage(m_session, "Item %u doesn't exist.", keyid);
return true;
}
std::stringstream qry;
qry << "DELETE FROM `gameobject_locks` WHERE guid = '" << GObj->m_spawn->id << "' AND keyid = '" << keyid << "')";
WorldDatabase.Execute( qry.str().c_str( ) );
RedSystemMessage(m_session, "Key %s (%u) deleted from the object %s ( GUID : %u | ID : %u )", it->Name1, it->ItemId, GameObjectNameStorage.LookupEntry( GObj->GetEntry() )->Name, GObj->m_spawn->id, GObj->GetEntry());
return true;
}