hjaelp til lidt mysql (small)
Hey der, jeg har et lille problem med det her mod til min cs server moddet er codet i small (amxx) kan ikke rigtigt finde hjaelp nogle steder men haaber der er nogen der kan hjaelpe mig her.mit mod ser saaledes ud.
#include <amxmodx>
#include <dbi>
// SQL RELATED VARIABLES
new Sql:dbc
new Result:result
#define MAXIUMSTR 1023
new Float:emptyFloat = 0.0
//Variable holding important information
new Float:returnMoney[33] = 0.0
new returnKills[33] = 0
new returnDeaths[33] = 0
// ********************* CHANGABLED BELOW **********************
new sqlHost[32] = "hidden"
new sqlUser[32] = "hidden"
new sqlPass[32] = "hidden"
new sqlDB[32] = "hidden"
new sqlTable[32] = "hidden"
new sqlAuthid[32] = "authid"
new sqlMoney[32] = "xmoney"
new sqlKills[32] = "kills"
new sqlDeaths[32] = "death"
new Float:cashGain = 0.98
new Float:cashLoss = 1.00
new cashKickReasons[3][] =
{
"", // Placeholder
"You are not registed, join ******** @ Qnet and /Q Exceed to join up for the beta test or see ********",
"You ran out of money, in the test you just have to join ******** and /Q Exceed to get more money or see ********"
}
// Value to control showing of messages
new bool:show_cash_msg = true
// Value to control showing of HUD
new bool:show_cash_hud = true
// ********************* CHANGABLED ABOVE **********************
public plugin_init() {
register_plugin("Money Plugin","1.0","Exceed")
register_event("DeathMsg","Event_DeathMsg","a")
register_event("ResetHUD","Event_ResetHUD", "be")
set_task(1.0,"sql_init")
if (show_cash_hud)
set_task(2.0,"HudUpdate",0,"",0,"b") //ACTIVEHUD - SALARY - DOTIME
}
// Initializing the MySQL database sc delete mysql
public client_authorized(id) {
user_money(id,"x",emptyFloat)
}
public sql_init() {
new error[32]
dbc = dbi_connect(sqlHost,sqlUser,sqlPass,sqlDB,error,32)
if (dbc == SQL_FAILED)
server_print("[AMXX] Could Not Connect To SQL Database [Error=%s]^n",error)
else
server_print("[AMXX] Connected To SQL, Have A Nice Day!^n")
}
public Event_ResetHUD(id) {
user_money(id,"x",emptyFloat)
set_hudmessage(0, 255, 0, -1.0, 0.00, 0, 6.0, 5.0)
show_hudmessage(id, "This server is running KG FFA^n stack is $%.2f^n you have $%.2f to play for",cashLoss,returnMoney[id])
client_print(id,print_chat,"[AMXX] You have %.2f",returnMoney[id])
return PLUGIN_HANDLED
}
public Event_DeathMsg()
{
new killer = read_data(1)
new victim = read_data(2)
if (is_user_connected(killer) && killer!=victim) // Check if user is connected and make sure he was killed by different person
{
new victimname[33]
get_user_name(victim,victimname,32)
if (get_cvar_num("csdm_active")==0) // CSDM is OFF
{
if(get_user_team(killer)==get_user_team(victim))
{ // SAME TEAM - TEAMKILL
if (show_cash_msg)
client_print(killer,print_chat,"[AMXX] You lost $%.2f for killing your team mate %s",cashGain,victimname);
user_money(killer,"-",cashLoss);
}
else
{ // DIFFERENT TEAMS
if (show_cash_msg)
client_print(killer,print_chat,"[AMXX] You got $%.2f for killing %s",cashGain,victimname);
user_money(killer,"+",cashGain);
if (show_cash_msg)
client_print(victim,print_chat,"[AMXX] You lost $%.2f for dying",cashLoss);
user_money(victim,"-",cashLoss);
}
}
else
{ // CSDM is ON
if (show_cash_msg)
client_print(killer,print_chat,"[AMXX] You got $%.2f for killing %s",cashGain,victimname)
user_money(killer,"+",cashGain)
if (show_cash_msg)
client_print(victim,print_chat,"[AMXX] You lost $%.2f for dying",cashLoss)
user_money(victim,"-",cashLoss)
}
}
return PLUGIN_HANDLED
}
user_kick(id,reasonid) { // Function that kicks a player when he isn`t registered or has too little cash
new userid = get_user_userid(id)
server_cmd("kick #%d ^"%s^"",userid,cashKickReasons[reasonid])
return 1
}
user_money(id,func[],Float:changeMoney) {
new userauth[32],userMoney[32], query[MAXIUMSTR+1]
get_user_authid(id,userauth,31)
format(query,MAXIUMSTR,"SELECT %s,%s,%s FROM %s WHERE %s='%s'",sqlMoney,sqlKills,sqlDeaths,sqlTable,sqlAuthid,userauth)
result = dbi_query(dbc,query)
if(dbi_nextrow(result) > 0) // Does User Exist in DataBase
{
// YES HE DOES
dbi_field(result,1,userMoney,MAXIUMSTR-1)
returnKills[id] = dbi_field(result,2)
returnDeaths[id] = dbi_field(result,3)
dbi_free_result(result)
if(equali(func,"-"))
{
new Float:newMoney = floatstr(userMoney)-changeMoney
if (newMoney<=0.99)
{
// user_kick(id,2)
}
format(query,MAXIUMSTR-1,"UPDATE %s SET %s='%.2f' WHERE %s='%s'",sqlTable,sqlMoney,newMoney,sqlAuthid,userauth)
dbi_query(dbc,query)
format(query,MAXIUMSTR-1,"UPDATE %s SET %s='%i' WHERE %s='%s'",sqlTable,sqlDeaths,returnDeaths[id]+1,sqlAuthid,userauth)
dbi_query(dbc,query)
return 1
}
if(equali(func,"+"))
{
new Float:newMoney = floatstr(userMoney)+changeMoney
format(query,MAXIUMSTR-1,"UPDATE %s SET %s='%.2f' WHERE %s='%s'",sqlTable,sqlMoney,newMoney,sqlAuthid,userauth)
dbi_query(dbc,query)
format(query,MAXIUMSTR-1,"UPDATE %s SET %s='%i' WHERE %s='%s'",sqlTable,sqlKills,returnKills[id]+1,sqlAuthid,userauth)
dbi_query(dbc,query)
return 1
}
if(equali(func,"="))
{
new Float:newMoney = changeMoney
format(query,MAXIUMSTR-1,"UPDATE %s SET %s='%.2f' WHERE %s='%s'",sqlTable,sqlMoney,newMoney,sqlAuthid,userauth)
dbi_query(dbc,query)
return 1
}
if(equali(func,"x"))
{
returnMoney[id] = floatstr(userMoney)
if (returnMoney[id]<=emptyFloat)
{
// user_kick(id,2)
}
return 1
}
}else{
// NO HE DOES'T
// user_kick(id,1)
}
return 1
}
public HudUpdate() {
for(new id=0;id < 33;id++) {
if (is_user_connected(id))
{
user_money(id,"x",emptyFloat)
set_hudmessage(255,255,255,-1.9,0.55,0,0.0,99.9,0.0,0.0,1)
show_hudmessage( id, " Balance: $%.2f^n Kills: %i^n Deaths: %i^n ",returnMoney[id],returnKills[id],returnDeaths[id])
}
}
}
Den der skal tabe penge i mod'et taber sine penge $1 som han nu skal, derudover faar han ogsaa et death til sin liste.
Ham der skal vinde penge ($0.98) faar ikke sine penge men faar dog et kill til sin liste. Forstaar ikke hvorfor den ikke opdaterer korrekt.
Er ikke saa god til at kode endnu saa haaber at jer hardcore coders vil kunne hjaelpe mig ud her.
Jeg ved godt at det her nok ikke er det rigtige sted at poste det her men ved ikke hvor jeg ellers skulle smide indlaegget.
Hvis du vil prQve mod'et som det er nu saa kQrer det paa 212.10.46.214:27015, men man skal have registreret sit steamid i min MySQL DB fQr det virker og som mod'et er nu vil du ikke blive kicket selvom du ikke er registreret.
Ps. mod'et er til spillet counter-strike.