IF get vehicle speed?
#1

So i when you pass 210 KM in your car it should send the message that you are driving too fast.


I tried it, but something doesnt work.


Code:
stock GetVehicleSpeed(vehicleid)
{
	    new Float:vx, Float:vy, Float:vz, Float:vel;
        vel = GetVehicleVelocity(vehicleid, vx, vy, vz);
        vel = (floatsqroot(((vx*vx)+(vy*vy))+(vz*vz))* 181.5);
        return Float:vel;
}

public OnFilterScriptInit()
{
	print("\n--------------------------------------");
	print(" Blank Filterscript by your name here");
	print("--------------------------------------\n");
	return 1;
}

public OnFilterScriptExit()
{
	return 1;
}

public VehicleSpeed(playerid)
{
	if(IsPlayerInAnyVehicle(playerid))
	{
		 if(GetVehicleSpeed(GetPlayerVehicleID(playerid)) >= 210)
		 {
			  SendClientMessage(playerid, COLOR_RED, "You drive too fast, cops are going to chase you now!");
			  IsWanted[playerid] = 1;
		 }
	}
	return 1;
}
1. I have argument mismatch on return Float:vel; i changed it to return vel; again..

2. It doesnt work at all, im passing 210 KMH and more, but there is no message. help?
Reply
#2

https://sampforum.blast.hk/showthread.php?tid=364124

Tag mismatch because in if you write 210, change to 210.0
Reply
#3

Quote:
Originally Posted by Lixyde
View Post
So i when you pass 210 KM in your car it should send the message that you are driving too fast.


I tried it, but something doesnt work.


Code:
stock GetVehicleSpeed(vehicleid)
{
	    new Float:vx, Float:vy, Float:vz, Float:vel;
        vel = GetVehicleVelocity(vehicleid, vx, vy, vz);
        vel = (floatsqroot(((vx*vx)+(vy*vy))+(vz*vz))* 181.5);
        return Float:vel;
}

public OnFilterScriptInit()
{
	print("\n--------------------------------------");
	print(" Blank Filterscript by your name here");
	print("--------------------------------------\n");
	return 1;
}

public OnFilterScriptExit()
{
	return 1;
}

public VehicleSpeed(playerid)
{
	if(IsPlayerInAnyVehicle(playerid))
	{
		 if(GetVehicleSpeed(GetPlayerVehicleID(playerid)) >= 210)
		 {
			  SendClientMessage(playerid, COLOR_RED, "You drive too fast, cops are going to chase you now!");
			  IsWanted[playerid] = 1;
		 }
	}
	return 1;
}
1. I have argument mismatch on return Float:vel; i changed it to return vel; again..

2. It doesnt work at all, im passing 210 KMH and more, but there is no message. help?
I would not advise to using a stock function as it hides errors.

I would change your function signature to this: Float:GetVehicleSpeed(vehicleid). By adding a float tag to the function header, you are telling the compiler you are going to be returning a float.

As such, the line `return Float:vel` would become `return vel` as the function is expected to return a floating point number because of how we used the tag Float.
Reply
#4

Your code will NEVER work because you're not calling ANYWHERE the VehicleSpeed function. It's just static, yes you added a message, yes you added the km/h check, but when and how VehicleSpeed gets called?

You have to call it somewhere to be sure the player will get the message. Place it in a timer maybe? (By checking if the player is in the vehicle and in the driver seat obv). Otherwise yours is just a "static" function, stays there just to increase lines in your code, nothing more.

And i suggest you to use this:

pawn Code:
GetVehicleSpeed(vehicleid, type)
{
    //Type 1: MPH - Any other type: KM/H
    //GetVehicleSpeed(GetPlayerVehicleID(playerid), 1);
   
    new s;
    new Float:x, Float:y, Float:z;
    GetVehicleVelocity(vehicleid, x, y, z);
    switch(type)
    {
        case 1: s = floatround((floatsqroot(floatpower(x, 2) + floatpower(y, 2) + floatpower(z, 2)))*112.1577, floatround_round);
        default: s = floatround((floatsqroot(floatpower(x, 2) + floatpower(y, 2) + floatpower(z, 2)))*180.5000, floatround_round);
    }
    return s;
}
Reply
#5

Why not do it like this.

Code:
static bool:IsSpeeding[MAX_PLAYERS];

