find other players in car
#1

hi everybody

today i tried out to figure my own taxi system. well it was just somt minutes ago however, now i want to find the driver via if. and i dont know how. i just thought of GetPlayerVehicleSeat, but that did not work. ill show you my code.
Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
new timer2;
{
	if (GetVehicleModel(vehicleid) == 420){
		SendClientMessage(playerid,COLOR_GREEN,"Willkommen im Taxi");
 	}
 	if (GetPlayerVehicleSeat(playerid) == 2 & 3 & 4){
  timer2 = SetTimer("taxi2", 30000, true);
  }
	return 1;
}
public taxi2
{
//here i want to find the driver and give him 300 dollars from the passengers
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
	KillTimer(timer2);
	return 1;
}
if you could help me i would be very thankful.

greetz m2d
Reply
#2

With a for loop finding the vehicle ID matching the vehicle ID of "playerid". The code you show there has a few syntactical and logical errors.
Reply
#3

Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
	if (GetVehicleModel(GetPlayerVehicleID(playerid)) == 420)
	{
		if (GetPlayerVehicleSeat(playerid) >0) // das hier is leichter. hauptsache, nicht der fahrer
		{
			SendClientMessage(playerid,0x00ff00ff,"Willkommen im Taxi");
			SetPVarInt(playerid,"InsideVehID",GetPlayerVehicleID(playerid))
			SetTimer("taxi2", 3000, true);
		}
	}
	return 1;
}
to find the driver you need to: find the VehicleID, then the players' ID of Seat 0 of that vehicle, a loop should do that job:
Код:
forward taxi2();
public taxi2()
{
	new MaxPlayers=GetMaxPlayers();
	for(new PassangerID=0;PassangerID<MaxPlayers;PassangerID++)
	{
		PassangerVehID=GetPlayerVehicleID(PassangerID);

	}
	new PassangerVehID=GetPVarInt(playerid,"InsideVehID")
	new VehicleID=GetPlayerVehicleID(PassangerVehID);
	new DriverVehID;

	for (new DriverID=0;DriverID<MaxPlayers;DriverID++)
	{
		if(VehID==420 && GetPlayerVehicleSeat(DriverVehID)==0)
		{
			GivePlayerMoney(playerid,GetPlayerMoney(playerid)-300);// vom fahrgast...
			GivePlayerMoney(DriverID,GetPlayerMoney(DriverID)+300);// ...zum chauffeur
			return 1; // wenn danach nix mehr kommt, ist es schneller, das script hier zu unterbrechen. die "arbeit" ist schon erledigt.
		}
		SendClientMessage(playerid,0x00ff00ff,"Wer soll das Teil fahren? Hier ist doch keiner drin!");
	}
	return 1;// falls es soweit kommt, ist der spieler in ein taxi ohne fahrer eingestiegen :)
}
edit: changed to english, fixed a closing bracket }, some bugs (didnt test it while writing)

the best prove how to NOT solve a problem, is simply modifying a few bytes and messing up the whole thing like i did - the following parts are not tested with a driver, but i hope it will work:
Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
	if (GetVehicleModel(GetPlayerVehicleID(playerid)) == 420)
	{
		if (GetPlayerVehicleSeat(playerid) >0)
		{
			SendClientMessage(playerid,0x00ff00ff,"Willkommen im Taxi");
			SetPVarInt(playerid,"InsideATaxi",1);
			SetPVarInt(playerid,"InsideVehID",GetPlayerVehicleID(playerid));
			SetTimer("taxi2", 3000, true);
		}
	}
	return 1;
}

forward taxi2();
public taxi2()
{
	new MaxPlayers=GetMaxPlayers();
	new PassangerID;
	new VehID;
	for (PassangerID=0;PassangerID<MaxPlayers;PassangerID++)
	{
		if(GetPVarInt(PassangerID,"InsideATaxi")==1)
		{
			VehID=GetPVarInt(PassangerID,"InsideVehID");
			for (new DriverID=0;DriverID<MaxPlayers;DriverID++)
			{
				if(GetPlayerVehicleID(DriverID)==VehID && GetPlayerVehicleSeat(DriverID)==0)
				{
					GivePlayerMoney(PassangerID,GetPlayerMoney(PassangerID)-300);// vom fahrgast...
					GivePlayerMoney(DriverID,GetPlayerMoney(DriverID)+300);// ...zum chauffeur
					return 1;
				}
			}
		}
	}
	return 1;
}
Reply
#4

ok, aber er will den code von dir einfach nicht kompilieren. pawno crasht immer schцn.
kannst du sonst mal pwn und amx iwo hochladen?
gruЯ m2d
Reply
#5

If you guys want to talk another language (in this case german) then go to the german subforum
=> SA-MP Forum > Non-English > Languages > Deutsch/German > Scripting Diskussion und Showroom

And this code still contains syntax errors
Reply
#6

that one doesnt work either. errors are following about 13 times
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)