SA-MP Forums Archive
Tag dismatch - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Tag dismatch (/showthread.php?tid=229463)



Tag dismatch - AlExAlExAlEx - 21.02.2011

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..


Re: Tag dismatch - JaTochNietDan - 21.02.2011

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.


Re: Tag dismatch - MrDeath537 - 21.02.2011

+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.


Re: Tag dismatch - JaTochNietDan - 21.02.2011

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;
}



Re: Tag dismatch - MrDeath537 - 21.02.2011

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;
}



Re: Tag dismatch - AlExAlExAlEx - 21.02.2011

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