×

Langue

Fermer
Atelier 801
  • Forums
  • Dev Tracker
  • Connexion
    • English Français
      Português do Brasil Español
      Türkçe Polski
      Magyar Română
      العربية Skandinavisk
      Nederlands Deutsch
      Bahasa Indonesia Русский
      中文 Filipino
      Lietuvių kalba 日本語
      Suomi עברית
      Italiano Česky
      Hrvatski Slovensky
      Български Latviešu
      Estonian
  • Langue
  • Forums
  • /
  • Transformice
  • /
  • Modules
  • /
  • Arrow shooting example
« ‹ 2 / 2
Arrow shooting example
Empty
« Citoyen »
1383485940000
    • Empty#8994
    • Profil
    • Derniers messages
    • Tribu
#21
  0
I have copy much parts of script of makinit , I could not adjust the angle for for evne click

Obs the math parts, script for spawn a object is simple

Y have translate look

local settings = {
mapa = "0",
qtdflechas = 6,
forcadotiro = 50,
recuo = 10,
maximodetirosnomapa = 30,
qtdflechasTicks = 2,
}

local players = {}
local objects = {}

function main()
objects = queue.new()
tfm.exec.disableAutoScore(false)
tfm.exec.disableAutoShaman(true)
tfm.exec.disableAutoNewGame(true)
tfm.exec.newGame(settings.mapa)
end

function eventNewGame()
tfm.exec.setGameTime(0, true)
players = {}
for name in pairs(tfm.get.room.playerList) do
initPlayer(name)
end
end

function initPlayer(name)
players[name] = {qtdflechas = 0}
ui.addTextArea(0, "", name, 10, 30, settings.qtdflechas * 15, 20, 0x010101, 0x000000, 0.5)
system.bindMouse(name, true)
end

function eventMouse(name, x, y)
local player = players[name]
if player and player.qtdflechas > 0 then
-- Remover quantidade de flechas
ui.removeTextArea(player.qtdflechas * 2 - 1, name)
ui.removeTextArea(player.qtdflechas * 2, name)
player.qtdflechas = player.qtdflechas - 1

local roomPlayer = tfm.get.room.playerList[name]

-- Calcula angulo do clique e lançamento
local dx = x - roomPlayer.x
local dy = y - roomPlayer.y
local angle = math.atan2(dy, dx)

-- Calcular velocidade da flecha
local vx = math.cos(angle)
local vy = math.sin(angle)

-- Criar flecha e coloca-la na espera para remoção
queue.insert(objects, tfm.exec.addShamanObject(35, roomPlayer.x + 20 * vx, roomPlayer.y + 20 * vy, angle*180/math.pi, settings.forcadotiro * vx, settings.forcadotiro * vy, false))

local recuo = -vx * settings.recuo
-- Procurar em volta para algum bug
if recuo <= -1 or recuo >= 1 then
tfm.exec.movePlayer(name, 0, 0, true, recuo, 0, true)
end

-- Remover primeiras flechas se houver muitas
if objects.size > settings.maximodetirosnomapa then
tfm.exec.removeObject(queue.remove(objects))
end
end
end

local loopCount = 0
function eventLoop()
-- Reseta a partir de uma contagem de flechas
if loopCount == 0 then
qtdflechas()
end
loopCount = (loopCount + 1) % settings.qtdflechasTicks
end

ui.addPopup(1,0,"Script Arrow Clicker By: Makinit | Tradução by: Chadgraygui",player,300,100,200)

function qtdflechas()
for name, player in pairs(players) do
local qtdflechas = player.qtdflechas
if qtdflechas < settings.qtdflechas then
-- Quantidades de flechas com o tempo
player.qtdflechas = qtdflechas + 1
ui.addTextArea(qtdflechas * 2 + 1, "", name, 14 + qtdflechas * 15, 39, 3, 3, 0x990000, 0x990000, 1)
ui.addTextArea(qtdflechas * 2 + 2, "", name, 15 + qtdflechas * 15, 40, 1, 1, 0xff0000, 0xcc0000, 1)
end
end
end

function eventNewPlayer(name)
initPlayer(name)
tfm.exec.respawnPlayer(name)
end

