Help with Speedo
#1

I have a big problem. I want to make a Speedometer for my Server but I don't understand, why it doesn't work:

I have the Speedo sourcecode once in a filterscript and once in a gamemode. But the Speedo only works in the gamemode. In the filterscript, the Speedo doesn't announced.
although it's the same code:

gamemode:

Code:
#include <a_samp>

forward TankVerbrauch(playerid);
forward Fahrzeuganzeige(playerid);

new Float:newX[MAX_PLAYERS], Float:newY[MAX_PLAYERS], Float:newZ[MAX_PLAYERS];
new Float:oldX[MAX_PLAYERS], Float:oldY[MAX_PLAYERS], Float:oldZ[MAX_PLAYERS];
new Float:diffX[MAX_PLAYERS], Float:diffY[MAX_PLAYERS], Float:diffZ[MAX_PLAYERS];
new Float:Num[MAX_PLAYERS];
new FahrzeugID;
new Tankinhalt[MAX_VEHICLES];
new GameText;

main()
{
	print("\n----------------------------------");
	print(" Blank Gamemode by your name here");
	print("----------------------------------\n");
}

public OnGameModeInit()
{

	SetTimer("TankVerbrauch",5000, true);
	SetTimer("Fahrzeuganzeige",1000,1);

	GameText = 0;
	new Vehicles;
	for(Vehicles = 0; Vehicles < MAX_VEHICLES; Vehicles++)
 	{
 		Tankinhalt[Vehicles] = 100;
 	}

	SetGameModeText("Blank Script");
	AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
	AddStaticVehicle(581, 1958.3783, 1343.1572, 15.3746, 269.1425,53,1);
	AddStaticVehicle(581, 1958.3783, 1343.1572, 15.3746, 269.1425,53,1);

	return 1;
}


public OnPlayerRequestClass(playerid, classid)
{
	SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
	SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
	SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
	return 1;
}

public TankVerbrauch(playerid)
{
		if(GameText == 0)
		{
              FahrzeugID = GetPlayerVehicleID(playerid);
			if(IsPlayerInAnyVehicle(playerid))
			{
				Tankinhalt[FahrzeugID] -= 1;
			}
		}
}

public Fahrzeuganzeige(playerid)
{
		for(new i=0; i<MAX_PLAYERS; i++)
		{
			new string[256];
              FahrzeugID = GetPlayerVehicleID(i);
			if(IsPlayerInAnyVehicle(playerid) == 1)
 			{
				GetPlayerPos(playerid, newX[i],newY[i], newZ[i]);
				diffX[i] = (newX[i]) - (oldX[i]); diffY[i] = (newY[i]) - (oldY[i]); diffZ[i] = (newZ[i]) - (oldZ[i]);
				Num[i] = floatsqroot((diffX[i] * diffX[i])+(diffY[i] * diffY[i])+(diffZ[i] * diffZ[i]));
				oldX[i] = newX[i]; oldY[i] = newY[i]; oldZ[i] = newZ[i];
				Num[i] = Num[i] * 4;

				if(Tankinhalt[FahrzeugID] > 0)
				{
					if(Tankinhalt[FahrzeugID] < 31)
					{
						format(string, sizeof(string), "~n~~n~~n~~n~~n~~n~~n~~n~~g~%0.0f/~r~%d", Num[i],Tankinhalt[FahrzeugID]);
						GameTextForPlayer(i,string,1500,5);
					}
					else
					{
						format(string, sizeof(string), "~n~~n~~n~~n~~n~~n~~n~~n~~g~%0.0f/~g~%d", Num[i],Tankinhalt[FahrzeugID]);
						GameTextForPlayer(i,string,1500,5);
					}
				}
				else
				{
					RemovePlayerFromVehicle(playerid);
  				}
			}
		}
}
filterscript:

Code:
#include <a_samp>

forward TankVerbrauch(playerid);
forward Fahrzeuganzeige(playerid);

new GameText;
new Float:newX[MAX_PLAYERS], Float:newY[MAX_PLAYERS], Float:newZ[MAX_PLAYERS];
new Float:oldX[MAX_PLAYERS], Float:oldY[MAX_PLAYERS], Float:oldZ[MAX_PLAYERS];
new Float:diffX[MAX_PLAYERS], Float:diffY[MAX_PLAYERS], Float:diffZ[MAX_PLAYERS];
new Float:Num[MAX_PLAYERS];
new FahrzeugID;
new Tankinhalt[MAX_VEHICLES];

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{

	SetTimer("TankVerbrauch",5000, true);
	SetTimer("Fahrzeuganzeige",1000,1);

	GameText = 0;
	new Vehicles;
	for(Vehicles = 0; Vehicles < MAX_VEHICLES; Vehicles++)
 	{
 		Tankinhalt[Vehicles] = 100;
 	}

	SetGameModeText("Blank Script");
	AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
	AddStaticVehicle(581, 1958.3783, 1343.1572, 15.3746, 269.1425,53,1);
	AddStaticVehicle(581, 1958.3783, 1343.1572, 15.3746, 269.1425,53,1);

	return 1;
}

public OnFilterScriptExit()
{
	return 1;
}

#endif

public OnGameModeInit()
{
	// Don't use these lines if it's a filterscript
	SetGameModeText("Blank Script");
	AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
	return 1;
}

public OnGameModeExit()
{
	return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
	SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
	SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
	SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
	return 1;
}

public TankVerbrauch(playerid)
{
		if(GameText == 0)
		{
              FahrzeugID = GetPlayerVehicleID(playerid);
			if(IsPlayerInAnyVehicle(playerid))
			{
				Tankinhalt[FahrzeugID] -= 1;
			}
		}
}

public Fahrzeuganzeige(playerid)
{
		for(new i=0; i<MAX_PLAYERS; i++)
		{
			new string[256];
              FahrzeugID = GetPlayerVehicleID(i);
			if(IsPlayerInAnyVehicle(playerid) == 1)
 			{
				GetPlayerPos(playerid, newX[i],newY[i], newZ[i]);
				diffX[i] = (newX[i]) - (oldX[i]); diffY[i] = (newY[i]) - (oldY[i]); diffZ[i] = (newZ[i]) - (oldZ[i]);
				Num[i] = floatsqroot((diffX[i] * diffX[i])+(diffY[i] * diffY[i])+(diffZ[i] * diffZ[i]));
				oldX[i] = newX[i]; oldY[i] = newY[i]; oldZ[i] = newZ[i];
				Num[i] = Num[i] * 4;

				if(Tankinhalt[FahrzeugID] > 0)
				{
					if(Tankinhalt[FahrzeugID] < 31)
					{
						format(string, sizeof(string), "~n~~n~~n~~n~~n~~n~~n~~n~~g~%0.0f/~r~%d", Num[i],Tankinhalt[FahrzeugID]);
						GameTextForPlayer(i,string,1500,5);
					}
					else
					{
						format(string, sizeof(string), "~n~~n~~n~~n~~n~~n~~n~~n~~g~%0.0f/~g~%d", Num[i],Tankinhalt[FahrzeugID]);
						GameTextForPlayer(i,string,1500,5);
					}
				}
				else
				{
					RemovePlayerFromVehicle(playerid);
  				}
			}
		}
}
I don't understand it, please help me
Reply
#2

it doesn't work because you got something wrong, sorry I cannot help you, wait for badger to read this
Reply
#3

Quote:
Originally Posted by Ignas1337
it doesn't work because you got something wrong, sorry I cannot help you, wait for badger to read this
Spam much? Obviously he got something wrong or else it would work. What is the point when someone asks for help and you tell them is that they have a problem and you can't help?
Reply
#4

ah, and i forget to say when i add "return 1;" ( to the gametext part ) , it doesn't work, too.
Reply
#5

Again the problem of #if defined FILTERSCRIPT. Why you put this?
Reply
#6

in fact, I wanted to transfer the Speedocode from the gamemode in an other gamemode, but there, it doesn't work,too. So i tryed with a filterscript to see if is the error in the gamemode I wanted to transfer the code in.
Reply
#7

Well first of all, if it works in the filterscript you wont need it in the gamemode. A few problems i saw in the filterscript:
Delete:
pawn Code:
#if defined FILTERSCRIPT
pawn Code:
#endif
pawn Code:
public OnGameModeInit()
{
    // Don't use these lines if it's a filterscript
    SetGameModeText("Blank Script");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    return 1;
}

