Ronit.GAMES
Implementacja systemu "currency" - Printable Version

+- Ronit.GAMES (https://forum.ronit.games)
+-- Forum: RonEngine Support / Wsparcie dla RonEngine (https://forum.ronit.games/forumdisplay.php?fid=18)
+--- Forum: LUA/XML Scripting / Skryptowanie LUA/XML (https://forum.ronit.games/forumdisplay.php?fid=22)
+--- Thread: Implementacja systemu "currency" (/showthread.php?tid=261)



Implementacja systemu "currency" - Meritus - 14-03-2011

Witajcie,

W najnowszej wersji RonEngine, została wprowadzona możliwość prostej konfiguracji systemu zamiany monet oraz dowolnego innego przedmiotu.

Implementacja:

1. Do głównego katalogu serwera należy wgrać plik o nazwie currency.xml przykładowo:

PHP Code:
<currency>
    <
group id="1" name="Coins">
        <
element itemid="2969" value="1" />
        <
element itemid="2973" value="100" />
        <
element itemid="2981" value="10000" />
        <
element itemid="13157" value="1000000" />
        <
element itemid="13158" value="100000000" />
    </
group>
    <
group id="2" name="Demonic Essence">
        <
element itemid="4524" value="1" />
        <
element itemid="13162" value="100" />
    </
group>
</
currency

Jak widać, deklaruję w nim 2 typy przedmiotów, pierwszy to zwykłe monety drugi demoniczne essencje.

2. Wgrywamy poniższy skrypt Lua do katalogu /actions/scripts/

PHP Code:
--/**
-- * Currency.lua
-- * @version 1.0
-- * @author Sławomir Jach
-- */ 
function onUse(ciditemfrompositem2topos)
    if 
item2.itemid ~= 0 then item item2 end -- Dla userable
    local groupid 
getCurrencyGroupID(item.itemid)
    
local nextitemid getCurrencyNextElement(groupiditem.itemid)
    
local beforeitemid getCurrencyPreviousElement(groupid,item.itemid)
    
local thisitemvalue getCurrencyElementValue(groupiditem.itemid)
    
local nextitemvalue getCurrencyElementValue(getCurrencyGroupID(nextitemid), nextitemid)
    
local beforeitemvalue getCurrencyElementValue(getCurrencyGroupID(beforeitemid), beforeitemid)
    if 
nextitemid == LUA_ERROR and beforeitemid == LUA_ERROR then log(cid"Item nie jest zdefiniowany w currency.xml") return 0 end
        
    
if beforeitemid == LUA_ERROR and nextitemid ~= LUA_ERROR then -- Pierwszy
        
if item.type == nextitemvalue/thisitemvalue then
            
if doRemoveItem(item.uid,nextitemvalue/thisitemvaluethen
                doPlayerAddItemEx
(cid,nextitemid,1)
            
end
        end
    
elseif beforeitemid ~= LUA_ERROR and nextitemid == LUA_ERROR then -- Ostatni
        
if doRemoveItem(item.uid,1then
            doPlayerAddItemEx
(cid,beforeitemid,thisitemvalue/beforeitemvalue)
        
end
    
else -- jakis srodkowy
        
if nextitemvalue/thisitemvalue == item.type then -- jest ilosc wymagana zamieniam na wieksze
            
if doRemoveItem(item.uid,nextitemvalue/thisitemvaluethen
                doPlayerAddItemEx
(cid,nextitemid,1)
            
end
        
elseif item.type nextitemvalue/thisitemvalue then    -- nie ma ilosci wymaganejusuwamy 1 i dodajemy x mniejszych
            
if doRemoveItem(item.uid,1then
                doPlayerAddItemEx
(cid,beforeitemid,thisitemvalue/beforeitemvalue)
            
end
        end
    end
 end 

3. Ostatnim etapem jest podpięcie skryptu w actions.xml do określonego przedmiotu:

PHP Code:
    <!-- Przedmioty laczone i rozlaczane NIE useable -->
    <
action itemid="2969" script="currency.lua" />
    <
action itemid="2973" script="currency.lua" />
    <
action itemid="2981" script="currency.lua" />
    <
action itemid="13157" script="currency.lua" />
    <
action itemid="13158" script="currency.lua" />
    <
action itemid="13159" script="currency.lua" />
    <
action itemid="13160" script="currency.lua" />
    <
action itemid="13161" script="currency.lua" />
    <!-- 
Przedmioty laczone i rozlaczane useable -->
    <
action itemid="4524" useself="1" script="currency.lua" /> 
    <
action itemid="13162" useself="1" script="currency.lua" /> 
    <
action itemid="4524" usewith="1" script="demonic_essence.lua" />
<
action itemid="13162" usewith="1" script="demonic_essence.lua" /> 

Warto zauważyć, że przedmioty, które można używać na czymś muszą być podpięte do 2 skryptów. Użycie przedmiotu na samym sobie wyzwoli pożądany efekt, łączenia/rozłączenia.


Do dyspozycji dodane są 3 bardzo przydatne funkcje Lua do prostego pobierania informacji o ilości jednostkowej danej grupy przedmiotów, do zabierania zadanej ilości przedmiotu oraz do dodawania w największym możliwym nominale:

PHP Code:
getPlayerCurrency(cidgroup_id)
doPlayerRemoveCurrency(cidgroup_idcount)
doPlayerAddCurrency(cidgroup_idcount

Pozdrawiam,
Meritus