function eventPlayerDied(name)
tfm.exec.respawnPlayer(name)
end

function eventPlayerWon(name)
tfm.exec.respawnPlayer(name)
end

-- Tableas nil que mudam de acordo com a variavel
queue = {}
function queue.new()
return {
tail = nil,
head = nil,
size = 0
}
end

function queue.insert(self, v)
local i = {
value = v,
next = nil
}
if self.tail and self.head then
self.tail.next = i
else
self.head = i
end
self.tail = i
self.size = self.size + 1
end
function queue.peek(self)
if self.head then
return self.head.value
else
error("Não há flechas")
end
end
function queue.remove(self)
local r = queue.peek(self)
self.head = self.head.next
if not self.head then
tail = nil
end
self.size = self.size - 1
return r
end

print ("Script by makinit, translate by Chadgraygui")
print ("Script de makinit, traduzido por Chadgraygui")

main()
Empty
1383494520000
    • Empty#8994
    • Profil
    • Derniers messages
    • Tribu
#22
[Modéré par Whiskypickle, raison : Double post]
Makinit
« Citoyen »
1383559800000
    • Makinit#0095
    • Profil
    • Derniers messages
    • Tribu
#23
  0
Chadgraygui a dit :
Makinit give-me your permission for you queue remove?

Everyone is free to use my code in any way they like.
Leikektor
« Citoyen »
1383600600000
    • Leikektor#0000
    • Profil
    • Derniers messages
    • Tribu
#24
  0
Only Code ?
Tardigradou
« Citoyen »
1383626580000
    • Tardigradou#0000
    • Profil
    • Derniers messages
#25
  0
Makinit a dit :
Everyone is free to use my code in any way they like.

Even if no credit is given? What if someone takes your script and claims it as his own minigame? With very small changes (or no changes at all) ?
Makinit
« Citoyen »
1383645000000
    • Makinit#0095
    • Profil
    • Derniers messages
    • Tribu
#26
  0
Tardigradou a dit :
Even if no credit is given? What if someone takes your script and claims it as his own minigame? With very small changes (or no changes at all) ?

Sure.
Azuli
« Citoyen »
1384123260000
    • Azuli#9482
    • Profil
    • Derniers messages
#27
  0
Hello I created a mini Makinit your script, I devo ati, but as your script arrows you did want you to join the minigame #Arrowhunt and be admin? forgiveness is in SPANISH and forgive the translation :/
Topic-495110
Makinit
« Citoyen »
1384189260000
    • Makinit#0095
    • Profil
    • Derniers messages
    • Tribu
#28
  0
Azulisocpp a dit :
Hello I created a mini Makinit your script, I devo ati, but as your script arrows you did want you to join the minigame #Arrowhunt and be admin?

I won't be actively involved in developing your minigame, but if you have questions you can always ask them.
Azuli
« Citoyen »
1384228080000
    • Azuli#9482
    • Profil
    • Derniers messages
#29
  0
Makinit a dit :
I won't be actively involved in developing your minigame, but if you have questions you can always ask them.

Ok thanks
Leafileaf
« Citoyen »
1384235100000
    • Leafileaf#0000
    • Profil
    • Derniers messages
    • Tribu
#30
  0
Makinit a dit :
An example which uses mouse clicks, objects, physics, timing, text areas and a queue. I added some comments where needed. Feel free to comment and ask questions.

*beautiful code*

Nice script maki. I could use the part that determines the angle.
Overjoy06
« Citoyen »
1530864060000
    • Overjoy06#8554
    • Profil
    • Derniers messages
    • Tribu
#31
  0
local settings = {
map = "0",
ammo = 6,
force = 50,
recoil = 10,
maxObjects = 30,
ammoTicks = 2,
}

local players = {}
local objects = {}

function main()
objects = queue.new()
tfm.exec.disableAutoScore(false)
tfm.exec.disableAutoShaman(true)
tfm.exec.disableAutoNewGame(true)
tfm.exec.newGame(settings.map)
end

function eventNewGame()
tfm.exec.setGameTime(0, true)
players = {}
for name in pairs(tfm.get.room.playerList) do
initPlayer(name)
end
end

