SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 12/06/2019, 12:06 PM   #1
TheLeech
Big Clucker
 
Join Date: Aug 2015
Location: Under your bed
Posts: 149
Reputation: 5
Default How to do this?

My old furniture system lived off Dialog's and list items for Material Editing, I thought it would be a good idea to change the Material system so it has all Material's in-game, This has confused me in how to save.

The old saving system was something like this. It would have a enum / array containing all the material object Id's, name, texture name and what it was called in the dialog. like this. The dialog would save the listitem that was selected so for example If I selected Roof with dark grey colour, it would save to BizMInfo as ID 16 and then it would load the information of that layer.

Code:
new BizMInfo[MAX_BUSINESSES][MAX_HOUSE_OBJ][Layer];

enum matLIST
{
	ModelID,
	TxdName[64],
	TextureName[64],
	Name[64]
}

new MaterialIDs[][matLIST] = {
{0,"none","none", "Default"},
{4242,"seabed","des_dirt1", "Sand"},
{3942, "bistro", "mp_snow", "Snow"},
{3942, "bistro", "ahoodfence2", "Flagstone"},
{3908, "libertyfar", "Grass_128HV", "Grass"},
{3903, "libertyhi", "Grass", "Grass 2"},
{3953, "rczero_track", "waterclear256", "Clear water"},
{3933, "weemap", "rocktb128", "Grey rocks"},
{4242, "seabed", "des_dirt1", "Dirty sand"},
{4242, "seabed", "sw_sand", "Dirty sand 2"},
{16008, "des_n", "des_ripplsand", "Dunes on the desert (Sahara)"},
{13734, "hillcliff_lahills", "cobbles_kb_256", "Flagstone 2 (LS lighthouse)"},
{16503, "desert", "des_redrock1", "Red rocks (from desert)"},
{16407, "des_airfieldhus", "btdeck256", "Wood floor 2 (brighter)"},
{16102, "des_cen", "sm_conc_hatch", "Yellow stripes (on the floor)"},
{16021, "des_geyser", "shingles1", "Roof with dark grey colour"},
{16016, "des_n", "ranchwall1", "Wall with rocks (looks nice)"},
{16571, "des_se1", "des_crackeddirt1", "Cracked ground"},
{18752, "Volcano","rocktb128", "Grey rocks"},
{18752, "Volcano","lavalake", "Lava"},
{18752, "Volcano","redgravel", "Ground under the lava"},
{16503, "desert","des_redrock1", "Red rocks (from desert)"},
{16407, "des_airfieldhus","btdeck256", "Wood floor 2 (brighter)"},
{16102, "des_cen","sm_conc_hatch", "Yellow stripes (on the floor)"},
{16021, "des_geyser","shingles1", "Roof with dark grey colour"},
{16016, "des_n","ranchwall1", "Wall with rocks (looks nice)"},
{16571, "des_se1","des_crackeddirt1", "Cracked ground"},
{19128, "dancefloors","dancefloor1", "Dance Floor"},
{2068, "cj_ammo_net","CJ_cammonet", "Camo Net"},
{18646, "matcolours","white", "White"},
{18646, "matcolours","red", "Red"},
{18646, "matcolours", "blue", "Blue"},
{18646, "matcolours","orange", "Orange"},
{18646, "matcolours","green", "Green"},
{964, "cj_crate_will","CJ_FLIGHT_CASE", "Metal Plate"},
{967, "cj_barr_set_1","Stop2_64", "Stop Sign"},
{7981, "vgsairport02","chevronYB_64", "Black and Yellow stripes"},
{7981, "vgsairport02","redwhite_stripe", "Red and White stripes"},
{7980, "vegasairprtland","gridchev_64HV", "Black and Yellow mesh"},
{7980, "vegasairprtland","chevron64HVa", "Yellow and White stripes"},
{6866, "vgncnstrct1","Circus_gls_05", "Red Rectangles"},
{1281, "benches","trafficcone", "Red and White stripes"},
{6295, "lawland2","lightglass", "Large Mesh Glass"},
{6295, "lawland2","boardwalk2_la", "Wood Planks"},
{12938, "sw_apartments","sw_policeline", "Police Line"},
{16004, "des_teepee","des_wigwam", "Wigwam Motel - Wall"},
{16004, "des_teepee","des_wigwamdoor", "Wigwam Motel - Door"},
{16004, "des_teepee","des_dustconc", "Concrete with Dust"},
{16005, "des_stownmain2","sanruf", "Grey Roof"},
{16005, "des_stownmain2","des_redslats", "Red Wooden Planks"},
{16005, "des_stownmain2","duskyred_64", "Light Purple Color"},
{16005, "des_stownmain2","des_ghotwood1", "Old Wooden Planks"},
{16005, "des_stownmain2","ws_green_wall1", "Wall 1 (Green)"},
{16005, "des_stownmain2","alleydoor3", "Door 1 (Blue)"},
{16005, "des_stownmain2","newall4-4", "Wall 2 (Normal)"},
{16005, "vdes_stownmain2","crencouwall1", "Wall 3 (Normal)"},
{16005, "des_stownmain2", "black32", "Black Color"}
}
I use all textures by pottus for my furniture material system.

