Raised This Month: $51 Target: $400
 12% 

Opening doors AMXX 1.9


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mikka
Member
Join Date: Dec 2018
Old 06-21-2022 , 02:47   Opening doors AMXX 1.9
Reply With Quote #1

Hello everyone, can anybody tell me why the code doesn't work?

Code:
public plugin_init() {
	RegisterHam(Ham_Use, "func_button", "ButtonUse", 1);
}
content of random map file .ini
HTML Code:
-1718.500000 -1102.500000 152.500000 func_button
Code:
public plugin_precache()
{
	new file[128];
	get_mapname(gMap, charsmax(gMap));

	formatex(file[get_localinfo("amxx_configsdir", file, charsmax(file))], charsmax(file), "/cells/%s.ini", gMap);

	if(file_exists(file)) {
		new value[4][32], data[256], iLen;
		for(new i = 0; i < file_size(file, 1); i++) {
			if(i > 1) break;

			read_file(file, i, data, 255, iLen);
			parse(data, value[0], charsmax(value[]), value[1], charsmax(value[]), value[2], charsmax(value[]), value[3], charsmax(value[]));

			new Float:vecOrigin[3];
			vecOrigin[0] = str_to_float(value[0]);
			vecOrigin[1] = str_to_float(value[1]);
			vecOrigin[2] = str_to_float(value[2]);

			new Float:fDistance = 9999.0, Float:fDistance2, iEnt;
			while((iEnt = engfunc(EngFunc_FindEntityByString, iEnt, "classname", value[3]))) {
				new Float:fOrigin[3], Float:fMin[3], Float:fMax[3];
				pev(iEnt, pev_origin, fOrigin);
				pev(iEnt, pev_mins, fMin);
				pev(iEnt, pev_maxs, fMax);

				fOrigin[0] += (fMin[0] + fMax[0]) * 0.5;
				fOrigin[1] += (fMin[1] + fMax[1]) * 0.5;
				fOrigin[2] += (fMin[2] + fMax[2]) * 0.5;

				if((fDistance2 = vector_distance(fOrigin, vecOrigin)) < fDistance) {
					fDistance = fDistance2;
					g_iButtons[i] = iEnt;
				}
			}
		}
	}
	else
	{
		set_fail_state("Cells bad load");
	}
}
Code:
public ButtonUse(iEnt, id, iActivator) {
	if(!pev_valid(iEnt) || !is_user_alive(id) || id != iActivator || cells) return;
	static i;
	for(i = 0; i < sizeof(g_iButtons); i++) {
		if(!pev_valid(g_iButtons[i]) || !g_iButtons[i] || iEnt != g_iButtons[i]) continue;
		ExecuteHam(Ham_Use, g_iButtons[i], 0, 0, 2, 1.0);
		client_print(0, print_center, "^n^nCells opened: %s", Time);

		cells = true;
	}
}
If i remove the if condition then thats work, but on all buttons.

Code:
if(!pev_valid(g_iButtons[i]) || !g_iButtons[i] || iEnt != g_iButtons[i]) continue;
Mikka is offline
DeMNiX
Veteran Member
Join Date: Nov 2011
Location: Russia
Old 06-21-2022 , 04:59   Re: Opening doors AMXX 1.9
Reply With Quote #2

iEnt != g_iButtons[i]

Are u trying to use object that already used?
what are u try to achive?
__________________
My channel with test codes
https://www.youtube.com/user/demnix03

Zombie Riot [Scenario & bots-zombie 11.11.2023]
https://youtu.be/8ZZan-aq2sc
DeMNiX is offline
Mikka
Member
Join Date: Dec 2018
Old 06-21-2022 , 07:13   Re: Opening doors AMXX 1.9
Reply With Quote #3

Quote:
Originally Posted by DeMNiX View Post
iEnt != g_iButtons[i]

Are u trying to use object that already used?
what are u try to achive?

Generally, wants to display client_print after opening the cell with the button (The button position is located in the file)
Mikka is offline
DeMNiX
Veteran Member
Join Date: Nov 2011
Location: Russia
Old 06-21-2022 , 21:22   Re: Opening doors AMXX 1.9
Reply With Quote #4

your event has already been called, because is in the post = true state.
Accordingly, you do not need to call the button press again.

For a place to search by origin, it's better to do a search by targetname.

Check what is in g_iButtons[i] , if there are any values there.
__________________
My channel with test codes
https://www.youtube.com/user/demnix03

Zombie Riot [Scenario & bots-zombie 11.11.2023]
https://youtu.be/8ZZan-aq2sc
DeMNiX is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 19:25.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode