Raised This Month: $ Target: $400
 0% 

Solved Give access to menu, Small problem :)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xTr3m3r
Member
Join Date: Feb 2010
Old 02-13-2017 , 06:27   Give access to menu, Small problem :)
Reply With Quote #1

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

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?

Last edited by xTr3m3r; 02-14-2017 at 01:16.
xTr3m3r is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 02-13-2017 , 07:58   Re: Give access to menu, Small problem :)
Reply With Quote #2

Check if the targeted entity is a connected player.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
xTr3m3r
Member
Join Date: Feb 2010
Old 02-13-2017 , 13:27   Re: Give access to menu, Small problem :)
Reply With Quote #3

Well, is_user_connected(id) does that, doesn't it?
xTr3m3r is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 02-13-2017 , 13:31   Re: Give access to menu, Small problem :)
Reply With Quote #4

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.
__________________

Last edited by OciXCrom; 02-13-2017 at 13:32.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
xTr3m3r
Member
Join Date: Feb 2010
Old 02-13-2017 , 14:28   Re: Give access to menu, Small problem :)
Reply With Quote #5

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

Last edited by xTr3m3r; 02-13-2017 at 14:34.
xTr3m3r is offline
xTr3m3r
Member
Join Date: Feb 2010
Old 02-13-2017 , 14:33   Re: Give access to menu, Small problem :)
Reply With Quote #6

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.

Last edited by xTr3m3r; 02-13-2017 at 14:34.
xTr3m3r is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 02-13-2017 , 15:34   Re: Give access to menu, Small problem :)
Reply With Quote #7

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.
__________________

Last edited by OciXCrom; 02-13-2017 at 15:35.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 02-13-2017 , 15:42   Re: Give access to menu, Small problem :)
Reply With Quote #8

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.
__________________

Last edited by Black Rose; 02-13-2017 at 15:43.
Black Rose is offline
xTr3m3r
Member
Join Date: Feb 2010
Old 02-14-2017 , 01:16   Re: Give access to menu, Small problem :)
Reply With Quote #9

Quote:
Originally Posted by Black Rose View Post
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!

Last edited by xTr3m3r; 02-14-2017 at 01:16.
xTr3m3r 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 21:01.


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