#batata LUA [script]

Sukela

ne yazsam bilemedim
Genel Moderatör
Mesajlar
485
En iyi cevaplar
83
Beğeniler
444
Puanları
3,190
Ruh hali
Evet, Transformice seven ve sunucusunu kurmak isteyen arkadaşlar için #batata minioyun lua script.​

Kod:
tfm.exec.disableAutoShaman()
tfm.exec.disableAutoNewGame()
tfm.exec.disableAutoTimeLeft()

game = {}
game.maps = {""} -- haritalar (deatmatch)
game.canStart = false
game.isStarted = false
game.isFinished = false
game.potato = nil
game.explosionTime = 15
game.currentTime = game.explosionTime * 2
game.playerCount = 0
game.isRoom = tfm.get.room.name:sub(1,2):find("#") and true or false
game.potatoImage = nil

game.data={}



lang = {
    ["en"] = {
        ["help"] = "Help",
        ["profile"] = "Profile",
        ["close"] = "Close",
        ["minPlayers"] = "<R>You need at least 2 players :(",
        ["welcome"] = "<N>Welcome to #batata module!",
        ["gotPotato"] = "<V>%s <BL>are with potato!",
        ["finishedRound"] = "<BL>Ended Up! <V>%s <BL>is the winner!",
        ["time"]  = "<J>%s <BL>- %s   |  <N>Time : <V>%i seconds",
        ["HowToPlay"] = "How to play"
    },

    ["tr"] = {
        ["help"] = "Yardım",
        ["profile"] = "Profil",
        ["close"] = "Kapat",
        ["minPlayers"] = "<R>Oyunu oynamak için en az 2 kullanıcı olmalı :(",
        ["welcome"] = "<N>#batata odasına hoşgeldiniz.",
        ["gotPotato"] = "<V>%s <BL>patates ile!",
        ["finishedRound"] = "<BL>Round bitti! <V>%s <BL>kazandı!",
        ["time"]  = "<J>%s <BL>- %s   |  <N>Süre : <V>%i seconds",
        ["HowToPlay"] = "Nasıl oynanır"
    }
}

function game.setPotato(name)
    if not game.isFinished and tfm.get.room.playerList[name] then
        if game.potato then
            tfm.exec.setNameColor(game.potato, 0)
            system.bindKeyboard(game.potato, 32, false, false)
            system.bindKeyboard(game.potato, 37, false, false)
            system.bindKeyboard(game.potato, 39, false, false)
            tfm.exec.removeImage(game.potatoImage)
        end
        
        game.potato = name
        if tfm.get.room.playerList[name].isFacingRight then
            game.potatoImage = tfm.exec.addImage("1d51f478746711e7af4488d7f643024a.png", "$"..game.potato, -2, -6)
        else
            game.potatoImage = tfm.exec.addImage("a5a3e21a746611e7af4488d7f643024a.png", "$"..game.potato, -22, -6)
        end
        tfm.exec.setNameColor(name, 0xFFFF00)
        system.bindKeyboard(name, 32, true, true)
        system.bindKeyboard(game.potato, 37, true, true)
        system.bindKeyboard(game.potato, 39, true, true)
        
        sendMessage(translate(name,"gotPotato"):format(name))
    end
end

