Raised This Month: $12 Target: $400
 3% 

Solved How to pass tagged variable to other plugins


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
davidto1995
Member
Join Date: Jul 2010
Location: hong kong
Old 04-25-2021 , 05:41   How to pass tagged variable to other plugins
Reply With Quote #1

I have the following codes in plugin A:

PHP Code:
enum PlayerClass
{

    
SDU// Human Type
    
Soldier,
    
Heavy,
    
Supporter,
    
Leader,

    
GVirusMonster// Zombie Type
    
Nemesis,
    
TVirusMonster,
    
Assassin,
    
Venom,
    
Vampire,
    
Speeder,
    
Horde,
    
Hunter

};

...

new 
PlayerClassPlayerTypeMAX_PLAYERS ];

...

public 
_GetPlayerTypeplugin params )
{
    new 
id get_param);

    if( ! 
is_user_aliveid ) )
        return;

    
set_param_byref_:PlayerTypeid ] );

In plugin B, i try to retrieve the value of PlayerType[ id ]

PHP Code:

enum _
:PlayerClass2
{

    
SDU// Human Type
    
Soldier,
    
Heavy,
    
Supporter,
    
Leader,

    
GVirusMonster// Zombie Type
    
Nemesis,
    
TVirusMonster,
    
Assassin,
    
Venom,
    
Vampire,
    
Speeder,
    
Horde,
    
Hunter

}

static 
player_type

GetPlayerType
(idplayer_type); 
.inc file
PHP Code:

native GetPlayerType
id type ); 
but player_type is always 0 and i cannot get the correct value. What are the recommended ways to exchange variables across plugins?

Last edited by davidto1995; 05-02-2021 at 03:56.
davidto1995 is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 04-25-2021 , 06:31   Re: How to pass tagged variable to other plugins
Reply With Quote #2

Try this one:

PHP Code:
enum PlayerClass
{

    
SDU// Human Type
    
Soldier,
    
Heavy,
    
Supporter,
    
Leader,

    
GVirusMonster// Zombie Type
    
Nemesis,
    
TVirusMonster,
    
Assassin,
    
Venom,
    
Vampire,
    
Speeder,
    
Horde,
    
Hunter

};

public 
_GetPlayerTypeplugin params )
{
    new 
id get_param);

    if( ! 
is_user_aliveid ) )
        return -
1;

    return 
PlayerTypeid ];


native GetPlayerTypeid PlayerClass:type); 
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 04-25-2021 , 10:41   Re: How to pass tagged variable to other plugins
Reply With Quote #3

Code:
native GetPlayerType( id , type );

Code:
native GetPlayerType( id , &type );
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 04-25-2021 at 10:42.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
davidto1995
Member
Join Date: Jul 2010
Location: hong kong
Old 04-25-2021 , 12:00   Re: How to pass tagged variable to other plugins
Reply With Quote #4

Quote:
Originally Posted by Natsheh View Post
Code:
native GetPlayerType( id , type );

Code:
native GetPlayerType( id , &type );
It is fixed, thank you.

Does it mean than by stripping the tag, the memory address of the PlayerType[ id ] will be passed as parameter instead?
davidto1995 is offline
davidto1995
Member
Join Date: Jul 2010
Location: hong kong
Old 04-25-2021 , 12:02   Re: How to pass tagged variable to other plugins
Reply With Quote #5

Quote:
Originally Posted by Natsheh View Post
Code:
native GetPlayerType( id , type );

Code:
native GetPlayerType( id , &type );
For other plugins if GetPlayerType() is also needed to be called, do I need to enum PlayerClass3, 4, ... for each of the plugin?
davidto1995 is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 04-25-2021 , 15:39   Re: How to pass tagged variable to other plugins
Reply With Quote #6

Tags doesn't actually do anything except makes the compiler capable of telling you that you might have used a variable in the wrong context. After compilation they're basically gone.
However, if you end up using a tag and enforce it's usage in other plugins I would recommend putting them in the API plugin as well.

The enum is basically useless in your API plugin if you're not using them individually in any way. It should be in the include which is used for the secondary plugin, along with the native declaration.

I strongly suggest using the first example of these.
Code:
// API Plugin public plugin_natives()     register_native("ExampleNative", "nativeExample"); public nativeExample(plugin, params) {     return 999; } // Secondary Plugin native ExampleNative(); Data ends up here      |      V new data = ExampleNative();

Code:
// API Plugin public plugin_natives()     register_native("ExampleNative", "nativeExample"); public nativeExample(plugin, params) {     set_param_byref(1, 999); } // Secondary Plugin native ExampleNative(&data); Data ends up here                |                V ExampleNative(data);

If you're using tagged byref. Look how CsTeams based natives are declared in the include for guidance:
Code:
native CsTeams:cs_get_user_team(index, &{CsInternalModel,_}:model = CS_DONTCHANGE);

Example of tag mismatching still working fine
__________________

Last edited by Black Rose; 04-25-2021 at 16:21.
Black Rose is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 04-25-2021 , 17:53   Re: How to pass tagged variable to other plugins
Reply With Quote #7

Quote:
Originally Posted by davidto1995 View Post
It is fixed, thank you.

Does it mean than by stripping the tag, the memory address of the PlayerType[ id ] will be passed as parameter instead?
still no, but it will be retrieved as parameter.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
davidto1995
Member
Join Date: Jul 2010
Location: hong kong
Old 05-01-2021 , 10:26   Re: How to pass tagged variable to other plugins
Reply With Quote #8

Thank you guys. Clear my minds now.
davidto1995 is offline
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 02:54.


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