AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Help admin acces laser sight (https://forums.alliedmods.net/showthread.php?t=329294)

Barlap 12-17-2020 14:46

Help admin acces laser sight
 
Hello guys can somebody help me with this code?
It's a laser sight plugin, i want to make it work only for users with "t" flag, i tried something but not working, can you check the code bellow?
Code:

#include <amxmodx>

#define MAX_TEAMS 4
#define VIPICE        ADMIN_LEVEL_H

new sprite
new numwpns
new weapons[32]

new ls_enabled
new ls_line
new ls_pvis
new ls_wpns
new ls_rgb

new numteams
new rgb[3][MAX_TEAMS]

public plugin_init()
{
        register_plugin("Lasers","0.5","Toster v2.1")
       
        ls_enabled = register_cvar("ls_enabled", "1")
        ls_line = register_cvar("ls_line", "1")
        ls_pvis = register_cvar("ls_pvis", "0")
        ls_wpns = register_cvar("ls_wpns", "0;1;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;19;20;21;22;23;24;25;26;27;28;29;30;")
        ls_rgb = register_cvar("ls_rgb", "255 0 0;")
       
        register_clcmd("ls_refresh", "getcvars", ADMIN_KICK)
        register_clcmd("ls_getteam", "getteam", ADMIN_KICK)
        register_clcmd("ls_getwpn", "getwpn", ADMIN_KICK)
       
        getcvars()
}

public getwpn(id)
{
        new clip, ammo
        new w = get_user_weapon(id, clip, ammo)
       
        console_print(id, "[ls] Your current weapon's id: %d", w)
        return PLUGIN_HANDLED
}

public getteam(id)
{
        new t = get_user_team(id)
        console_print(id, "[ls] Your current team's id: %d", t)
        return PLUGIN_HANDLED
}

public getcvars()
{
        getwpns()
        getrgb()
       
        return PLUGIN_HANDLED
}

public getrgb()
{
        new txt[MAX_TEAMS * 16]
        new team[MAX_TEAMS][16]
        new tmp[4]
       
        get_pcvar_string(ls_rgb, txt, 64)
        add(txt, 64, " ")
       
        for(numteams = 0; contain(txt, ";")!=-1; numteams++)
        {
          strtok(txt, team[numteams], 16, txt, MAX_TEAMS * 16, ';')
         
          for(new i=0; i<2; i++)
          {
            strtok(team[numteams], tmp, 4, team[numteams], 16, ' ')
            rgb[i][numteams] = str_to_num(tmp)
          }
          trim(team[numteams])
          rgb[2][numteams] = str_to_num(team[numteams])
         
          trim(txt)
        }
}

public getwpns()
{
        new txt[64]
        new wpns[3]
       
        get_pcvar_string(ls_wpns, txt, 64)
        add(txt, 64, " ")
       
        for(numwpns = 0; contain(txt, ";")!=-1; numwpns++)
        {
          strtok(txt, wpns, 3, txt, 64, ';')
          weapons[numwpns] = str_to_num(wpns)
        }
}

public plugin_precache()
{
        sprite = precache_model("sprites/white.spr")
}

public client_PreThink(id)
{
        if(!is_user_alive(id)||get_pcvar_num(ls_enabled)!=1) return PLUGIN_HANDLED
       
        new clip, ammo
        new w = get_user_weapon(id, clip, ammo)
       
        for(new i=0; i<numwpns; i++) if(w == weapons[i]) return PLUGIN_HANDLED
       
        new e[3]
        new t = get_user_team(id)
       
        get_user_origin(id, e, 3)
       
        if(get_pcvar_num(ls_pvis) == 0)message_begin( MSG_BROADCAST,SVC_TEMPENTITY)
        else message_begin( MSG_ONE_UNRELIABLE,SVC_TEMPENTITY, _, id)
       
        if(get_user_flags(id) == VIPICE || get_pcvar_num(ls_line) != 0)
        {
          write_byte (TE_BEAMENTPOINT)
          write_short(id | 0x1000)
          write_coord (e[0])
          write_coord (e[1])
          write_coord (e[2])
        }
        else
        {
          write_byte (0)
          write_coord (e[0] + 1)
          write_coord (e[1] + 1)
          write_coord (e[2] + 1)
          write_coord (e[0] - 1)
          write_coord (e[1] - 1)
          write_coord (e[2] - 1)
        }
       
        write_short(sprite)
        write_byte (0)                                                     
        write_byte (10)                                                   
        write_byte (1)
        write_byte (5)                                                 
        write_byte (0)   
       
        if(numteams>=t) 
        {
          write_byte (rgb[0][t-1])       
          write_byte (rgb[1][t-1])
          write_byte (rgb[2][t-1])
        }
        else
        {
          write_byte (rgb[0][0])       
          write_byte (rgb[1][0])
          write_byte (rgb[2][0])
        }
       
        write_byte (255)                                                   
        write_byte (10)                                                     
        message_end()
       
        return PLUGIN_HANDLED
}


OciXCrom 12-17-2020 14:55

Re: Help admin acces laser sight
 
get_user_flags(id) & VIP_ICE

Barlap 12-17-2020 16:24

Re: Help admin acces laser sight
 
Not working, all users can use the laser sight

OciXCrom 12-17-2020 17:33

Re: Help admin acces laser sight
 
That's because the check is not in the proper place. Place it in the beginning of the function and stop it if it's false.

+ARUKARI- 12-17-2020 20:48

Re: Help admin acces laser sight
 
You said.
Quote:

It's a laser sight plugin, i want to make it work only for users with "t" flag,
but.
Code:

#define VIPICE        ADMIN_LEVEL_H

Natsheh 12-17-2020 21:24

Re: Help admin acces laser sight
 
inside client_prethink add whats highlighted in red.

Code:

if(!is_user_alive(id)||!(get_user_flags(id) & VIP_ICE)||get_pcvar_num(ls_enabled)!=1) return PLUGIN_HANDLED

OciXCrom 12-18-2020 07:38

Re: Help admin acces laser sight
 
Quote:

Originally Posted by +ARUKARI- (Post 2729121)
You said.


but.
Code:

#define VIPICE        ADMIN_LEVEL_H

There's nothing wrong there. ADMIN_LEVEL_H is flag "t".

+ARUKARI- 12-18-2020 07:47

Re: Help admin acces laser sight
 
omg, Looks like I've been wrong for 16 years.

Natsheh 12-18-2020 10:07

Re: Help admin acces laser sight
 
lmao..

that's alot period of time....

Barlap 12-18-2020 12:40

Re: Help admin acces laser sight
 
Thx guys


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

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