Script problems (Random Players, get positions)
#1

Hi.

I'm working on a Mini-mission like GM, to play with some friends, but, after timers don't working, various bugs/things fixed, etc, I can't solve the random players and car positions (MTA Grid/Adrenaline GM like)...

I do the random player select like I've do with other GM, but on the other GM this method works, on this GM not...
The player who's put on the hunter is always the ID 0.
Код:
public Time1()
{
    new randompl = random(MAX_PLAYERS);
    PutPlayerInVehicle(randompl, hunter, 0);
    IsHunter[randompl] = 1;
    plhunter = randompl;
    SetVehicleHealth(hunter, 9999999999);
    printf("O ID Randomico eh %d", randompl); //Check if he generates the random ID

    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && !IsHunter[i])
        {
            carplayers[i] = SetTimerEx("CarPlayers", 1000, 1, "d", i);
        }
    }
    SetTimer("Time2", 20000, 0);
}
I've tried to use the random with the for(new i=0; i<MAX_PLAYERS; i++) and tried with various ways, but doesn't work. It's always the ID 0.


Other problem is the random spawn (spawn on randomic position), but he needs to check if exist any player at the same coordinate. In the first time, the GM spawns too much cars, bugging/lagging the server and the game for players, but i've fixed using SetTimerEx and running for each player the check position. I get/set the random positions for the players/cars, and a fixed position for the hunter (where's created on the OnGameModeInit), but he doesn't check if someone stays at the same pos, he only spawns 2+ players at the same pos.

Код:
public CarPlayers(playerid)
{
    new pname[24];
    GetPlayerName(playerid, pname, sizeof(pname));
    printf("Rodou CarPlayers para %s", pname); //Check if the timer runs for all players
    new rand;
    rand = random(sizeof(RandomSpawnCars));
    if(!IsPlayerInRangeOfPoint(playerid, 3.0, RandomSpawnCars[rand][0], RandomSpawnCars[rand][1], RandomSpawnCars[rand][2]) && IsHunter[playerid] == 0)
    {
       SetPlayerPos(playerid, RandomSpawnCars[rand][0], RandomSpawnCars[rand][1], RandomSpawnCars[rand][2]);
       SetPlayerFacingAngle(playerid, RandomSpawnCars[rand][3]);
       SetTimerEx("PutPlayer",500,false,"d",playerid);
       return KillTimer(carplayers[playerid]);
    }
    else if(IsPlayerInRangeOfPoint(playerid, 3.0, RandomSpawnCars[rand][0], RandomSpawnCars[rand][1], RandomSpawnCars[rand][2]) && IsHunter[playerid] == 0)
    {
        return rand = random(sizeof(RandomSpawnCars));
    }
    else if(IsPlayerInAnyVehicle(playerid) && !IsHunter[playerid])
    {
       return KillTimer(carplayers[playerid]);
    }
    return 0;
}

public PutPlayer(playerid)
{
    new Float:X, Float:Y, Float:Z, Float:A;
    GetPlayerPos(playerid, X, Y, Z);
    GetPlayerFacingAngle(playerid, A);
    new veh = CreateVehicle(475, X, Y, Z, A, -1, -1, 10);
    PutPlayerInVehicle(playerid, veh, 0);
    Fugitivo[playerid] = 1;
    KillTimer(carplayers[playerid]);
    return 1;
}
What's wrong with these codes?
If I can't fix in this way, I gonna try other way for the random cars. But I need to fix the random player on Hunter first, because this is the most important.

Thanks

(My english is horrible, but I think it's understandable)
Reply
#2

Anyone can help?

At least with the random players...
Reply
#3

Get a random connected player ID:
pawn Код:
new playerids[MAX_VEHICLES];
new size = 0;
for (new i=0; i < MAX_VEHICLES; i++)
{
    if (IsPlayerConnected(i))
    {
        playerids[size] = i;
        size++;
    }
}

new random_playerid = playerids[ random(size) ];
Reply
#4

I do the random spawn on other way and works...

Now I want a help with the random cars at spawn...
How can I do a random car with the entries that I've created?

I tried this

Код:
new carro0,carro1,carro2,carro3,carro4,carro5,carro6,carro7,carro8,carro9;

new RandomCars[] = { carro0,carro1,carro2,carro3,carro4,carro5,carro6,carro7,carro8,carro9 };

public OnGameModeInit()
{
    hunter = CreateVehicle(425,1651.7878,1303.0947,10.5345,44.7510,-1,-1,1000); // HUNTER
    carro0 = CreateVehicle(475,1678.5441,-249.3617,42.7771,0.2308,-1,-1,1000); // 0
    carro1 = CreateVehicle(475,1660.0725,-206.9549,35.9988,180.0155,-1,-1,1000); // 1
    carro2 = CreateVehicle(475,1657.1025,-221.2363,36.6769,179.5737,-1,-1,1000); // 2
    carro3 = CreateVehicle(475,1660.6664,-240.8206,37.5004,181.1402,-1,-1,1000); // 3
    carro4 = CreateVehicle(475,1656.9583,-264.0608,38.4412,180.5185,-1,-1,1000); // 4
    carro5 = CreateVehicle(475,1662.3196,-288.0078,39.4460,180.5305,-1,-1,1000); // 5
    carro6 = CreateVehicle(475,1682.1814,-334.3429,44.7200,5.6508,-1,-1,1000); // 6
    carro7 = CreateVehicle(475,1677.4847,-318.6137,44.8005,0.9589,-1,-1,1000); // 7
    carro8 = CreateVehicle(475,1680.8165,-299.7959,44.5819,2.8753,-1,-1,1000); // 8
    carro9 = CreateVehicle(475,1675.7644,-277.6075,43.8853,0.1026,-1,-1,1000); // 9
}
But this returns this error:
Код:
E:\Server SA-MP (0.3a)\gamemodes\catchthecar2.pwn(49) : error: 008: must be a constant expression; assumed zero
What I need to do?
Reply
#5

Forgot that, I do using other way and works the problem with the cars.

But the random(MAX_PLAYERS) or the new MaxPlayers = GetMaxPlayers(); / random(MaxPlayers) doesn't work. He gets the max slots, and not the players online...

How to fix that?
Reply
#6

Fixed the Random players function again, now I have some bugs to fix (timers)

How can I check if have only hunter stays alive (IsHunter[playerid]) or dead, or the other players stays dead (Fugitivo[playerid]) or alive, and show messages like:

IF HUNTER'S DEAD AND PLAYERS ALIVE - One Message / Restart GM
IF HUNTER'S ALIVE AND PLAYERS DEAD - Other Message / Restart GM
IF HUNTER'S AND PLAYERS STILL ALIVE (AFTER ## MINUTES) - Other Message / Restart GM

And checking all the time in a loop

I do a timer with the messages but when all players dead or the hunter's dead aren't showing any message.

And how can I do a "Time-Left" textdraw? I do a SetTimer running in a loop in 1 second, but he updates the string too slow (after ## seconds or minutes, not 1 second), but the server aren't lagging, the players/chat still normal.

How can I convert the seconds in minuteseconds? I use a TimeDuration function created by other player but in this case I think isn't working better (but works on other GM)...

Thanks anyway
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)