AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Block Button ID (https://forums.alliedmods.net/showthread.php?t=308330)

PurposeLessx 06-16-2018 16:42

Block Button ID
 
I made a plugin to block using block with button ID. But It's not working. I guess it doesn't get file or something like that. Could you fix my mistake? Thanks for helping :)

Example file is "configs/block_buttons/mapname.ini"
There are IDs in the file.
Like;
Code:

213
230
102

PHP Code:

#include <amxmodx>
#include <reapi>
#include <hamsandwich>

#pragma semicolon 1

new komutdosyasi[250], satirsayisisonucpurposeless[250][250],LeaderGM[250][250],
PurposeLess;

public 
plugin_init() {
    
register_plugin("Buton Engel""1.0""PurposeLess");

    
register_clcmd("say /info""button_info");
    
RegisterHam(Ham_Use"func_button""RHam_Use");
    
LoadButtons();
}

public 
RHam_Use(entid)
{
    if(
get_user_team(id) == 1)
    {
        if(
get_godmode())
        {
            
client_print(idprint_center"[LeaderGaming] You cannot use buttons while godmode is on");
            return 
4;
        }
        if(
ent == PurposeLess)
        {
            
client_print(idprint_center"[LeaderGaming] You cannot use this button");
            return 
4;
        }
    }
    return 
1;
}

public 
LoadButtons()
{
    static 
filename[64], mapname[32];
    
get_localinfo("amxx_configsdir"filenamecharsmax(filename));
    
get_mapname(mapnamecharsmax(mapname));
    
format(filenamecharsmax(filename), "%s/block_buttons/%s.ini"filenamemapname);

    for(new 
i=0degeri<250i++)
    {
        
sonuc read_file(komutdosyasiipurposeless[i], charsmax(purposeless), satirsayisi);
        if(
sonuc != 0)
        {
            
PurposeLess++;
            
LeaderGM[PurposeLess] = purposeless[i];
            
deger++;
        }
    }
}

public 
get_godmode()
{
    new 
a=0b=0;
    for(new 
id 1id <= MAX_CLIENTSid++)
    {
        if(!
is_user_connected(id)) continue;
        new 
team get_user_team(id);
        if(
team == && is_user_alive(id))
        {
            
a++;
            if(!
get_entvar(idvar_takedamage))
            {
                
b++;
            }
        }
    }
    return (
&& 0) ? 1:0;
}

public 
button_info(id)
{
    if(
get_user_flags(id) & ADMIN_RCON)
    {
        new 
menu menu_create("Button Menu""button_info2");
        
menu_additem(menu"\yFind Button ID""1");
        
menu_additem(menu"\yBlock Button ID in map""2");
        
//menu_additem(menu, "\yUnBlock Button ID in map", "3");     ; I Couldn't have done.
        
menu_setprop(menuMPROP_EXITNAME"Exit");
        
menu_display(idmenu);
    }
    return 
PLUGIN_HANDLED;
}

public 
button_info2(idmenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }
    static 
data[6], accesscallback;
    
menu_item_getinfo(menuitemaccessdatacharsmax(data), __callback);
    new 
key str_to_num(data);
    switch(
key)
    {
        case 
1: {
            new 
entaim;
            
get_user_aiming(identaim);

            if(
ent)
            {
                
client_print_color(idid"^1[^4LeaderGaming^1] ^3Button ID^1: ^4%d"ent);
            }
            
menu_display(idmenu);
        }
        case 
2: {
            new 
entaim;
            
get_user_aiming(identaim);

            if(
ent)
            {
                static 
filename[64], mapname[32], buttonID[10];
                
get_localinfo("amxx_configsdir"filenamecharsmax(filename));
                
get_mapname(mapnamecharsmax(mapname));
                
format(filenamecharsmax(filename), "%s/block_buttons/%s.ini"filenamemapname);
                
format(buttonIDcharsmax(buttonID), "%d"ent);
                
write_file(filenamebuttonID);
            }
        }
    }
    return 
PLUGIN_HANDLED;



maqi 06-16-2018 16:45

Re: Block Button ID
 
What are those variable names xD

Anyway when reading from a file in a loop you shouldn't use read_file, read more about it here. ( Not saying that is the issue tho )

Did you see if your values actually get read, so I know what to look for, because i can hardly find my way with your variable names hahaha ?

EDIT:
but here is your issue
Code:
    if(ent == PurposeLess)
You are checking entity index against some sort of a counter.

Ghosted 06-16-2018 16:46

Re: Block Button ID
 
I think its better to use fopen feof fread fclose natives instead of read_line

PurposeLessx 06-16-2018 16:51

Re: Block Button ID
 
I don't know about fopen or any commands like them. So, I am sorry for variable names. I forgot to change their names from Turkish to English. You don't have to have a fun with them as a idiot :S (My bad)

maqi 06-16-2018 16:58

Re: Block Button ID
 
It's ok, try fixing what we told you

Also heres an example how to read from a text file properly


PHP Code:

new iFileHandle fopensFilename"rt" );

new 
sData[128];
if( 
iFileHandle )
{
    while( !
feof(iFileHandle) )
    {
        
fgetsiFileHandlesDatacharsmax(sData) );
        
trim(sData);

        
// Do something with a line of file ( sData )
    
}

    
fclose(iFileHandle);
}
else
{
    
set_fail_state"Couldn't read from a file" );



PurposeLessx 06-16-2018 17:05

Re: Block Button ID
 
It still does not work. I guess I cannot do it how get IDs from file.

Spoiler

maqi 06-16-2018 17:11

Re: Block Button ID
 
You just read sData, and counted it, you didn't place the result anywhere, sData is a local variable ( Outside of the function, it doesn't exist ).

You are using the var ButtonsID wrong.

Try doing something like:

PHP Code:

//Make a global var
new g_iButtons[MAX_BUTTONS],
       
g_iButtonCounter;


new 
sData[128];
    if(
iFileHandle)
    {
        while(!
feof(iFileHandle))
        {
            
fgets(iFileHandlesDatacharsmax(sData)); // Read data to a local variable sData
            
trim(sData);

            
g_iButtons[g_iButtonCounter] = str_to_numsData ); // This will hold your button id

            
g_iButtonCounter++; // Count the number of buttons, also use it to index an array in the line above
        
}

        
fclose(iFileHandle);
    }
    else
    {
        
set_fail_state("Couldn't read from a file");
    }


That is if you don't feel comfortable using cellarrays

PurposeLessx 06-16-2018 17:15

Re: Block Button ID
 
You mean this? I tried to make it correctly. Can I use g_iButtons[g_iButtonCounter] to find that is equal to ent (Button I use).

Spoiler

maqi 06-16-2018 17:20

Re: Block Button ID
 
I hope you understand what we are doing and not just copy pasting tho :D

Now, You read the file correctly, you wan't to check if a player pushed a button from your array right ?

You can't use g_iButtons[ButtonIDs], because ButtonIDs is just a counter ( You should change its name tho ), so if ButtonIDs == 3, You would just be getting iButtons[3], but in our example it would cause an index out of bounds error anyway.

So what you need to use is loop through all g_iButtons and check if any of them match.

PurposeLessx 06-16-2018 17:24

Re: Block Button ID
 
Can you give a example to me? I cannot understand how I should do. (So I understand what we have done) :)
What I should use?

PHP Code:

if(ent ==  not g_iButtons[ButtonIDs]  so what g_iButtons[...] 

I guess I don't understand with no example (my english is terrible bad :))


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

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