PDA

View Full Version : Assigning a player in a car


JaKe Elite
12/10/2015, 07:17 PM
Hi.

I wanted to know on how to place the newly spawned players on the server vehicles (at least 30+ vehicles) For example, player 1 gets assign on the first vehicle, second one... and so on.

I am coding it for my race mode. (Minigames)

JaKe Elite
13/10/2015, 10:35 AM
Bump.

iFiras
13/10/2015, 10:39 AM
Hi.

I wanted to know on how to place the newly spawned players on the server vehicles (at least 30+ vehicles) For example, player 1 gets assign on the first vehicle, second one... and so on.

I am coding it for my race mode. (Minigames)

Do you mean player ID 1 by saying player 1?
If so, I don't know if you can do that because as far as I know, there's no function that allows you to check for players' IDs.

thefirestate
13/10/2015, 12:35 PM
I think it should be done like that.

new avehicle, racestarted;

public OnPlayerConnect(playerid)
{
if(racestarted == 0)
{
SetTimer("RaceStart", **INTERVALINMILLISECONDSHERE** , false);
racestarted = 1;
}
}

public OnPlayerSpawn(playerid)
{
avehicle = CreateVehicle(411, 0.0, 0.0, 0.0, 0.0 , 0, 0, -1, 0);
PutPlayerInVehicle(playerid, avehicle, 0);
TogglePlayerControllable(playerid, 0);
SendClientMessage(playerid, -1, "You have been putted in your vehicle and frozen untill the race starts.");
}

forward RaceStart();
public RaceStart()
{
for(new i = 0; i < MAX_PLAYERS; i++) //Loop through all players
{
TogglePlayerControllable(i, 1);
SendClientMessage(i, -1, "Go go go!");
}
}

That's a little bit more than you might actually need but creating race mini-game would required even more scripting, much more, I am showing how to put him in the vehicle and make him unable to go untill the race starts.

BroZeus
13/10/2015, 01:45 PM
You can create different cars for every player when he/she spawns and doesn't have a car already. Something like this :

new race_veh[MAX_PLAYERS] = {INVALID_VEHICLE_ID, ...};// this sets all index to invalid vehicle id
new car_pos_index = 0;

new Float:car_pos[][3] ={
//car pos of races
{0.00, 0.00, 0.00},
{0.00, 0.00, 0.00},
{0.00, 0.00, 0.00},
{0.00, 0.00, 0.00},
{0.00, 0.00, 0.00},
{0.00, 0.00, 0.00},
{0.00, 0.00, 0.00}
}
public OnPlayerDisconnect(playerid, reason)
{
if(race_veh[playerid] != INVALID_VEHICLE_ID)
{
DestroyVehicle(race_veh[playerid]);
race_veh[playerid] = INVALID_VEHICLE_ID;
}
return 1;
}

public OnPlayerSpawn(playerid)
{
if(race_veh[playerid] == INVALID_VEHICLE_ID)
{
//create vehicle wtih car pos :
race_veh[playerid] = CreateVehicle(..., car_pos[car_pos_index][0], car_pos[car_pos_index][1], car_pos[car_pos_index][2], ...);
PutPlayerInVehicle(playerid, race_veh[playerid], 0);
//this will do different pos for every player :
car_pos_index++;
if(car_pos_index == sizeof(car_pos))car_pos_index = 0;//if car pos index reached at last place it resets to 0
}//else if he has car already put him in car :
else PutPlayerInVehicle(playerid, race_veh[playerid], 0);
return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
if(race_veh[playerid] != INVALID_VEHICLE_ID)SetVehicleToRespawn(race_veh[playerid]);
return 1;
}

JaKe Elite
13/10/2015, 08:46 PM
I will try it out when i get home.

Edit. Is it possible to create the race vehicles KnGameModeInit and place the vehicle automatically there instead of creating them when player spawns.

BroZeus
14/10/2015, 04:39 AM
That is but that is not recommended as in that condition number of vehicles = No. of max players, as there should be vehicle of each player possible. So if you create these vehicle at starting point of race then this may crash players and if not crash then it would lag them for sure because 100 vehicles together very close together. And if you are not planning to create those vehicles at starting point of race then too it will occupy vehicle slots.

Sew_Sumi
14/10/2015, 05:01 AM
That is but that is not recommended as in that condition number of vehicles = No. of max players, as there should be vehicle of each player possible. So if you create these vehicle at starting point of race then this may crash players and if not crash then it would lag them for sure because 100 vehicles together very close together. And if you are not planning to create those vehicles at starting point of race then too it will occupy vehicle slots.

What, are, you, talking, about?

Recommended? I've seen races with over 100 vehicles, not a problem... crashing players and "lagging" players, should just ditch their mods, and fix their installs.


As for this thread, the section is Scripting Help, not Script Requests, pasting code up in here without any regard for how much skill the person has, is reckless, and encourages people to seek "Copy-Pasta" fixes... Of which, this section, isn't for that.



OP, At least post some of your code when asking for help... Otherwise you are looking for a scripter, or a gamemode.

Those that pasted, take note...

Threshold
14/10/2015, 11:08 AM
You should only create vehicles where necessary. There's no point in having 30+ unused vehicles that just sit there and do nothing but look pretty. If you're trying to make a race system, spawn the vehicles when a player joins the race.

Having 100 vehicles in the same location will definitely cause some FPS decrease, despite what the above poster says. There is nothing wrong with 'example codes' either. I learned my knowledge mostly from other people's codes, so there's no point in saying "it isn't helpful".

The structure you should be looking at would be something like this:

Player Joins Race
Spawn Vehicle and assign vehicle ID to the player ID
Put the player inside the vehicle
When the player leaves the race, dies, quits or crashes from the server, delete the vehicle assigned to their player ID
Delete all vehicles assigned to player IDs when the race ends
Reset vehicle ID variables

JaKe Elite
14/10/2015, 07:14 PM
Thank you didnt knew about that, I will be coding on it.

Thank you to everyone who helped me ;)