• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

PHP delete selected monsters from spawn file

emil92b

Intermediate OT User
Joined
Aug 21, 2013
Messages
335
Solutions
13
Reaction score
134
Location
Sweden
i'm trying to delete selected monsters from the spawn.xml file, so far i've added a list of these. im not sure how i could make a script that loops through the file and deletes em in a special way

PHP:
ExampleRemoveList = {"Demon", "Behemoth", "Hydra"}

only delete the demon, but leave the rats since they are not in the list
XML:
<spawn centerx="1" centery="2" centerz="7" radius="3">
    <monster name="Rat" x="2" y="-2" z="12" spawntime="90" />
    <monster name="Rat" x="1" y="-1" z="12" spawntime="90" />
    <monster name="Demon" x="-3" y="1" z="12" spawntime="90" /> <!-- delete -->
</spawn>

should delete spawn block since it only contains monster from the list
XML:
<spawn centerx="1" centery="2" centerz="7" radius="3"> <!-- delete -->
    <monster name="Behemoth" x="-3" y="1" z="12" spawntime="90" /> <!-- delete -->
    <monster name="Behemoth" x="-3" y="1" z="12" spawntime="90" /> <!-- delete -->
</spawn> <!-- delete -->
 
You can make a script so that it goes through each line and you copy and paste these lines in a new file, you must check if the word "Demon" exists in the current line and if it does exist then we ignore this line and go to the next one and so on.

Code Example:

test.lua
Lua:
local removes = {
    "Demon",
    "Rat"
}

function getNthLine(fileName, n)
    local f = io.open(fileName, "r")
    local o = io.open("output.xml", "w")
    for line in f:lines() do
        for _, rem in pairs(removes) do
            if line:find(rem) or line:find(rem:lower()) then
                goto continue
            end
        end
        o:write(line .. "\n")
        ::continue::
    end

    f:close()
    o:close()
end

getNthLine("test.lua")

Output:
output.xml
XML:
local removes = {
}

function getNthLine(fileName, n)
    local f = io.open(fileName, "r")
    local o = io.open("output.xml", "w")
    for line in f:lines() do
        for _, rem in pairs(removes) do
            if line:find(rem) or line:find(rem:lower()) then
                goto continue
            end
        end
        o:write(line .. "\n")
        ::continue::
    end

    f:close()
    o:close()
end

getNthLine("test.lua")
 
Last edited:
Back
Top