AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Stop set_task if menu doesn't exist. (https://forums.alliedmods.net/showthread.php?t=207841)

Unkolix 02-07-2013 11:38

Stop set_task if menu doesn't exist.
 
I would like to remake that code below (it makes the menu shutdown after 10 seconds if it's called) not to turn of after 10 seconds if the menu is already closed...

I mean when you call the menu and you close it, then you call it again, it will shutdown faster then 10 seconds because the task is still active from the first call.

PHP Code:

public Showrod(id)
{
    
set_task(10.0"CancelMenu"id);
    
get_mapnameszMap charsmaxszMap ) );
    for( new 
sizeofmapnames ) ; i++ )
    {
        if ( 
containiszMap mapnames] ) !=-1  )
        return;
    }
    new 
menu menu_create("\rVIP'u meniu:""Pressedrod");
    
    
menu_additem(menu"\yM4A1 su Deagle""1"0);
    
menu_additem(menu"\yAK47 su Deagle""2"0);
    
    
menu_setprop(menuMPROP_EXITMEXIT_ALL);
    
menu_display(idmenu0);
}
public 
Pressedrod(idmenuitem)
{
    if( 
item == MENU_EXIT )
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }
    new 
data[6], szName[64];
    new 
accesscallback;
    
menu_item_getinfo(menuitemaccessdata,charsmax(data), szName,charsmax(szName), callback);
    new 
key str_to_num(data);
    switch(
key)
    {
    case 
1: { 
        
StripWeapons(idPrimary);
        
StripWeapons(idSecondary);
        
give_item(id,"weapon_m4a1")
        
give_item(id,"ammo_556nato")
        
give_item(id,"ammo_556nato")
        
give_item(id,"ammo_556nato")
        
give_item(id,"weapon_deagle")
        
give_item(id,"ammo_50ae")
        
give_item(id,"ammo_50ae")
        
give_item(id,"ammo_50ae")
        
give_item(id,"ammo_50ae")
        
give_item(id,"ammo_50ae")
        
give_item(id,"ammo_50ae")
        
give_item(id,"ammo_50ae")
        
give_item(id,"weapon_knife")
        
give_item(id,"weapon_hegrenade")
        
give_item(id"weapon_flashbang");
        
give_item(id"weapon_flashbang");
        
give_item(id"weapon_smokegrenade");
        
give_item(id"item_assaultsuit");
        
give_item(id"item_thighpack");
        
client_print(idprint_center"Pasiemei M4A1 su Deagle!")
        
gbUsed[id] = true;
        }
    case 
2: { 
        
StripWeapons(idPrimary);
        
StripWeapons(idSecondary);
        
give_item(id,"weapon_ak47")
        
give_item(id,"ammo_762nato")
        
give_item(id,"ammo_762nato")
        
give_item(id,"ammo_762nato")
        
give_item(id,"weapon_deagle")
        
give_item(id,"ammo_50ae")
        
give_item(id,"ammo_50ae")
        
give_item(id,"ammo_50ae")
        
give_item(id,"ammo_50ae")
        
give_item(id,"ammo_50ae")
        
give_item(id,"ammo_50ae")
        
give_item(id,"ammo_50ae")
        
give_item(id,"weapon_knife")
        
give_item(id,"weapon_hegrenade")
        
give_item(id"weapon_flashbang");
        
give_item(id"weapon_flashbang");
        
give_item(id"weapon_smokegrenade");
        
give_item(id"item_assaultsuit");
        
give_item(id"item_thighpack");
        
client_print(idprint_center"Pasiemei AK47 su Deagle!")
        
gbUsed[id] = true;
        }
    }
    
menu_destroy(menu);
    return 
PLUGIN_CONTINUE
}

