What's new

Talkactions Automatyczne rozdawanie punkt?w dla gildii komend? + zabezpieczenia

Status
Not open for further replies.

Forseti

Senior User
Joined
Dec 23, 2011
Messages
954
Reaction score
82
Hej.

Przedstawiam skrypt na komende "!gpoints", dzi?ki kt?remu Punkty na gildie b?d? rozdawane w pe?ni automatycznie.
Komendy tej mog? u?ywa? liderzy gildii.

W talkactions/scripts tworzymy plik "points.lua" i dodajemy do niego:
PHP:
----------------
local minPlayer = 15  -- Minimalna ilo?? graczy online w gildii.
local points = 130  -- Ilo?? punkt?w dla ka?dego cz?onka online.
local p_mL = 2  -- Mno?nik dla lidera[tego kt?ry u?ywa tej funkcji]. np. 130punkt?w * x = 260 dla lidera.
local active=true  -- czy komenda !gpoints jest aktywna?
 
 
function getGStatus(id)
 local db = db.getResult("SELECT * FROM `guilds` WHERE `id` = '".. id .."';")
 local status = tonumber(db:getDataInt("points"))
 db:free()
 return status
end
 
function setGStatus(id)
db.executeQuery("UPDATE `guilds` SET `points` = 1 WHERE `id` = '".. id .."' LIMIT 1;")
return true
end
 
 local function isLeader(cid)
 local guild = getPlayerGuildId(cid)
    if(not guild or getPlayerGuildLevel(cid) < GUILDLEVEL_LEADER) then
 
		return false
	end
	return true
end
function checkIp(cid)
 local guild = getPlayerGuildId(cid)
    for _, sid in pairs(getPlayersOnline()) do
        if guild == getPlayerGuildId(sid) then
            if getPlayerIp(cid) == getPlayerIp(sid) then
			 return false
			end
        end
    end
	return true
end
local function getOPlayerInGuild(cid)
    local players = {}
	local guild = getPlayerGuildId(cid)
    for _, sid in pairs(getPlayersOnline()) do
        if guild == getPlayerGuildId(sid) then
            table.insert(players, sid)
        end
    end
	if players then
    return players
	else 
	return false
	end
end
 
local function addPoints(cid, players)
 for i=1, #players do
  if checkIp(players[i]) == false then
    doPlayerSendTextMessage(cid, 22, "There are mc players.["..getCreatureName(players[i]).."]")
	return true
  end
 end
 for i=1, #players do
   local p = players[i]
   if p==cid then 
     db.executeQuery("UPDATE `accounts` SET `premium_points` = `premium_points` + "..(points*p_mL).." WHERE `id` = " .. getPlayerAccountId(p) .. ";")
	doPlayerSendTextMessage(p,22,'You get '..(points*p_mL)..' premium from Guild Points.ss')
   else
   db.executeQuery("UPDATE `accounts` SET `premium_points` = `premium_points` + "..points.." WHERE `id` = " .. getPlayerAccountId(p) .. ";")
	doPlayerSendTextMessage(p,22,'You get '..points..' premium from Guild Points.')
   end
 end
 setGStatus(getPlayerGuildId(players[1]))
 doBroadcastMessage(getPlayerGuildName(players[1]).." get points from Guild Points System!")
 return true
end
---------------
function onSay(cid, words, param) 
if not active then
 return true
end
local guild = getPlayerGuildId(cid)
 if not isLeader(cid) then
  return true
 end
 if getGStatus(guild) > 0 then
	doPlayerSendTextMessage(cid, 22, "Points for your guild has been added.")
	return true
 end
 local players = #getOPlayerInGuild(cid)
 if players < minPlayer then
  doPlayerSendTextMessage(cid, 22, "There are only "..players.." player online! Req. "..minPlayer..".")
  return true
 end
 addPoints(cid, getOPlayerInGuild(cid))
 
return true
end

Natomiast w talkactions.xml dajemy:
PHP:
<talkaction words="!gpoints" script="points.lua" />


Ostatnim krokiem b?dzie w bazie danych, do tabeli "guilds" da? kolumne "points".
 

Placek

Blue Waffle
Joined
Sep 30, 2008
Messages
6,793
Reaction score
672
Age
9
Odp: Automatyczne rozdawanie punkt?w dla gildii komend? + zabezpieczenia

/mc
18:01 Currently there aren't any players with same IP address(es).
/gpoints
18:01 There are mc players.[Aas]

W koncu znalazlem chwile zeby przetestowac.
Nie wiem jak te mcki sprawdzasz bo nie chce mi sie tego doglebniej analizowac, ale nie bylem zalogowany z jednego ip a mimo wszystko punktow nie dostalem...

W kazdym razie, zastanawiam sie czy jest dobrze zabezpieczony, bo poprzednie wersje ktore widzialem na roznych forach nie byly do konca zazwyczaj.
- Co jesli rozda sie punkty w gildii, wszyscy opuszcza gildie i stworza nowa. Dla postaci jest jakos zapisane, ze ma punkty? Jesli sie zmienia gildia to tez jakies tam informacje zapisane o starej nie maja znaczenia.
- Co jesli kazdy stworzy nowe konto, nowa postac, nowa gildie i w xx osob 2 uzyja komendy? Dostana punkty? Jesli zabezpieczenia sa na postaciach czy tez na gildiach to tak. Musialo by sie zapisywac w jakis sposob, ze ktos z danym ip juz otrzymal punkty.

No i taka rzecz, czy jesli dojdzie kolejne 20 osob do gildii bedzie mozna jeszcze raz uzyc komendy, zeby nowi gracze dostali punkty? To by moglo byc nawet konfigurowalen, zeby kazdy sobie mogl wlaczyc/wylaczyc jesli chce.
 
Status
Not open for further replies.
Top