Funkcje pomocnicze.

Status
Zamknięty.

Michael Angelo

User
Zarejestrowany
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]])
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.
 
Odp: Funkcje pomocnicze.

W pierwszej funkcji dla szukania gracza u?y?bym funkcji getTopCreature(uid).
Zastanawia mnie te? instrukcja
Kod:
if (not stop) then
Nie widz? nigdzie deklaracji stop.

Co do reszty, dobra robota.

Pozdrawiam.
 
Odp: Funkcje pomocnicze.

Witam , nie no gratulacje skryptu naprawde jestem pod wra?eniem w?a?nie go wstawiam na swojego Ots'a masz u mnie 10/10 jeszcze raz wielkie Gratz
 
Odp: Funkcje pomocnicze.

M?g?by? da? u?ycie 1 jako skrypt?
Poniewa? potrzebuje takiego czego? ?e je?li na danych pozycjach jest 1 potw?r oraz brak gracza usuwa potwora. Oraz ?e jak na danych pozycjach jest tylko 1 gracz i nic wi?cej nie ma teleportuje gracza.

Jest to tylko propozycja, poniewa? nie wiem jak mam korzysta? z tej fukncji.
 
Status
Zamknięty.
Back
Do góry