AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help for script.. (https://forums.alliedmods.net/showthread.php?t=325465)

Aleku. 06-23-2020 03:11

Help for script..
 
Hey, I would like you to help me a little.. I would like the last 2 weapons to be just for VIP and if he doesn't have a vip, a message will come in chat... what code should i put?

Code:

menu_additem(Menu, "\rM4A1", "1", 0)
                menu_additem(Menu, "\rAK47", "2", 0)
                menu_additem(Menu, "M3", "3", 0)
                menu_additem(Menu, "Aug", "4", 0)
                menu_additem(Menu, "Famas", "5", 0)
                menu_additem(Menu, "\rMP5 Navy \w- \r[\yACCES V.I.P\r]", "6", VIP_LEVEL_ACCES)
                menu_additem(Menu, "\rXM1014 \w- \r[\yACCES V.I.P\r]", "7", VIP_LEVEL_ACCES)
               
                menu_setprop(Menu, MPROP_EXIT, MEXIT_ALL);
                menu_display(id, Menu, 0);


Shadows Adi 06-23-2020 05:57

Re: Help for script..
 
Code:
        menu_additem(Menu, "\rM4A1", "1")         menu_additem(Menu, "\rAK47", "2")         menu_additem(Menu, "M3", "3")         menu_additem(Menu, "Aug", "4")         menu_additem(Menu, "Famas", "5")         if(get_user_flags(id) & VIP_LEVEL_ACCES)         {             menu_additem(Menu, "\rMP5 Navy \w- \r[\yACCES V.I.P\r]", "6")             menu_additem(Menu, "\rXM1014 \w- \r[\yACCES V.I.P\r]", "7")         }                 menu_setprop(Menu, MPROP_EXIT, MEXIT_ALL);         menu_display(id, Menu, 0);
and you need to do the same thing in the menu handler.

fysiks 06-23-2020 20:28

Re: Help for script..
 
You can use a menu callback if you want to have the items shown but be disabled if they don't have the requisite flag. Callback example found here.

If you want them to see a chat message then you have to let them select the item and then check their flags in the handler and show the message if needed. Optionally, you can re-show the menu if you want.

Aleku. 06-24-2020 07:32

Re: Help for script..
 
[QUOTE=Shadows Adi;2706923][pawn]
menu_additem(Menu, "\rM4A1", "1")
menu_additem(Menu, "\rAK47", "2")
menu_additem(Menu, "M3", "3")
menu_additem(Menu, "Aug", "4")
menu_additem(Menu, "Famas", "5")
if(get_user_flags(id) & VIP_LEVEL_ACCES)
{
menu_additem(Menu, "\rMP5 Navy \w- \r[\yACCES V.I.P\r]", "6")
menu_additem(Menu, "\rXM1014 \w- \r[\yACCES V.I.P\r]", "7")
}

menu_setprop(Menu, MPROP_EXIT, MEXIT_ALL);
menu_display(id, Menu, 0);


Sorry, but you could like that when you're not a VIP to show you the menu but can't you take it?

In this code, if you don't have a VIP, they don't show you the weapons from the VIP, I want them to appear but they can't take them.

Shadows Adi 06-24-2020 08:25

Re: Help for script..
 
Quote:

Originally Posted by Aleku. (Post 2707089)
Sorry, but you could like that when you're not a VIP to show you the menu but can't you take it?

In this code, if you don't have a VIP, they don't show you the weapons from the VIP, I want them to appear but they can't take them.

Then put
Code:
if(get_user_flags(id) & VIP_LEVEL_ACCES)
in the handler of menu.

fysiks 06-24-2020 23:12

Re: Help for script..
 
Quote:

Originally Posted by Aleku. (Post 2707089)
I want them to appear but they can't take them.

The proper way to handle this is to use callbacks like I said in my previous post. It should be quite simple actually. The callback function would only need to be a single line:

Code:

public menuitem_callback( id, menu, item )
{
        return (get_user_flags(id) & VIP_LEVEL_ACCESS) ? ITEM_IGNORE : ITEM_DISABLED;
}

Doing it this way will show the items but they will be grey and they can't be selected. So, it will be obvious that they exist but can't be chosen.

AnimalMonster 06-26-2020 09:10

Re: Help for script..
 
Aleku. they said wronger than you , you did good but did you define that value?
PHP Code:

#define VIP_LEVEL_ACCES ADMIN_.... 

If you did then idk, you can make in other way like in the handle
and if you didn't ,do it and your code will be working
PHP Code:

case x: if(get_user_flags(id) & VIP_LEVEL_ACCESS)
{
        
giveitem(id)
}
else 
client_print(id,print_chat,"Not Vip Member"

and btw for everyone is the next message
Every if(get_user_flags(id) & x) has to do a else after you wrote the code because then the code will let anyone use it bcs it's like without else it's creating a invisible one that does the same thing, i found out this thing when i was doing my menu. and btw you could also do like this
PHP Code:

if(get_user_flags(id) & VIP_LEVEL_ACCESS)
{
menu_additem(Menu,"lala","key")
}
else 
menu_additem(Menu,"\dlala",""

as you seen in the third param i didn't put anything else than "" so the item would do nothing and that /d will make the item look like it can't be accesed.

AnimalMonster 06-26-2020 09:18

Re: Help for script..
 
Quote:

Originally Posted by fysiks (Post 2707168)
The proper way to handle this is to use callbacks like I said in my previous post. It should be quite simple actually. The callback function would only need to be a single line:

Code:

public menuitem_callback( id, menu, item )
{
        return (get_user_flags(id) & VIP_LEVEL_ACCESS) ? ITEM_IGNORE : ITEM_DISABLED;
}

Doing it this way will show the items but they will be grey and they can't be selected. So, it will be obvious that they exist but can't be chosen.

and btw dw bcs i didn't say about you about the thing with Wronger, you showed also another simple method that can be super simple used but not everytime is needed a callback

supertrio17 06-26-2020 09:27

Re: Help for script..
 
Quote:

Originally Posted by AnimalMonster (Post 2707329)
Every if(get_user_flags(id) & x) has to do a else after you wrote the code because then the code will let anyone use it bcs it's like without else it's creating a invisible one that does the same thing, i found out this thing when i was doing my menu.

This is the funniest thing I heard, I know that you are new in coding, and that you want to show yourself, but veterans in here have more than 5 years of coding experience, so you can't teach them, what you said is not true, it will just skip that action for player who doesn't have required flags. In this case it just won't show that 2 menu items.

supertrio17 06-26-2020 09:34

Re: Help for script..
 
Easiest way to do this (that I can think of) is something like this
PHP Code:

        menu_additem(Menu"\rM4A1""1")
        
menu_additem(Menu"\rAK47""2")
        
menu_additem(Menu"M3""3")
        
menu_additem(Menu"Aug""4")
        
menu_additem(Menu"Famas""5")
        if(
get_user_flags(id) & VIP_LEVEL_ACCES)
        {
            
menu_additem(Menu"\rMP5 Navy \w- \r[\yACCES V.I.P\r]""6")
            
menu_additem(Menu"\rXM1014 \w- \r[\yACCES V.I.P\r]""7")
        }
        else
        {
            
menu_additem(Menu"\dMP5 Navy [\yACCES V.I.P]""6")
            
menu_additem(Menu"\dXM1014 [\yACCES V.I.P]""7")
        }
        
        
menu_setprop(MenuMPROP_EXITMEXIT_ALL);
        
menu_display(idMenu0); 

And than I would do this in cases:
PHP Code:

        case 6:
        {
            if(
get_user_flags(id) & VIP_LEVEL_ACCES)
            {
                
give_item(id"");
            }
            else
            {
                
WeaponMenu(id);
            }
        }
        case 
7:
        {
            if(
get_user_flags(id) & VIP_LEVEL_ACCES)
            {
                
give_item(id"");
            }
            else
            {
                
WeaponMenu(id);
            }
        } 



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

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