Page 1 of 1

BFLogBot

PostPosted: Wed Apr 03, 2013 6:17 pm
by Fordcars
Sorry, I was bored again :/

This bot will log everything said in chat. Make sure that you create a file called "bflog.txt" and write the path to that file in the code, where it says so :roll:

Examples:
  Code:
file = io.open("/users/BitfighterRocks/DesktopFolder/bflog.txt", "a+")

file = io.open("C:/Documents and Settings/BF/desktop/bflog.txt", "a+")

file = io.open("/usr/BF/desktop/bflog.txt", "a+")


Happy bitting!

BOT CODE:
  Code:
---------BFLogBot
---------by fordcars


function getName() -- Called once
    return("BFLogBot")
end

function main() -- This is the first code ran, after loose code
    playerShip = nil

    subscribe(Event.MsgReceived)

    file = nil

    file = io.open("ENTER TXT PATH HERE", "a+")
    file:write("---------------------------------- \n")
    file:close()
end

function onMsgReceived(message, player)

    file = io.open("ENTER TXT PATH HERE", "a+")

    if (player:getName() == nil) then
        file:write("UNKNOWN: " .. message .. "\n")
        file:close()
        return
    else
        playerShip = player:getName()
        file:write(playerShip .. ": " .. message .. "\n")
        file:close()
        return
    end
end


 

Re: BFLogBot

PostPosted: Wed Apr 03, 2013 6:25 pm
by raptor
This is awesome!

Re: BFLogBot

PostPosted: Wed Apr 03, 2013 6:31 pm
by Fordcars
Thanks!

Re: BFLogBot

PostPosted: Thu Apr 04, 2013 8:21 am
by watusimoto
I think this might be better as a levelgen script, so people can't kill the logbot!

Re: BFLogBot

PostPosted: Thu Apr 04, 2013 4:10 pm
by Fordcars
haha yeah, well this was a test for using external files...
But I can't get levelgens to work, probably need a newer Bitfighter.

Re: BFLogBot

PostPosted: Mon Apr 08, 2013 8:22 pm
by amgine
actually this could be helpful for reporting bad players but should be off screen auto running as a option not a bot......

Re: BFLogBot

PostPosted: Wed Apr 10, 2013 3:00 pm
by Little_Apple
edited version that runs as a levelgen:
  Code:
---------BFLogBot
---------by fordcars
---------edited by that handsome devil Little_Apple

function main() -- This is the first code ran, after loose code
    playerShip = nil

    subscribe(Event.MsgReceived)

    file = nil

    file = io.open("PUT PATH HERE", "a+")
    file:write("---------------------------------- \n")
    file:close()
end

function onMsgReceived(message, player)

    file = io.open("PUT PATH HERE", "a+")

    if (player:getName() == nil) then
        file:write("UNKNOWN: " .. message .. "\n")
        file:close()
        return
    else
        playerShip = player:getName()
        file:write(playerShip .. ": " .. message .. "\n")
        file:close()
        return
    end
end


 

Re: BFLogBot

PostPosted: Wed Apr 10, 2013 3:01 pm
by Fordcars
handsome devil :twisted:

Re: BFLogBot

PostPosted: Thu Jul 25, 2013 3:02 am
by karamazovapy
Neat idea.

Re: BFLogBot

PostPosted: Thu Jul 25, 2013 7:20 am
by watusimoto
It would be better not to open and close the file with each write... ideally, you'd open it once when the script is run, and we'd have an onShutdown() method that gets run when the script is terminating that would close the file.

That would be far more efficient.

Re: BFLogBot

PostPosted: Wed Jul 31, 2013 11:16 am
by Fordcars
Hehe, yeah :p