[Include] All models array
#1

Models Array - 0.3.7+ Only
This is not completly mine, most of the array code was designed and written by Slice, but i have been adding vehicles, pickups, skins name so far and i think it would be useful for some of you.
  • What does this cover?
    Here is a detailed list:
    • All objects (0.3.7 +)
    • All vehicle models
    • All pickup models
    • All weapon models
    • All skin models

  • What are the stocks?
    2 stocks mainly, This one is used to find a model name from inputted modelid:
    pawn Код:
    GetModelName(modelid, dest[], type = -1, maxlength = sizeof(dest));
    This one locates a modelid from inputted model name:
    pawn Код:
    GetModelId(const modelname[], type = -1);
    The last one gives you the type of model it is:
    pawn Код:
    GetModelType(modelid = -1, const modelname[] = "");
You will get any of these types, defined in the include:
pawn Код:
#define MODEL_TYPE_NONE (0)
#define MODEL_TYPE_OBJECT (1)
#define MODEL_TYPE_VEHICLE (2)
#define MODEL_TYPE_SKIN (3)
#define MODEL_TYPE_WEAPON (4)
The most useful stock of this include, used for searching a match to the keyword in search of models.
pawn Код:
SearchModel(result[], const search[], type = -1, size = sizeof(result));
Here is an example:
pawn Код:
new
    result[10]
;
print("Match foud for the keyword 'm4'");
for (new i = 0, j = SearchModel(result, "m4"); i < j; i++) {
    printf("%i. %s", i, result[i]);
}
Where to use?
Mostly this is for map editors, in case anyone want all models included in one array, this will be probably handy.

Also, maybe you want to use this include for making a model searcher.

Download
Here is the GITHUB repo:

https://github.com/Gammix/Models-Array
Reply
#2

The maximum number of models supported is 20,000 why not just use that instead of looping over an indeterminate array? Then also change up your enum to support model types.

Код:
#define MODEL_TYPE_NONE 0
#define MODEL_TYPE_PED 1
#define MODEL_TYPE_VEHICLE 2
#define MODEL_TYPE_MODEL 3

enum e_MODEL_NAMES {
	e_modelType,
	e_modelName[24 char]
};
Reply
#3

Thanks for the suggestion, Pottus.

Update:
  • Added new model types param in both functions (let you search for only a specific type of models)
  • Added a new stocks:
    pawn Код:
    GetModelType(modelid = -1, const modelname[] = "");
    SearchModel(result[], const search[], size = sizeof(result));
  • Instead of sizeof, we use a macro for looping i.e. MAX_MODELS (which is 20000).
Reply
#4

I think you misunderstood what I was trying to suggest the array indexes should align to the model id and model type be defined as well.

