SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 16/07/2012, 06:57 PM   #1
Daslee
Big Clucker
 
Join Date: Jul 2009
Location: Lithuania
Posts: 111
Reputation: 0
Default Textdraws problem

Hello. First time i tried with textdraw to make my own speedometer for vehicles. So the problem now i have is that when i enter to vehicle it shows speedometer, when i enter to vehicle with my other player, then for first player speedometer disappears, and for second player it will be visible. If second player exits vehicle, then first player can see speedometer again. Damn it really sucks.. My code:
Code:
new Text:SpeedO[MAX_PLAYERS];
new Text:Box[MAX_PLAYERS];
new Text:DrawInfo[MAX_PLAYERS];
new Text:Kilometrazas
new KmBonusTmr[MAX_PLAYERS];
new RodomDegalus[MAX_PLAYERS];[MAX_PLAYERS];

new SpeedOTmr[MAX_PLAYERS];
Code:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
	if(!IsPlayerInAnyVehicle(playerid)){
		KillTimer(SpeedOTmr[playerid]);
		KillTimer(KmBonusTmr[playerid]);
		KillTimer(RodomDegalus[playerid]);
		TextDrawDestroy(DrawInfo[playerid]);
		TextDrawDestroy(Box[playerid]);
		TextDrawDestroy(SpeedO[playerid]);
		TextDrawDestroy(Kilometrazas[playerid]);
	}else{
		if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER){
			SpeedOTmr[playerid] = SetTimerEx("Speedometer", 50, 1, "i", playerid);
			KmBonusTmr[playerid] = SetTimerEx("KmBonusCheck", 50, 1, "i", playerid);
			RodomDegalus[playerid] = SetTimerEx("RodomDegaluss", 30000, 1, "i", playerid);
	    }
	}
	return 1;
}
Code:
forward Speedometer(playerid);
public Speedometer(playerid)
{
	new string[256], infoText[256], kilometrzDraw[256];
	TextDrawDestroy(DrawInfo[playerid]);
	TextDrawDestroy(Box[playerid]);
	TextDrawDestroy(SpeedO[playerid]);
	TextDrawDestroy(Kilometrazas[playerid]);

    new vehicleid, Float:speed_x, Float:speed_y, Float:speed_z, Float:final_speed, final_speed_int;
	vehicleid = GetPlayerVehicleID(playerid);
	GetVehicleVelocity(vehicleid,speed_x,speed_y,speed_z);
	final_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*216.666667; // 136.666667 = kmph  // 85.4166672= mph
	final_speed_int = floatround(final_speed,floatround_round);
    MasinosInfo[vehicleid][rida] += final_speed;

	if(final_speed_int >= 310){
	    new name[MAX_PLAYER_NAME], msg[256];
	    GetPlayerName(playerid, name, sizeof(name));
	    format(msg, sizeof(msg), "[Serveris]: %s buvo isspirtas! (Aptiktas speed hack)", name);
	    SendClientMessageToAll(COLOR_YELLOW, msg);
	    Kick(playerid);
	}

	if(GiveDrivingMoney[playerid] == false){
	    if(final_speed_int > 20){
	    	GiveDrivingMoney[playerid] = true;
	    	new Intervalas;
	    	Intervalas = (300-final_speed_int);
	    	if(Intervalas < 50){
	    	    GiveDrivingMoneyTmr[playerid] = SetTimerEx("IncreaseMoney", 50*7, false, "i", playerid);
			}else{
	    	    GiveDrivingMoneyTmr[playerid] = SetTimerEx("IncreaseMoney", Intervalas*7, false, "i", playerid);
	    	}
		}
	}
	if(GiveDrivingLicense[playerid] == false){
	    if(final_speed_int > 20){
	    	GiveDrivingLicense[playerid] = true;
	    	new Intervalas;
	    	Intervalas = (300-final_speed_int);
	    	if(Intervalas < 50){
	    		GiveDrivingLicenseTmr[playerid] = SetTimerEx("IncreaseLicense", 50*14, false, "i", playerid);
			}else{
			    GiveDrivingLicenseTmr[playerid] = SetTimerEx("IncreaseLicense", Intervalas*14, false, "i", playerid);
			}
	    }
	}
	
	format(string, sizeof(string), "%i Km/h", final_speed_int);
	SpeedO[playerid] = TextDrawCreate(475.0, 400.0, string);
	TextDrawFont(SpeedO[playerid], 2);
	TextDrawColor(SpeedO[playerid], COLOR_BLUE);
	TextDrawSetShadow(SpeedO[playerid], 0);
	TextDrawShowForPlayer(playerid, SpeedO[playerid]);
	
	format(kilometrzDraw, sizeof(kilometrzDraw), "Rida: %.2fKm", MasinosInfo[vehicleid][rida] / 100000);
	Kilometrazas[playerid] = TextDrawCreate(475.0, 415.0, kilometrzDraw);
	TextDrawFont(Kilometrazas[playerid], 2);
	TextDrawColor(Kilometrazas[playerid], COLOR_BLUE);
	TextDrawSetShadow(Kilometrazas[playerid], 0);
	TextDrawShowForPlayer(playerid, Kilometrazas[playerid]);
	
	Box[playerid] = TextDrawCreate(-5.0, 0.0, "I");
	TextDrawUseBox(Box[playerid], 1);
	TextDrawShowForPlayer(playerid, Box[playerid]);

    format(infoText, sizeof(infoText), "Pinigai: %iLt || Licenzijos: %0.1f", PlayerInfo[playerid][Pinigai], PlayerInfo[playerid][Licenzijos]);

	DrawInfo[playerid] = TextDrawCreate(0.5, 0.5, infoText);
    TextDrawColor(DrawInfo[playerid], COLOR_YELLOW);
    TextDrawSetShadow(DrawInfo[playerid], 0);
    TextDrawFont(DrawInfo[playerid], 2);
    TextDrawShowForPlayer(playerid, DrawInfo[playerid]);
	return 1;
}
And where could be the problem?
Daslee is offline   Reply With Quote
Old 16/07/2012, 08:36 PM   #2
hansen111
Big Clucker
 
