Vehicle Streamer Problem
#1

Heey all,

I use the taxi vehicle streamer but i have a problem with trailers.
When i attach a trailer to my truck and i driver away from the spawn the trailer gets respawned.
Code:
pawn Код:
/*
This code was designed to allow users to have a larger number of vehicle spawns in their script than
sa-mp will normally allow. The script will allow you to have in theory up to 9999 vehicle
spawns in your gamemode but only 700 of these can be active at any one point simultaneously...basically the script
will only create vehicles if there is somebody around to see them.

The default distance it will spawn a car for u is set at 100 meters but you can change that very simply by changing
SPAWN_DISTANCE

In order to add streaming vehicle spawns u must add your vehicle spawns into this fs under OnFilterscriptInit using:

AddStreamingVehicle(modelid,x,y,z,angle,color1,color2);

rather than addstaticvehicle.

This script and all code contained within was designed by <tAxI> and is released to the public as freeware.
Any attempts to claim this code as your own will not be taken lightly so don't even try it :-P

HOPE U ALL LIKE IT...ENJOY!!!!

<tAxI>

*/

#include <a_samp>

#define SPAWN_DISTANCE 150
#define MAX_ACTIVE_VEHICLES 675
#define MODEL_LIMIT 212
#define MAX_ACTIVE_MODELS 65

forward proxcheck();

new modelcount[MODEL_LIMIT];
new vehcount = 0;
new streamcount = 0;
new vehused[MAX_ACTIVE_VEHICLES];

enum vInfo2
{
    model,
    Float:x_spawn,
    Float:y_spawn,
    Float:z_spawn,
    Float:za_spawn,
    color_1,
    color_2,
    spawned,
    idnum,
};
new VehicleInfo2[9999][vInfo2];

public OnFilterScriptInit()
{
//cars
    AddStreamingVehicle(523,1560.7695,-1694.4358,5.6122,32.7235,-1,-1);//cop bike
    AddStreamingVehicle(523,1563.5020,-1694.8240,5.4627,21.6809,-1,-1);//cop bike
    AddStreamingVehicle(420,1713.9504,-2323.2983,12.9492,273.7584,-1,-1);//car taxi
    AddStreamingVehicle(565,2489.3066,-2605.5688,13.3711,0.4802,-1,-1);
    AddStreamingVehicle(596,1570.5022,-1710.5771,5.6091,179.8262,-1,-1);//cop car
// -----------------------------------------------------------------------------
    SetTimer("proxcheck",1000,1);
    new string[256];
    print(" ");
    print(" ");
    print("tAxI's Dynamic Vehicle Streamer v0.1");
    print(" ");
    print("-----------------------------------------------------------------");
    print(" ");
    format(string,sizeof(string),"tAxI's Dynamic Vehicle Streamer has detected %d Vehicle Spawns...",vehcount);
    printf(string);
    print(" ");
    format(string,sizeof(string),"Only %d spawns may be activated at any one time simultaneously...",MAX_ACTIVE_VEHICLES);
    printf(string);
    print(" ");
    print("tAxI's Dynamic Vehicle Streamer is now running...ENJOY!!!");
    print(" ");
    print("-----------------------------------------------------------------");
    print(" ");
    print(" ");
    print(" ");
    return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
        SetTimerEx("DeactivateStreamedVehicle",6000,0,"x",vehicleid);
        return 1;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    vehused[vehicleid] = 1;
    return 1;
}

public proxcheck()
{
    for(new i = 1;i<vehcount;i++) {
        if(VehicleInfo2[i][spawned] == 0){
            if(IsPlayerClose(i,SPAWN_DISTANCE) == 1){
                if(streamcount <= MAX_ACTIVE_VEHICLES) {
                    if(modelcount[VehicleInfo2[i][model]-400] < MAX_ACTIVE_MODELS) {
                        VehicleInfo2[i][idnum] = CreateVehicle(VehicleInfo2[i][model], VehicleInfo2[i][x_spawn], VehicleInfo2[i][y_spawn], VehicleInfo2[i][z_spawn], VehicleInfo2[i][za_spawn], VehicleInfo2[i][color_1], VehicleInfo2[i][color_2],11000);
                        VehicleInfo2[i][spawned] = 1;
                        modelcount[VehicleInfo2[i][model]-400]++;
                        streamcount++;
                    }
                }
            }
        }
        else {
            if(vehused[VehicleInfo2[i][idnum]] == 0) {
                if(IsPlayerClose(i,SPAWN_DISTANCE) == 0) {
                    DestroyVehicle(VehicleInfo2[i][idnum]);
                    VehicleInfo2[i][spawned] = 0;
                    modelcount[VehicleInfo2[i][model]-400]--;
                    streamcount--;
                }
            }
        }
    }
}

stock AddStreamingVehicle(modelid,Float:x,Float:y,Float:z,Float:a,col1,col2)
{
    vehcount++;
    VehicleInfo2[vehcount][model] = modelid;
    VehicleInfo2[vehcount][x_spawn] = x;
    VehicleInfo2[vehcount][y_spawn] = y;
    VehicleInfo2[vehcount][z_spawn] = z;
    VehicleInfo2[vehcount][za_spawn] = a;
    VehicleInfo2[vehcount][color_1] = col1;
    VehicleInfo2[vehcount][color_2] = col2;
    return 1;
}

stock DeactivateStreamedVehicle(vehicleid)
{
    vehused[vehicleid] = 0;
    return 1;
}

