Problem with taxi script
#1

Hey,
Today i make a taxi-script. The player that enters the taxi sees a gametext, that shows him the price of his ride. The price becomes higher and higher every ten seconds. If the player exits the taxi, the cost of the taxi ride will be take, and the money have to go to the taxidriver (thats a player to). My problem is its dont work, and i dont see whats wrong. I get no errors or warnings. Here you see my script:

Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	new seat;
	new veh;
	veh = GetVehicleModel(vehicleid);
 	seat = GetPlayerVehicleSeat(playerid);
	if(veh == 420) //taxi id
	{
	  if(seat > 0) // we dont show the timer if the player is a driver
	  {
			SetTimer("TaxiCost",10000,true); /the timer
			SendClientMessage(playerid, COLOR_YELLOW,"You has entered the taxi as a passenger.");
			taxiride[playerid] = 1;
			taxicost[playerid] = 0;
		}
	}
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
  KillTimer(taxitimer);
	if(taxiride[playerid] == 1)
	{
	  new dvehicle;
	  new pvehicle;
	  new seat;
		new tstring2[128];
		new tstring3[128];
  	format(tstring2, sizeof(tstring2),"~g~paid: $%d!",taxicost[playerid]);
  	GameTextForPlayer(playerid, tstring2, 4000, 1);
  	format(tstring3, sizeof(tstring3),"You have exited the taxi. You have paid $%d to the taxi driver.",taxicost[playerid]);
  	SendClientMessage(playerid, COLOR_YELLOW, tstring3);
  	taxiride[playerid] = 0;
  	GameTextForPlayer(playerid,"_",10000, 1);
  	GivePlayerMoney(playerid, -taxicost[playerid]);
		pvehicle = GetPlayerVehicleID(playerid);
		for(new i=0; i<MAX_PLAYERS; i++) /// look for the taxi drivers id
  	{
  	  if(IsPlayerInVehicle(i, 420))
    	{
				dvehicle = GetPlayerVehicleID(i);
				if(dvehicle == pvehicle)
				{
				  seat = GetPlayerVehicleSeat(i);
				  if(seat == 0)
				  {
				  	new dstring[128];
				  	GivePlayerMoney(i, taxicost[playerid]);
				  	format(dstring, sizeof(dstring),"Your passenger has exited your taxi, your earnings: $%d",taxicost[playerid]);
				  	SendClientMessage(i, COLOR_YELLOW, dstring);
  					taxicost[playerid] = 0;
				  	return 1;
					}
				}
			}
		}
	}
}
Greetz
Sean5874
Reply
#2

Could you show us the timer too?

I mean the TaxiCost

EDIT: Also put the KillTimer in the if(taxiride[playerid] == 1). But by this way, it wont work for multiple players. Only one player will be able to "use" the timer, which means it will be bugged if 2 players are using the taxi, and one of them leave the taxi.
((I dont have enough time to tell you how to change your timer, at least you know which is the bug. I will help you tomorrow if you still need my help))
Reply
#3

Ok, thanks. I have edited the KillTimer piece. Here you have the timer:

Код:
public TaxiCost(playerid)
{
	if(taxiride[playerid] == 1)
	{
		new tstring[128];
		taxicost[playerid] += 50;
		format(tstring, sizeof(tstring),"Taxicost: $%d",taxicost[playerid]);
		GameTextForPlayer(playerid, tstring, 10000, 1);
	}
}
Reply
#4

bump!
Reply
#5

Today is the "tomorrow"!

Ok lets start.

First i would suggest you to change the "new taxiride/taxicost[MAX_PLAYERS]" to PVars.(I will talk about that later)

Fixing the timers.

Part 1:
Change the SetTimer("TaxiCost"......
to SetPVarInt(playerid, "TaxiTimer", SetTimerEx("TaxiCost", 10000, false, "i", playerid);

Part 2:
Change the KillTimer(taxitimer);
to KillTimer(GetPVarInt(playerid, "TaxiTimer"));

After changing these 2 things, taxi cost will work fine for ALL ids and not only for ID 0, as it is now.
Also it would be better to add at OnPlayerDisconnect
pawn Код:
if(GetPVarInt(playerid, "TaxiTimer") != 0) KillTimer(GetPVarInt(playerid, "TaxiTimer"));
By adding this, when a player is in taxi as passenger and he disconnects, it will kill the timer.

Changing the taxiride/taxicost into PVars

Part 1:
Remove the
"new taxiride[MAX_PLAYERS];"
and
"new taxicost[MAX_PLAYERS];"

Part 2:
Change this in the TaxiCost timer
taxicost[playerid] += 50;
to
SetPVarInt(playerid, "TaxiCost", GetPVarInt(playerid, "TaxiCost")+50);
AND
format(tstring, sizeof(tstring),"Taxicost: $%d",taxicost[playerid]);
to
format(tstring, sizeof(tstring),"Taxicost: $%d",GetPVarInt(playerid, "TaxiCost"));

Part 3:
Replace all the other taxicost/taxiride into PVars
taxiride[playerid] = 1;
to
SetPVarInt(playerid, "TaxiRide", 1);
AND
taxicost[playerid] = 0;
to
SetPVarInt(playerid, "TaxiCost");

And yeah! I finished. After doing all these everything will work fine!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)