×

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
  • /
  • [Module] Synergie
[Module] Synergie
Axiome
« Citoyen »
1545754380000
    • Axiome#3619
    • Profil
    • Derniers messages
#1
  1
  • Présentation
  • Code

Synergie



Petite présentation

Synergie est un petit module où doivent s'affronter différentes équipes constituées de plusieurs joueurs sur des cartes racing (P17).
(!) Les équipes doivent être manuellement configurées dans les premières lignes de code.

Dans chaque équipe, il y'a une rotation des joueurs. Un seul joueur à la fois de chaque équipe est présent sur la map et lorsqu'il rentre dans le trou ou meurt, c'est le joueur suivant qui prend le relais. Quand un joueur de l'équipe rentre dans le trou, l'équipe gagne un point, le but étant donc d'amasser un maximum de fromages.

La durée par défaut de chaque map (configurable) est plus grande que la normale, ce qui permet de rentrer plusieurs fois sur la même map. Un petit classement est maintenu en dehors du cadre de jeu. Les scores des joueurs (dans la liste des joueurs du salon) représentent le rang de leur équipe dans le classement (le score 0 décrit un spectateur).


Screenshots

https://i.imgur.com/hRorC7w.png


https://i.imgur.com/74dvN4C.png


Futures évolutions ?

Le but de ce module était avant tout de me remettre doucement au Lua, pas forcément d'en faire un mini-jeu intéressant (c'est un échauffement ^^). Si le concept vous intéresse toutefois, que vous utilisez ce module et avez des remarques/suggestions à faire, n'hésitez pas à m'en faire part.

v1.0 (25 décembre)
(!) Les équipes doivent être manuellement configurées dans les premières lignes de code (partie "Settings").

