AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Opening doors AMXX 1.9 (https://forums.alliedmods.net/showthread.php?t=338244)

Mikka 06-21-2022 02:47

Opening doors AMXX 1.9
 
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;

DeMNiX 06-21-2022 04:59

Re: Opening doors AMXX 1.9
 
iEnt != g_iButtons[i]

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

Mikka 06-21-2022 07:13

Re: Opening doors AMXX 1.9
 
Quote:

Originally Posted by DeMNiX (Post 2782047)
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)

DeMNiX 06-21-2022 21:22

Re: Opening doors AMXX 1.9
 
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.


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

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