public OnPlayerUpdate(playerid)
{
	// Get the seat this determines everything about what the player is doing with
	// the vehicle and if they are even in one
	new seat = GetPlayerVehicleSeat(playerid);

	// Is the player speeding?
	if(IsSpeeding[playerid])
		// Can't be speeding if not in a vehicle
		if(seat == -1)
			IsSpeeding[playerid] = false;
		// Player is driving
		else if(seat == 0)
		{
			// Have they stopped speeding yet?
		    if(GetVehicleSpeed(GetPlayerVehicleID(playerid)) <= 210)
		    {
				// Not speeding anymore let them know
		        IsSpeeding[playerid] = false;
		        SendClientMessage(playerid, COLOR_GREEN, "You have stopped speeding watch out for the cops");
			}
		}
	}
	// Player is not speeding
	else
	{
		// Player is driving
		if(seat == 0)
		{
			// Player is speeding issue the warning set as wanted
			if(GetVehicleSpeed(GetPlayerVehicleID(playerid)) >= 210)
			{
				SendClientMessage(playerid, COLOR_RED, "You are drivin too fast, thw cops are going to chase you now!");
				IsWanted[playerid] = 1;
			}
		}
	}
	return 1;
}
Reply
#6

So i added what SymonClash said.
and added what Pottus


It works. But not everything.

The full code:

Code:
new IsWanted[MAX_PLAYERS];
static bool:IsSpeeding[MAX_PLAYERS];

GetVehicleSpeed(vehicleid, type)
{
    //Type 1: MPH - Any other type: KM/H
    //GetVehicleSpeed(GetPlayerVehicleID(playerid), 1);

    new s;
    new Float:x, Float:y, Float:z;
    GetVehicleVelocity(vehicleid, x, y, z);
    switch(type)
    {
        case 1: s = floatround((floatsqroot(floatpower(x, 2) + floatpower(y, 2) + floatpower(z, 2)))*112.1577, floatround_round);
        default: s = floatround((floatsqroot(floatpower(x, 2) + floatpower(y, 2) + floatpower(z, 2)))*180.5000, floatround_round);
    }
    return s;
}

public OnPlayerUpdate(playerid)
{
    new seat = GetPlayerVehicleSeat(playerid);
    if(IsSpeeding[playerid])
    {
	    if(seat == -1)
	    {
		    IsSpeeding[playerid] = false;
	    }
	    if(seat == 0)
	    {
		    if(GetVehicleSpeed(GetPlayerVehicleID(playerid)) <= 210)
		    {
			    IsSpeeding[playerid] = false;
			    SendClientMessage(playerid, COLOR_RED, "You stopped driving fast, watch out for the cops");
		    }
	    }
    }
    else
    {
        if(seat == 0)
		{
			if(GetVehicleSpeed(GetPlayerVehicleID(playerid)) >= 210)
			{
				SendClientMessage(playerid, COLOR_RED, "You are drivin too fast, thw cops are going to chase you now!");
				IsWanted[playerid] = 1;
			}
		}
    }
    return 1;
}

1. I have argument mismatch on:

Code:
if(GetVehicleSpeed(GetPlayerVehicleID(playerid)) <= 210)
and on:

Code:
if(GetVehicleSpeed(GetPlayerVehicleID(playerid)) >= 210)
I tried changing 210 with 210.0 and again its the same.



2. When i decrease my vehicle speed and gets below 210. it should send the message:

Code:
SendClientMessage(playerid, COLOR_RED, "You stopped driving fast, watch out for the cops");
But it doesnt work?. There is no message send
Reply
#7

Tag mismatch can be related to missing second argument (type) - GetVehicleSpeed(vehicleid, type).

Do it like that:

if(GetVehicleSpeed(GetPlayerVehicleID(playerid), 2) <= 210)
Reply
#8

I got:

number of arguments does not match definition.

On:

line 51: if(GetVehicleSpeed(GetPlayerVehicleID(playerid, 2)) <= 210)
line 62: if(GetVehicleSpeed(GetPlayerVehicleID(playerid, 2)) >= 210)

If i remove the problem. then i have tag mismatch on them.
Reply
#9

PHP Code:
if(GetVehicleSpeed(GetPlayerVehicleID(playerid), 2) <= 210)
if(
GetVehicleSpeed(GetPlayerVehicleID(playerid), 2) >= 210
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)