My new object system is done with 3d menu's and I can't find a good way of saving the material's and loading.

I was wondering if it was possible to get the values of these and return the number / area of the array / enum it's stored at, So If i picked texture { 9514, "711_sfw", "rebrckwall_128" } it would return 30 (The number it is going down the way).

Code:
enum TEXTUREDEF { TModel, TXDName[32], TextureName[32] }

new ObjectTextures[][TEXTUREDEF] =
{
////////////////////////////////////////////////////////////////////////////////
// Original SA textures ////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
	{0,"INVALID","INVALID"},
    { 10101, "2notherbuildsfe", "Bow_Abpave_Gen" },
    { 10101, "2notherbuildsfe", "Bow_church_grass_alt" },
    { 10101, "2notherbuildsfe", "ferry_build14" },
    { 10101, "2notherbuildsfe", "flatdoor01_law" },
    { 10101, "2notherbuildsfe", "gz_vicdoor1" },
    { 10101, "2notherbuildsfe", "gz_vicdoor2" },
    { 10101, "2notherbuildsfe", "sl_vicbrikwall01" },
    { 10101, "2notherbuildsfe", "sl_vicrfedge" },
    { 10101, "2notherbuildsfe", "sl_vicwall01" },
    { 10101, "2notherbuildsfe", "sl_vicwall02" },
    { 10101, "2notherbuildsfe", "sl_vicwin01" },
    { 10101, "2notherbuildsfe", "sl_vicwin02" },
    { 10101, "2notherbuildsfe", "ws_rooftarmac1" },
    { 14668, "711c", "bwtilebroth" },
    { 14668, "711c", "CJ_7_11_TILE" },
    { 14668, "711c", "CJ_7_11_win" },
    { 14668, "711c", "CJ_CHIP_M2" },
    { 14668, "711c", "cj_white_wall2" },
    { 14668, "711c", "forumstand1_LAe" },
    { 14668, "711c", "gun_ceiling1128" },
    { 14668, "711c", "gun_ceiling3" },
    { 14668, "711c", "sec_camera1" },
    { 9514, "711_sfw", "beachwall_law" },
    { 9514, "711_sfw", "brick" },
    { 9514, "711_sfw", "dt_carpark_line_texture" },
    { 9514, "711_sfw", "mono1_sfe" },
    { 9514, "711_sfw", "mono2_sfe" },
    { 9514, "711_sfw", "pcut_bot_law" },
    { 9514, "711_sfw", "rebrckwall_128" },
    { 9514, "711_sfw", "shingles2" },
    { 9514, "711_sfw", "staddoors1" },
    { 9514, "711_sfw", "supasave_sfw" },
    { 9514, "711_sfw", "supasave_wintemp" },
    { 9514, "711_sfw", "sw_sheddoor2" },
    { 9514, "711_sfw", "ws_carpark2" },
    { 1560, "7_11_door", "CJ_CHROME2" },
    { 1560, "7_11_door", "cj_sheetmetal2" },
    { 14690, "7_11_posters", "CJ_7_11_POST" },
    { 14690, "7_11_posters", "CJ_7_11_POST2" },
    { 14690, "7_11_posters", "cokopops_1" },
    { 14690, "7_11_posters", "munkyJuice_2" },
    { 13659, "8bars", "AH_gbarrier" }
}
Code I'm using to save Material for current system need to set BizMinfo to material they pick.

