SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 03/01/2010, 12:02 PM   #1
[HiC]TheKiller
High-roller
 
Join Date: Mar 2008
Location: New Zealand
Posts: 3,074
Reputation: 406
Default [TUT]Basic Object Streamer

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 Code:
#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 Code:
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 Code:
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 Code:
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 Code:
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 .
__________________
People seem to enjoy negitive repping me for topics that I made in 2009.
Therefore, if you want to view my releases, you can go here.

Skype: TheKiller@dr.com
I do NOT script for cash. Add me on MSN if you need help with small issues.
[HiC]TheKiller is offline   Reply With Quote
Old 03/01/2010, 01:45 PM   #2
[03]Garsino
Guest
 
Posts: n/a
Default Re: [TUT]Basic Object Streamer

Nice tutorial
  Reply With Quote
Old 03/01/2010, 11:36 PM   #3
[HiC]TheKiller
High-roller
 
Join Date: Mar 2008
Location: New Zealand
Posts: 3,074
Reputation: 406
Default Re: [TUT]Basic Object Streamer

Quote:
Originally Posted by [03
Garsino ]
Nice tutorial
Thanks .
__________________
People seem to enjoy negitive repping me for topics that I made in 2009.
Therefore, if you want to view my releases, you can go here.

Skype: TheKiller@dr.com
I do NOT script for cash. Add me on MSN if you need help with small issues.
[HiC]TheKiller is offline   Reply With Quote
Old 03/01/2010, 11:43 PM   #4
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,492
Reputation: 1028
Default Re: [TUT]Basic Object Streamer

That's a good one I might have a bash at making my own, I can make it more efficient than the one i got and just make the stock function the same so no more converting!

Thanks
[HLF]Southclaw is online now   Reply With Quote
Old 04/01/2010, 02:53 AM   #5
[HiC]TheKiller
High-roller
 
Join Date: Mar 2008
Location: New Zealand
Posts: 3,074
Reputation: 406
Default Re: [TUT]Basic Object Streamer

Quote:
Originally Posted by [ŠǾǖŦĦÇŁΛẄ
~ [HellFire] ]
That's a good one I might have a bash at making my own, I can make it more efficient than the one i got and just make the stock function the same so no more converting!

Thanks
Good luck on your own object streamer, it's not that hard if you think about it .
__________________
People seem to enjoy negitive repping me for topics that I made in 2009.
Therefore, if you want to view my releases, you can go here.

Skype: TheKiller@dr.com
I do NOT script for cash. Add me on MSN if you need help with small issues.
[HiC]TheKiller is offline   Reply With Quote
Old 04/01/2010, 01:47 PM   #6
Wasim_Cortez
Little Clucker
 
Join Date: Jan 2010
Posts: 44
Reputation: 1
Default Re: [TUT]Basic Object Streamer

Nice Tut, Would be useful for some people.
Wasim_Cortez is offline   Reply With Quote
Old 04/01/2010, 03:31 PM   #7
V1ceC1ty
High-roller
 
V1ceC1ty's Avatar
 
Join Date: Oct 2008
Location: West Australia
Posts: 1,994
Reputation: 250
Default Re: [TUT]Basic Object Streamer

Quote:
Originally Posted by [HiC
TheKiller ]
pawn Code:
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]);
        }
    }
}
Destroy spelling mistake, DestoryObjectEx(ObjectId)
__________________

A wild project-samp has re-appeared!


www.project-samp.net
V1ceC1ty is offline   Reply With Quote
Old 04/01/2010, 07:21 PM   #8
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,492
Reputation: 1028
Default Re: [TUT]Basic Object Streamer

Quote:
Originally Posted by [HiC
TheKiller ]
it's not that hard if you think about it .
Yeah I always thought that, just detect if their near and create the object! I always wanted to make my own but never did now I found this it's motivated me! thanks again
[HLF]Southclaw is online now   Reply With Quote
Old 04/01/2010, 07:26 PM   #9
[HiC]TheKiller
High-roller
 
Join Date: Mar 2008
Location: New Zealand
Posts: 3,074
Reputation: 406
Default Re: [TUT]Basic Object Streamer

Quote:
Originally Posted by V1ceC1ty
Quote:
Originally Posted by [HiC
TheKiller ]
pawn Code:
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]);
        }
    }
}
Destroy spelling mistake, DestoryObjectEx(ObjectId)
Oh thanks, I'll fix that.

Quote:
Originally Posted by [ŠǾǖŦĦÇŁΛẄ
~ [HellFire] ]
Quote:
Originally Posted by [HiC
TheKiller ]
it's not that hard if you think about it .
Yeah I always thought that, just detect if their near and create the object! I always wanted to make my own but never did now I found this it's motivated me! thanks again
Good luck .
__________________
People seem to enjoy negitive repping me for topics that I made in 2009.
Therefore, if you want to view my releases, you can go here.

Skype: TheKiller@dr.com
I do NOT script for cash. Add me on MSN if you need help with small issues.
[HiC]TheKiller is offline   Reply With Quote
Old 06/03/2010, 12:59 PM   #10
adytzu32
Big Clucker
 
Join Date: Dec 2009
Posts: 120
Reputation: 0
Default Re: [TUT]Basic Object Streamer

sorry,but i've created a FS with yours code,everything is good but how create an object with my streamer?
adytzu32 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] [TUT]Basic Checkpoint Streamer [HiC]TheKiller Tutorials 22 12/11/2013 04:11 PM
[Tutorial] [TUT]Basic Icon streamer! [HiC]TheKiller Tutorials 19 29/06/2012 07:40 PM
[Include] [INC] >>Object Streamer Object<<< (OStreamerO) DorkAZoid Includes 9 11/12/2009 03:28 PM
Dominator's Object Streamer - a wize and new streamer - invisible objects fix tsha Filterscripts 23 19/09/2009 08:37 PM
Object Streamer - Looking for a little streamer! ~300 obj. BeCometA Help Archive 1 26/06/2009 05:47 PM


All times are GMT. The time now is 10:31 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.