public 
CancelMenu(id)
{
    
show_menu(id0"^n"1);



Doc-Holiday 02-07-2013 14:52

Re: Stop set_task if menu doesn't exist.
 
Make sure you include... This should work if you use the code ive changed if not post full code and ill fix until i get a compiled version.


PHP Code:

#include <cstrike>
#include <hamsandwich>
#include <fakemeta>

const OFFSET_PRIMARYWEAPON 116
const 
OFFSET_C4_SLOT 372

new 
g_iMenu;

public 
Showrod(id)

    
set_task(10.0"CancelMenu"id);
    
get_mapnameszMap charsmaxszMap ) ); 
    for( new 
sizeofmapnames ) ; i++ ) 
    { 
        if ( 
containiszMap mapnames] ) !=-1  
            return; 
    } 
    
g_iMenu menu_create("\rVIP'u meniu:""Pressedrod"); 
     
    
menu_additem(g_iMenu"\yM4A1 su Deagle""1"0); 
    
menu_additem(g_iMenu"\yAK47 su Deagle""2"0); 
     
    
menu_setprop(g_iMenuMPROP_EXITMEXIT_ALL); 
    
menu_display(idg_iMenu0); 

public 
Pressedrod(idmenuitem

    if( 
item == MENU_EXIT 
    { 
        
menu_destroy(menu); 
        return 
PLUGIN_HANDLED
    } 
    new 
data[6], szName[64]; 
    new 
accesscallback
    
menu_item_getinfo(menuitemaccessdata,charsmax(data), szName,charsmax(szName), callback); 
    new 
key str_to_num(data);
    
    
StripUserWeapons(id);
    
    switch(
key
    {
        case 
1
        {
            
give_item(id,"weapon_m4a1"
            
cs_set_user_bpammo(idCSW_M4A190);
            
            
give_item(id,"weapon_deagle"
            
cs_set_user_bpammo(idCSW_DEAGLE21);
            
            
give_item(id,"weapon_hegrenade"
            
give_item(id"weapon_flashbang"); 
            
give_item(id"weapon_flashbang"); 
            
give_item(id"weapon_smokegrenade"); 
            
            
cs_set_user_armor(id120CS_ARMOR_VESTHELM);
            
            if(
cs_get_user_team(id) == CS_TEAM_CT)
                
cs_set_user_defuse(id1);
                
            
client_print(idprint_center"Pasiemei M4A1 su Deagle!"
            
gbUsed[id] = true
        } 
        case 
2
        {  
            
give_item(id,"weapon_ak47"
            
cs_set_user_bpammo(idCSW_AK4790);
            
            
give_item(id,"weapon_deagle"
            
cs_set_user_bpammo(idCSW_DEAGLE21);
            
            
give_item(id,"weapon_hegrenade"
            
give_item(id"weapon_flashbang"); 
            
give_item(id"weapon_flashbang"); 
            
give_item(id"weapon_smokegrenade"); 
            
            
cs_set_user_armor(id120CS_ARMOR_VESTHELM);
            
            if(
cs_get_user_team(id) == CS_TEAM_CT)
                
cs_set_user_defuse(id1);
            
            
client_print(idprint_center"Pasiemei AK47 su Deagle!"
            
gbUsed[id] = true
        } 
    }
    
remove_task(id); //Stops the timer
    
menu_destroy(menu); 
    return 
PLUGIN_CONTINUE 


public 
CancelMenu(id

    
menu_destroy(g_iMenu);
}

StripUserWeapons(id

    new 
iC4Ent get_pdata_cbase(idOFFSET_C4_SLOT); 
     
    if( 
iC4Ent 
    { 
        
set_pdata_cbase(idOFFSET_C4_SLOTFM_NULLENT); 
    } 

    
strip_user_weapons(id); 
    
give_item(id"weapon_knife"); 
    
set_pdata_int(idOFFSET_PRIMARYWEAPON0); 

    if( 
iC4Ent 
    { 
        
entity_set_int(idEV_INT_weaponsentity_get_int(idEV_INT_weapons) | (1<<CSW_C4)); 
        
set_pdata_cbase(idOFFSET_C4_SLOTiC4Ent); 
        
cs_set_user_bpammo(idCSW_C41); 
        
cs_set_user_plant(id1); 
    } 
    return 
PLUGIN_HANDLED


I also recommend something like this for the defuser otherwise it gives it all the time.

PHP Code:


new bool:g_bHasBombSite;

//in plugin init
if( find_ent_by_class(-1"func_bomb_target") > || find_ent_by_class(-1"info_bomb_target") > )
{
        
g_bHasBombSitetrue;
}

//Where you give the defuse kits
if(g_bHasBombSite && cs_get_user_team(id) == CS_TEAM_CT)
{
        
cs_set_user_defuse(id1);



Unkolix 02-07-2013 15:06

Re: Stop set_task if menu doesn't exist.
 
I am using stripweapons.inc, it strips only the weapons that are in certain slot.

While compiling I get undefined symbol find_ent_by_class...

Thanks for the defuser suggestion!

EDIT:
Can you make that thing with the bombsite in one code? It's hard to make them into 1

Doc-Holiday 02-07-2013 16:15

Re: Re: Stop set_task if menu doesn't exist.
 
Quote:

Originally Posted by Unkolix (Post 1889451)
I am using stripweapons.inc, it strips only the weapons that are in certain slot.

While compiling I get undefined symbol find_ent_by_class...

Thanks for the defuser suggestion!

EDIT:
Can you make that thing with the bombsite in one code? It's hard to make them into 1

Find went by class name is engine. I forgot to have you add that. I have an fm stock for it but I'm not at home. And place the first if statement into the public plugin_init() the other part goes in your switch statement.

If your going to give the same stuff only thing different is the rifles. You can pull all of it out and have your switch only contain the rifle stuff the rest can go under it.

As for the strip weapons. The stock is easier than an include when you release your plugin. If you do

Unkolix 02-07-2013 16:26

Re: Stop set_task if menu doesn't exist.
 
I just realized, that the code you written removes task after the player chose something. And I needed that it would remove task if the player close it or for example a vote appears over the menu. EDIT: I believe that the remove task should be something with menu_display function. How to check if menu_dislay is true or the menu_display exist?

Doc-Holiday 02-08-2013 02:53

Re: Re: Stop set_task if menu doesn't exist.
 
Quote:

Originally Posted by Unkolix (Post 1889520)
I just realized, that the code you written removes task after the player chose something. And I needed that it would remove task if the player close it or for example a vote appears over the menu. EDIT: I believe that the remove task should be something with menu_display function. How to check if menu_dislay is true or the menu_display exist?

I don't think you can catch when a different menu covers that one in fact there is talk in the snippet section that we should use his include because of a memory leak

Unkolix 02-08-2013 03:11

Re: Stop set_task if menu doesn't exist.
 
I don't need to catch that. What I really need is to ckek if menu displays.

Doc-Holiday 02-08-2013 09:15

Re: Re: Stop set_task if menu doesn't exist.
 
Quote:

Originally Posted by Unkolix (Post 1889909)
I don't need to catch that. What I really need is to ckek if menu displays.

And like I said you can't. The menu when closed due to an other menu doesn't call anything. Like I said check out that guys include. It correctly destroys the menu so if it destroys the menu them remove the task.

He explains exactly why what you want won't work without the include.

He's got a forward that's called when the menu is destroyed by another menu but not every menu uses this method yet so it still wouldn't work.

Maybe someone with better knowledge can figure something out but afaik there is no way

Unkolix 02-08-2013 09:24

Re: Stop set_task if menu doesn't exist.
 
I've coded that so you could use the menu only once per round and your code just stops the task if the player chooses something then the task is removed.

Btw, something wrond with your StripUserWeapons(id)

Doc-Holiday 02-08-2013 12:45

Re: Re: Stop set_task if menu doesn't exist.
 
Quote:

Originally Posted by Unkolix (Post 1890062)
I've coded that so you could use the menu only once per round and your code just stops the task if the player chooses something then the task is removed.

Btw, something wrond with your StripUserWeapons(id)

And that something is? My bones plugin uses it and works perfect.

Secondly them the remove task there is pointless but in the code you gave us you can't tell that.


All times are GMT -4. The time now is 20:33.

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