http://forum.sa-mp.com/showpost.php?p=1734858&postcount=3180Ha valakit érdekel összetákoltam egy c++ kódot valahogy, amivel CreatePlayerObjectID alapján le lehet kérni a CreateDynamicObjectID-t.
Ezáltal szerkeszthetõ 0.3e ben a CreateDynamicObjectek és menthetõek adatbázisban az adatai, ki mire szeretné használni.
0.3e javaslat
// main.cpp
{ \"GDO_ID_to_CPO_ID\", Natives::GDO_ID_to_CPO_ID },
// natives.h
cell AMX_NATIVE_CALL GDO_ID_to_CPO_ID(AMX *amx, cell *params);
// natives.cpp
template <class K, class V>
class value_equals {
private:
V value;
public:
// constructor (initialize value to compare with)
value_equals (const V& v)
: value(v) {
}
// comparison
bool operator() (std::pair<const K, V> elem) {
return elem.second == value;
}
};
//native GDO_ID_to_CPO_ID(playerid, objectid); // return streamer objectid
cell AMX_NATIVE_CALL Natives::GDO_ID_to_CPO_ID( AMX* amx, cell* params )
{
CHECK_PARAMS(2, \"GDO_ID_to_CPO_ID\");
boost::unordered_map<int, Player>::iterator p = core->getData()->players.find(static_cast<int>(params[1]));
if (p != core->getData()->players.end())
{
boost::unordered_map<int, int>::iterator o;
o = find_if(p->second.internalObjects.begin(),p->second.internalObjects.end(), value_equals<int,int>(static_cast<int>(params[2])));
if(o != p->second.internalObjects.end())
{
return o->first;
}
}
return 0xFFFF;
}
[pawn]
// pawn script
CMD:selectobject(playerid, params[])
{
SelectObject(playerid);
return 1;
}
CMD:cancelobject(playerid, params[])
{
CancelEdit(playerid);
return 1;
}
new
dynamicobjectselect[MAX_PLAYERS];
public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ)
{
if(!playerobject) {
if(!IsValidObject(objectid)) return;
MoveObject(objectid, fX, fY, fZ, 10.0, fRotX, fRotY, fRotZ);
} else {
if(!IsValidPlayerObject(playerid, objectid)) return;
// MoveDynamicObject(dynamicobjectselect[playerid], fX, fY, fZ, 10.0, fRotX, fRotY, fRotZ);
MovePlayerObject(playerid, objectid, fX, fY, fZ, 10.0, fRotX, fRotY, fRotZ);
}
if(response == EDIT_RESPONSE_FINAL)
{
new
message[256+1];
format(message, sizeof(message), \"(Final) o_id:%d d_id:%d | Pos: %.4f,%.4f,%.4f | RPos: %.4f,%.4f,%.4f\", objectid, dynamicobjectselect[playerid], fX, fY, fZ, fRotX, fRotY, fRotZ);
SendClientMessage(playerid, 0xFFFFFFFF, message);
// etc..
Streamer_SetFloatData(STREAMER_TYPE_OBJECT, dynamicobjectselect[playerid], E_STREAMER_X, fX);
Streamer_SetFloatData(STREAMER_TYPE_OBJECT, dynamicobjectselect[playerid], E_STREAMER_Y, fY);
Streamer_SetFloatData(STREAMER_TYPE_OBJECT, dynamicobjectselect[playerid], E_STREAMER_Z, fZ);
Streamer_SetFloatData(STREAMER_TYPE_OBJECT, dynamicobjectselect[playerid], E_STREAMER_R_X, fRotX);
Streamer_SetFloatData(STREAMER_TYPE_OBJECT, dynamicobjectselect[playerid], E_STREAMER_R_Y, fRotY);
Streamer_SetFloatData(STREAMER_TYPE_OBJECT, dynamicobjectselect[playerid], E_STREAMER_R_Z, fRotZ);
dynamicobjectselect[playerid] = INVALID_OBJECT_ID;
MoveDynamicObject(dynamicobjectselect[playerid], fX, fY, fZ, 10.0, fRotX, fRotY, fRotZ); // Moved object all players
// etc..
// and saved object data database sql, mysql, file, etc..
SelectObject(playerid);
}
if(response == EDIT_RESPONSE_CANCEL)
{
// put them back in selection mode after they click save
SelectObject(playerid);
}
}
//-------------------------------------------
native GDO_ID_to_CPO_ID(playerid, objectid); // return streamer objectid (GetDynamicObjectID to CreatePlayerObjectID
public OnPlayerSelectObject(playerid, type, objectid, modelid, Float:fX, Float:fY, Float:fZ)
{
new
message[256+1];
if(type == SELECT_OBJECT_GLOBAL_OBJECT)
{
if(!IsValidObject(objectid)) return 0;
format(message,sizeof(message),\"(Object) You selected: %d model: %d Pos: %.4f,%.4f,%.4f\", objectid, modelid, fX, fY, fZ);
SendClientMessage(playerid, 0xFFFFFFFF, message);
EditObject(playerid, objectid);
return 1;
}
if(type == SELECT_OBJECT_PLAYER_OBJECT)
{
if(!IsValidPlayerObject(playerid, objectid)) return 0;
new
dynamicobjectid = GDO_ID_to_CPO_ID(playerid, objectid); //printf(\"dynamicobjectid: %d\", dynamicobjectid);
if(dynamicobjectid == INVALID_OBJECT_ID) return print(\"No connected players or no streamed object.\");
format(message,sizeof(message),\"(Player Object) You selected: {FF0000}%d {FFFFFF}model: %d Pos: %.4f,%.4f,%.4f dynamicobjectid: {FF0000}%d\", objectid, modelid, fX, fY, fZ, dynamicobjectid);
SendClientMessage(playerid, 0xFFFFFFFF, message);
EditPlayerObject(playerid, objectid);
dynamicobjectselect[playerid] = dynamicobjectid;
return 1;
}
return 0;
}
[/pawn]