What's new

Mods System g?odu

Status
Not open for further replies.

Forseti

Senior User
Joined
Dec 23, 2011
Messages
954
Reaction score
82
Autor: Hellboy
Typ: Mod (globalevent, creatureevent, talkaction)
Testowane na: TFS 0.3.5pl1

Dzia?anie:
Gdy poziom najedzenia spadnie do 0 gracz dostaje ilo?? dmg ustalon? w zmiennej "dmgAmount", co jednostk? czasu ustalon? w zmiennej "dmgTime" (standard 5 sekund). Ponadto zmiana stanu najedzenia jest sygnalizowana w czasie gry odpowiednim komunikatem, kt?ry dostaje gracz.

Mo?na sprawdzi? poziom najedzenia komend? "/hunger".

Ponadto:
- poziom najedzenia jest zachowany po ?mierci gracza (co nie mia?o miejsca w standardowym TFSie)
- wprowadzi?em blokad?, aby nowi gracze nie dostawali dmg przy pierwszym zalogowaniu si?

Do zrobienia:
- dmg od g?odu nie powinno uniemo?liwia? wylogowanie si? (zabawa z pz)
- optymalizacja (estetyka kodu etc.)

Spos?b wstawienia na serwer:
Zapisujesz plik w formacie XML, o oboj?tnie jakiej nazwie z zawarto?ci? podan? poni?ej w folderze "mods", znajduj?cym si? w tym samym katalogu co folder "data".

PHP:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Hunger System by Kronos" version="1.1" author="Hellboy aka Kronos (idea Nandonalt)" contact="otfans.pl or otland.net" enabled="yes">
    <description>
        This mod adds hunger system to your's server.
    </description>
    <config name="hunger_config"><![CDATA[
        hungryStorageInfo = 3636
        dmgStorageInfo = 3637
 
        hungryTable = {{minFeed = 15, msg = "You will die if you don't eat something.", strCount = 1},
            {minFeed = 90, msg = "You are very hungry.", strCount = 2},
            {minFeed = 200, msg = "You are hungry.", strCount = 3},
            {minFeed = 395, msg = "You can eat something.", strCount = 4},
            {minFeed = 400, msg = "You are full.", strCount = 5}
        }
 
        dmgTime = 5*1000
        dmgAmount = 1
    ]]></config>
 
<event type="login" name="HungerLogin" event="script"><![CDATA[
        domodlib('hunger_config')
 
    function onLogin(cid)
        if getPlayerStorageValue(cid, dmgStorageInfo) > 1 then
            doPlayerFeed(cid, (getPlayerStorageValue(cid, dmgStorageInfo) - getPlayerStorageValue(cid, dmgStorageInfo)%3)/3) --- ((hungryTable[3]).minFeed - (hungryTable[3]).minFeed%3)/3
        end
        if getPlayerStorageValue(cid, dmgStorageInfo) == -1 then
            doPlayerFeed(cid, ((hungryTable[3]).minFeed - ((hungryTable[3]).minFeed)%3)/3) --- ((hungryTable[3]).minFeed - (hungryTable[3]).minFeed%3)/3
        end
 
        setPlayerStorageValue(cid, dmgStorageInfo, 0)
        registerCreatureEvent(cid, "HungerDeath")
        registerCreatureEvent(cid, "Hunger")
        feed = getPlayerFood(cid)
 
        for i = 1, table.maxn(hungryTable) do
            TABLE = hungryTable[i]
            if i == 1 then
                if feed <= TABLE.minFeed then
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, TABLE.msg)
                    setPlayerStorageValue(cid, hungryStorageInfo, TABLE.strCount)
                    break
                end
            end
 
            if i == table.maxn(hungryTable) then
                TABLE2 = hungryTable[i -1]
                if feed > TABLE2.minFeed then
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, TABLE.msg)
                    setPlayerStorageValue(cid, hungryStorageInfo, TABLE.strCount)
                    break
                end
            end
 
            if i ~= 1 then
                TABLE2 = hungryTable[i -1]
                if feed <= TABLE.minFeed and feed > TABLE2.minFeed then
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, TABLE.msg)
                    setPlayerStorageValue(cid, hungryStorageInfo, TABLE.strCount)
                    break
                end
            end
        end
        return true
    end
    ]]></event>
 
 