Код:
new const g_ModelNames[MAX_MODELS][e_MODEL_NAMES] = {
Fill in any unused with {0, "Unused" },
Reply
#5

Quote:
Originally Posted by Pottus
Посмотреть сообщение
I think you misunderstood what I was trying to suggest the array indexes should align to the model id and model type be defined as well.

Код:
new const g_ModelNames[MAX_MODELS][e_MODEL_NAMES] = {
Fill in any unused with {0, "Unused" },
Actually i appended the array using SAMP file functions. Something like this:
pawn Код:
#include <a_samp>

new VehicleNames[212][] = {
{"Landstalker"},{"Bravura"},{"Buffalo"},{"Linerunner"},{"Perrenial"},{"Sentinel"},{"Dumper"},
{"Firetruck"},{"Trashmaster"},{"Stretch"},{"Manana"},{"Infernus"},{"Voodoo"},{"Pony"},{"Mule"},
{"Cheetah"},{"Ambulance"},{"Leviathan"},{"Moonbeam"},{"Esperanto"},{"Taxi"},{"Washington"},
{"Bobcat"},{"Mr Whoopee"},{"BF Injection"},{"Hunter"},{"Premier"},{"Enforcer"},{"Securicar"},
{"Banshee"},{"Predator"},{"Bus"},{"Rhino"},{"Barracks"},{"Hotknife"},{"Trailer 1"},{"Previon"},
{"Coach"},{"Cabbie"},{"Stallion"},{"Rumpo"},{"RC Bandit"},{"Romero"},{"Packer"},{"Monster"},
{"Admiral"},{"Squalo"},{"Seasparrow"},{"Pizzaboy"},{"Tram"},{"Trailer 2"},{"Turismo"},
{"Speeder"},{"Reefer"},{"Tropic"},{"Flatbed"},{"Yankee"},{"Caddy"},{"Solair"},{"Berkley's RC Van"},
{"Skimmer"},{"PCJ-600"},{"Faggio"},{"Freeway"},{"RC Baron"},{"RC Raider"},{"Glendale"},{"Oceanic"},
{"Sanchez"},{"Sparrow"},{"Patriot"},{"Quad"},{"Coastguard"},{"Dinghy"},{"Hermes"},{"Sabre"},
{"Rustler"},{"ZR-350"},{"Walton"},{"Regina"},{"Comet"},{"BMX"},{"Burrito"},{"Camper"},{"Marquis"},
{"Baggage"},{"Dozer"},{"Maverick"},{"News Chopper"},{"Rancher"},{"FBI Rancher"},{"Virgo"},{"Greenwood"},
{"Jetmax"},{"Hotring"},{"Sandking"},{"Blista Compact"},{"Police Maverick"},{"Boxville"},{"Benson"},
{"Mesa"},{"RC Goblin"},{"Hotring Racer A"},{"Hotring Racer B"},{"Bloodring Banger"},{"Rancher"},
{"Super GT"},{"Elegant"},{"Journey"},{"Bike"},{"Mountain Bike"},{"Beagle"},{"Cropdust"},{"Stunt"},
{"Tanker"}, {"Roadtrain"},{"Nebula"},{"Majestic"},{"Buccaneer"},{"Shamal"},{"Hydra"},{"FCR-900"},
{"NRG-500"},{"HPV1000"},{"Cement Truck"},{"Tow Truck"},{"Fortune"},{"Cadrona"},{"FBI Truck"},
{"Willard"},{"Forklift"},{"Tractor"},{"Combine"},{"Feltzer"},{"Remington"},{"Slamvan"},
{"Blade"},{"Freight"},{"Streak"},{"Vortex"},{"Vincent"},{"Bullet"},{"Clover"},{"Sadler"},
{"Firetruck LA"},{"Hustler"},{"Intruder"},{"Primo"},{"Cargobob"},{"Tampa"},{"Sunrise"},{"Merit"},
{"Utility"},{"Nevada"},{"Yosemite"},{"Windsor"},{"Monster A"},{"Monster B"},{"Uranus"},{"Jester"},
{"Sultan"},{"Stratum"},{"Elegy"},{"Raindance"},{"RC Tiger"},{"Flash"},{"Tahoma"},{"Savanna"},
{"Bandito"},{"Freight Flat"},{"Streak Carriage"},{"Kart"},{"Mower"},{"Duneride"},{"Sweeper"},
{"Broadway"},{"Tornado"},{"AT-400"},{"DFT-30"},{"Huntley"},{"Stafford"},{"BF-400"},{"Newsvan"},
{"Tug"},{"Trailer 3"},{"Emperor"},{"Wayfarer"},{"Euros"},{"Hotdog"},{"Club"},{"Freight Carriage"},
{"Trailer 3"},{"Andromada"},{"Dodo"},{"RC Cam"},{"Launch"},{"Police Car (LSPD)"},{"Police Car (SFPD)"},
{"Police Car (LVPD)"},{"Police Ranger"},{"Picador"},{"S.W.A.T. Van"},{"Alpha"},{"Phoenix"},{"Glendale"},
{"Sadler"},{"Luggage Trailer A"},{"Luggage Trailer B"},{"Stair Trailer"},{"Boxville"},{"Farm Plow"},
{"Utility Trailer"}
};

main() {
    new File:h = fopen("varray.ini", io_append);
    new str[128];
    new line;
    for (new i = 400; i <= 611; i++) {
        if (line >= 6) {
            format(str, sizeof(str), "{%i, !\"%s\"},\n", i, VehicleNames[i - 400]);
           
            line = 0;
        }
        else {
            format(str, sizeof(str), "{%i, !\"%s\"}, ", i, VehicleNames[i - 400]);
        }
        fwrite(h, str);
       
        line += 1;
    }
}
And it would be really a hard work for me to re edit. Though it will be the fastest method to search using modelids.

But if you look practically, we search modelids using characters, so it won't be useful to locate matches.
Reply
#6

Exactly what I was looking for, thank you so much for this.

Код HTML:
stock IsValidObjectModel(modelid)
{
    if (modelid < 611) return 0;
    for (new i = 0; i < MAX_MODELS; i++)
	{
		  if(modelid == g_ModelNames[i][e_modelId])
		  {
			  return 1;
		  }
	}
	return 0;
}
Reply
#7

Quote:
Originally Posted by DoDler
Посмотреть сообщение
Код HTML:
stock IsValidObjectModel(modelid)
{
    if (modelid < 611) return 0;
    for (new i = 0; i < MAX_MODELS; i++)
	{
		  if(modelid == g_ModelNames[i][e_modelId])
		  {
			  return 1;
		  }
	}
	return 0;
}
Actually weapon models (331,..333,..358,...) are also objects.
https://sampwiki.blast.hk/wiki/Weapons
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)