Custom stock - GetVehicleName - bug
#1

Here's my stock. I wrote it myself because I couldn't find anything better.

Код:
stock GetVehicleName(vehid)
{
	new namestring[24];
	if(vehid == 400) format(namestring,sizeof(namestring),"Landstalker");
	if(vehid == 401) format(namestring,sizeof(namestring),"Bravura");
	if(vehid == 402) format(namestring,sizeof(namestring),"Buffalo");
..... etc
if(vehid == 610) format(namestring,sizeof(namestring),"Farm Trailer");
    if(vehid == 611) format(namestring,sizeof(namestring),"Utility Trailer");
	return namestring;
}
Here's my command:

Код:
dcmd_veh(playerid, params[])
{
	new vehmod;
	new color1;
	new color2;
	if(PlayerInfo[playerid][AdminLevel] < 3) return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use this command.");
	if(AdminCar[playerid])
	{
	    new estring[128];
	    new evehname[24];
		format(evehname,sizeof(evehname),"%s",GetVehicleName(AdminCar[playerid]));
	    format(estring,sizeof(estring), "ERROR: You already spawned an Admin Vehicle(%s). Use /gotov (%d) to find it.",evehname,AdminCar[playerid]);
        SendClientMessage(playerid, COLOR_GREY, estring);
        return 1;
	}
	if(sscanf(params,"ddd",vehmod,color1,color2)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /veh (Vehicle Model ID) (Color ID 1) (Color ID 2)");
	if(vehmod < 400 || vehmod > 611) return SendClientMessage(playerid, COLOR_GREY, "Invalid Vehicle Model ID. [400-611]");
	new Float:ax, Float:ay, Float:az, Float:angle;
	GetPosInFrontOfPlayer(playerid, ax, ay, 10.0);
	new Float:lolx, Float:loly;
	GetPlayerPos( playerid, lolx, loly, az );
	GetPlayerFacingAngle(playerid, angle);
	AdminCar[playerid] = CreateVehicle(vehmod, ax, ay, az+0.60, angle, color1, color2, -1);
	new vehstring[128];
	new vehname[24];
	format(vehname,sizeof(vehname),"%s",GetVehicleName(AdminCar[playerid]));
	format(vehstring,sizeof(vehstring),"** You spawned a vehicle: %s(Model %d) - Color 1: %d - Color 2: %d - Remember to delete it!", vehname, vehmod, color1, color2);
	SendClientMessage(playerid, COLOR_CYAN, vehstring);
	new astring[128];
	format(astring,sizeof(astring),"has spawned: %s (Model %d, ID %d).",vehname,vehmod,AdminCar[playerid]);
	return 1;
}
PROBLEM: When in-game, the name doesn't show up in the cyan message(the vehstring). It's just 2 brackets.

Obviously, my stock doesn't return that string properly, so what did I do wrong.
Reply
#2

Well look:

pawn Код:
stock GetVehicleName(vehid)
{
    new namestring[24];
    if(vehid == 400) format(namestring,sizeof(namestring),"Landstalker");
    if(vehid == 401) format(namestring,sizeof(namestring),"Bravura");
    if(vehid == 402) format(namestring,sizeof(namestring),"Buffalo");
..... etc
if(vehid == 610) format(namestring,sizeof(namestring),"Farm Trailer");
    if(vehid == 611) format(namestring,sizeof(namestring),"Utility Trailer");
    return namestring;
}
For example, if you put in:
pawn Код:
GetVehicleName(400);
it would request this:
pawn Код:
if(400 == 400)
Change that if(vehid == blabla) to
pawn Код:
if(GetVehicleModel(vehid) == 400) return format(namestring,sizeof(namestring)."Landstalker");
Do you understand?
Reply
#3

That's probably THE most inefficient function I have ever seen.

pawn Код:
new eVehicleNames[212][] = {
{"Landstalker"}, // 400
{"Bravura"},
{"Buffalo"},

// Etc, etc

{"Farm Trailer"},
{"Utility Trailer"} // 611
};

stock GetVehicleNameFromID(vehicleid)
{
    return (vehicleid > 0) ? eVehicleNames[GetVehicleModel(vehicleid)-400] : "On Foot";
}
Reply
#4

pawn Код:
return (vehicleid >= 0) ? eVehicleNames[GetVehicleModel(vehicleid)-400] : "On Foot";
first vehicleid is 0
Reply
#5

First vehicleid is 1. Know your values.
Reply
#6

Not when using AddStaticVehicle it isn't
Reply
#7

Quote:
Originally Posted by Vince
Посмотреть сообщение
First vehicleid is 1. Know your values.
How is one's values related to vehicle ids? I doubt motivational beliefs are even remotely related to this!


Quote:
Originally Posted by LarzI
Посмотреть сообщение
Not when using AddStaticVehicle it isn't
Starts with 1 no matter what. I believe it was made like this so you can tell if it is a valid vehicle id easily.
Reply
#8

This could be the most simple...

pawn Код:
stock GetVehicleName(vehid)
{
    new namestring[24];
    if(GetVehicleModel(vehid) == 400) format(namestring,sizeof(namestring),"Landstalker");
    if(GetVehicleModel(vehid) == 401) format(namestring,sizeof(namestring),"Bravura");
    if(GetVehicleModel(vehid) == 402) format(namestring,sizeof(namestring),"Buffalo");
if(GetVehicleModel(vehid) == 610) format(namestring,sizeof(namestring),"Farm Trailer");
    if(GetVehicleModel(vehid) == 611) format(namestring,sizeof(namestring),"Utility Trailer");
    return namestring;
}
Reply
#9

Use array for storing vehicle model names.
If you MUST have a fuction, this would be more efficient:

Код:
stock GetModelName(modelid)
{
new modelname[32];
switch(modelid)
{
case 400: modelname = "Landstalker";
case 401: modelname = "Bravura";
...
default: modelname = "Unknown";
}
return modelname;
}
Reply
#10

See, I knew it.

Every time I post something on the forums, it's some goddamn simple bug that I could've edited if I had spotted it.

Who cares if it's inefficient, it works when I've fixed this.

Thanks gaise.

EDIT: I just made a new vehmod = GetVehicleModel(vehid); on top and edited all 'vehid' to 'vehmod'.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)