<event type="think" name="Hunger" event="script"><![CDATA[
        domodlib('hunger_config')
 
    function onThink(cid, interval)
 
        local online = {}
        if table.maxn(getPlayersOnline()) == 0 then
            stopEvent(hungerDmg)
            return true
        end
 
        for _, name in ipairs(getPlayersOnline()) do
            table.insert(online, name)
        end
 
        if isInArray(online, cid) == false then
            setPlayerStorageValue(cid, dmgStorageInfo, 0)
            stopEvent(hungerDmg)
            return true
        end
 
        if getPlayerFood(cid) > 0 then
            setPlayerStorageValue(cid, dmgStorageInfo, 0)
        end
 
        if getPlayerFood(cid) <= 0 and getPlayerStorageValue(cid, dmgStorageInfo) == 0 then
            hungerDmg(cid)
            setPlayerStorageValue(cid, dmgStorageInfo, 1)
        end
        return true
    end
 
    function hungerDmg (cid)
        local online = {}
        if table.maxn(getPlayersOnline()) == 0 then
            stopEvent(hungerDmg)
            return true
        end
 
        for _, name in ipairs(getPlayersOnline()) do
            table.insert(online, name)
        end
 
        if getPlayerFood(cid) > 0 or isInArray(online, cid) == false then
            setPlayerStorageValue(cid, dmgStorageInfo, 0)
            stopEvent(hungerDmg)
            return true
        end
 
        if not getPlayerFlagValue(cid, PLAYERFLAG_CANNOTBEATTACKED) then
            doTargetCombatHealth(0, cid, COMBAT_UNDEFINEDDAMAGE, -dmgAmount, -dmgAmount, CONST_ME_NONE)
            doSendAnimatedText(getCreaturePosition(cid), dmgAmount, TEXTCOLOR_RED)
            setPlayerStorageValue(cid, dmgStorageInfo, 1)
            addEvent(hungerDmg, dmgTime, cid)
        end
        return true
    end
    ]]></event>
<event type="death" name="HungerDeath" event="script"><![CDATA[
        domodlib('hunger_config')
 
    function onDeath (cid, corpse, killer)    
        feed = getPlayerFood(cid)
        if feed <= (hungryTable[3]).minFeed then
            setPlayerStorageValue(cid, dmgStorageInfo, (hungryTable[3]).minFeed)
        else
            setPlayerStorageValue(cid, dmgStorageInfo, feed)
        end
        return true
    end
    ]]></event>
 
 
<globalevent name="GiveHunger" interval="2" event="script"><![CDATA[
        domodlib('hunger_config')
 
    function onThink(interval, lastExecution, thinkInterval)
        local online = {}
 
        if table.maxn(getPlayersOnline()) == 0 then
            return true
        end
 
        for _, name in ipairs(getPlayersOnline()) do
            table.insert(online, name)
        end
 
        if table.maxn(online) == 0 then
            return true
        end
 
        for a = 1, table.maxn(online) do --- / ipairs
            cid = online[a]
            feed = getPlayerFood(cid)
            getStr = getPlayerStorageValue(cid, hungryStorageInfo)
 
            for i = 1, table.maxn(hungryTable) do
                TABLE = hungryTable[i]
                if i == 1 then
                    if feed <= TABLE.minFeed and TABLE.strCount ~= getStr then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, TABLE.msg)
                        setPlayerStorageValue(cid, hungryStorageInfo, TABLE.strCount)
                        break
                    end
                end
 
                if i == table.maxn(hungryTable) then
                    TABLE2 = hungryTable[i -1]
                    if feed > TABLE2.minFeed and TABLE.strCount ~= getStr then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, TABLE.msg)
                        setPlayerStorageValue(cid, hungryStorageInfo, TABLE.strCount)
                        break
                    end
                end
 
                if i ~= 1 then
                    TABLE2 = hungryTable[i -1]
                    if feed <= TABLE.minFeed and feed > TABLE2.minFeed and TABLE.strCount ~= getStr then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, TABLE.msg)
                        setPlayerStorageValue(cid, hungryStorageInfo, TABLE.strCount)
                        break
                    end
                end
            end
        end
        return true
    end
    ]]></globalevent>
 
<talkaction words="/hunger" hide="yes" event="script"><![CDATA[
        domodlib('hunger_config')
 
        function onSay(cid, words, param, channel)
            feed = getPlayerFood(cid)
 
            for i = 1, table.maxn(hungryTable) do
                TABLE = hungryTable[i]
                if i == 1 then
                    if feed <= TABLE.minFeed then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, TABLE.msg)
                        setPlayerStorageValue(cid, hungryStorageInfo, TABLE.strCount)
                        break
                    end
                end
 
                if i == table.maxn(hungryTable) then
                    TABLE2 = hungryTable[i -1]
                    if feed > TABLE2.minFeed then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, TABLE.msg)
                        setPlayerStorageValue(cid, hungryStorageInfo, TABLE.strCount)
                        break
                    end
                end
 
                if i ~= 1 then
                    TABLE2 = hungryTable[i -1]
                    if feed <= TABLE.minFeed and feed > TABLE2.minFeed then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, TABLE.msg)
                        setPlayerStorageValue(cid, hungryStorageInfo, TABLE.strCount)
                        break
                    end
                end
            end
            return true
        end
    ]]></talkaction>
 
</mod>
 

DanJ93

ElfBot Helper
Joined
Jan 18, 2009
Messages
2,631
Reaction score
200
Odp: System g?odu

Jak dla mnie skrypt troch? bez sensu,
lepiej go przerobi? ?e im bardziej jeste?my g?odni, tym wolniej chodzimy ; )
Wtedy to by mia?o sens
 
Status
Not open for further replies.
Top