03.01.2010, 11:02
Basic Object Streamer
This took me a total of 10 minutes .Defines (This time I'm not using a enum because there isn't as much data and it's easier).
pawn Код:
#define MAX_STREAMED_OBJECTS 5000 //The less the better, this will total at around 3mb AMX file size.
new ObjectModel[MAX_STREAMED_OBJECTS]; //Objectmodel
new Float:ObjectPos[MAX_STREAMED_OBJECTS][3]; //ObjectPos (X, Y, Z)
new Float:ObjectRotation[MAX_STREAMED_OBJECTS][3]; //ObjectRotation (X, Y, Z)
new Float:ObjectDistance[MAX_STREAMED_OBJECTS]; //Veiw distance
new ObjectIDS[MAX_PLAYERS][MAX_STREAMED_OBJECTS]; //Object ID's.
new ObjectStreamed[MAX_PLAYERS][MAX_STREAMED_OBJECTS]; //Objects being viewed by a player
new ObjectID = -1; //ObjectCount
new ObjectUsed[MAX_STREAMED_OBJECTS]; //Disable = 0 enable = 1
pawn Код:
SetTimer("Stream", 400, true);
pawn Код:
stock CreateObjectEx(ModelID, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ, Float:Dist = 100.0)
{
ObjectID++; //ObjectID
ObjectModel[ObjectID] = ModelID; //Model
ObjectPos[ObjectID][0] = X; //XPos
ObjectPos[ObjectID][1] = Y; //YPos
ObjectPos[ObjectID][2] = Z; //ZPos
ObjectRotation[ObjectID][0] = rX; //RotationX
ObjectRotation[ObjectID][1] = rY;//RotationY
ObjectRotation[ObjectID][2] = rZ; //RotationZ
ObjectDistance[ObjectID] = Dist; //View distance
ObjectUsed[ObjectID] = 1; //Disable/enable the object, it's starting off being enabled.
}
pawn Код:
forward Stream();
public Stream()
{
for(new i; i<MAX_PLAYERS; i++)//Goes through all players
{
if(IsPlayerConnected(i)) //All online players
{
for(new S; S<ObjectID+1; S++) //All active Checkpoints
{
if(ObjectUsed[S] == 1) //Checks if the object is enabled
{
if(IsPlayerInRangeOfPoint(i, ObjectDistance[S], ObjectPos[S][0], ObjectPos[S][1], ObjectPos[S][2]) && ObjectStreamed[i][S] == 0)//Is the player close enough to the object
{
ObjectIDS[i][S] = CreatePlayerObject(i, ObjectModel[S], ObjectPos[S][0], ObjectPos[S][1], ObjectPos[S][2], ObjectRotation[S][0], ObjectRotation[S][1], ObjectRotation[S][2]);//Create the object
ObjectStreamed[i][S] = 1; //Shows the object streamed for the player
continue;
}
}
if(!IsPlayerInRangeOfPoint(i, ObjectDistance[S], ObjectPos[S][0], ObjectPos[S][1], ObjectPos[S][2]) && ObjectStreamed[i][S] == 1) //If the object isn't in distance and the player is viewing, then we destory it!
{
ObjectStreamed[i][S] = 0;
DestroyPlayerObject(i, ObjectIDS[i][S]);
continue;
}
}
}
}
return 1;
}
pawn Код:
stock DestoryObjectEx(ObjectId) //Destroys the object
{
ObjectUsed[ObjectId] = 0;
for(new i; i<MAX_PLAYERS; i++)
{
if(ObjectStreamed[i][ObjectId] == 1)
{
ObjectStreamed[i][ObjectId] = 0;
DestroyPlayerObject(i, ObjectIDS[i][ObjectId]);
}
}
}
stock SetObjectDistance(ObjectId, Float:Dist) //Sets the view distance of a object
{
ObjectDistance[ObjectId] = Dist;
}