Code:
forward OnPlayerKeyStateChangeMenu(playerid,newkeys,oldkeys);
public OnPlayerKeyStateChangeMenu(playerid,newkeys,oldkeys)
{
	// Show list system textures PREVIEW_STATE_ALLTEXTURES
	if(Menu3DData[playerid][TPreviewState] == PREVIEW_STATE_ALLTEXTURES)
	{
		// Scroll right
		if(newkeys & KEY_ANALOG_RIGHT)
		{
			// Next 16 entries
			Menu3DData[playerid][CurrTextureIndex] += 16;

			// Too high of entries set default
			if(Menu3DData[playerid][CurrTextureIndex] >= sizeof(ObjectTextures) - 1) Menu3DData[playerid][CurrTextureIndex] = 1;

			// Were at the end of the list use the maximum index
			if(sizeof(ObjectTextures) - 1 - Menu3DData[playerid][CurrTextureIndex] - 16 < 0) Menu3DData[playerid][CurrTextureIndex] = sizeof(ObjectTextures) - 16 - 1;

			// Update the textures
			for(new i = 0; i < 16; i++)
			{
			   if(i+Menu3DData[playerid][CurrTextureIndex] >= sizeof(ObjectTextures) - 1) continue;
			   new h = GetPVarInt(playerid, "FurnEditH"), key2 = FurnRight(playerid, 1);
			   new ObjMatIndexEdit = GetPVarInt(playerid, "ObjMatIndex");
		       SetBoxMaterial(Menu3DData[playerid][Menus3D],i,0,ObjectTextures[i+Menu3DData[playerid][CurrTextureIndex]][TModel],ObjectTextures[i+Menu3DData[playerid][CurrTextureIndex]][TXDName],ObjectTextures[i+Menu3DData[playerid][CurrTextureIndex]][TextureName], 0, 0xFF999999);
		       SetDynamicObjectMaterial(BusinessInfo[key2][bObject][h], ObjMatIndexEdit, ObjectTextures[i+Menu3DData[playerid][CurrTextureIndex]][TModel], ObjectTextures[i+Menu3DData[playerid][CurrTextureIndex]][TXDName], ObjectTextures[i+Menu3DData[playerid][CurrTextureIndex]][TextureName], 0);
			}

			// Update the info
			UpdateTextureInfo(playerid, SelectedBox[playerid]);
			new h = GetPVarInt(playerid, "FurnEditH"), key2 = FurnRight(playerid, 1);
	        new ObjMatIndexEdit = GetPVarInt(playerid, "ObjMatIndex");
	        new MenuID = SelectedMenu[playerid];
	        new model,txd[32],texture[32], color;
			GetDynamicObjectMaterial(MenuInfo[MenuID][Objects][SelectedBox[playerid]],0,model, txd, texture, color);
   			SetDynamicObjectMaterial(BusinessInfo[key2][bObject][h], ObjMatIndexEdit, model, txd, texture, MenuInfo[MenuID][UnselectColor][SelectedBox[playerid]]);
			Streamer_Update(playerid);
		}

		// Pressed left (Same as right almost)
		if(newkeys & KEY_ANALOG_LEFT)
		{
			Menu3DData[playerid][CurrTextureIndex] -= 16;

			if(Menu3DData[playerid][CurrTextureIndex] < 1) Menu3DData[playerid][CurrTextureIndex] = sizeof(ObjectTextures) - 1 - 16;

			if(Menu3DData[playerid][CurrTextureIndex] >= sizeof(ObjectTextures) - 1) Menu3DData[playerid][CurrTextureIndex] = 1;

			for(new i = 0; i < 16; i++)
			{
				if(i+Menu3DData[playerid][CurrTextureIndex] >= sizeof(ObjectTextures) - 1) continue;
				new h = GetPVarInt(playerid, "FurnEditH"), key2 = FurnRight(playerid, 1);
				new ObjMatIndexEdit = GetPVarInt(playerid, "ObjMatIndex");
	   		    SetBoxMaterial(Menu3DData[playerid][Menus3D],i,0,ObjectTextures[i+Menu3DData[playerid][CurrTextureIndex]][TModel],ObjectTextures[i+Menu3DData[playerid][CurrTextureIndex]][TXDName],ObjectTextures[i+Menu3DData[playerid][CurrTextureIndex]][TextureName], 0, 0xFF999999);
	   		    SetDynamicObjectMaterial(BusinessInfo[key2][bObject][h], ObjMatIndexEdit, ObjectTextures[i+Menu3DData[playerid][CurrTextureIndex]][TModel], ObjectTextures[i+Menu3DData[playerid][CurrTextureIndex]][TXDName], ObjectTextures[i+Menu3DData[playerid][CurrTextureIndex]][TextureName], 0);
			}

	        UpdateTextureInfo(playerid, SelectedBox[playerid]);
	        new h = GetPVarInt(playerid, "FurnEditH"), key2 = FurnRight(playerid, 1);
	        new ObjMatIndexEdit = GetPVarInt(playerid, "ObjMatIndex");
	        new MenuID = SelectedMenu[playerid];
	        new model,txd[32],texture[32], color;
			GetDynamicObjectMaterial(MenuInfo[MenuID][Objects][SelectedBox[playerid]],0,model, txd, texture, color);
   			SetDynamicObjectMaterial(BusinessInfo[key2][bObject][h], ObjMatIndexEdit, model, txd, texture, MenuInfo[MenuID][UnselectColor][SelectedBox[playerid]]);
			Streamer_Update(playerid);
		}
		if(newkeys == KEY_NO)
	    {
	        new h = GetPVarInt(playerid, "FurnEditH"), key2 = FurnRight(playerid, 1);
	        new ObjMatIndexEdit = GetPVarInt(playerid, "ObjMatIndex");
	        new MenuID = SelectedMenu[playerid];
	        new model,txd[32],texture[32], color;
			GetDynamicObjectMaterial(MenuInfo[MenuID][Objects][SelectedBox[playerid]],0,model, txd, texture, color);
   			SetDynamicObjectMaterial(BusinessInfo[key2][bObject][h], ObjMatIndexEdit, model, txd, texture, MenuInfo[MenuID][UnselectColor][SelectedBox[playerid]]);
			Streamer_Update(playerid);
			new string[256];
			format(string, sizeof(string), "Object %d's material layer %d changed Menu ID selected %d.",BusinessInfo[key2][bObject][h],GetPVarInt(playerid,"FurnEditL"), SelectedBox[playerid]);
			SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
	    }
	    if(newkeys == KEY_YES)
	    {
	        new h = GetPVarInt(playerid, "FurnEditH"), key2 = FurnRight(playerid, 1);
	        new ObjMatIndexEdit = GetPVarInt(playerid, "ObjMatIndex");
	        new MenuID = SelectedMenu[playerid];
	        new model,txd[32],texture[32], color;
			GetDynamicObjectMaterial(MenuInfo[MenuID][Objects][SelectedBox[playerid]],0,model, txd, texture, color);
   			SetDynamicObjectMaterial(BusinessInfo[key2][bObject][h], ObjMatIndexEdit, model, txd, texture, MenuInfo[MenuID][UnselectColor][SelectedBox[playerid]]);
			Streamer_Update(playerid);
			new string[256];
			format(string, sizeof(string), "Object %d's material layer %d changed Menu ID selected %d.",BusinessInfo[key2][bObject][h],GetPVarInt(playerid,"FurnEditL"), SelectedBox[playerid]);
			SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
		}
		if(newkeys == KEY_SPRINT)
	    {
	        new string[256];
	        new h = GetPVarInt(playerid, "FurnEditH"), key2 = FurnRight(playerid, 1);
			SaveBizzObj(key2, h);
			format(string, sizeof(string), "Object %d's material layer %d changed.",BusinessInfo[key2][bObject][h],GetPVarInt(playerid,"FurnEditL"));
			SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
			DeletePVar(playerid,"FurnEditL");
	    }
	}
	return 0;
}
__________________
The sa-mp server 2Real Roleplay is being re-made from the ground up, Join in on development progress and request features on the discord channel. https://discord.gg/cgtttkD
TheLeech is offline   Reply With Quote
Old 12/06/2019, 01:55 PM   #2
TheLeech
Big Clucker
 
