[Tutorial] [TUT]Basic Object Streamer
#1

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
We need to now set a timer for our streamed objects. You can muck around with the timing time because it does pass alot of info per time. Place this under OnGameModeInit or OnFilterScriptInit.
pawn Код:
SetTimer("Stream", 400, true);
OK, time for creating the objects, I've used a optional distance so the parameters are the same as create object . I would recommending using the distance if you are in a crowed object area.

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.
}
Now that was fast, lets STREAM!!

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;
}
Here is a few extra functions that we may find useful:
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;
}
Have fun making your own object streamer, I'll make more tomorrow .
Reply


Messages In This Thread
[TUT]Basic Object Streamer - by [HiC]TheKiller - 03.01.2010, 11:02
Re: [TUT]Basic Object Streamer - by [03]Garsino - 03.01.2010, 12:45
Re: [TUT]Basic Object Streamer - by [HiC]TheKiller - 03.01.2010, 22:36
Re: [TUT]Basic Object Streamer - by [HiC]TheKiller - 04.01.2010, 01:53
Re: [TUT]Basic Object Streamer - by Wasim_Cortez - 04.01.2010, 12:47
Re: [TUT]Basic Object Streamer - by V1ceC1ty - 04.01.2010, 14:31
Re: [TUT]Basic Object Streamer - by [HiC]TheKiller - 04.01.2010, 18:26
Re: [TUT]Basic Object Streamer - by adytzu32 - 06.03.2010, 11:59
Re: [TUT]Basic Object Streamer - by adytzu32 - 06.03.2010, 18:01
Re: [TUT]Basic Object Streamer - by wups - 25.08.2010, 13:32
Re: [TUT]Basic Object Streamer - by almighty - 25.08.2010, 15:36
Re: [TUT]Basic Object Streamer - by wups - 25.08.2010, 19:14
Re: [TUT]Basic Object Streamer - by wups - 25.08.2010, 19:38
Re: [TUT]Basic Object Streamer - by [HiC]TheKiller - 25.08.2010, 19:53
Re: [TUT]Basic Object Streamer - by wups - 25.08.2010, 19:53
Re: [TUT]Basic Object Streamer - by almighty - 25.08.2010, 21:55
Re: [TUT]Basic Object Streamer - by Jay_ - 25.08.2010, 22:29
Respuesta: [TUT]Basic Object Streamer - by ipsBruno - 25.08.2010, 22:49
Re: [TUT]Basic Object Streamer - by wups - 26.08.2010, 10:45
Re: [TUT]Basic Object Streamer - by Las Venturas CNR - 24.10.2010, 15:50
Re: [TUT]Basic Object Streamer - by [FSaF]Jarno - 07.07.2011, 18:20
Re: [TUT]Basic Object Streamer - by [HiC]TheKiller - 07.07.2011, 20:25
Re: [TUT]Basic Object Streamer - by §с†¶e®РµРe - 12.01.2012, 13:08
Re: [TUT]Basic Object Streamer - by Guitar - 19.02.2012, 13:25

Forum Jump:


Users browsing this thread: 4 Guest(s)