View Single Post
Author Message
Crackhead69
Member
Join Date: Feb 2021
Old 08-08-2021 , 15:24   Getting global data from non-id publics
Reply With Quote #1

Hello! I am wondering how could i retrieve global id saved variable to a public whom doesn't have the typical id index.
Example :
PHP Code:
#include <amxmodx>
#include <hamsandwich>

new g_Example[33]

public 
plugin_init()
{
    
RegisterHam(Ham_Spawn"player""player_spawn"1)
    
    
register_logevent("ev_round_end"2"1=Round_End")
}

public 
player_spawn(id)
{
    
g_Example[id] += 1
}

public 
ev_round_end()    // no  id  index
{
    if(
g_Example[id] >= 2)
    {
        
client_print(idprint_chat"Retrieved player's variable")
    }

It has nothing specific in the example that i want, i am just curious.
I have seen some plugins which used get_players for retrieving gobal data like that but it seemed pretty much situational, since in this example i don't see logic on how get_players will work.

Although i guess i could set a variable to hold the player's Id i guess.
Like so
PHP Code:
#include <amxmodx>
#include <hamsandwich>

new g_Example[33]
new 
temp_id

public plugin_init()
{
    
RegisterHam(Ham_Spawn"player""player_spawn"1)
    
    
register_logevent("ev_round_end"2"1=Round_End")
}

public 
player_spawn(id)
{
    
temp_id id
    g_Example
[temp_id] += 1
}

public 
ev_round_end()
{
    if(
g_Example[temp_id] >= 2)
    {
        
client_print(temp_idprint_chat"Retrieved player's variable")
    }

But is there any other more modern-like way of doing this?

Last edited by Crackhead69; 08-09-2021 at 13:40.
Crackhead69 is offline