本文整理汇总了C++中PreparedStatement::setFloat方法的典型用法代码示例。如果您正苦于以下问题:C++ PreparedStatement::setFloat方法的具体用法?C++ PreparedStatement::setFloat怎么用?C++ PreparedStatement::setFloat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PreparedStatement
的用法示例。
在下文中一共展示了PreparedStatement::setFloat方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SaveToDB
void ComplaintTicket::SaveToDB() const
{
SQLTransaction trans = CharacterDatabase.BeginTransaction();
uint8 idx = 0;
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_GM_COMPLAINT);
stmt->setUInt32(idx, _id);
stmt->setUInt64(++idx, _playerGuid.GetCounter());
stmt->setString(++idx, _note);
stmt->setUInt32(++idx, _mapId);
stmt->setFloat(++idx, _pos.x);
stmt->setFloat(++idx, _pos.y);
stmt->setFloat(++idx, _pos.z);
stmt->setFloat(++idx, _facing);
stmt->setUInt64(++idx, _targetCharacterGuid.GetCounter());
stmt->setUInt8(++idx, _complaintType);
if (_chatLog.ReportLineIndex)
stmt->setInt32(++idx, *_chatLog.ReportLineIndex);
else
stmt->setInt32(++idx, -1); // empty ReportLineIndex
stmt->setInt64(++idx, _closedBy.GetCounter());
stmt->setUInt64(++idx, _assignedTo.GetCounter());
stmt->setString(++idx, _comment);
trans->Append(stmt);
uint32 lineIndex = 0;
for (auto const& c : _chatLog.Lines)
{
idx = 0;
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_GM_COMPLAINT_CHATLINE);
stmt->setUInt32(idx, _id);
stmt->setUInt32(++idx, lineIndex);
stmt->setUInt32(++idx, c.Timestamp);
stmt->setString(++idx, c.Text);
trans->Append(stmt);
++lineIndex;
}
CharacterDatabase.CommitTransaction(trans);
}
示例2: SaveToDB
void Corpse::SaveToDB()
{
// prevent DB data inconsistence problems and duplicates
SQLTransaction trans = CharacterDatabase.BeginTransaction();
DeleteFromDB(trans);
uint16 index = 0;
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CORPSE);
stmt->setUInt64(index++, GetGUID().GetCounter()); // corpseGuid
stmt->setUInt64(index++, GetOwnerGUID().GetCounter()); // guid
stmt->setFloat (index++, GetPositionX()); // posX
stmt->setFloat (index++, GetPositionY()); // posY
stmt->setFloat (index++, GetPositionZ()); // posZ
stmt->setFloat (index++, GetOrientation()); // orientation
stmt->setUInt16(index++, GetMapId()); // mapId
stmt->setUInt32(index++, GetUInt32Value(CORPSE_FIELD_DISPLAY_ID)); // displayId
stmt->setString(index++, _ConcatFields(CORPSE_FIELD_ITEM, EQUIPMENT_SLOT_END)); // itemCache
stmt->setUInt32(index++, GetUInt32Value(CORPSE_FIELD_BYTES_1)); // bytes1
stmt->setUInt32(index++, GetUInt32Value(CORPSE_FIELD_BYTES_2)); // bytes2
stmt->setUInt8 (index++, GetUInt32Value(CORPSE_FIELD_FLAGS)); // flags
stmt->setUInt8 (index++, GetUInt32Value(CORPSE_FIELD_DYNAMIC_FLAGS)); // dynFlags
stmt->setUInt32(index++, uint32(m_time)); // time
stmt->setUInt8 (index++, GetType()); // corpseType
stmt->setUInt32(index++, GetInstanceId()); // instanceId
trans->Append(stmt);
for (uint32 phaseId : GetPhases())
{
index = 0;
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CORPSE_PHASES);
stmt->setUInt32(index++, GetGUID().GetCounter()); // Guid (corpse's)
stmt->setUInt32(index++, phaseId); // PhaseId
stmt->setUInt32(index++, GetOwnerGUID().GetCounter()); // OwnerGuid
stmt->setUInt32(index++, uint32(m_time)); // Time
stmt->setUInt8(index++, GetType()); // CorpseType
trans->Append(stmt);
}
CharacterDatabase.CommitTransaction(trans);
}
示例3: HandleTicketCreate
static bool HandleTicketCreate(ChatHandler* handler, char const* args)
{
Player* player = handler->GetSession()->GetPlayer();;
if (!player)
return false;
//
if (*args)
{
uint8 index = 0;
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_GM_TICKET);
stmt->setUInt32(index, sTicketMgr->GenerateTicketId());
stmt->setUInt32(++index, GUID_LOPART(handler->GetSession()->GetPlayer()->GetGUID()));
stmt->setString(++index, handler->GetSession()->GetPlayer()->GetName());
stmt->setString(++index, args);
stmt->setUInt32(++index, uint32(000));
stmt->setUInt16(++index, 1);
stmt->setFloat(++index, 1.0f);
stmt->setFloat(++index, 1.0f);
stmt->setFloat(++index, 1.0f);
stmt->setUInt32(++index, uint32(000));
stmt->setInt32(++index, GUID_LOPART(0));
stmt->setUInt32(++index, GUID_LOPART(0));
stmt->setString(++index, "NO COMMENT");
stmt->setBool(++index, false);
stmt->setUInt8(++index, uint8(0));
stmt->setBool(++index, false);
stmt->setBool(++index, true);
CharacterDatabase.Execute(stmt);
return true;
ChatHandler(player->GetSession()).PSendSysMessage("You have created a new ticket, and it'll soon be addressed by one of our staff members, please, be patient.");
}
else
{
ChatHandler(player->GetSession()).PSendSysMessage("You must include some content of text in your ticket, the way of doing is by writing like in the following example: .pticket create my warrior is stuck, please help me gm!");
return false;
}
}
示例4: HandleSubmitBugOpcode
//Todo Questlog AuraLog PhaseLog!
void WorldSession::HandleSubmitBugOpcode(WorldPacket& recvData)
{
TC_LOG_DEBUG("network", "WORLD: CMSG_SUBMIT_BUG");
float posX, posY, posZ, posO;
uint32 mapID;
recvData >> posZ;
recvData >> posY;
recvData >> posX;
recvData >> posO;
recvData >> mapID;
uint32 length = recvData.ReadBits(10);
recvData.FlushBits();
std::string bug = recvData.ReadString(length);
ObjectGuid plrGuid = GUID_LOPART(GetPlayer()->GetGUID());
std::string name = "<unknown>";
sObjectMgr->GetPlayerNameByGUID(plrGuid, name);
SQLTransaction trans = SQLTransaction(NULL);
// 0 1 2 3 4 5 6 7 8
// realm, guid, message, createTime, pool, mapId, posX, posY, posZ
uint8 index = 0;
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_BUG_TICKET);
stmt->setUInt32(index, realmID);
stmt->setUInt32(++index, plrGuid);
stmt->setString(++index, bug);
stmt->setUInt32(++index, uint32(time(NULL)));
stmt->setString(++index, name.c_str());
stmt->setUInt16(++index, uint16(mapID));
stmt->setFloat(++index, (float)posX);
stmt->setFloat(++index, (float)posY);
stmt->setFloat(++index, (float)posZ);
LoginDatabase.ExecuteOrAppend(trans, stmt);
}
示例5: SaveToDB
void GmTicket::SaveToDB(SQLTransaction& trans) const
{
uint8 index = 0;
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_ADD_GM_TICKET);
stmt->setUInt32( index, _id);
stmt->setUInt32(++index, GUID_LOPART(_playerGuid));
stmt->setString(++index, _playerName);
stmt->setString(++index, _message);
stmt->setUInt32(++index, uint32(_createTime));
stmt->setUInt16(++index, _mapId);
stmt->setFloat (++index, _posX);
stmt->setFloat (++index, _posY);
stmt->setFloat (++index, _posZ);
stmt->setUInt32(++index, uint32(_lastModifiedTime));
stmt->setInt32 (++index, GUID_LOPART(_closedBy));
stmt->setUInt32(++index, GUID_LOPART(_assignedTo));
stmt->setString(++index, _comment);
stmt->setBool (++index, _completed);
stmt->setUInt8 (++index, uint8(_escalatedStatus));
stmt->setBool (++index, _viewed);
CharacterDatabase.ExecuteOrAppend(trans, stmt);
}
示例6: OnSave
void OnSave(Player *plr)
{
if( !plr || !WebsiteDatabase->IsOpen() )
return;
uint32 psi = ConfigMgr::GetIntDefault("PlayerSaveInterval", 0);
float pph = ConfigMgr::GetFloatDefault("Vote.PointsPerHour", 0.f);
if( psi == 0 || pph == 0.f )
return;
PreparedStatement *stmt = (*WebsiteDatabase)->GetPreparedStatement(WEB_ADD_VOTE_POINTS);
stmt->setFloat(0, ((pph / 60.f / 60.f) * ((float)psi / 1000)));
stmt->setUInt32(1, plr->GetSession()->GetAccountId());
(*WebsiteDatabase)->Execute(stmt);
}
示例7: SaveToDB
void GmTicket::SaveToDB(SQLTransaction& trans) const
{
uint8 idx = 0;
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_GM_TICKET);
stmt->setUInt32(idx, _id);
stmt->setUInt64(++idx, _playerGuid.GetCounter());
stmt->setString(++idx, _description);
stmt->setUInt32(++idx, _createTime);
stmt->setUInt16(++idx, _mapId);
stmt->setFloat(++idx, _pos.x);
stmt->setFloat(++idx, _pos.y);
stmt->setFloat(++idx, _pos.z);
stmt->setUInt32(++idx, uint32(_lastModifiedTime));
stmt->setInt64(++idx, int64(_closedBy.GetCounter()));
stmt->setUInt64(++idx, _assignedTo.GetCounter());
stmt->setString(++idx, _comment);
stmt->setString(++idx, _response);
stmt->setBool(++idx, _completed);
stmt->setUInt8(++idx, uint8(_assignedToStatus));
stmt->setUInt8(++idx, _openedByGmStatus);
stmt->setBool(++idx, _needMoreHelp);
CharacterDatabase.ExecuteOrAppend(trans, stmt);
}
示例8: HandleNpcSetSpawnDistCommand
//set spawn dist of creature
static bool HandleNpcSetSpawnDistCommand(ChatHandler* handler, const char* args)
{
if (!*args)
return false;
float option = (float)(atof((char*)args));
if (option < 0.0f)
{
handler->SendSysMessage(LANG_BAD_VALUE);
return false;
}
MovementGeneratorType mtype = IDLE_MOTION_TYPE;
if (option >0.0f)
mtype = RANDOM_MOTION_TYPE;
Creature* creature = handler->getSelectedCreature();
uint32 guidLow = 0;
if (creature)
guidLow = creature->GetDBTableGUIDLow();
else
return false;
creature->SetRespawnRadius((float)option);
creature->SetDefaultMovementType(mtype);
creature->GetMotionMaster()->Initialize();
if (creature->isAlive()) // dead creature will reset movement generator at respawn
{
creature->setDeathState(JUST_DIED);
creature->Respawn();
}
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_CREATURE_SPAWN_DISTANCE);
stmt->setFloat(0, option);
stmt->setUInt8(1, uint8(mtype));
stmt->setUInt32(2, guidLow);
WorldDatabase.Execute(stmt);
handler->PSendSysMessage(LANG_COMMAND_SPAWNDIST, option);
return true;
}
示例9: HandleWpModifyCommand
//.........这里部分代码省略.........
Creature* wpCreature = NULL;
if (wpGuid != 0)
{
wpCreature = handler->GetSession()->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(wpGuid, VISUAL_WAYPOINT, HIGHGUID_UNIT));
wpCreature->CombatStop();
wpCreature->DeleteFromDB();
wpCreature->AddObjectToRemoveList();
}
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_WAYPOINT_DATA);
stmt->setUInt32(0, pathid);
stmt->setUInt32(1, point);
WorldDatabase.Execute(stmt);
stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_WAYPOINT_DATA_POINT);
stmt->setUInt32(0, pathid);
stmt->setUInt32(1, point);
WorldDatabase.Execute(stmt);
handler->PSendSysMessage(LANG_WAYPOINT_REMOVED);
return true;
} // del
if (show == "move" && target)
{
handler->PSendSysMessage("|cff00ff00DEBUG: wp move, PathID: |r|cff00ffff%u|r", pathid);
Player* chr = handler->GetSession()->GetPlayer();
Map* map = chr->GetMap();
{
// wpCreature
Creature* wpCreature = NULL;
// What to do:
// Move the visual spawnpoint
// Respawn the owner of the waypoints
if (wpGuid != 0)
{
wpCreature = handler->GetSession()->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(wpGuid, VISUAL_WAYPOINT, HIGHGUID_UNIT));
wpCreature->CombatStop();
wpCreature->DeleteFromDB();
wpCreature->AddObjectToRemoveList();
// re-create
Creature* wpCreature2 = new Creature;
if (!wpCreature2->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, chr->GetPhaseMaskForSpawn(), VISUAL_WAYPOINT, 0, 0, chr->GetPositionX(), chr->GetPositionY(), chr->GetPositionZ(), chr->GetOrientation()))
{
handler->PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT);
delete wpCreature2;
return false;
}
wpCreature2->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
// To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
//TODO: Should we first use "Create" then use "LoadFromDB"?
if (!wpCreature2->LoadCreatureFromDB(wpCreature2->GetDBTableGUIDLow(), map))
{
handler->PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT);
delete wpCreature2;
return false;
}
//sMapMgr->GetMap(npcCreature->GetMapId())->Add(wpCreature2);
}
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_WAYPOINT_DATA_POSITION);
stmt->setFloat(0, chr->GetPositionX());
stmt->setFloat(1, chr->GetPositionY());
stmt->setFloat(2, chr->GetPositionZ());
stmt->setUInt32(3, pathid);
stmt->setUInt32(4, point);
WorldDatabase.Execute(stmt);
handler->PSendSysMessage(LANG_WAYPOINT_CHANGED);
}
return true;
} // move
const char *text = arg_str;
if (text == 0)
{
// show_str check for present in list of correct values, no sql injection possible
WorldDatabase.PExecute("UPDATE waypoint_data SET %s=NULL WHERE id='%u' AND point='%u'", show_str, pathid, point); // Query can't be a prepared statement
}
else
{
// show_str check for present in list of correct values, no sql injection possible
std::string text2 = text;
WorldDatabase.EscapeString(text2);
WorldDatabase.PExecute("UPDATE waypoint_data SET %s='%s' WHERE id='%u' AND point='%u'", show_str, text2.c_str(), pathid, point); // Query can't be a prepared statement
}
handler->PSendSysMessage(LANG_WAYPOINT_CHANGED_NO, show_str);
return true;
}
示例10: HandleWpEventCommand
//.........这里部分代码省略.........
char* arg_3;
std::string arg_str_2 = arg_2;
arg_3 = strtok(NULL, " ");
if (!arg_3)
{
handler->SendSysMessage("|cffff33ffERROR: No additional argument present.|r");
return true;
}
if (arg_str_2 == "setid")
{
uint32 newid = atoi(arg_3);
handler->PSendSysMessage("%s%s|r|cff00ffff%u|r|cff00ff00%s|r|cff00ffff%u|r", "|cff00ff00", "Wp Event: Wypoint scipt guid: ", newid, " id changed: ", id);
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_WAYPOINT_SCRIPT_ID);
stmt->setUInt32(0, newid);
stmt->setUInt32(1, id);
WorldDatabase.Execute(stmt);
return true;
}
else
{
QueryResult result = WorldDatabase.PQuery("SELECT id FROM waypoint_scripts WHERE guid='%u'", id);
if (!result)
{
handler->SendSysMessage("|cffff33ffERROR: You have selected an non existing waypoint script guid.|r");
return true;
}
if (arg_str_2 == "posx")
{
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_WAYPOINT_SCRIPT_X);
stmt->setFloat(0, float(atof(arg_3)));
stmt->setUInt32(1, id);
WorldDatabase.Execute(stmt);
handler->PSendSysMessage("|cff00ff00Waypoint script:|r|cff00ffff %u|r|cff00ff00 position_x updated.|r", id);
return true;
}
else if (arg_str_2 == "posy")
{
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_WAYPOINT_SCRIPT_Y);
stmt->setFloat(0, float(atof(arg_3)));
stmt->setUInt32(1, id);
WorldDatabase.Execute(stmt);
handler->PSendSysMessage("|cff00ff00Waypoint script: %u position_y updated.|r", id);
return true;
}
else if (arg_str_2 == "posz")
{
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_WAYPOINT_SCRIPT_Z);
stmt->setFloat(0, float(atof(arg_3)));
stmt->setUInt32(1, id);
WorldDatabase.Execute(stmt);
handler->PSendSysMessage("|cff00ff00Waypoint script: |r|cff00ffff%u|r|cff00ff00 position_z updated.|r", id);
return true;
}
else if (arg_str_2 == "orientation")
{
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_WAYPOINT_SCRIPT_O);
stmt->setFloat(0, float(atof(arg_3)));
stmt->setUInt32(1, id);
WorldDatabase.Execute(stmt);
handler->PSendSysMessage("|cff00ff00Waypoint script: |r|cff00ffff%u|r|cff00ff00 orientation updated.|r", id);
return true;
}
else if (arg_str_2 == "dataint")
{
WorldDatabase.PExecute("UPDATE waypoint_scripts SET %s='%u' WHERE guid='%u'", arg_2, atoi(arg_3), id); // Query can't be a prepared statement
handler->PSendSysMessage("|cff00ff00Waypoint script: |r|cff00ffff%u|r|cff00ff00 dataint updated.|r", id);
return true;
}
else
{
std::string arg_str_3 = arg_3;
WorldDatabase.EscapeString(arg_str_3);
WorldDatabase.PExecute("UPDATE waypoint_scripts SET %s='%s' WHERE guid='%u'", arg_2, arg_str_3.c_str(), id); // Query can't be a prepared statement
}
}
handler->PSendSysMessage("%s%s|r|cff00ffff%u:|r|cff00ff00 %s %s|r", "|cff00ff00", "Waypoint script:", id, arg_2, "updated.");
}
return true;
}
示例11: HandleWpAddCommand
/**
* Add a waypoint to a creature.
*
* The user can either select an npc or provide its GUID.
*
* The user can even select a visual waypoint - then the new waypoint
* is placed *after* the selected one - this makes insertion of new
* waypoints possible.
*
* eg:
* .wp add 12345
* -> adds a waypoint to the npc with the GUID 12345
*
* .wp add
* -> adds a waypoint to the currently selected creature
*
*
* @param args if the user did not provide a GUID, it is NULL
*
* @return true - command did succeed, false - something went wrong
*/
static bool HandleWpAddCommand(ChatHandler* handler, const char* args)
{
// optional
char* path_number = NULL;
uint32 pathid = 0;
if (*args)
path_number = strtok((char*)args, " ");
uint32 point = 0;
Creature* target = handler->getSelectedCreature();
if (!path_number)
{
if (target)
pathid = target->GetWaypointPath();
else
{
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_DATA_MAX_ID);
PreparedQueryResult result = WorldDatabase.Query(stmt);
uint32 maxpathid = result->Fetch()->GetInt32();
pathid = maxpathid+1;
handler->PSendSysMessage("%s%s|r", "|cff00ff00", "New path started.");
}
}
else
pathid = atoi(path_number);
// path_id -> ID of the Path
// point -> number of the waypoint (if not 0)
if (!pathid)
{
handler->PSendSysMessage("%s%s|r", "|cffff33ff", "Current creature haven't loaded path.");
return true;
}
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_DATA_MAX_POINT);
stmt->setUInt32(0, pathid);
PreparedQueryResult result = WorldDatabase.Query(stmt);
if (result)
point = (*result)[0].GetUInt32();
Player* player = handler->GetSession()->GetPlayer();
//Map* map = player->GetMap();
stmt = WorldDatabase.GetPreparedStatement(WORLD_INS_WAYPOINT_DATA);
stmt->setUInt32(0, pathid);
stmt->setUInt32(1, point + 1);
stmt->setFloat(2, player->GetPositionX());
stmt->setFloat(3, player->GetPositionY());
stmt->setFloat(4, player->GetPositionZ());
WorldDatabase.Execute(stmt);
handler->PSendSysMessage("%s%s%u%s%u%s|r", "|cff00ff00", "PathID: |r|cff00ffff", pathid, "|r|cff00ff00: Waypoint |r|cff00ffff", point+1, "|r|cff00ff00 created. ");
return true;
} // HandleWpAddCommand
示例12: HandleNpcMoveCommand
//move selected creature
static bool HandleNpcMoveCommand(ChatHandler* handler, const char* args)
{
uint32 lowguid = 0;
Creature* creature = handler->getSelectedCreature();
if (!creature)
{
// number or [name] Shift-click form |color|Hcreature:creature_guid|h[name]|h|r
char* cId = handler->extractKeyFromLink((char*)args, "Hcreature");
if (!cId)
return false;
lowguid = atoi(cId);
/* FIXME: impossible without entry
if (lowguid)
creature = ObjectAccessor::GetCreature(*handler->GetSession()->GetPlayer(), MAKE_GUID(lowguid, HIGHGUID_UNIT));
*/
// Attempting creature load from DB data
if (!creature)
{
CreatureData const* data = sObjectMgr->GetCreatureData(lowguid);
if (!data)
{
handler->PSendSysMessage(LANG_COMMAND_CREATGUIDNOTFOUND, lowguid);
handler->SetSentErrorMessage(true);
return false;
}
uint32 map_id = data->mapid;
if (handler->GetSession()->GetPlayer()->GetMapId() != map_id)
{
handler->PSendSysMessage(LANG_COMMAND_CREATUREATSAMEMAP, lowguid);
handler->SetSentErrorMessage(true);
return false;
}
}
else
{
lowguid = creature->GetDBTableGUIDLow();
}
}
else
{
lowguid = creature->GetDBTableGUIDLow();
}
float x = handler->GetSession()->GetPlayer()->GetPositionX();
float y = handler->GetSession()->GetPlayer()->GetPositionY();
float z = handler->GetSession()->GetPlayer()->GetPositionZ();
float o = handler->GetSession()->GetPlayer()->GetOrientation();
if (creature)
{
if (CreatureData const* data = sObjectMgr->GetCreatureData(creature->GetDBTableGUIDLow()))
{
const_cast<CreatureData*>(data)->posX = x;
const_cast<CreatureData*>(data)->posY = y;
const_cast<CreatureData*>(data)->posZ = z;
const_cast<CreatureData*>(data)->orientation = o;
}
creature->SetPosition(x, y, z, o);
creature->GetMotionMaster()->Initialize();
if (creature->isAlive()) // dead creature will reset movement generator at respawn
{
creature->setDeathState(JUST_DIED);
creature->Respawn();
}
}
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_CREATURE_POSITION);
stmt->setFloat(0, x);
stmt->setFloat(1, y);
stmt->setFloat(2, z);
stmt->setFloat(3, o);
stmt->setUInt32(4, lowguid);
WorldDatabase.Execute(stmt);
handler->PSendSysMessage(LANG_COMMAND_CREATUREMOVED);
return true;
}
示例13: HandleNpcAddCommand
//add spawn of creature
static bool HandleNpcAddCommand(ChatHandler* handler, const char* args)
{
if (!*args)
return false;
char* charID = handler->extractKeyFromLink((char*)args, "Hcreature_entry");
if (!charID)
return false;
char* team = strtok(NULL, " ");
int32 teamval = 0;
if (team) { teamval = atoi(team); }
if (teamval < 0) { teamval = 0; }
uint32 id = atoi(charID);
Player* chr = handler->GetSession()->GetPlayer();
float x = chr->GetPositionX();
float y = chr->GetPositionY();
float z = chr->GetPositionZ();
float o = chr->GetOrientation();
Map* map = chr->GetMap();
if (chr->GetTransport())
{
uint32 tguid = chr->GetTransport()->AddNPCPassenger(0, id, chr->GetTransOffsetX(), chr->GetTransOffsetY(), chr->GetTransOffsetZ(), chr->GetTransOffsetO());
if (tguid > 0)
{
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_INS_CREATURE_TRANSPORT);
stmt->setInt32(0, int32(tguid));
stmt->setInt32(1, int32(id));
stmt->setInt32(2, int32(chr->GetTransport()->GetEntry()));
stmt->setFloat(3, chr->GetTransOffsetX());
stmt->setFloat(4, chr->GetTransOffsetY());
stmt->setFloat(5, chr->GetTransOffsetZ());
stmt->setFloat(6, chr->GetTransOffsetO());
WorldDatabase.Execute(stmt);
}
return true;
}
Creature* creature = new Creature();
if (!creature->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, chr->GetPhaseMaskForSpawn(), id, 0, (uint32)teamval, x, y, z, o))
{
delete creature;
return false;
}
creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
uint32 db_guid = creature->GetDBTableGUIDLow();
// To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
if (!creature->LoadCreatureFromDB(db_guid, map))
{
delete creature;
return false;
}
sObjectMgr->AddCreatureToGrid(db_guid, sObjectMgr->GetCreatureData(db_guid));
return true;
}