Speedometer issue
#1

Uh, I join the server and enter a vehicle, everything is working fine, the speedo is working fine, for others that come it is not working, just showing 000(the default textdraw).


Код:
forward Speedometer(playerid);
public Speedometer(playerid)
{
	new vehicleid,Float:speed_x,Float:speed_y,Float:speed_z,Float:final_speed,speed_string[256],final_speed_int;
	vehicleid = GetPlayerVehicleID(playerid);
	//new Float:vehicle_health,final_vehicle_health,health_string[256];
	if(vehicleid != 0)
	{
		GetVehicleVelocity(vehicleid,speed_x,speed_y,speed_z);
		final_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*250.666667; // 250.666667 = kmph  // 199,4166672= mph
		final_speed_int = floatround(final_speed,floatround_round);
		format(speed_string,256,"%i",final_speed_int);
		TextDrawSetString(speedo0[playerid], speed_string);
	}
	else
	{
		TextDrawSetString(speedo0[playerid], " ");
		TextDrawSetString(speedo1[playerid], " ");
	}
    return 1;
}
OnPlayerEnterVehicle
Код:
TextDrawShowForPlayer(playerid, speedo0[playerid]);
	TextDrawShowForPlayer(playerid, speedo1[playerid]);
	TextDrawShowForPlayer(playerid, speedo2[playerid]);
 	TextDrawShowForPlayer(playerid, speedo3[playerid]);
Why
Reply
#2

You need to use player TextDraws instead of global TextDraws: click.

And instead of making a timer for every player, create just one that iterates over every player.
Lots of timers is a bad idea.

EDIT:
I feel like I should explain some things a bit more:
  • Only use player textdraws for the things that can be different for every player, such as: speed, health, name, altitude, ...
  • Use global textdraws for other things that will remain the same for every player, such as: a nice transparant box for your speedometer or things like that, ...
  • Initialize your textdraws to avoid conflicts:
    new Text:myTD = Text:INVALID_TEXT_DRAW; for global textdraws,
    new PlayerText:myTD[MAX_PLAYERS] = {PlayerText:INVALID_TEXT_DRAW, ...}; for player textdraws.
  • Global textdraws should be created in OnGameModeInit, player textdraws should be created in OnPlayerConnect.
  • Use 1 timer with no parameters and iterate over the players with a loop, start the timer in OnGameModeInit.
  • It's better to use OnPlayerStateChange instead of OnPlayerEnter/ExitVehicle.
EDIT2:
Wow, third thread about the same thing ...
https://sampforum.blast.hk/showthread.php?tid=625485
https://sampforum.blast.hk/showthread.php?tid=625496
Reply
#3

And still noone solved my problem, if I use player text draw I get alot of warnings for tag mismatch, and thats how most of the speedos are made at the tutorials on forum, using global textdraws.
Reply
#4

Use This i am using it in my gm and it works like a charm!
Reply
#5

Is there any other textdraw called like that?
Reply
#6

Quote:
Originally Posted by AndreiWow
Посмотреть сообщение
And still noone solved my problem
I've just told you what you need to do.

Quote:
Originally Posted by AndreiWow
Посмотреть сообщение
if I use player text draw I get alot of warnings for tag mismatch
That's because you need to use the player textdraw functions with player textdraws + an array (you would've known that if you read the wiki page I linked).
You can't use for example TextDrawSetString for both global textdraws and player textdraws.
TextDrawSetString is for global textdraws.
PlayerTextDrawSetString is for player textdraws.

Quote:
Originally Posted by AndreiWow
Посмотреть сообщение
and thats how most of the speedos are made at the tutorials on forum, using global textdraws.
Then clearly those tutorials are bad, or you didn't understand a good one.
Judging from your comment on this one, that's what you're referring to. That tutorial is from august 2010, that's 6.3 years! Of course it's outdated!
Reply
#7

Quote:
Originally Posted by Freaksken
Посмотреть сообщение
I've just told you what you need to do.


That's because you need to use the player textdraw functions with player textdraws + an array (you would've known that if you read the wiki page I linked).
You can't use for example TextDrawSetString for both global textdraws and player textdraws.
TextDrawSetString is for global textdraws.
PlayerTextDrawSetString is for player textdraws.


Then clearly those tutorials are bad, or you didn't understand a good one.
Judging from your comment on this one, that's what you're referring to. That tutorial is from august 2010, that's 6.3 years! Of course it's outdated!
This is what I get with player textdraws.


Код:
C:\Users\andrei\Desktop\Scripting SA-MP\Advanced Roleplay (IBP)\gamemodes\panda.pwn(9054) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Advanced Roleplay (IBP)\gamemodes\panda.pwn(9055) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Advanced Roleplay (IBP)\gamemodes\panda.pwn(9056) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Advanced Roleplay (IBP)\gamemodes\panda.pwn(9057) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Advanced Roleplay (IBP)\gamemodes\panda.pwn(40316) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Advanced Roleplay (IBP)\gamemodes\panda.pwn(40317) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Advanced Roleplay (IBP)\gamemodes\panda.pwn(40318) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Advanced Roleplay (IBP)\gamemodes\panda.pwn(40319) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Advanced Roleplay (IBP)\gamemodes\panda.pwn(40349) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Advanced Roleplay (IBP)\gamemodes\panda.pwn(40350) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Advanced Roleplay (IBP)\gamemodes\panda.pwn(40351) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Advanced Roleplay (IBP)\gamemodes\panda.pwn(40352) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Advanced Roleplay (IBP)\gamemodes\panda.pwn(41814) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Advanced Roleplay (IBP)\gamemodes\panda.pwn(41815) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Advanced Roleplay (IBP)\gamemodes\panda.pwn(41816) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Advanced Roleplay (IBP)\gamemodes\panda.pwn(41817) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Advanced Roleplay (IBP)\gamemodes\panda.pwn(41875) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Advanced Roleplay (IBP)\gamemodes\panda.pwn(41876) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Advanced Roleplay (IBP)\gamemodes\panda.pwn(41877) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Advanced Roleplay (IBP)\gamemodes\panda.pwn(41878) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Advanced Roleplay (IBP)\gamemodes\panda.pwn(43681) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Advanced Roleplay (IBP)\gamemodes\panda.pwn(43682) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Advanced Roleplay (IBP)\gamemodes\panda.pwn(43683) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Advanced Roleplay (IBP)\gamemodes\panda.pwn(43684) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Advanced Roleplay (IBP)\gamemodes\panda.pwn(43690) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Advanced Roleplay (IBP)\gamemodes\panda.pwn(43691) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Advanced Roleplay (IBP)\gamemodes\panda.pwn(43692) : warning 213: tag mismatch
C:\Users\andrei\Desktop\Scripting SA-MP\Advanced Roleplay (IBP)\gamemodes\panda.pwn(43693) : warning 213: tag mismatch
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


28 Warnings.
Reply
#8

Well, show us some of this lines , to know what you do there
Edit: Show how you declare the text , like " new Text: speedo " or how you have
Reply
#9

If you've simply started replacing TextDrawSetString with PlayerTextDrawSetString, and haven't converted the complete textdraws, then that's your issue...

You need to be constant, rather than simply throwing things together to try and "hope" to fix it.


Everything Text: related to this HAS to be changed to PlayerText: along with the TextDrawCreate and all of the rest.
Reply
#10

I changed everything with the right format, still get the tag mismatch issue, used PlayerText: but I reverted back to global textdraw and show it to one player, it worked so no need anymore, thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)