SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 25/03/2019, 07:13 PM   #1
Lixyde
Big Clucker
 
Join Date: Feb 2018
Posts: 92
Reputation: 1
Exclamation IF get vehicle speed?

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?
__________________
Code:
Hello!
Lixyde is offline   Reply With Quote
Old 25/03/2019, 07:20 PM   #2
Heress
Huge Clucker
 
Heress's Avatar
 
Join Date: Mar 2018
Location: Lithuania
Posts: 262
Reputation: 7
Default Re: IF get vehicle speed?

https://forum.sa-mp.com/showthread.php?t=364124

Tag mismatch because in if you write 210, change to 210.0
__________________
==============
Sorry for my bad English









Respect: Kalcor, ******. Thank you for this great game!
Heress is offline   Reply With Quote
Old 25/03/2019, 07:27 PM   #3
4D1L
Big Clucker
 
Join Date: Mar 2016
Location: United Kingdom
Posts: 64
Reputation: 20
Default Re: IF get vehicle speed?

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.
4D1L is offline   Reply With Quote
Old 25/03/2019, 08:03 PM   #4
SymonClash
Banned
 
Join Date: Dec 2018
Posts: 257
Reputation: 25
Default Re: IF get vehicle speed?

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;
}
SymonClash is offline   Reply With Quote
Old 25/03/2019, 08:27 PM   #5
Pottus
High-roller
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 4,854
Reputation: 1292
Default Re: IF get vehicle speed?

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;
}
Pottus is offline   Reply With Quote
Old 26/03/2019, 06:42 PM   #6
Lixyde
Big Clucker
 
Join Date: Feb 2018
Posts: 92
Reputation: 1
Default Re: IF get vehicle speed?

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
__________________
Code:
Hello!
Lixyde is offline   Reply With Quote
Old 26/03/2019, 07:24 PM   #7
raydx
Huge Clucker
 
raydx's Avatar
 
Join Date: Feb 2017
Posts: 203
Reputation: 73
Default Re: IF get vehicle speed?

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

Do it like that:

if(GetVehicleSpeed(GetPlayerVehicleID(playerid), 2) <= 210)
raydx is offline   Reply With Quote
Old 27/03/2019, 05:29 PM   #8
zepfiz
Little Clucker
 
Join Date: Nov 2018
Posts: 2
Reputation: 0
Default Re: IF get vehicle speed?

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.
zepfiz is offline   Reply With Quote
Old 27/03/2019, 07:17 PM   #9
Lokii
Huge Clucker
 
Join Date: Sep 2017
Posts: 338
Reputation: 85
Default Re: IF get vehicle speed?

PHP Code:
if(GetVehicleSpeed(GetPlayerVehicleID(playerid), 2) <= 210)
if(
GetVehicleSpeed(GetPlayerVehicleID(playerid), 2) >= 210
Lokii 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
Speed vehicle NPC Chipardeur Scripting Help 3 15/10/2017 12:39 PM
Getting vehicle speed. TaLhA XIV Scripting Help 10 17/08/2012 01:36 AM
Vehicle Max Speed (Km/H) Rapgangsta Scripting Help 4 30/04/2012 06:07 AM
Vehicle speed ... ? :D theheroo Help Archive 1 02/06/2011 03:00 PM


All times are GMT. The time now is 10:13 AM.


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