Hey, got some problems with this one:
Code:
#include <amxmodx>
#include <ApolloRP>
#include <ApolloRP_Skills>
new Handle: g_SqlTuple, g_Cache[512]
new g_Skill[32][SkillType]
public plugin_init()
{
g_SqlTuple = ARP_SqlHandle()
register_clcmd("myskill", "myskill")
if (g_SqlTuple == Empty_Handle)
set_fail_state("[ARP] Skills: Failed to retrieve SQL handle.")
}
public myskill(id)
for(new SkillType:iVar = Lockpicking; iVar < SkillType; iVar++)
client_cmd(id, "echo %d: %d", iVar, g_Skill[id][iVar])
public plugin_natives()
{
register_library("arp_skills")
register_native("ARP_GetUserSkill", "_ARP_GetUserSkill")
register_native("ARP_SetUserSkill", "_ARP_SetUserSkill")
}
public _ARP_GetUserSkill(Plugin, Params)
{
if(Params != 2)
return -1
log_amx("GETTING SKILL: %d", _:get_param(2))
return g_Skill[get_param(1)][SkillType:get_param(2)]
}
public _ARP_SetUserSkill(Plugin, Params)
{
if(Params != 3)
return -1
log_amx("SETTING SKILL: %d", _:get_param(2))
g_Skill[get_param(1)][SkillType:get_param(2)] = get_param(3)
return 1
}
public client_putinserver(id)
{
new Authid[36]
get_user_authid(id, Authid, 35)
new Data[1]
Data[0] = id
format(g_Cache, 511, "SELECT * FROM arp_skills WHERE steamid='%s'", Authid)
SQL_ThreadQuery(g_SqlTuple, "SelectHandle", g_Cache, Data, 1)
}
public SelectHandle(FailState, Handle:hQuery, szError[], iErrorCode, iData[], iDataSize)
{
if (FailState == TQUERY_CONNECT_FAILED)
set_fail_state("Could not connect to SQL database!")
else if (FailState == TQUERY_QUERY_FAILED)
set_fail_state("Query failed to execute!")
if(SQL_NumResults(hQuery) == 0)
{
new Authid[36]
get_user_authid(iData[0], Authid, 35)
format(g_Cache, 511, "INSERT IGNORE INTO arp_skills (steamid) VALUES ('%s')", Authid)
SQL_ThreadQuery(g_SqlTuple, "IgnoreHandle", g_Cache)
Set(iData[0], 1)
return
}
for(new SkillType: iVar = Lockpicking; iVar < SkillType; iVar++)
g_Skill[iData[0]][iVar] = SQL_ReadResult(hQuery, _:iVar + 1)
}
public IgnoreHandle(FailState, Handle:hQuery, szError[], iErrorCode, iData[], iDataSize)
{
if(iErrorCode)
set_fail_state(szError)
if (FailState == TQUERY_CONNECT_FAILED)
set_fail_state("Could not connect to SQL database!")
else if (FailState == TQUERY_QUERY_FAILED)
set_fail_state("Query failed to execute! Error")
return PLUGIN_CONTINUE
}
public client_disconnect(id)
{
new Authid[36]
get_user_authid(id, Authid, 35)
format(g_Cache, 511, "UPDATE arp_skills SET lockpicking=%d, mining=%d, herbalism=%d, enchanting=%d, engineering=%d, cooking=%d, guncrafting=%d WHERE steamid='%s'",
g_Skill[id][Lockpicking], g_Skill[id][Mining], g_Skill[id][Herbalism], g_Skill[id][Enchanting],g_Skill[id][Engineering], g_Skill[id][Cooking], g_Skill[id][Guncrafting], Authid)
SQL_ThreadQuery(g_SqlTuple, "IgnoreHandle", g_Cache)
Set(id, 1)
}
Set(Who, With)
for(new SkillType: iVar; iVar < SkillType; iVar++)
g_Skill[Who][iVar] = With
Trying to create a skills API, it all works pretty well but for some reason the enums go wrong.
Code:
#pragma library "arp_skills"
native ARP_GetUserSkill(const Client, const SkillType: Skill)
native ARP_SetUserSkill(const Client, const SkillType: Skill, EndValue)
enum SkillType
{
Lockpicking = 0,
Mining,
Herbalism,
Enchanting,
Engineering,
Cooking,
Guncrafting
}
With this usage:
ARP_GetUserSkill(id, Lockpicking)
ARP_SetUserSkill(id, Lockpicking, ...)
The "lockpicking" is 2. I don't know why, it should be 0, but then the data saved in database are wrong and things (it saves in Herbalism).
Not only that, the funny thing is that it loads data the same weird way:
Code:
for(new SkillType: iVar = Lockpicking; iVar < SkillType; iVar++)
g_Skill[iData[0]][iVar] = SQL_ReadResult(hQuery, _:iVar + 1)
Not only it reads data the same wrong way (it reads Herbalism [which is third or something] into lockpicking), it also works as it should, but simply the enum is somehow wrongly organised.
I've been trying to find the mistake I made for a long time till now but couldn't think of anything, I have never had these problems with enums before.