stock IsPlayerClose(streamid, Float:MAX)
{
    for(new i = 0;i<MAX_PLAYERS;i++){
        if(!IsPlayerConnected(i)) continue;
        new Float:PPos[3];
        GetPlayerPos(i, PPos[0], PPos[1], PPos[2]);
        if (PPos[0] >= floatsub(VehicleInfo2[streamid][x_spawn], MAX) && PPos[0] <= floatadd(VehicleInfo2[streamid][x_spawn], MAX)
        && PPos[1] >= floatsub(VehicleInfo2[streamid][y_spawn], MAX) && PPos[1] <= floatadd(VehicleInfo2[streamid][y_spawn], MAX)
        && PPos[2] >= floatsub(VehicleInfo2[streamid][z_spawn], MAX) && PPos[2] <= floatadd(VehicleInfo2[streamid][z_spawn], MAX))
        {
            return 1;
        }
    }
    return 0;
}
How can i fix this?

Admigo
Reply
#2

Are you really going to add more than 2000 vehicles on your server? If not, don't use that streamer.
Reply
#3

Quote:
Originally Posted by YJIET
Посмотреть сообщение
Are you really going to add more than 2000 vehicles on your server? If not, don't use that streamer.
Yes i do cause my server owns a vehicle ownership system so i really need the streamer.
Reply
#4

I tried this:
pawn Код:
public proxcheck()
{
    for(new i = 1;i<vehcount;i++) {
        if(VehicleInfo2[i][spawned] == 0){
            if(IsPlayerClose(i,SPAWN_DISTANCE) == 1){
                if(streamcount <= MAX_ACTIVE_VEHICLES)
                {
                    if(!IsTrailerAttachedToVehicle(i))
                    {
                        if(!GetVehicleTrailer(GetPlayerVehicleID(i)))
                        {
                            VehicleInfo2[i][idnum] = CreateVehicle(VehicleInfo2[i][model], VehicleInfo2[i][x_spawn], VehicleInfo2[i][y_spawn], VehicleInfo2[i][z_spawn], VehicleInfo2[i][za_spawn], VehicleInfo2[i][color_1], VehicleInfo2[i][color_2],11000);
                            VehicleInfo2[i][spawned] = 1;
                            modelcount[VehicleInfo2[i][model]-400]++;
                            streamcount++;
                        }
                    }
                }
            }
        }
        else {
            if(vehused[VehicleInfo2[i][idnum]] == 0) {
                if(IsPlayerClose(i,SPAWN_DISTANCE) == 0)
                {
                    if(!IsTrailerAttachedToVehicle(i))
                    {
                        if(!GetVehicleTrailer(GetPlayerVehicleID(i)))
                        {
                            DestroyVehicle(VehicleInfo2[i][idnum]);
                            VehicleInfo2[i][spawned] = 0;
                            modelcount[VehicleInfo2[i][model]-400]--;
                            streamcount--;
                        }
                    }
                }
            }
        }
    }
}
But still when i attach the trailer and i driver out of the stream distance the trailer gets respawned to his spawn location.
How to fix this?
Reply
#5

This streamer allows 9999 vehicles in theory. That doesn't mean every vehicle will be created when it's in 150 meter radius from a player. For example, a server has five large areas 1000 meters apart, and each area has 500 streamed vehicles. If four of these areas have players, everything works fine, but when a player goes to the fifth area, vehicles won't be created (2000 vehicles reached). You would need to destroy 500 vehicles from another area to create them in the fifth area, but because every area has players, there aren't any vehicles to destroy etc.
Reply
#6

I only ask the fix for the trailers. I dont ask for if the streamer works or not cause thats not the problem. The streamer works great only when i attach a trailer and i driver some meter away from the trailer spawn the trailer will be respawned.
Reply
#7

Fine. Trailers respawn because the distance is measured from the spawn coordinates. You need to measure the distance from the actual coordinates (GetVehiclePos).

I'd also like to add that tAxI's Vehicle Streamer is pretty outdated. Now you can utilize OnVehicleStreamIn and OnVehicleStreamOut callbacks to create a vehicle streamer, and no timers would be needed at all.
Reply
#8

Okay, Thanks for reply. You know how to fix the trailer problem? The trailer doesn't get counted as an used vehicle so its updating everytime.
Reply
#9

Replace the old function with this one and see if it works.
pawn Код:
stock IsPlayerClose(streamid, Float:MAX)
{
    new
        Float:x,
        Float:y,
        Float:z,
        Float:px,
        Float:py,
        Float:pz;
    GetVehiclePos(streamid, x, y, z);
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(i))
        {
            continue;
        }
        GetPlayerPos(i, px, py, pz);
        if(px >= (x - MAX) && px <= (x + MAX)
        && py >= (y - MAX) && py <= (y + MAX)
        && pz >= (z - MAX) && pz <= (z + MAX))
        {
            return 1;
        }
    }
    return 0;
}
Reply
#10

Quote:
Originally Posted by YJIET
Посмотреть сообщение
Replace the old function with this one and see if it works.
pawn Код:
stock IsPlayerClose(streamid, Float:MAX)
{
    new
        Float:x,
        Float:y,
        Float:z,
        Float:px,
        Float:py,
        Float:pz;
    GetVehiclePos(streamid, x, y, z);
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(i))
        {
            continue;
        }
        GetPlayerPos(i, px, py, pz);
        if(px >= (x - MAX) && px <= (x + MAX)
        && py >= (y - MAX) && py <= (y + MAX)
        && pz >= (z - MAX) && pz <= (z + MAX))
        {
            return 1;
        }
    }
    return 0;
}
Now only the vehicles where i spawn get spawned and the other vehicles doesnt get spawned.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)