Tag dismatch
#1

Code:
//---------------/b-------------------------
//------------------------------------------
CMD:b(playerid, params[])
{
	new veh;
	if(sscanf(params, "d", veh)) SendClientMessage(playerid, LIGHTBLUE2, "USAGE: b [speed]");
	veh = GetPlayerVehicleID(playerid);
	SetVehicleSpeed(veh, params);
	SendClientMessage(playerid, orange, "YAHOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!");
	return 1;
}

stock SetVehicleSpeed(vehicleid,mph) //Miles Per Hour
{
	new Float:Vx,Float:Vy,Float:Vz,Float:DV,Float:multiple;
	GetVehicleVelocity(vehicleid,Vx,Vy,Vz);
	DV = floatsqroot(Vx*Vx + Vy*Vy + Vz*Vz);
	if(DV > 0) //Directional velocity must be greater than 0 (display strobes if 0)
	{
		multiple = (mph / (DV * 100)); //Multiplying DV by 100 calculates speed in MPH
		return SetVehicleVelocity(vehicleid,Vx*multiple,Vy*multiple,Vz*multiple);
	}
	return 0;
}
I don't see any reason to tagdismatch..
Reply
#2

Well the problem is simple, this function "SetVehicleSpeed" requires an integer in its second parameter, but you're sending a string to it, so you need to convert the string to an integer first, for example:

Code:
SetVehicleSpeed(veh, strval(params));
Again I recommend reading the official Pawn documentation available on CompuPhase.
Reply
#3

+1 with JaTochNietDan

Also why are you using sscanf to convert a string into integer?
You can use strval. And floatstr to convert a string into float.
Reply
#4

Exactly, there's other problems with this code too, the use of sscanf is not needed at all. Also you're creating the veh variable before it's even confirmed it will be used, which is a bad coding habit to get into. In fact, in this case the creation of the variable is not needed either, since it's only ever going to be used once.

Example:

Code:
CMD:b(playerid, params[])
{
    if(!strlen(params)) return SendClientMessage(playerid, LIGHTBLUE2, "USAGE: b [speed]");
    SetVehicleSpeed(GetPlayerVehicleID(playerid), strval(params));
    SendClientMessage(playerid, orange, "YAHOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!");
    return 1;
}
Reply
#5

Quote:
Originally Posted by JaTochNietDan
View Post
Exactly, there's other problems with this code too, the use of sscanf is not needed at all. Also you're creating the veh variable before it's even confirmed it will be used, which is a bad coding habit to get into. In fact, in this case the creation of the variable is not needed either, since it's only ever going to be used once.

Example:

Code:
CMD:b(playerid, params[])
{
    if(!strlen(params)) SendClientMessage(playerid, LIGHTBLUE2, "USAGE: b [speed]");
    SetVehicleSpeed(GetPlayerVehicleID(playerid), strval(params));
    SendClientMessage(playerid, orange, "YAHOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!");
    return 1;
}
Yes, but if you don't return on "!strlen(params)" it will execute the next code, fixed command:

Code:
CMD:b(playerid, params[])
{
    if(isnull(params))
    {
        SendClientMessage(playerid, LIGHTBLUE2, "USAGE: b [speed]");
        return 1;
    }
    SetVehicleSpeed(GetPlayerVehicleID(playerid), strval(params));
    SendClientMessage(playerid, orange, "YAHOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!");
    return 1;
}
Reply
#6

I saw that..already added the return no need to { return 1; }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)