Descriere: Din titlul iti cam dai seama ce face, practic la un NPC vor aparea 2 categorii, Voteaza si Vezi Voturile unde bineinteles poti vota candidatii sau poti vedea cate voturi au. Totul se salveaza in db, voturile le afiseaza din db.
Poti seta un numar de minute necesare pentru a putea vota si ai dreptul la un singur vot per caracter care are minutele necesare.
Am avut nevoie candva de asa ceva, nu exista. Acum exista si nu trebuie sa te mai chinui pe site-uri.
Quest:
Cod: Selectaţi tot
----------------------------------------------------
-- klynaTz -------------------
----------------------------------------------------
quest vote_miss_mister begin
state start begin
when 20092.chat."Voteaza Miss si Mister" begin
-- Configurare
minuteNecesare = 2500 -- Cate minute sa aibe player sa poata vota
editia = 1 -- Numar editiei . Acesta trebuie schimbat intotdeauna cand faci evenimentul altfel v-a numara si voturile din evenimentul anterior.
maxCandidati = 3 -- Modifici in caz ca ai mai mult de 3 persoane aici candidatMiss sau aici candidatMister.
candidatMiss = {"X", "Y", "Z"} -- Aici adaugi candidatele pentru miss
candidatMister = {"X", "Y", "Z"} -- Aici adaugi candidatii pentru mister
-- End
say_title("Aici poti vota Miss si Mister")
if pc.get_playtime() < minuteNecesare then
say("Se pare ca nu ai minutele necesare pentru a vota")
say("")
say("Minute minime:" .. minuteNecesare)
return
else
say("Ce doresti sa votezi?")
voteazaCat = select ("Miss", "Mister", "Iesire")
if voteazaCat == 1 then
say_title("Voteaza Miss")
say("Aici poti vota pentru Miss, Editia a " .. editia)
if pc.getqf("votedMiss") == editia then
wait()
say("Imi pare rau dar ai votat deja")
return
else
say("Doresti sa votezi pentru Miss?")
local proceed = select ( "Da", "Nu")
if proceed == 1 then
say("Pe cine vrei sa votezi?")
say("")
for i = 1,table.getn(candidatMiss),1
do
say_verde(i .. ". " .. candidatMiss[i])
end
say_rosu("X. Iesire")
say("")
say("Introdu numarul candidatului:")
say("Introdu X pentru a iesi")
local choice = input()
if tonumber(choice) >= 1 and tonumber(choice) <= maxCandidati then
say("Felicitari, votul tau a fost inregistrat![ENTER]")
say("Ai votat cu: " .. candidatMiss[tonumber(choice)])
pc.setqf("votedMiss", editia)
voteMissMister("miss_votes", editia, choice, candidatMiss[tonumber(choice)])
wait()
return
elseif choice == "" or choice == "X" or choice == "x" then
say_rosu ( "Nu ai ales niciun candidat.[ENTER]" )
wait()
return
end
end
end
elseif voteazaCat == 2 then
say_title("Voteaza Mister")
say("Aici poti vota pentru Mister, Editia a " .. editia)
if pc.getqf("votedMister") == editia then
wait()
say("Imi pare rau dar ai votat deja")
return
else
say("Doresti sa votezi pentru Mister?")
local proceed = select ( "Da", "Nu")
if proceed == 1 then
say("Pe cine vrei sa votezi?")
say("")
for i = 1,table.getn(candidatMister),1
do
say_verde(i .. ". ".. candidatMister[i])
end
say_rosu("X. Iesire")
say("")
say("Introdu numarul candidatului:")
say("Introdu X pentru a iesi")
local choice = input()
if tonumber(choice) >= 1 and tonumber(choice) <= maxCandidati then
say("Felicitari, votul tau a fost inregistrat![ENTER]")
say("Ai votat cu: " .. candidatMister[tonumber(choice)])
pc.setqf("votedMister", editia)
voteMissMister("mister_votes", editia, choice, candidatMister[tonumber(choice)])
wait()
return
elseif choice == "" or choice == "X" or choice == "x" then
say_rosu ( "Nu ai ales niciun candidat.[ENTER]" )
wait()
return
end
end
end
end
end
end
end
end
quest topMissMister begin
state start begin
when 20092.chat."Top Miss Mister" begin
say_title("Vezi voturi")
say("Aici poti vedea voturile de la")
say("miss si mister")
say("")
say("Ce voturi vrei sa vezi?")
local choices = select ("Miss", "Mister", "Iesire")
if choices == 1 then
say("Acestea sunt voturile pentru Miss:")
say("")
for i = 1,table.getn(candidatMiss),1
do
returnTop("miss_votes", i, editia)
end
elseif choices == 2 then
say("Acestea sunt voturile pentru Mister:")
say("")
for i = 1,table.getn(candidatMister),1
do
returnTop("mister_votes", i, editia)
end
end
end
end
end
Cod: Selectaţi tot
function voteMissMister(tabel, ed, voteChoice, nume)
mysql_direct_query("INSERT INTO ".. tabel .."(account_id, editia, name, numar_candidat, data) VALUES (".. pc.get_account_id() ..", ".. ed ..", '".. nume .."', ".. voteChoice ..", NOW());")
end
function returnTop(tabel, candidat, ed)
local index, values = mysql_direct_query("SELECT COUNT(player."..tabel..".numar_candidat) as votes, player."..tabel..".name as name FROM player."..tabel.." WHERE player."..tabel..".numar_candidat = ".. candidat .." AND player."..tabel..".editia = ".. ed .." ORDER BY votes DESC LIMIT 10;");
for index, value in ipairs(values) do
say(string.format("Candidat: %s - %s", value.name, value.votes));
end return 0
end
Cod: Selectaţi tot
voteMissMister
returnTop
Cod: Selectaţi tot
CREATE TABLE `miss_votes` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`account_id` int(10) unsigned NOT NULL,
`editia` int(10) unsigned NOT NULL,
`name` varchar(24) NOT NULL,
`numar_candidat` int(10) unsigned NOT NULL,
`data` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE `mister_votes` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`account_id` int(10) unsigned NOT NULL,
`editia` int(10) unsigned NOT NULL,
`name` varchar(24) NOT NULL,
`numar_candidat` int(10) unsigned NOT NULL,
`data` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Cod: Selectaţi tot
minuteNecesare = 2500 -- Cate minute sa aibe player sa poata vota
editia = 1 -- Numar editiei . Acesta trebuie schimbat intotdeauna cand faci evenimentul altfel v-a numara si voturile din evenimentul anterior.
maxCandidati = 3 -- Modifici in caz ca ai mai mult de 3 persoane aici candidatMiss sau aici candidatMister.
candidatMiss = {"X", "Y", "Z"} -- Aici adaugi candidatele pentru miss
candidatMister = {"X", "Y", "Z"} -- Aici adaugi candidatii pentru mister
Parte de sursa/game pentru cei cu surse mai vechi
Cod: Selectaţi tot
// add
#include "db.h"
// after int _get_special_item_group( lua_State* L ) add
#ifdef _MSC_VER
#define INFINITY (DBL_MAX+DBL_MAX)
#define NAN (INFINITY-INFINITY)
#endif
int _mysql_direct_query(lua_State* L)
{
// char szQuery[1024];
if (!lua_isstring(L, 1))
return 0;
// strncpy(szQuery, lua_tostring(L, 1), sizeof(szQuery));
int i=0, m=1;
MYSQL_ROW row;
MYSQL_FIELD * field;
MYSQL_RES * result;
// SQLMsg * pMsg = DBManager::instance().DirectQuery(szQuery);
std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery(lua_tostring(L, 1)));
if (pMsg.get())
{
// ret1 (number of affected rows)
lua_pushnumber(L, pMsg->Get()->uiAffectedRows);
//-1 if error such as duplicate occurs (-2147483648 via lua)
// if wrong syntax error occurs (4294967295 via lua)
// ret2 (table of affected rows)
lua_newtable(L);
if ((result = pMsg->Get()->pSQLResult) &&
!(pMsg->Get()->uiAffectedRows == 0 || pMsg->Get()->uiAffectedRows == (uint32_t)-1))
{
// LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
// ch->ChatPacket(CHAT_TYPE_INFO, "<%s> Retrieved %u fields\n", __FUNCTION__, mysql_num_fields(result));
// ch->ChatPacket(CHAT_TYPE_INFO, "<%s> Retrieved %u rows\n", __FUNCTION__, mysql_num_rows(result));
// ch->ChatPacket(CHAT_TYPE_INFO, "<%s> Affected %u rows\n", __FUNCTION__, pMsg->Get()->uiAffectedRows);
// ch->ChatPacket(CHAT_TYPE_INFO, "<%s> Num %u rows\n", __FUNCTION__, pMsg->Get()->uiNumRows);
while((row = mysql_fetch_row(result)))
{
lua_pushnumber(L, m);
lua_newtable(L);
while((field = mysql_fetch_field(result)))
{
lua_pushstring(L, field->name);
if (!(field->flags & NOT_NULL_FLAG) && (row[i]==NULL))
{
// lua_pushstring(L, "NULL");
lua_pushnil(L);
}
else if (IS_NUM(field->type))
{
double val = NAN;
lua_pushnumber(L, (sscanf(row[i],"%lf",&val)==1)?val:NAN);
}
else if (field->type == MYSQL_TYPE_BLOB)
{
lua_newtable(L);
for (DWORD iBlob=0; iBlob < field->max_length; iBlob++)
{
lua_pushnumber(L, row[i][iBlob]);
lua_rawseti(L, -2, iBlob+1);
}
}
else
lua_pushstring(L, row[i]);
// LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
// ch->ChatPacket(CHAT_TYPE_INFO, "<%s> Retrieved %d flag %s for %s\n", __FUNCTION__, field->type, field->name, row[i]?row[i]:"NULL");
lua_rawset(L, -3);
i++;
}
mysql_field_seek(result, 0);
i=0;
lua_rawset(L, -3);
m++;
}
}
}
else {lua_pushnumber(L, 0); lua_newtable(L);}
// delete pMsg;
return 2;
}
// after { "get_special_item_group", _get_special_item_group }, add
{ "mysql_direct_query", _mysql_direct_query },
Cod: Selectaţi tot
mysql_direct_query

de