#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
SetTimer("Stream", 400, true);
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.
}
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;
}
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;
}
Originally Posted by [03
Garsino ]
Nice tutorial ![]() |
Originally Posted by [ЉǾǖŦĦЗŁΛẄ
~ [HellFire] ]
That's a good one ![]() Thanks ![]() |
Originally Posted by [HiC
TheKiller ]
pawn Код:
|
Originally Posted by V1ceC1ty
Quote:
|
Originally Posted by [ЉǾǖŦĦЗŁΛẄ
~ [HellFire] ]
Quote:
![]() ![]() ![]() |
Originally Posted by XRVX
Quote:
and then convert it to sa-mp www.convertffs.com |
yes,i know that but how can i add into my streamer...what function?
|
CreateObjectEx(ModelID, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ, Float:Dist = 100.0)
stock CreateDynamicObject(ModelID, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ,Float:Dist = 200.0) //Creates Objects { ObjectID++; //Id of the Object ObjectModel[ObjectID] = ModelID; //Model of the Object ObjectPos[ModelID][0] = X; //X Position ObjectPos[ModelID][1] = Y; //Y position ObjectPos[ModelID][2] = Z; //Z Position ObjectRotation[ObjectID][0] = rX; //Rotation X ObjectRotation[ObjectID][1] = rY; //Rotation Y ObjectRotation[ObjectID][2] = rZ; //Rotation Z ObjectDistance[ObjectID] = Dist; //Viewing Distance ObjectUsed[ObjectID] = 1; //Disable/Enable the object, Its enabled at creation }
#define ForEachPlayer(%0) for(new index_%0=0, %0=ConnectedPlayerList[0]; index_%0<ConnectedPlayers; index_%0++, %0=ConnectedPlayerList[index_%0])
public OnPlayerConnect(playerid)
{
ConnectedPlayerList[ConnectedPlayers++]=playerid;
}
public OnPlayerDisconnect(playerid, reason)
{
for(new i=0;i<ConnectedPlayers;i++)
{
if(ConnectedPlayerList[i]==playerid)
{
ConnectedPlayers--;
ConnectedPlayerList[i]=ConnectedPlayerList[ConnectedPlayers];
}
}
}
I'm sorry but there's a reason for this! This is not a tutorial, it's a script release in topic form. A tutorial tells people WHY things happen. There has been a distinct increase in frankly low quality non-tutorials. This post took me longer than 10 minutes!
Isn't as much as what? That's also not really a reason, but that's beside the point. |
"The less the better" - not really the point of a streamer, if there's too few you could fall below the limit of normal objects, and besides, 3mb isn't THAT much memory when most machines have several GB.
|
What does all this do? There's no explanations of the lines at all. Or WAY too little - three comments in that huge chunk of code really doesn't cut it for a tutorial. Think of it this way, if you knew NOTHING about PAWN scripting and wanted to use this object streamer tutorial to make a checkpoint streamer, what information is there to help you?
|
Why is there a timer? What purpose does that serve? Firstly why do you need a looping function at all? Why not use OnPlayerUpdate? Why not use main and sleep etc?
What are the advantages of doing it this way? What other streaming algorithms are there? How does this method compare in speed to other streamers - the streamer plugin, xobjects, yobjects, mido stream etc? |
Why might we find them useful? What does it do? Why is there a loop (and why is that loop, being placed in a tutorial to tell people how to do things well, not using foreach - the current fastest loop method)?
|
#include <a_samp>
#include <foreach>
forward OneSecTimer();
#define ForEachPlayer(%0) for(new index_%0=0, %0=ConnectedPlayerList[0]; index_%0<ConnectedPlayers; index_%0++, %0=ConnectedPlayerList[index_%0])
new item1[MAX_PLAYERS][10000],item2[MAX_PLAYERS][10000];
new ConnectedPlayers;
new ConnectedPlayerList[MAX_PLAYERS+1];//Loop would bug when server is full D:
main()
{
print("\n----------------------------------");
print(" This is a blank GameModeScript");
print("----------------------------------\n");
//printf("GetVehicleComponentType %u",GetVehicleComponentType(1100));
}
public OnGameModeInit()
{
// Set timer of 1 second.
for(new i;i<100;i++)
{
Itter_Add(Player, i);
ConnectedPlayerList[ConnectedPlayers++]=i;
}
SetTimer("OneSecTimer", 1000, 1);
print("GameModeInit()");
SetGameModeText("Timer Test");
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
return 1;
}
public OneSecTimer() {
new sText[256];
format(sText,sizeof(sText),"GetTickCount = %d",GetTickCount());
print(sText);
SendClientMessageToAll(0xFF0000, sText);
new time = GetTickCount();
for (new i = 0; i < 10000; i++)
{
foreach(Player,I)
{
item1[I][i]=100;
}
}
printf("Time #1: %d", GetTickCount() - time);
time = GetTickCount();
for (new i = 0; i < 10000; i++)
{
ForEachPlayer(I)
{
item2[I][i]=200;
}
}
printf("Time #2: %d", GetTickCount() - time);
}
#include <a_samp>
#include <foreach>
forward OneSecTimer();
#define ForEachPlayer(%0) for(new index_%0=0, %0=ConnectedPlayerList[0]; index_%0<ConnectedPlayers; index_%0++, %0=ConnectedPlayerList[index_%0])
new item1[MAX_PLAYERS][10000],item2[MAX_PLAYERS][10000],item3[MAX_PLAYERS][10000];
new ConnectedPlayers;
new ConnectedPlayerList[MAX_PLAYERS+1];//Loop would bug when server is full D:
main()
{
print("\n----------------------------------");
print(" This is a blank GameModeScript");
print("----------------------------------\n");
//printf("GetVehicleComponentType %u",GetVehicleComponentType(1100));
}
public OnGameModeInit()
{
// Set timer of 1 second.
for(new i;i<100;i++)
{
Itter_Add(Player, i);
ConnectedPlayerList[ConnectedPlayers++]=i;
}
Itter_Remove(Player,random(50));
Itter_Remove(Player,random(100));
for(new i=0;i<100;i++)
{
if(ConnectedPlayerList[i]==5)
{
ConnectedPlayers--;
ConnectedPlayerList[i]=ConnectedPlayerList[ConnectedPlayers];
}
}
SetTimer("OneSecTimer", 1000, 1);
print("GameModeInit()");
SetGameModeText("Timer Test");
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
return 1;
}
public OneSecTimer() {
new sText[256];
format(sText,sizeof(sText),"GetTickCount = %d",GetTickCount());
print(sText);
new time = GetTickCount();
for (new i = 0; i < 10000; i++)
{
foreach(Player,I)
{
item1[I][i]=100;
}
}
printf("Time #1: %d", GetTickCount() - time);
time = GetTickCount();
for (new i = 0; i < 10000; i++)
{
ForEachPlayer(I)
{
item2[I][i]=200;
}
}
printf("Time #2: %d", GetTickCount() - time);
time = GetTickCount();
for (new i = 0; i < 10000; i++)
{
for(new I;I<100;I++)
{
if(I != 40)
{
item3[I][i]=300;
}
}
}
printf("Time #3: %d", GetTickCount() - time);
}
Why is there a timer? What purpose does that serve? Firstly why do you need a looping function at all? Why not use OnPlayerUpdate?
|