function initPlayer(name)
players[name] = {ammo = 0}
ui.addTextArea(0, "", name, 10, 30, settings.ammo * 15, 20, 0x010101, 0x000000, 0.5)
system.bindMouse(name, true)
end

function eventMouse(name, x, y)
local player = players[name]
if player and player.ammo > 0 then
-- remove one ammo
ui.removeTextArea(player.ammo * 2 - 1, name)
ui.removeTextArea(player.ammo * 2, name)
player.ammo = player.ammo - 1

local roomPlayer = tfm.get.room.playerList[name]

-- calculate angle between player and click
local dx = x - roomPlayer.x
local dy = y - roomPlayer.y
local angle = math.atan2(dy, dx)

-- calculate speeds to direct arrow and always have the same total speed
local vx = math.cos(angle)
local vy = math.sin(angle)

-- spawn arrow and add to queue
queue.insert(objects, tfm.exec.addShamanObject(35, roomPlayer.x + 20 * vx, roomPlayer.y + 20 * vy, angle*180/math.pi, settings.force * vx, settings.force * vy, false))

local recoil = -vx * settings.recoil
-- workaround to avoid argument exception bug
if recoil <= -1 or recoil >= 1 then
tfm.exec.movePlayer(name, 0, 0, true, recoil, 0, true)
end

-- remove first arrow when there are too many
if objects.size > settings.maxObjects then
tfm.exec.removeObject(queue.remove(objects))
end
end
end

local loopCount = 0
function eventLoop()
-- loopCount resets after a certain amount
if loopCount == 0 then
ammo()
end
loopCount = (loopCount + 1) % settings.ammoTicks
end

function ammo()
for name, player in pairs(players) do
local ammo = player.ammo
if ammo < settings.ammo then
-- add one ammo
player.ammo = ammo + 1
ui.addTextArea(ammo * 2 + 1, "", name, 14 + ammo * 15, 39, 3, 3, 0x990000, 0x990000, 1)
ui.addTextArea(ammo * 2 + 2, "", name, 15 + ammo * 15, 40, 1, 1, 0xff0000, 0xcc0000, 1)
end
end
end

function eventNewPlayer(name)
initPlayer(name)
tfm.exec.respawnPlayer(name)
end

function eventPlayerDied(name)
tfm.exec.respawnPlayer(name)
end

function eventPlayerWon(name)
tfm.exec.respawnPlayer(name)
end

-- simple queue for performance, much faster than system table queues, can contain nils
queue = {}
function queue.new()
return {
tail = nil,
head = nil,
size = 0
}
end
function queue.insert(self, v)
local i = {
value = v,
next = nil
}
if self.tail and self.head then
self.tail.next = i
else
self.head = i
end
self.tail = i
self.size = self.size + 1
end
function queue.peek(self)
if self.head then
return self.head.value
else
error("queue is empty")
end
end
function queue.remove(self)
local r = queue.peek(self)
self.head = self.head.next
if not self.head then
tail = nil
end
self.size = self.size - 1
return r
end

main()
players = {}
for name,player in pairs(tfm.get.room.playerList) do
table.insert(players,name)
end
local blue, red = {}, {}
local inBlue = false
local blueRespawn = { x = 100 , y = 380 }
local redRespawn = { x = 850, y = 380 }

function eventNewPlayer(name)
inBlue = not inBlue
if inBlue then
blue[name] = true
else
red[name] = true
end
end

for n in next, tfm.get.room.playerList do
eventNewPlayer(n)
end

function eventNewGame()
for n in next, blue do
tfm.exec.movePlayer(n, blueRespawn.x, blueRespawn.y)
end

for n in next, red do
tfm.exec.movePlayer(n, redRespawn.x, redRespawn.y)
end
end

--Now why doesnt it work..
• # [*The vampires tribe] Runtime Error : org.luaj.vm2.LuaError: Overjoy06#0000.lua:82: attempt to compare __lt on nil and number
  • Forums
  • /
  • Transformice
  • /
  • Modules
  • /
  • Arrow shooting example
« ‹ 2 / 2
© Atelier801 2018

Equipe Conditions Générales d'Utilisation Politique de Confidentialité Contact

Version 1.27