Code Lua

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
-- Synergie v1.0 (by Axiome#3619)

-- Settings

timePerGame = 200 -- (seconds)
canSkip = {}
canSkip["Axiome#3619"] = true

teamsList = {}
teamsList["Test"] = {"Axiome#3619", "Souris778#3456", "Souris779#3456"}
teamsList["Ennemis"] = {"Souris780#3456", "Souris781#3456"}

-- Teams init

playerToTeam = {}

for teamName, team in pairs(teamsList) do
team.points = 0
team.curPlayer = 1
for pid, player in ipairs(team) do
playerToTeam[player] = {name=teamName, pid=pid}
end
end


-- User Interface

areaID = {}
areaID.infoBox = 1
areaID.ranking = 2

function updateInfoBox(playerName)
local text = ""
local playerTeam = playerToTeam[playerName]

local color = 0xEDE91B -- yellow

if playerToTeam[playerName] == nil then
text = "<font face='Calibri' size='20' color='#000001'><p align='center'>Vous êtes spectateur</p></span>"
elseif teamsList[playerTeam.name].curPlayer ~= playerTeam.pid then
text = "<font face='Calibri' size='20' color='#000001'><p align='center'>Vous êtes en attente dans l'équipe " .. playerToTeam[playerName].name .. "</p></span>"
else
color = 0x1BED3B -- green
text = "<font face='Calibri' size='20' color='#000001'><p align='center'>Vous jouez dans l'équipe " .. playerToTeam[playerName].name .. "</p></span>"
end

ui.addTextArea(areaID.infoBox, text, playerName, 30, 30, 700, 30, color, nil, 0.35, nil)
end

function cmpPoints(a, b)
return teamsList[a].points > teamsList[b].points
end

function updateRanking()
local teamsScores = {}
for teamName, team in pairs(teamsList) do
table.insert(teamsScores, teamName)
end
table.sort(teamsScores, cmpPoints)

for playerName, infos in pairs(tfm.get.room.playerList) do
if playerToTeam[playerName] == nil then
tfm.exec.setPlayerScore(playerName, 0)
end
end

local text = "<p>"
local lineBreak = false
for rank, teamName in ipairs(teamsScores) do

if lineBreak then
text = text .. "<br>"
end
lineBreak = true

text = text..rank.." - "..teamName.." ("..teamsList[teamName].points..")"
for _, playerName in ipairs(teamsList[teamName]) do
tfm.exec.setPlayerScore(playerName, rank)
end
end
text = text.."</p>"

ui.addTextArea(areaID.ranking, text, playerName, -150, 10, 130)
end

-- Timers

timersIds = {}
timersIds.mapRotation = 1

timersList = {}

function addTimer(id, delay, callback, ...)
timersList[id] = {triggerDate=os.time() + math.floor(delay*1000) - 50, callback=callback, args={...}}
end

function removeTimer(tid)
if timersList[tid] then
table.remove(timersList, tid)
end
end

function eventLoop(currentTime, timeRemaining)
local curTime = os.time()
local toProcess = {}

for tid, timer in pairs(timersList) do
if timer and curTime >= timer.triggerDate then
table.insert(toProcess, tid)
end
end

for _, tid in pairs(toProcess) do
local timer = timersList[tid]
if timer then
removeTimer(tid)
timer.callback(table.unpack(timer.args))
end
end
end

-- Event handler

function eventPlayerDied(playerName)
local info = playerToTeam[playerName]
if info and info.pid == teamsList[info.name].curPlayer then
teamNextPlayer(playerToTeam[playerName].name, false)
end
end

function eventPlayerWon(playerName)
local info = playerToTeam[playerName]
if info and info.pid == teamsList[info.name].curPlayer then
teamNextPlayer(playerToTeam[playerName].name, true)
end
end

function eventNewPlayer(playerName)
updateInfoBox(playerName)
updateRanking()
local info = playerToTeam[playerName]
if info and info.pid == teamsList[info.name].curPlayer then
tfm.exec.respawnPlayer(playerName)
end
end

function eventChatCommand(playerName, message)
if canSkip[playerName] and message == "skip" then
mapRotation()
end
end

-- Core

function teamNextPlayer(teamName, hasWon)
local team = teamsList[teamName]

if hasWon then
team.points = team.points + 1
updateRanking()
end

local oldPlayer = team[team.curPlayer]
updateInfoBox(team[team.curPlayer])
team.curPlayer = team.curPlayer + 1
if team.curPlayer > #team then
team.curPlayer = 1
end

updateInfoBox(oldPlayer)
updateInfoBox(team[team.curPlayer])
tfm.exec.killPlayer(oldPlayer)
tfm.exec.respawnPlayer(team[team.curPlayer])
end

function mapRotation()
removeTimer(timersIds.mapRotation)
tfm.exec.newGame("#17")
addTimer(timersIds.mapRotation, timePerGame, mapRotation)
tfm.exec.setGameTime(timePerGame)

for playerName, _ in pairs(tfm.get.room.playerList) do
local info = playerToTeam[playerName]
if info == nil or info.pid ~= teamsList[info.name].curPlayer then
tfm.exec.killPlayer(playerName)
end
end
end

tfm.exec.disableAfkDeath()
tfm.exec.disableAutoNewGame()
tfm.exec.disableAutoTimeLeft()
tfm.exec.disableAutoScore()

addTimer(timersIds.mapRotation, 1, mapRotation)
for playerName, _ in pairs(tfm.get.room.playerList) do
updateInfoBox(playerName)
end
updateRanking()

Dernière modification le 1545772140000
Nightingale
« Consul »
1545760440000
    • Nightingale#8883
    • Profil
    • Derniers messages
    • Tribu
#2
  1
Ça à l'air trop bien, merci et bravo !
Carmin
« Consul »
1559924940000
    • Carmin#3116
    • Profil
    • Derniers messages
    • Tribu
#3
  0
Super lua, merci à toi Axiome#3619 ;)
Jordanalica
« Citoyen »
1561508580000
    • Jordanalica#0000
    • Profil
    • Derniers messages
    • Tribu
#4
  0
ok....
  • Forums
  • /
  • Transformice
  • /
  • Modules
  • /
  • [Module] Synergie
© Atelier801 2018

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

Version 1.27