Join Date: Aug 2007
Posts: 177
Reputation: 9
Default Re: Textdraws problem

change
if(!IsPlayerInAnyVehicle(playerid)){
to
if(newstate != PLAYER_STATE_DRIVER){

and change
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
to
if(newstate == PLAYER_STATE_DRIVER)

I assume that you only want the driver to see the textdraw.
__________________
Quote:
<frank> can you help me install GTA3?
<knightmare> first, shut down all programs you aren't using
frank has quit IRC. (Quit)
<knightmare>...
hansen111 is offline   Reply With Quote
Old 17/07/2012, 11:06 AM   #3
Daslee
Big Clucker
 
Join Date: Jul 2009
Location: Lithuania
Posts: 111
Reputation: 0
Default Re: Textdraws problem

Thanks, but this didn't helped me. Also i forgot to say, that there is also rendering another text "Rida: %.2fKm" This one works good, doesn't disappears like speed. :/
Daslee is offline   Reply With Quote
Old 19/07/2012, 12:39 PM   #4
Daslee
Big Clucker
 
Join Date: Jul 2009
Location: Lithuania
Posts: 111
Reputation: 0
Default Re: Textdraws problem

No more suggestions? :// (Sry for doubleposting.)
Daslee is offline   Reply With Quote
Old 19/07/2012, 01:19 PM   #5
hansen111
Big Clucker
 
Join Date: Aug 2007
Posts: 177
Reputation: 9
Default Re: Textdraws problem

is this still the problem: ?

" So the problem now i have is that when i enter to vehicle it shows speedometer, when i enter to vehicle with my other player, then for first player speedometer disappears, and for second player it will be visible. If second player exits vehicle, then first player can see speedometer again"
__________________
Quote:
<frank> can you help me install GTA3?
<knightmare> first, shut down all programs you aren't using
frank has quit IRC. (Quit)
<knightmare>...
hansen111 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[HELP] Problem with textdraws. Type-R Scripting Help 0 23/02/2012 10:27 PM
Problem with Textdraws SpiderWalk Scripting Help 7 04/02/2012 12:25 AM
Problem with textdraws Peep Help Archive 3 31/03/2011 02:40 PM
problem with textdraws [Ha]Lommo Help Archive 1 19/09/2010 01:25 PM


All times are GMT. The time now is 06:08 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.