Problem with FS' TextDraw
#1

Hey people! I was editing a FS and I realised it has a bug that I don't know how to fix It's a car radio system, just imagine: I get out of the car while I am listening to a selected station (radio isn`t off), the problem comes when I get in the car, the station's textraw is showed. buf the "radio off" textraw is also showed and it doesn't disappear :S Here's the FS, thanks!

Код:
#include <a_samp>

#undef MAX_PLAYERS
#define MAX_PLAYERS 120

forward PlayVehicleRadioForPlayer(playerid,online);
forward NonChangeRadio(playerid);
forward IsAVel(vehicleid);
forward HideStationTitle(playerid,numberid);

new VehRadio[MAX_VEHICLES];
new PassengerInCar[MAX_VEHICLES][8];

new bool:WaitForBuf[MAX_PLAYERS];
new PassengerSeat[MAX_PLAYERS];
new OldCar[MAX_PLAYERS]; 
enum params
{
	Float:X,Float:Y,Title[64],URL[200]
};
new RadioParams[15][params] = {
	{220.0,20.0,"Radio OFF","none"},// 1
	{220.0,20.0,"MiamiBiza 1","http://mp3plate.com/audio/176601577/-43188317/David_Guetta_feat_Taped_Rai-Just_One_Last_Time_Extended_Mix(mp3plate.com).mp3"},// 2
	{220.0,20.0,"MiamiBiza 2","http://ru-fm.ru/files/mp3/78dcdb72aabb68706426d9eec59d4578.mp3"},// 3
	{220.0,20.0,"MiamiBiza 3","http://8tracks.s3.amazonaws.com/tf/028/073/025/45168.mp3"},// 4
	{220.0,20.0,"MiamiBiza 4","http://www.deejaycee.com/wp-content/uploads/2012/09/David-Guetta-Alesso-Feat.-Tegan-Sara-Every-Chance-We-Get-We-Run.mp3"},// 5
	{220.0,20.0,"MiamiBiza 5","http://houseanthems.com/wp-content/uploads/2012/09/In-My-Head.mp3"},// 6
	{220.0,20.0,"MiamiBiza 6","http://mp3.wapos.ru/base/b/0/6/2480/wapos101980.mp3"},// 7
	{220.0,20.0,"MiamiBiza 7","http://a.tumblr.com/tumblr_luvh5ePzX61qepmsko1.mp3"},// 8
	{220.0,20.0,"MiamiBiza 8","http://www.audiblecoffee.com/mp3/Coldplay_Paradise_Tiesto_Remix.mp3"},// 9
	{220.0,20.0,"MiamiBiza 9","http://www.myndal.com/smileforcamera/audio/d/Deadmau5%20feat%20Kaskade%20-%20I%20Remember.mp3"},// 10
	{220.0,20.0,"MiamiBiza 10","http://www.missls.net/wp-content/uploads/2010/05/Swedish-House-Mafia-ft.-Pharrell-One-Your-Name.mp3"},// 11
	{220.0,20.0,"MiamiBiza 11","http://www.rollingtuff.com/wp-content/uploads/2011/12/04-Internet-Friends.mp3"},// 12
	{220.0,20.0,"MiamiBiza 12","http://thissongissick.com/blog/wp-content/uploads/2012/05/Knife-Party-Bonfire-Original-Mix.mp3"},// 13
	{220.0,20.0,"MiamiBiza 13","http://tiobiloute59.free.fr/tiesto/DJ%20Tiesto%20-%20Sunset%20on%20Ibiza.mp3"},// 14
	{220.0,20.0,"MiamiBiza 14","http://freshmp3music.ru/music/08.2011/David_Guetta_-_Paris_%28www.freshmp3music.ru%29.mp3"}// 15
};
new Text:StationText[17];

public OnFilterScriptInit()
{
	for(new i = 0; i < MAX_VEHICLES; i++)
	{
		VehRadio[i] = 2;
		for(new s = 1; s < 8; s++) PassengerInCar[i][s] = INVALID_PLAYER_ID;
	}
	for(new t = 0; t < sizeof(StationText); t++)
	{
		StationText[t] = TextDrawCreate(RadioParams[t][X],RadioParams[t][Y],RadioParams[t][Title]);
		TextDrawAlignment(StationText[t],0);
		TextDrawBackgroundColor(StationText[t],0x000000ff);
		TextDrawFont(StationText[t],2);
		TextDrawLetterSize(StationText[t],0.4,1.6);
		TextDrawColor(StationText[t],0x906010ff);
		TextDrawSetOutline(StationText[t],1);
		TextDrawSetProportional(StationText[t],2);
		TextDrawSetShadow(StationText[t],1);
	}
	return 1;
}

public OnFilterScriptExit()
{
	for(new t = 0; t < sizeof(StationText); t++) TextDrawDestroy(StationText[t]);
	return 1;
}

public OnPlayerConnect(playerid)
{
    WaitForBuf[playerid] = false;
    OldCar[playerid] = INVALID_VEHICLE_ID;
    PassengerSeat[playerid] = 0;
    return 0;
}

public OnPlayerDisconnect(playerid)
{
    if(OldCar[playerid] != INVALID_VEHICLE_ID) PassengerInCar[OldCar[playerid]][PassengerSeat[playerid]] = INVALID_PLAYER_ID;
	return 0;
}

public OnPlayerStateChange(playerid,newstate,oldstate)
{
	if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
	{
		new veh = GetPlayerVehicleID(playerid);
		if(IsAVel(veh)) return 0;
  		new seat = GetPlayerVehicleSeat(playerid);
    	if(seat != 0)
		{
			PassengerInCar[veh][seat] = playerid;
			PassengerSeat[playerid] = seat;
			OldCar[playerid] = veh;
			TextDrawHideForPlayer(playerid, StationText[0]);
		}
  		PlayVehicleRadioForPlayer(playerid,VehRadio[veh]);
 	}
 	if(oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER)
 	{
  		new veh = GetPlayerVehicleID(playerid);
  		if(IsAVel(veh)) return 0;
  		StopAudioStreamForPlayer(playerid);
		if(OldCar[playerid] != INVALID_VEHICLE_ID)
		{
  			PassengerInCar[OldCar[playerid]][PassengerSeat[playerid]] = INVALID_PLAYER_ID;
   			OldCar[playerid] = INVALID_VEHICLE_ID;
		}
	}
 	return 0;
}

public PlayVehicleRadioForPlayer(playerid,online)
{
	if(online == 0)
	{
	    StopAudioStreamForPlayer(playerid);
		TextDrawShowForPlayer(playerid,StationText[16]);
		WaitForBuf[playerid] = true;
		SetTimerEx("NonChangeRadio",1000,false,"i",playerid);
		SetTimerEx("HideStationTitle",3500,false,"id",playerid,16);
		return 1;
	}
	StopAudioStreamForPlayer(playerid);
	PlayAudioStreamForPlayer(playerid,RadioParams[online - 2][URL]);
	TextDrawHideForPlayer(playerid,StationText[16]);
	TextDrawShowForPlayer(playerid,StationText[online - 2]);
	WaitForBuf[playerid] = true;
	SetTimerEx("NonChangeRadio",1000,false,"i",playerid);
	SetTimerEx("HideStationTitle",5000,false,"id",playerid,online - 2);
	return 1;
}

public OnPlayerKeyStateChange(playerid,newkeys,oldkeys)
{
	if(newkeys == KEY_YES)
	{
	    if(!IsPlayerInAnyVehicle(playerid)) return 0;
     	if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return 0;
   		new veh = GetPlayerVehicleID(playerid);
		if(IsAVel(veh)) return 0;
		if(WaitForBuf[playerid]) return SendClientMessage(playerid,0xFF0000FF,"* Conectando con la radio...");
		VehRadio[veh]++;
		if(VehRadio[veh] == 17) VehRadio[veh] = 0;
		PlayVehicleRadioForPlayer(playerid,VehRadio[veh]);
		for(new s = 1; s < 8; s++)
		{
			if(PassengerInCar[veh][s] != INVALID_PLAYER_ID) PlayVehicleRadioForPlayer(PassengerInCar[veh][s],VehRadio[veh]);
		}
	}
	if(newkeys == KEY_NO)
	{
	    if(!IsPlayerInAnyVehicle(playerid)) return 0;
     	if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return 0;
   		new veh = GetPlayerVehicleID(playerid);
		if(IsAVel(veh)) return 0;
		if(WaitForBuf[playerid]) return SendClientMessage(playerid,0xFF0000FF,"* Conectando con la radio...");
		VehRadio[veh]--;
		if(VehRadio[veh] == -1) VehRadio[veh] = 16;
		PlayVehicleRadioForPlayer(playerid,VehRadio[veh]);
		for(new s = 1; s < 8; s++)
		{
			if(PassengerInCar[veh][s] != INVALID_PLAYER_ID) PlayVehicleRadioForPlayer(PassengerInCar[veh][s],VehRadio[veh]);
		}
	}
	return 0;
}

public NonChangeRadio(playerid) return WaitForBuf[playerid] = false;

public HideStationTitle(playerid,numberid) return TextDrawHideForPlayer(playerid,StationText[numberid]);

public IsAVel(vehicleid)
{
	new model = GetVehicleModel(vehicleid);
	if(model == 481 || model == 509 || model == 510) return 1;
	return 0;
}
Reply
#2

Scripters of the world! I need your help!
Reply
#3

Ok, please, is very very important! I tried a lot of things and no one worked
Reply
#4

remove the GetPlayerVehicleID checks when they leave a vehicle, if they're on foot they're probably not going to have a vehicleid
I don't work with vehicles but I'm pretty sure that's whats wrong
Reply
#5

Oh... thanks for your attention but I tried it and the problem still exists :S



EDIT: I tried a lot of things, and I could fix this problem in a different way, thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)