Join Date: Aug 2015
Location: Under your bed
Posts: 149
Reputation: 5
Default Re: How to do this?

Would something like this work (Returns 0 all the time though.)

Code:
GetTextureIDfromlist(objid, objTXDName[], objTextureName[])
{
    for (new i = 0; i < sizeof(ObjectTextures); i ++)
	{
	    if(objid == ObjectTextures[i][TModel] && strlen(objTXDName) > 0 && strlen(objTextureName) > 0 && strcmp(objTXDName, ObjectTextures[i][TXDName], true) && strcmp(objTextureName, ObjectTextures[i][TextureName], true))
	    {
			return i;
	    }
	}
	return false;
}
__________________
The sa-mp server 2Real Roleplay is being re-made from the ground up, Join in on development progress and request features on the discord channel. https://discord.gg/cgtttkD
TheLeech is offline   Reply With Quote
Old 12/06/2019, 02:56 PM   #3
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,625
Reputation: 535
Default Re: How to do this?

Quote:
Originally Posted by TheLeech View Post
Would something like this work (Returns 0 all the time though.)

Code:
GetTextureIDfromlist(objid, objTXDName[], objTextureName[])
{
    for (new i = 0; i < sizeof(ObjectTextures); i ++)
	{
	    if(objid == ObjectTextures[i][TModel] && strlen(objTXDName) > 0 && strlen(objTextureName) > 0 && strcmp(objTXDName, ObjectTextures[i][TXDName], true) && strcmp(objTextureName, ObjectTextures[i][TextureName], true))
	    {
			return i;
	    }
	}
	return false;
}
That would work, although there might be a faster/more efficient way if you can retrieve the array index from the 3D menu (not sure on that one since I never used those myself), I think there should be some kind of index (similar to listitem from dialogs), which could resemble the array ID directly.

If that's not possible, a loop to find the proper ID would be correct.

The reason it always returns 0 is probably because you need to compare strcmp against 0 to check for a match:

strcmp(...) == 0

or

!strcmp(...)
NaS is offline   Reply With Quote
Old 12/06/2019, 03:39 PM   #4
TheLeech
Big Clucker
 
Join Date: Aug 2015
Location: Under your bed
Posts: 149
Reputation: 5
Default Re: How to do this?

Quote:
Originally Posted by NaS View Post
That would work, although there might be a faster/more efficient way if you can retrieve the array index from the 3D menu (not sure on that one since I never used those myself), I think there should be some kind of index (similar to listitem from dialogs), which could resemble the array ID directly.

If that's not possible, a loop to find the proper ID would be correct.

The reason it always returns 0 is probably because you need to compare strcmp against 0 to check for a match:

strcmp(...) == 0

or

!strcmp(...)
Found out how yaaay.
__________________
The sa-mp server 2Real Roleplay is being re-made from the ground up, Join in on development progress and request features on the discord channel. https://discord.gg/cgtttkD

Last edited by TheLeech; 12/06/2019 at 06:03 PM.
TheLeech 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



All times are GMT. The time now is 03:37 AM.


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