View Single Post
Timocop
AlliedModders Donor
Join Date: Mar 2013
Location: Germany
Old 01-06-2019 , 09:02   Re: Enum Structs Available This Holiday Season
Reply With Quote #17

methodmaps != classes

While 'enum structs' can hold multiple values because they are arrays, methodmaps can only hold one.

If you want to store something *in* methodmaps use StringMap's (or any other list). StringMap's are more readable. Example:

PHP Code:
methodmap Player StringMap
{
    public 
Player(int id)
    {
        
StringMap map = new StringMap();
        
        
map.SetValue("id"id);
        
map.SetValue("userid"GetClientUserId(id));
        
map.SetValue("money"100);
        
        return 
view_as<Player>(map);
    }
    
    
property int Userid
    
{
        public 
get() {
            
int i;
            
this.GetValue("userid"i);
            return 
i;
        }
    }
    
    
property int Id
    
{
        public 
get() {
            
int i;
            
this.GetValue("id"i);
            return 
i;
        }
    }
    
    
property int Money
    
{
        public 
get() {
            
int i;
            
this.GetValue("money"i);
            return 
i;
        }
        public 
set(int i) {
            
this.SetValue("money"i);
        }
    }
    
    public 
bool IsValid()
    {
        return (
GetClientOfUserId(this.Userid) > 0);
    }
    
    public 
bool InGame()
    {
        return (
IsClientInGame(this.Id));
    }
}

public 
void OnClientPutInServer(int client)
{
    
Player player = new Player(client);
    
    
CreateTimer(30.0SetPlayerMoneyTimerplayer);
}

public 
Action SetPlayerMoneyTimer(Handle timerPlayer player)
{
    if(!
player.IsValid() || !player.InGame())
        return;
    
    
player.Money 2500;
    
    
delete player;

if you remove the sugar it will look like this (decompiled):
PHP Code:
Player:Player.Player(id)
{
    new 
StringMap:map StringMap.StringMap();
    
StringMap.SetValue(map"id"idtrue);
    
StringMap.SetValue(map"userid"GetClientUserId(id), true);
    
StringMap.SetValue(map"money"any:100true);
    return 
map;
}

Player.Userid.get(Player:this)
{
    new 
i;
    
StringMap.GetValue(this"userid"i);
    return 
i;
}

Player.Id.get(Player:this)
{
    new 
i;
    
StringMap.GetValue(this"id"i);
    return 
i;
}

void:Player.Money.set(Player:thisi)
{
    
StringMap.SetValue(this"money"itrue);
    return 
void:0;
}

bool:Player.IsValid(Player:this)
{
    return 
GetClientOfUserId(Player.Userid.get(this)) > 0;
}

bool:Player.InGame(Player:this)
{
    return 
IsClientInGame(Player.Id.get(this));
}

public 
void:OnClientPutInServer(client)
{
    new 
Player:player Player.Player(client);
    
CreateTimer(30.0SetPlayerMoneyTimerplayer0);
    return 
void:0;
}

public 
Action:SetPlayerMoneyTimer(Handle:timerPlayer:player)
{
    new 
var1;
    if (!
Player.IsValid(player) || !Player.InGame(player))
    {
        return 
Action:0;
    }
    
Player.Money.set(player2500);
    
CloseHandle(player);
    
player MissingTAG:0;
    return 
Action:0;

__________________

Last edited by Timocop; 01-06-2019 at 09:07.
Timocop is offline