28.08.2014, 21:57
One issue with "ReplaceObject":
For instance, I create two objects:
Then, I destroy "object1":
And I replace "object2" with another model:
In the "ReplaceObject" code, you have this:
Since "object1" was deleted, any object created afterwards will use the first free object ID, which would be the old ID from "object1". This would render "object2" useless because "objectid" now has a different ID.
My version:
So then you could do this:
For instance, I create two objects:
pawn Код:
new object1 = CreateObject(3095, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
new object2 = CreateObject(9000, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
pawn Код:
DestroyObject(object1);
pawn Код:
ReplaceObject(object2, 3089);
pawn Код:
DestroyObject(objectid);
objectid = CreateObject(newmodel, data[0], data[1], data[2], data[3], data[4], data[5]);
My version:
pawn Код:
ReplaceObject(objectid, modelid)
{
new
Float:fX,
Float:fY,
Float:fZ,
Float:fRotX,
Float:fRotY,
Float:fRotZ;
if (GetObjectPos(objectid, fX, fY, fZ) && GetObjectRot(objectid, fRotX, fRotY, fRotZ))
{
DestroyObject(objectid);
return CreateObject(modelid, fX, fY, fZ, fRotX, fRotY, fRotZ);
}
return INVALID_OBJECT_ID;
}
pawn Код:
new object;
main()
{
object = CreateObject(3095, 0.0, 0.0, 10.0, 0.0, 0.0, 0.0);
// ...
object = ReplaceObject(object, 3000);
}