function game.newGame()
    tfm.exec.newGame(game.maps[math.random(#game.maps)])
       tfm.exec.setGameTime(360)
end

function game.highScore()
    local hs, hsName = -1, nil
    for name, player in pairs(tfm.get.room.playerList) do
        if player.score > hs and not player.isDead then
            hs = player.score
            hsName = name
        end
    end
    return hsName
end


function split(t,s)
    local a={}
    for i,v in string.gmatch(t,string.format("[^%s]+",s or "%s")) do
        table.insert(a,i)
    end
    return a
end

eventChatCommand = function(name,cmd)
    if split(cmd," ")[1] == "lang" and split(cmd," ")[2] then
        game.data[name].lang=split(cmd," ")[2]   
    end
end

sendMessage = function(message, name)
    if game.isRoom then
        tfm.exec.chatMessage(message, name)
    else
        print(message)
    end
end

translate = function(name,message)
    return lang[game.data[name].lang] and lang[game.data[name].lang][message] or lang["en"][message]
end

eventNewGame = function()
    game.isStarted = false
    game.isFinished = false
    game.currentTime = game.explosionTime * 2
end

eventNewPlayer = function(name)
    if not game.data[name] then
        game.data[name]={
            press=0,
            lang="en"
        }
    end
    game.playerCount = game.playerCount + 1
    ui.addTextArea(3, "<a href='event:menu'><p align='center'><font size='13'>Menu >", name, 9, 29, 57, 22, 0x324650, 0x23343d, 1, true)
    
    if game.playerCount > 1 then
        game.canStart = true
    end
    
    if game.isRoom then
        sendMessage(translate(name,"welcome"), name)
        tfm.exec.lowerSyncDelay(name)
    end
    
    eventTextAreaCallback(0,name,"help")
end

eventPlayerLeft = function(name)
    game.playerCount = game.playerCount - 1
    
    if game.playerCount < 2 then
        game.canStart = false
    end
end

eventTextAreaCallback = function(id, name, callback)
    if callback == "menu" then
        ui.addTextArea(3, "<a href='event:menu'><p align='center'><font size='13'>Menu", name, 9, 29, 57, 22, 0x324650, 0x23343d, 1, true)
        ui.addTextArea(4, "<font size='13'><a href='event:help'>"..translate(name,"help").."</a> | <a href='event:Profile'>"..translate(name,"profile").."</a> | <a href='event:closeMenu'><", name, 74, 29, 200, 22, 0x101d24, 0x1c3d4d, 0.8, true)
    elseif callback == "closeMenu" then
        ui.removeTextArea(id, name)
        ui.addTextArea(3, "<a href='event:menu'><p align='center'><font size='13'>Menu >", name, 9, 29, 57, 22, 0x324650, 0x23343d, 1, true)
    elseif callback == "help" then
        eventTextAreaCallback(4,name,"closeMenu")
        found='<img src="http://imgur.com/hsOKuaU.png" />'
        ui.addTextArea(6, found, name, 100, 30, 600, 400, 0, 0, 0, true)
        ui.addTextArea(7, "<p align='center'>"..translate(name,"HowToPlay"), name, 100, 80, 100, 20, 0, 0, 0, true)
        ui.addTextArea(8, "<p align='center'><a href='event:closeHelp'>"..translate(name,"close"), name, 130, 312, 600, 20, 0, 0, 0, true)
    elseif callback == "closeHelp" then
        ui.removeTextArea(id,name)
        ui.removeTextArea(id-1,name)
        ui.removeTextArea(id-2,name)
        ui.removeTextArea(id-3,name)
        eventTextAreaCallback(4,name,"menu")
    elseif callback == "Profile" then
        eventTextAreaCallback(4,name,"closeMenu")
        found='<img src="https://i.hizliresim.com/P1llR7.png" />'
        potatoImage='<img src="http://cdn.miceforce.com/image/1d51f478746711e7af4488d7f643024a.png" />'
        ui.addTextArea(6, found, name, 200, 15, 600, 400, 0, 0, 0, true)
        ui.addTextArea(7, potatoImage, name, 245, 55, 100, 50, 0, 0, 0, true)
        ui.addTextArea(8, "<B><V><font size='20'>"..name, name, 340, 65, 200, 50, 0, 0, 0, true)
        ui.addTextArea(9, "<p align='center'><a href='event:closeHelp'>"..translate(name,"close"), name, 130, 362, 600, 20, 0, 0, 0, true)
    end
end

eventKeyboard = function(name, key, down, y, x)
    if key == 32 then
        if name == game.potato and game.data[name].press < os.time()-1000 then
            for target, player in pairs(tfm.get.room.playerList) do
                if (target -= name) and not player.isDead then
                    if x >= player.x - 15 and x <= player.x + 15 and y >= player.y - 20 and y <= player.y + 20 then
                        tfm.exec.removeImage(game.potatoImage)
                        game.setPotato(target)
                        game.data[target].press=os.time();
                        break
                    end
                end
            end
        end
    end

    if key == 37 and game.isStarted and name == game.potato then
        tfm.exec.removeImage(game.potatoImage)
        game.potatoImage = tfm.exec.addImage("a5a3e21a746611e7af4488d7f643024a.png", "$"..name, -22, -6)
    elseif key == 39 and game.isStarted and name == game.potato then
        tfm.exec.removeImage(game.potatoImage)
        game.potatoImage = tfm.exec.addImage("1d51f478746711e7af4488d7f643024a.png", "$"..name, -2, -6)
    end
end

eventPlayerDied = function(name)
    if name == game.potato and not game.isFinished then
        local n = {}
        
        for i,v in pairs(tfm.get.room.playerList) do if not v.isDead then table.insert(n,i) end end
        if #n > 0 then
            game.setPotato(n[math.random(#n)])
        else
            if game.canStart then
                game.newGame()
            else
                sendMessage(translate(name,"minPlayers"))
            end
        end
    end
end

eventLoop = function(current, remaining)
    if game.canStart then
        if game.isStarted then
            local alive, namesAlive = 0, {}
            
            for name, player in pairs(tfm.get.room.playerList) do
                if not player.isDead then
                    alive = alive + 1
                    namesAlive[#namesAlive+1] = name
                end
            end
            
            if alive == 1 then
                game.isFinished = true
                tfm.exec.giveCheese(namesAlive[1])
                tfm.exec.playerVictory(namesAlive[1])
                tfm.exec.setGameTime(6)
                for i,v in pairs(tfm.get.room.playerList) do
                    sendMessage(translate(i,"finishedRound"):format(namesAlive[1]),i)
                end
            end
            
            if remaining <= 0 then game.newGame() end
            
            if not game.isFinished then
                ui.addTextArea(10, "<p align=\"center\"><font size=\"25\"><J><B>"..math.floor(game.currentTime/2).." (tfm.get.room.xmlMapInfo.author, tfm.get.room.currentMap, math.floor(game.currentTime/2)", nil, 740, 355, 46, 39, 0x000001, 0x000000, 0.8, true)
                game.currentTime = game.currentTime - 1
                
                local particles = {2, 13}
                for i = 1, 3 do
                    tfm.exec.displayParticle(particles[math.random(#particles)], tfm.get.room.playerList[game.potato].y, tfm.get.room.playerList[game.potato].x - math.random(5, 15), math.random(-2, 2), math.random(-2, 2))
                end
            
                if game.currentTime == 0 then
                    if alive == 2 then
                        game.currentTime = game.explosionTime * 2
                        tfm.exec.killPlayer(game.potato)
                        
                        local i = 1
                        while(game.potato == namesAlive) do
                            i = i + 1
                        end
                        
                        game.isFinished = true
                        tfm.exec.giveCheese(namesAlive)
                        tfm.exec.playerVictory(namesAlive)
                        tfm.exec.setGameTime(6)
                        for i,v in pairs(tfm.get.room.playerList) do
                            sendMessage(translate(i,"finishedRound"):format(namesAlive),i)
                        end
                    else
                        game.currentTime = game.explosionTime * 2
                        tfm.exec.killPlayer(game.potato)
                    end
                end
            end
        else
            if current >= 5000 then
                game.setPotato(game.highScore())
                game.isStarted = true
                
                tfm.exec.setPlayerScore(game.potato, 0)
            end
        end
    end
end

for name,v in pairs(tfm.get.room.playerList) do
    eventNewPlayer(name)
    tfm.exec.setPlayerScore(name, 0)
end

if game.canStart then
    game.newGame()
else
    for name,v in pairs(tfm.get.room.playerList) do
        sendMessage(translate(name,"minPlayers"),name)
    end
end
 



Üst