AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved How to pass tagged variable to other plugins (https://forums.alliedmods.net/showthread.php?t=332138)

davidto1995 04-25-2021 05:41

How to pass tagged variable to other plugins
 
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?

Shadows Adi 04-25-2021 06:31

Re: How to pass tagged variable to other plugins
 
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); 


Natsheh 04-25-2021 10:41

Re: How to pass tagged variable to other plugins
 
Code:
native GetPlayerType( id , type );
:arrow:
Code:

native GetPlayerType( id , &type );

davidto1995 04-25-2021 12:00

Re: How to pass tagged variable to other plugins
 
Quote:

Originally Posted by Natsheh (Post 2745071)
Code:
native GetPlayerType( id , type );
:arrow:
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 04-25-2021 12:02

Re: How to pass tagged variable to other plugins
 
Quote:

Originally Posted by Natsheh (Post 2745071)
Code:
native GetPlayerType( id , type );
:arrow:
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?

Black Rose 04-25-2021 15:39

Re: How to pass tagged variable to other plugins
 
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

Natsheh 04-25-2021 17:53

Re: How to pass tagged variable to other plugins
 
Quote:

Originally Posted by davidto1995 (Post 2745075)
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.

davidto1995 05-01-2021 10:26

Re: How to pass tagged variable to other plugins
 
Thank you guys. Clear my minds now.


All times are GMT -4. The time now is 01:16.

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