• Home
  • Members
  • Team
  • Help
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Ronit.GAMES RonEngine Support / Wsparcie dla RonEngine LUA/XML Scripting / Skryptowanie LUA/XML Implementacja systemu "currency"

 
  • 0 Vote(s) - 0 Average
Implementacja systemu "currency"
Meritus
Offline

Uzytkownik

Posts: 28
Threads: 19
Joined: Jun 2010
Reputation: 4
#1
14-03-2011, 12:04 PM (This post was last modified: 14-03-2011, 12:15 PM by Meritus.)
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(cid, item, frompos, item2, topos)
    if 
item2.itemid ~= 0 then item = item2 end -- Dla userable
    local groupid 
= getCurrencyGroupID(item.itemid)
    
local nextitemid = getCurrencyNextElement(groupid, item.itemid)
    
local beforeitemid = getCurrencyPreviousElement(groupid,item.itemid)
    
local thisitemvalue = getCurrencyElementValue(groupid, item.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/thisitemvalue) then
                doPlayerAddItemEx
(cid,nextitemid,1)
            
end
        end
    
elseif beforeitemid ~= LUA_ERROR and nextitemid == LUA_ERROR then -- Ostatni
        
if doRemoveItem(item.uid,1) then
            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/thisitemvalue) then
                doPlayerAddItemEx
(cid,nextitemid,1)
            
end
        
elseif item.type < nextitemvalue/thisitemvalue then    -- nie ma ilosci wymaganej, usuwamy 1 i dodajemy x mniejszych
            
if doRemoveItem(item.uid,1) then
                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(cid, group_id)
doPlayerRemoveCurrency(cid, group_id, count)
doPlayerAddCurrency(cid, group_id, count) 

Pozdrawiam,
Meritus
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D - Powered by MyBB

Linear Mode
Threaded Mode