SA-MP Forums Archive
Putting player in random cars - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Putting player in random cars (/showthread.php?tid=520468)



Putting player in random cars - GwENiko - 19.06.2014

Well i have setted up a command that sets players on random vehicles, but i can't understand exactly how "random" works beyond setting up random positions. I've searched the wiki and tutorials, sadly all of them only shows how to use random on that specific case. What i want to do is, when a player uses /join, he gets set inside one of these vehicles, and eliminate the risk of players being choosen by occupied cars, this is how i am trying to do it:

pawn Код:
new eventcars[][8] =
{
    {517, 494, 504, 525},
    {588, 524, 495, 543} //
};


CMD:join(playerid, params[]) // this code is down below the entire script.
{

    else // some code lines on top of else.
    {
    if(derbydm[playerid] == true)
    {
    new randcar = random(sizeof(eventcars));
    SendClientMessage(playerid, -1, "You have joined the derby DM!");
    playingderbydm[playerid]++;
    PutPlayerInVehicle(playerid, eventcars[randcar][0], 0);
    }
    }
    return 1;
}



Re: Putting player in random cars - Laurey - 19.06.2014

Have a stock to check if vehicle is occupied.
pawn Код:
stock IsVehicleOccupied(vehicleid)
{
    for(new i =0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInVehicle(i,vehicleid))
        {
            return 1;
        }
    }
return 0;
}
Then
pawn Код:
CMD:join(playerid, params[]) // this code is down below the entire script.
{

    else // some code lines on top of else.
    {
    if(derbydm[playerid] == true)
    {
    new randcar = random(sizeof(eventcars));
    SendClientMessage(playerid, -1, "You have joined the derby DM!");
    playingderbydm[playerid]++;
    if(!IsVehicleOccupied(vehicleid))
    {
        PutPlayerInVehicle(playerid, eventcars[randcar][0], 0);
    }
    }
    }
    return 1;
}



Re: Putting player in random cars - Eth - 19.06.2014

this:
pawn Код:
new eventcars[][8] =
{
    {517, 494, 504, 525},
    {588, 524, 495, 543} //
};
should be:
pawn Код:
new eventcars[][] =
{
    {517, 494, 504, 525},
    {588, 524, 495, 543} //
};
and now on the command:
pawn Код:
CMD:join(playerid, params[]) // this code is down below the entire script.
{

    else // some code lines on top of else.
    {
    if(derbydm[playerid] == true)
    {
    new randcar = random(sizeof(eventcars));
    SendClientMessage(playerid, -1, "You have joined the derby DM!");
    playingderbydm[playerid]++;
    new car = CreateVehicle(520, eventcars[randcar][0], eventcars[randcar][1], eventcars[randcar][3], eventcars[randcar][4], 0, 1, 60);
    PutPlayerInVehicle(playerid, car, 0);
    }
    }
    return 1;
}



Re: Putting player in random cars - GwENiko - 19.06.2014

Quote:
Originally Posted by Eth
Посмотреть сообщение
this:
pawn Код:
new eventcars[][8] =
{
    {517, 494, 504, 525},
    {588, 524, 495, 543} //
};
should be:
pawn Код:
new eventcars[][] =
{
    {517, 494, 504, 525},
    {588, 524, 495, 543} //
};
and now on the command:
pawn Код:
CMD:join(playerid, params[]) // this code is down below the entire script.
{

    else // some code lines on top of else.
    {
    if(derbydm[playerid] == true)
    {
    new randcar = random(sizeof(eventcars));
    SendClientMessage(playerid, -1, "You have joined the derby DM!");
    playingderbydm[playerid]++;
    new car = CreateVehicle(520, eventcars[randcar][0], eventcars[randcar][1], eventcars[randcar][3], eventcars[randcar][4], 0, 1, 60);
    PutPlayerInVehicle(playerid, car, 0);
    }
    }
    return 1;
}
I don't need cars to spawn in random positions, as i already have them set and created where they are supposed to be, all i want to learn how do i put players randonly inside cars that are standing there for when they type /join

pawn Код:
CMD:join(playerid, params[])
{
    // ...
    else
    {
    if(derbydm[playerid] == true)
    {
    new randcar = random(sizeof(eventcars));
    SendClientMessage(playerid, -1, "You have joined the derby DM!");
    playingderbydm[playerid]++;
    new vehicleid = GetPlayerVehicleID(playerid);
    if(!IsVehicleOccupied(vehicleid))
    {
    PutPlayerInVehicle(playerid, eventcars[randcar][0], 0);
    }
    }
    }
    return 1;
}
Writting the code like this doesn't seems to work