AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Give access to menu, Small problem :) (https://forums.alliedmods.net/showthread.php?t=293871)

xTr3m3r 02-13-2017 06:27

Give access to menu, Small problem :)
 
Hello there!

So I made a menu from which you can give any player some flags with just aiming at him and a text is shown but the small problem I have is when I aim at the air (not a player) and try to give these flags it says the server name and that the it must be alive to get these flags :D

These are the things I check:

PHP Code:

if (is_user_connected(id) && is_user_alive(player) && get_user_flags(player) & ACCESS_ADMIN_LEVEL)
            {
                
client_print(idprint_chat"%s %s has got  access already."PrefixszPlayerName);
            }
            else if(!
is_user_alive(player))
            {
                
client_print(idprint_chat"%s %s must be alive to get access."PrefixszPlayerName);
            } 

Any idea how do I fix that?

OciXCrom 02-13-2017 07:58

Re: Give access to menu, Small problem :)
 
Check if the targeted entity is a connected player.

xTr3m3r 02-13-2017 13:27

Re: Give access to menu, Small problem :)
 
Well, is_user_connected(id) does that, doesn't it?

OciXCrom 02-13-2017 13:31

Re: Give access to menu, Small problem :)
 
You check "id" (yourself), not the targeted player, which is "player" in this case. Basically you only need is_user_connected(player) and the flag check. You can't possibly aim a dead player, so you don't need is_user_alive and there's definitely no need to check if you are connected.

xTr3m3r 02-13-2017 14:28

Re: Give access to menu, Small problem :)
 
I corrected that error, but still the message is displayed.

Also I give access this way:

PHP Code:

new flags read_flags("u");
                
set_user_flags(playerflags);
                
                
client_print(playerprint_chat"%s You now have access. Enjoy!"Prefix);
                
client_print(idprint_chat"%s %s has access now."PrefixszPlayerName); 

It gives the player U flag and when he reconnects he no longer has access - which is perfect for me,
but when I give acces and the player doesnt reconnect and just stays in the server he has access for random time from 2 to 10 minutes and then it dissappears (the access). How can I make it only when he leaves the server to take his given access?

EDIT: I tried removing the is user alive, and now It says that it gives ME access to the menu and I already got access at the same time

xTr3m3r 02-13-2017 14:33

Re: Give access to menu, Small problem :)
 
PHP Code:

GiveAccess(id)
{
    if (
get_user_flags(id) & ACCESS_ADMIN_LEVEL)
    {
        new 
playerbodyszPlayerName[32];
        
get_user_aiming(idplayerbody);
        
get_user_name(playerszPlayerName32);
        
        if(
get_user_flags(id) & ACCESS_ADMIN_LEVEL)
        {
            if (
is_user_connected(player) && get_user_flags(player) & ACCESS_ADMIN_LEVEL)
            {
                
client_print(idprint_chat"%s %s has got access already."PrefixszPlayerName);
            }
            else
            {      
                new 
flags read_flags("u");
                
set_user_flags(playerflags);
                
                
client_print(playerprint_chat"%s You now have access. Enjoy!"Prefix);
                
client_print(idprint_chat"%s %s has access now."PrefixszPlayerName);
            }
        }
    }


This is the whole GiveAccess script.

OciXCrom 02-13-2017 15:34

Re: Give access to menu, Small problem :)
 
Why are you checking the flags 3 times?!

PHP Code:

GiveAccess(id)
{
    if (
get_user_flags(id) & ACCESS_ADMIN_LEVEL)
    {
        new 
playerbody;
        
get_user_aiming(idplayerbody);
        
        if (
is_user_connected(player))
        {
            new 
szPlayerName[32];
            
get_user_name(playerszPlayerName32);

            if(
get_user_flags(player) & ACCESS_ADMIN_LEVEL)
            {
                
client_print(idprint_chat"%s %s has got access already."PrefixszPlayerName);
            }
            else
            {      
                new 
flags read_flags("u");
                
set_user_flags(playerflags);
                
                
client_print(playerprint_chat"%s You now have access. Enjoy!"Prefix);
                
client_print(idprint_chat"%s %s has access now."PrefixszPlayerName);
            }
        }
    }


If this doesn't work, the error is somewhere else in the plugin, so post the full code.

Black Rose 02-13-2017 15:42

Re: Give access to menu, Small problem :)
 
I don't really understand your error. Code does exactly what you tell it to, so the problem that it would print both messages is impossible. Unless you're sending the command twice.

I don't know of anything that would strip the flags unless you have conflicting plugins.

Code:
GiveAccess(id) {     if ( ! ( get_user_flags(id) & ACCESS_ADMIN_LEVEL ) )         return;     new player, body;     get_user_aiming(id, player, body);     if ( ! player || ! is_user_connected(player) )         return;     new szPlayerName[32]     get_user_name(player, szPlayerName, charsmax(szPlayerName));     new tempFlags = get_user_flags(player);     if ( tempFlags & ACCESS_ADMIN_LEVEL) {         client_print(id, print_chat, "%s %s has got access already.", Prefix, szPlayerName);         return;     }     set_user_flags(player, tempFlags & read_flags("u"));     client_print(player, print_chat, "%s You now have access. Enjoy!", Prefix);     client_print(id, print_chat, "%s %s has access now.", Prefix, szPlayerName); }
Just a side note: Keeping the code structure flat enables you to more easily handle different outcomes and understand the code.

xTr3m3r 02-14-2017 01:16

Re: Give access to menu, Small problem :)
 
Quote:

Originally Posted by Black Rose (Post 2495227)
I don't really understand your error. Code does exactly what you tell it to, so the problem that it would print both messages is impossible. Unless you're sending the command twice.

I don't know of anything that would strip the flags unless you have conflicting plugins.

Code:
GiveAccess(id) {     if ( ! ( get_user_flags(id) & ACCESS_ADMIN_LEVEL ) )         return;     new player, body;     get_user_aiming(id, player, body);     if ( ! player || ! is_user_connected(player) )         return;     new szPlayerName[32]     get_user_name(player, szPlayerName, charsmax(szPlayerName));     new tempFlags = get_user_flags(player);     if ( tempFlags & ACCESS_ADMIN_LEVEL) {         client_print(id, print_chat, "%s %s has got access already.", Prefix, szPlayerName);         return;     }     set_user_flags(player, tempFlags & read_flags("u"));     client_print(player, print_chat, "%s You now have access. Enjoy!", Prefix);     client_print(id, print_chat, "%s %s has access now.", Prefix, szPlayerName); }
Just a side note: Keeping the code structure flat enables you to more easily handle different outcomes and understand the code.

Works perfectly. Thanks!


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

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