- Dołączył
- Październik 27, 2009
- Posty
- 10
- Liczba reakcji
- 2
Chcia?bym wam udost?pni? kilka funkcji, kt?re by? mo?e komu? si? przydadz?. Wszystkie funkcje dzia?aj? na wszelkich silnikach.
1. Funkcja, kt?ra szuka graczy w okre?lonych pozycjach.
getPlayersInRoom(frompos, topos [, czy_zatrzymywac_gdy_znajdzcie_jakas_postac [, funkcja uzywana do sprawdzania]])
2. doPlayerAddQuestItem(cid, tabela_z_itemami, tabela_z_iloscia_itemow(wprost proporcjonalnie co do itemow), storage, storage_value, typ_wiadomosci, aid_przedmiotu, opis)
Przyk?ad u?ycia:
doPlayerAddQuestItem(cid, {2160, 2160, 2148, 2151}, {100, 36, 74, 34})
doPlayerAddQuestItem(cid, {2390}, {1}, 273841, 1, MESSAGE_STATUS_CONSOLE_BLUE, 5600, "Magiczny miecz.")
3. getPlayerBestSkill(cid)
Przyk?ad u?ycia:
P?ki co to tyle.
@down
Poprawione, dzi?ki.
1. Funkcja, kt?ra szuka graczy w okre?lonych pozycjach.
getPlayersInRoom(frompos, topos [, czy_zatrzymywac_gdy_znajdzcie_jakas_postac [, funkcja uzywana do sprawdzania]])
PHP:
function getPlayersInRoom(frompos, topos, stopAtFind, func)
local stopAtFind, uids, func = stopAtFind or 0, {}, func or isPlayer
if(type(func) ~= 'function') then
error('Parameter "func" should be a function!')
return false
end
for x = frompos.x, topos.x do
for y = frompos.t, topos.y do
local pos = {x=x, y=y, z=frompos.z, stackpos=253}
local player = getThingfromPos(pos)
if(func(player)) then
table.insert(uids, player.uid)
ile = ile + 1
if(not stopAtFind) then
break
end
end
end
end
return uids
end
2. doPlayerAddQuestItem(cid, tabela_z_itemami, tabela_z_iloscia_itemow(wprost proporcjonalnie co do itemow), storage, storage_value, typ_wiadomosci, aid_przedmiotu, opis)
PHP:
function doPlayerAddQuestItem(cid, items, count, storage, value, type, aid, descr)
local count = count or 1
local type = type or MESSAGE_INFO_DESCR
if(type(items) ~= "table" or type(count) ~= "table") then
error("Parameter \"items\" and \"count\" should be a table!")
return
end
if(#items ~= #count) then
error("Tables \"items\" and \"count\" should have a same count of values.")
return
end
if(storage and value) then
if(getPlayerStorageValue(cid, storage) == value) then
doPlayerSendTextMessage(cid, type, "This is empty!")
return FALSE
end
setPlayerStorageValue(cid, storage, value)
end
local uids, text_items = {}, {}
local text = "You have found "
for i, v in ipairs(items) do
local item = doPlayerAddItem(cid, v, count[i])
if(aid) then doSetItemActionId(item, aid) end
if(descr) then doSetItemSpecialDescription(item, descr) end
table.insert(uids, item)
local name = getItemName(item)
if(count == 1) then
table.insert(text_items, getArticle(name) .. " " name)
else
table.insert(text_items, count .. " " name)
end
end
doPlayerSendTextMessage(cid, type, text .. table.concat(text_items, ", ") .. ".")
return uids
end
Przyk?ad u?ycia:
doPlayerAddQuestItem(cid, {2160, 2160, 2148, 2151}, {100, 36, 74, 34})
doPlayerAddQuestItem(cid, {2390}, {1}, 273841, 1, MESSAGE_STATUS_CONSOLE_BLUE, 5600, "Magiczny miecz.")
3. getPlayerBestSkill(cid)
PHP:
function getPlayerBestSkill(cid)
local best, id = 0, 0
for i = 0, 4 do
local level = getPlayerSkill(cid, i)
if(level > best) then
best = level
id = i
end
end
return {id = id, level = best}
end
Przyk?ad u?ycia:
PHP:
local bestSkill = getPlayerBestSkill(cid)
local skillsNames = {"Fist fighting", "Club Fighting", "Sword fighting", "Axe fighting", "Distance fighting", "Shielding", "Fishing"}
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your best skill is " .. skillsNames[bestSkill.id] .. " with level " .. best.level .. ".")
P?ki co to tyle.
@down
Poprawione, dzi?ki.