Quote:
Originally Posted by EasSidezz
|
Methodmap built using the
class builder.
Save this to `include/Dynamic/methodmaps/PlayerStats.inc`
Code:
#if defined _dynamic_class_playerstats_
#endinput
#endif
#define _dynamic_class_playerstats_
methodmap PlayerStats < Dynamic
{
public PlayerStats()
{
// First we make a new dymanic object
Dynamic myclass = Dynamic(64, 0);
// Next we will define all the members
// -> We do this to force the offsets to always be in the same location
// over multiple instances of the same class.
myclass.SetString("SteamID", "", 64);
myclass.SetFloat("Coins", 0.0);
myclass.SetInt("Kills", 0);
return view_as<PlayerStats>(myclass);
}
// Note that I use static offsets to access members.
// -> This improves performance by caching member offsets
// -> This is why we force the members in during the contructor
// -> Failure to force members in the constructor will cause corruption
public bool GetSteamID(char[] buffer, int length)
{
static DynamicOffset offset = INVALID_DYNAMIC_OFFSET;
if (offset == INVALID_DYNAMIC_OFFSET)
{
offset = this.GetMemberOffset("SteamID");
if (offset == INVALID_DYNAMIC_OFFSET)
SetFailState("A serious error occured in Dynamic!");
}
this.GetStringByOffset(offset, buffer, length);
return true;
}
public void SetSteamID(const char[] buffer)
{
static DynamicOffset offset = INVALID_DYNAMIC_OFFSET;
if (offset == INVALID_DYNAMIC_OFFSET)
{
offset = this.GetMemberOffset("SteamID");
if (offset == INVALID_DYNAMIC_OFFSET)
{
offset = this.SetString("SteamID", buffer);
return;
}
}
this.SetStringByOffset(offset, buffer);
}
property float Coins
{
public get()
{
static DynamicOffset offset = INVALID_DYNAMIC_OFFSET;
if (offset == INVALID_DYNAMIC_OFFSET)
{
offset = this.GetMemberOffset("Coins");
if (offset == INVALID_DYNAMIC_OFFSET)
SetFailState("A serious error occured in Dynamic!");
}
return this.GetFloatByOffset(offset);
}
public set(float value)
{
static DynamicOffset offset = INVALID_DYNAMIC_OFFSET;
if (offset == INVALID_DYNAMIC_OFFSET)
{
offset = this.GetMemberOffset("Coins");
if (offset == INVALID_DYNAMIC_OFFSET)
{
offset = this.SetFloat("Coins", value);
return;
}
}
this.SetFloatByOffset(offset, value);
}
}
property int Kills
{
public get()
{
static DynamicOffset offset = INVALID_DYNAMIC_OFFSET;
if (offset == INVALID_DYNAMIC_OFFSET)
{
offset = this.GetMemberOffset("Kills");
if (offset == INVALID_DYNAMIC_OFFSET)
SetFailState("A serious error occured in Dynamic!");
}
return this.GetIntByOffset(offset);
}
public set(int value)
{
static DynamicOffset offset = INVALID_DYNAMIC_OFFSET;
if (offset == INVALID_DYNAMIC_OFFSET)
{
offset = this.GetMemberOffset("Kills");
if (offset == INVALID_DYNAMIC_OFFSET)
{
offset = this.SetInt("Kills", value);
return;
}
}
this.SetIntByOffset(offset, value);
}
}
}
Your code converted for Dynamic.
Code:
#include <Dynamic>
#include <Dynamic/methodmaps/PlayerStats>
#pragma newdecls required
public void OnPlayerConnected(int client);
{
Dynamic settings = Dynamic.GetPlayerSettings(client);
PlayerStats stats = PlayerStats();
settings.SetDynamic("PlayerStats", stats);
}
public bool isClientsDataStored(int client, const char[] steamid)
{
PlayerStats stats = getClientsData(client);
if(stats.CompareString("SteamID", steamid))
return true;
else
return false;
}
stock PlayerStats getClientsData(int client)
{
return Dynamic.GetPlayerSettings(client).GetDynamic("PlayerStats");
}
public void storeNewClientData(char[] steamid, int client, float coins)
{
PlayerStats stats = getClientsData(client);
stats.SetSteamID(steamid);
stats.Coins = coins;
}
__________________