public OnGameModeExit()
{
    return 1;
}



public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
    return 1;
}
Since you don't need any of these.


And Under OnFilterScriptInit delete:
pawn Code:
SetGameModeText("Blank Script");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    AddStaticVehicle(581, 1958.3783, 1343.1572, 15.3746, 269.1425,53,1);
    AddStaticVehicle(581, 1958.3783, 1343.1572, 15.3746, 269.1425,53,1);

And At the end of
pawn Code:
public TankVerbrauch(playerid)
and
pawn Code:
public Fahrzeuganzeige(playerid)
put return 1;, so it should look like this:

pawn Code:
#include <a_samp>

forward TankVerbrauch(playerid);
forward Fahrzeuganzeige(playerid);

new GameText;
new Float:newX[MAX_PLAYERS], Float:newY[MAX_PLAYERS], Float:newZ[MAX_PLAYERS];
new Float:oldX[MAX_PLAYERS], Float:oldY[MAX_PLAYERS], Float:oldZ[MAX_PLAYERS];
new Float:diffX[MAX_PLAYERS], Float:diffY[MAX_PLAYERS], Float:diffZ[MAX_PLAYERS];
new Float:Num[MAX_PLAYERS];
new FahrzeugID;
new Tankinhalt[MAX_VEHICLES];

public OnFilterScriptInit()
{

    SetTimer("TankVerbrauch",5000, true);
    SetTimer("Fahrzeuganzeige",1000,1);

    GameText = 0;
    new Vehicles;
    for(Vehicles = 0; Vehicles < MAX_VEHICLES; Vehicles++)
    {
        Tankinhalt[Vehicles] = 100;
    }

    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

public TankVerbrauch(playerid)
{
    if(GameText == 0)
    {
        FahrzeugID = GetPlayerVehicleID(playerid);
        if(IsPlayerInAnyVehicle(playerid))
        {
            Tankinhalt[FahrzeugID] -= 1;
        }
    }
    return 1;
}

public Fahrzeuganzeige(playerid)
{
        for(new i=0; i<MAX_PLAYERS; i++)
        {
            new string[256];
              FahrzeugID = GetPlayerVehicleID(i);
            if(IsPlayerInAnyVehicle(playerid) == 1)
            {
                GetPlayerPos(playerid, newX[i],newY[i], newZ[i]);
                diffX[i] = (newX[i]) - (oldX[i]); diffY[i] = (newY[i]) - (oldY[i]); diffZ[i] = (newZ[i]) - (oldZ[i]);
                Num[i] = floatsqroot((diffX[i] * diffX[i])+(diffY[i] * diffY[i])+(diffZ[i] * diffZ[i]));
                oldX[i] = newX[i]; oldY[i] = newY[i]; oldZ[i] = newZ[i];
                Num[i] = Num[i] * 4;

                if(Tankinhalt[FahrzeugID] > 0)
                {
                    if(Tankinhalt[FahrzeugID] < 31)
                    {
                        format(string, sizeof(string), "~n~~n~~n~~n~~n~~n~~n~~n~~g~%0.0f/~r~%d", Num[i],Tankinhalt[FahrzeugID]);
                        GameTextForPlayer(i,string,1500,5);
                    }
                    else
                    {
                        format(string, sizeof(string), "~n~~n~~n~~n~~n~~n~~n~~n~~g~%0.0f/~g~%d", Num[i],Tankinhalt[FahrzeugID]);
                        GameTextForPlayer(i,string,1500,5);
                    }
                }
                else
                {
                    RemovePlayerFromVehicle(playerid);
                }
            }
        }
        return 1;
}
Reply
#8

did you tested it, because now I'm at my old Pc and here I can't play GTA very well, so I can't test it jet, first in a few hours.
Reply
#9

ok one sec.

But I'm suprised that this will even work since the timers don't define playerid, they just set the time. Try putting the part that makes the speedo appear under OnPlayerEnterVehicle, or when their playerstate changes to in any vehicle.
Reply
#10

But that is the Problem. Because the Speed changes very often, I must update the gametext part for example every second to show an other speed and that I do with the timers.
I can't make it, I must do it with the timers.

Or can you show me how ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)