SA-MP Forums Archive
Filterscript only working for ID 0 (speedometer) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Filterscript only working for ID 0 (speedometer) (/showthread.php?tid=561217)



Filterscript only working for ID 0 (speedometer) - xX4m4zingXx - 01.02.2015

I downloaded this speedometer, but it does only work for the player with the id 0
pawn Код:
#define FILTERSCRIPT
//-------------------------------------------------------
#include <a_samp>
//-------------------------------------------------------
new Text:SPEEDOS[MAX_PLAYERS];
//-------------------------------------------------------
forward Speedometer(playerid);
//-------------------------------------------------------
public OnFilterScriptInit()
{
    SetTimer("Speedometer", 100, true);
    return 1;
}
//-------------------------------------------------------
public OnPlayerConnect(playerid)
{
    SPEEDOS[playerid] = TextDrawCreate(500.0,400.0," ");
    TextDrawShowForPlayer(playerid,SPEEDOS[playerid]);
    return 1;
}
//-------------------------------------------------------
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);
    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 km/h",final_speed_int);
        TextDrawSetString(SPEEDOS[playerid], speed_string);
    }
    else
    {
        TextDrawSetString(SPEEDOS[playerid], " ");
    }
    return 1;
}
//-------------------------------------------------------



Re: Filterscript only working for ID 0 (speedometer) - Sime30 - 01.02.2015

You need to use Player Textdraws, not default global textdraws


Re: Filterscript only working for ID 0 (speedometer) - Matess - 01.02.2015

PHP код:
SetTimerEx("Speedometer"100true,"i",playerid); 



Re: Filterscript only working for ID 0 (speedometer) - ExtremeReality - 01.02.2015

You need to be using player textdraws for this kind of stuff, not general server textdraws. Whoever made that script either made it for only the first player, or just did it wrong to begin with.


Re: Filterscript only working for ID 0 (speedometer) - Jefff - 01.02.2015

and https://sampwiki.blast.hk/wiki/VectorSize instead of floatsqroot


Re: Filterscript only working for ID 0 (speedometer) - xX4m4zingXx - 02.02.2015

Ok, I tried doing the player textdraws.
I got these errors now:
Код:
C:\Users\Ruud\Documents\Samp\RP alles in 1\filterscripts\speedometer.pwn(17) : warning 213: tag mismatch
C:\Users\Ruud\Documents\Samp\RP alles in 1\filterscripts\speedometer.pwn(18) : warning 213: tag mismatch
This is my code:
Код:
#define FILTERSCRIPT
//-------------------------------------------------------
#include <a_samp>
//-------------------------------------------------------
new Text:SPEEDOS[MAX_PLAYERS];
//-------------------------------------------------------
forward Speedometer(playerid);
//-------------------------------------------------------
public OnFilterScriptInit()
{
	SetTimer("Speedometer", 100, true);
	return 1;
}
//-------------------------------------------------------
public OnPlayerConnect(playerid)
{
	SPEEDOS[playerid] = CreatePlayerTextDraw(playerid, 500.0, 400.0, " ");
	PlayerTextDrawShow(playerid, SPEEDOS[playerid]);
	return 1;
}
//-------------------------------------------------------
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);
	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 km/h",final_speed_int);
		TextDrawSetString(SPEEDOS[playerid], speed_string);
	}
	else
	{
		TextDrawSetString(SPEEDOS[playerid], " ");
	}
    return 1;
}
//-------------------------------------------------------



Re: Filterscript only working for ID 0 (speedometer) - Abagail - 02.02.2015

You still have things like "TextDrawSetString" in your script. Pretty much all textdraw functions such start with the prefix "Player", along with playerid being the first parameter.


Re: Filterscript only working for ID 0 (speedometer) - xX4m4zingXx - 02.02.2015

Like this then?
Код:
#define FILTERSCRIPT
//-------------------------------------------------------
#include <a_samp>
//-------------------------------------------------------
new Text:SPEEDOS[MAX_PLAYERS];
//-------------------------------------------------------
forward Speedometer(playerid);
//-------------------------------------------------------
public OnFilterScriptInit()
{
	SetTimer("Speedometer", 100, true);
	return 1;
}
//-------------------------------------------------------
public OnPlayerConnect(playerid)
{
	SPEEDOS[playerid] = CreatePlayerTextDraw(playerid, 500.0, 400.0, " ");
	PlayerTextDrawShow(playerid, SPEEDOS[playerid]);
	return 1;
}
//-------------------------------------------------------
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);
	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 km/h",final_speed_int);
		PlayerTextDrawSetString(playerid, SPEEDOS[playerid], speed_string);
	}
	else
	{
		PlayerTextDrawSetString(playerid, SPEEDOS[playerid], " ");
	}
    return 1;
}
//-------------------------------------------------------
Got these errors on those lines:
Код:
C:\Users\Ruud\Documents\Samp\RP alles in 1\filterscripts\speedometer.pwn(17) : warning 213: tag mismatch
C:\Users\Ruud\Documents\Samp\RP alles in 1\filterscripts\speedometer.pwn(18) : warning 213: tag mismatch
C:\Users\Ruud\Documents\Samp\RP alles in 1\filterscripts\speedometer.pwn(32) : warning 213: tag mismatch
C:\Users\Ruud\Documents\Samp\RP alles in 1\filterscripts\speedometer.pwn(36) : warning 213: tag mismatch



Re: Filterscript only working for ID 0 (speedometer) - xX4m4zingXx - 02.02.2015

NVM, I fixed the error.
new PlayerText:SPEEDOS[MAX_PLAYERS];


Re: Filterscript only working for ID 0 (speedometer) - xX4m4zingXx - 02.02.2015

Quote:
Originally Posted by Matess
Посмотреть сообщение
PHP код:
SetTimerEx("Speedometer"100true,"i",playerid); 
Quote:
Originally Posted by Jefff
Посмотреть сообщение
And what's the difference if I don't use this?