Raised This Month: $32 Target: $400
 8% 

Solved multi bools


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LearninG
Senior Member
Join Date: Apr 2019
Location: Iran
Old 08-16-2019 , 07:37   multi bools
Reply With Quote #1

Hi,
How to use one bool in two plugins.
Example : execute a function in plugin 1 if a bool is set to true in plugin 2.
thanks.

Last edited by LearninG; 08-17-2019 at 03:42.
LearninG is offline
thEsp
BANNED
Join Date: Aug 2017
Old 08-16-2019 , 07:54   Re: multi bools
Reply With Quote #2

Use natives.
thEsp is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 08-16-2019 , 08:38   Re: multi bools
Reply With Quote #3

Or you can declare the bool as "public" and retreive it via "get_xvar_num". But, yes, it's probably better to use natives.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
LearninG
Senior Member
Join Date: Apr 2019
Location: Iran
Old 08-16-2019 , 12:26   Re: multi bools
Reply With Quote #4

Quote:
Originally Posted by OciXCrom View Post
Or you can declare the bool as "public" and retreive it via "get_xvar_num". But, yes, it's probably better to use natives.
other plugin does not read bool value when i change it in , Event_NewRound , client_putinserver , client_disconnected , etc. it only reads this :
PHP Code:
public bool:has_anti_bazooka[33
PHP Code:
/*
             Description :
                            An extra item that is made for zombies , which will reduce "Bazooka" damage.
*/

#include <amxmodx>
#include <zombieplague>

#if AMXX_VERSION_NUM < 183
#include <colorchat>
#define Red print_team_red
#define Blue print_team_blue
#define Grey print_team_grey
#define DontChange print_team_default
#endif

#define VERSION         "1.0"


new const NAME[] = "Anti-Bazooka"


new damage_reduce



new g_item


public bool:has_anti_bazooka[33]

public 
plugin_init()
{
    
register_plugin("Anti-Bazooka" VERSION "LearninG")
    

    
register_event("HLTV""Event_NewRound""a""1=0""2=0");
    

    
damage_reduce register_cvar("zp_anti_bazooka_damage_reduce" "300")
    

    
g_item zp_register_extra_item(NAME 25 ZP_TEAM_ZOMBIE)
}

public 
zp_extra_item_selected(playeritemid)
{

    if (
itemid == g_item && has_anti_bazooka[player])
    {
        return 
ZP_PLUGIN_HANDLED
    
}
    else if (
itemid == g_item && is_user_alive(player))
    {
        
client_print_color(playerprint_chat "^4[ZP]^1 You bought Anti-Bazooka! [%2.1f damage reduce]"get_pcvar_num(damage_reduce))
        
has_anti_bazooka[player] = true
    
}
    return 
PLUGIN_CONTINUE
}

public 
Event_NewRound()
{
    static 
players[32], numid
    get_players
(playersnum)
    for (new 
0numi++)
    {
        
id players[i]
        
has_anti_bazooka[id] = false
    
}
}

public 
client_disconnected(id)
{
    
has_anti_bazooka[id] = false
}

public 
client_putinserver(id)
{
    
has_anti_bazooka[id] = false

any suggestion ?
LearninG is offline
raizo11
BANNED
Join Date: Dec 2013
Location: https://t.me/pump_upp
Old 08-16-2019 , 13:13   Re: multi bools
Reply With Quote #5

Code:
/* 
             Description : 
                            An extra item that is made for zombies , which will reduce "Bazooka" damage. 
*/ 

#include <amxmodx> 
#include <zombieplague> 

#if AMXX_VERSION_NUM < 183 
#include <colorchat> 
#define Red print_team_red 
#define Blue print_team_blue 
#define Grey print_team_grey 
#define DontChange print_team_default 
#endif 

#define VERSION         "1.0" 


new const NAME[] = "Anti-Bazooka" 


new damage_reduce 



new g_item 


public bool:has_anti_bazooka[33] 

public plugin_init() 
{ 
    register_plugin("Anti-Bazooka" , VERSION , "LearninG") 
     

    register_event("HLTV", "Event_NewRound", "a", "1=0", "2=0"); 
     

    damage_reduce = register_cvar("zp_anti_bazooka_damage_reduce" , "300") 
     

    g_item = zp_register_extra_item(NAME , 25 , ZP_TEAM_ZOMBIE) 
} 

public plugin_natives()
{
    register_library("bazooka")
    register_native("is_user_bazooka","_is_user_bazooka")
}

public _is_user_bazooka(plugin, iParams)
{
    new id = get_param(1)
    if(!is_user_connected(id))
        return PLUGIN_CONTINUE
    if(has_anti_bazooka[id])
        return PLUGIN_HANDLED
    return PLUGIN_CONTINUE
}


public zp_extra_item_selected(player, itemid) 
{ 

    if (itemid == g_item && has_anti_bazooka[player]) 
    { 
        return ZP_PLUGIN_HANDLED 
    } 
    else if (itemid == g_item && is_user_alive(player)) 
    { 
        client_print_color(player, print_chat , "^4[ZP]^1 You bought Anti-Bazooka! [%2.1f damage reduce]", get_pcvar_num(damage_reduce)) 
        has_anti_bazooka[player] = true 
    } 
    return PLUGIN_CONTINUE 
} 

public Event_NewRound() 
{ 
    static players[32], num, id 
    get_players(players, num) 
    for (new i = 0; i < num; i++) 
    { 
        id = players[i] 
        has_anti_bazooka[id] = false 
    } 
} 

public client_disconnected(id) 
{ 
    has_anti_bazooka[id] = false 
} 

public client_putinserver(id) 
{ 
    has_anti_bazooka[id] = false 
}
Code:
#if defined _bazooka_included
  #endinput
#endif
#define _bazooka_included


native is_user_bazooka(index);
Code:
#include <bozooka>

public something_else(id)
{
    if(is_user_bazooka(id))
    {
        // Put the command here
    }
}

Last edited by raizo11; 08-16-2019 at 13:16.
raizo11 is offline
Send a message via ICQ to raizo11 Send a message via AIM to raizo11 Send a message via MSN to raizo11 Send a message via Yahoo to raizo11 Send a message via Skype™ to raizo11
Natsheh
Veteran Member
Join Date: Sep 2012
Old 08-16-2019 , 13:29   Re: multi bools
Reply With Quote #6

That's because you have to retrieve the value using get_xvar_num(var_index)

And to get the var_index you should use this native get_xvar_id with the name of the variable in the 1st param to return a unquie address of the variable.

also declare the variable with 1 cell and use bitsum values to check the player whether has a bazooka or not.

Example :
PHP Code:
// Core plugin

public iBits_HAS_ANTI_BAZOOKA // using all chars capital's for readability to determine the variable is on long scoop


// External plugin

new VarIndexHasAntiBazooka;

public 
plugin_native()
{
     
VarIndexHasAntiBazooka get_xvar_id("iBits_HAS_ANTI_BAZOOKA"
}

MyFunction(id)
{
        if( 
get_xvar_num(VarIndexHasAntiBazooka) & (1<<id&31))
             
//code...
        // TO update the public variable value from the external plugin you have to use set_xvar_num(VarIndexHasAntiBazooka, 0); native that mean the public variable is now holding the value of 0. 
Note :
XVars only support cells (integers, floats, bools, etc.).
Arrays (including strings, since strings are arrays of characters) cannot be used with XVars, in the other hand
Make sure your public variable name is unique and its not repeated that will make confusion if it did.



Again if you have read the documentation or even searched you won't need to make a useless thread.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 08-17-2019 at 09:44.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Reply


Thread Tools
Display Modes

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 12:05.


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