naotriix Posted February 11, 2015 Share Posted February 11, 2015 Bonjour, j'ai un soucis avec mon userpanel, je voudrais limiter le nombre de maps dans la queue à 1 pour pouvoir ajouter un script de voteredo par les joueurs, je veux donc limite les maps par ne pas perdre de maps dans la queue en cas de voteredo. J'ai essayé de touché un peu au code mais sans succès. Je pense qu'il faut modifier du code a 2 endroits: _outputChatBox = outputChatBox local colorCode = "#0088FF" local colorTable = {0,136,255} local minPlayerCount = 0 shopPrice = { carColor = 10000, headlightColor = 15000, disco = 50000, police = 80000, gray = 150000, pink = 200000, map = 5000, } function onPanelStarted() makeScoreboardColumns() for _,thePlayer in pairs(getElementsByType("player")) do if isPlayerLogged(thePlayer) then refreshScoreboard(thePlayer) setElementData(thePlayer,"timeLogged",getTickCount()) end end updateSettings() end addEventHandler("onResourceStart",getRootElement(),onPanelStarted) function onPanelStop() for _,thePlayer in pairs(getElementsByType("player")) do if isPlayerLogged(thePlayer) then addValue(thePlayer,"timePlayed",(getTickCount()-getElementData(thePlayer,"timeLogged"))) setElementData(thePlayer,"timeLogged",getTickCount()) end end end addEventHandler("onResourceStop",getRootElement(),onPanelStop) function onPlayerLoginToServer() if isPlayerLogged(source) then setElementData(source,"timeLogged",getTickCount()) if not getElementData(source,"joinAdded") then addValue(source,"timesJoined",1) setElementData(source,"joinAdded",true) end onPlayerLoginHandler(source) sentMapQueueToClients() end end addEventHandler("onPlayerLogin",getRootElement(),onPlayerLoginToServer) function onPlayerLoginHandler(thePlayer) if isPlayerLogged(thePlayer) then checkPlayerDataOnLogin(thePlayer) refreshScoreboard(thePlayer) updateUserpanelData(thePlayer) premiumPlayerLogin(thePlayer) updatePlayerAchievements(thePlayer) checkAchievements(thePlayer,1) checkAchievements(thePlayer) callClientFunction(thePlayer,"allowBind",true) updatePlayerRank(thePlayer) setPlayerData(source,"nickName",getPlayerName(thePlayer)) end end function onPlayerLogoutFromServer(thePreviousAccount) setAccountData(thePreviousAccount,"timePlayed",tonumber(getAccountData(thePreviousAccount,"timePlayed"))+(getTickCount()-getElementData(source,"timeLogged"))) setElementData(source,"timeLogged",getTickCount()) callClientFunction(source,"allowBind",false) end addEventHandler("onPlayerLogout",getRootElement(),onPlayerLogoutFromServer) function onPlayerQuitFromServer() if isPlayerLogged(source) then declinePVPForPlayer(source) addValue(source,"timePlayed",getTickCount()-getElementData(source,"timeLogged")) setElementData(source,"timeLogged",getTickCount()) end end addEventHandler("onPlayerQuit",getRootElement(),onPlayerQuitFromServer) function makeScoreboardColumns() call(getResourceFromName("scoreboard"),"scoreboardAddColumn","Cash",getRootElement(),70) call(getResourceFromName("scoreboard"),"scoreboardAddColumn","Points",getRootElement(),70) call(getResourceFromName("scoreboard"),"scoreboardAddColumn","Rank",getRootElement(),70) end function refreshScoreboard(thePlayer) if isPlayerLogged(thePlayer) then local playerCash = getPlayerData(thePlayer,"cash") local playerPoints = getPlayerData(thePlayer,"EXP") setElementData(thePlayer,"Cash","$"..playerCash) setElementData(thePlayer,"Points",playerPoints) else setElementData(thePlayer,"Cash","Guest") setElementData(thePlayer,"Points","Guest") setElementData(thePlayer,"Rank","?") end end function getServerMaps(thePlayer) --if isPlayerLogged(thePlayer) then local mapsTable = call(getResourceFromName("mapmanager"),"getMapsCompatibleWithGamemode",getResourceFromName("race")) local mapsToSent = {mapName = {},resourceName = {}} for id,map in pairs(mapsTable) do table.insert(mapsToSent.mapName,getResourceInfo(map, "name") or getResourceName(map)) table.insert(mapsToSent.resourceName,getResourceName(map)) end callClientFunction(thePlayer,"updateMapList",mapsToSent) --end end function updatePlayersGridlist() local playersTable = {} for i,thePlayer in pairs(getElementsByType("player")) do if isPlayerLogged(thePlayer) then table.insert(playersTable,getPlayerName(thePlayer)) end end callClientFunction(getRootElement(),"updatePlayerGridlist",playersTable) end addEventHandler("onPlayerJoin",getRootElement(),updatePlayersGridlist) addEventHandler("onPlayerLogin",getRootElement(),updatePlayersGridlist) addEventHandler("onPlayerLogout",getRootElement(),updatePlayersGridlist) addEventHandler("onPlayerQuit",getRootElement(),updatePlayersGridlist) function onPlayerChangeNickHandler(arg1,arg2) if arg2 and isPlayerLogged(source) then setPlayerData(source,"nickName",arg2) end setTimer(updatePlayersGridlist,1000,1) end addEventHandler("onPlayerChangeNick",getRootElement(),onPlayerChangeNickHandler) function getPlayerStats(searchPlayer,playerWanted) if searchPlayer and playerWanted then if isPlayerLogged(searchPlayer) then local playerStats = {} playerStats[1] = getPlayerData(searchPlayer,"cash") playerStats[2] = getPlayerData(searchPlayer,"EXP") playerStats[3] = getPlayerData(searchPlayer,"mapsPlayed") playerStats[4] = getPlayerData(searchPlayer,"mapsWon") if playerStats[3] ~= 0 then playerStats[5] = (math.floor(playerStats[4]/playerStats[3]*100)).."%" else playerStats[5] = "0%" end playerStats[6] = getPlayerData(searchPlayer,"totalHunters") playerStats[7] = getPlayerData(searchPlayer,"totalToptimes") playerStats[8] = getPlayerData(searchPlayer,"firstToptimes") playerStats[9] = getPlayerData(searchPlayer,"playedPVP") playerStats[10] = getPlayerData(searchPlayer,"wonPVP") if playerStats[9] ~= 0 then playerStats[11] = tonumber(math.floor(playerStats[10]/playerStats[9]*100)).."%" else playerStats[11] = "0%" end playerStats[12] = msToTimeString(getPlayerData(searchPlayer,"timePlayed")) playerStats[13] = getPlayerData(searchPlayer,"timesJoined") playerStats[14] = getPlayerData(searchPlayer,"totalSpins") playerStats[15] = getPlayerData(searchPlayer,"wonSpins") playerStats[16] = getPlayerData(searchPlayer,"totalBets") playerStats[17] = getPlayerData(searchPlayer,"betsWon") local achU = 0 for i=1,achievementCount do if getPlayerData(searchPlayer,"ach"..i) == 1 then achU = achU + 1 end end playerStats[18] = achU.."/"..achievementCount playerStats[19] = getPlayerData(searchPlayer,"maxWinstreak") playerStats[20] = getPlayerData(searchPlayer,"playedDM") playerStats[21] = getPlayerData(searchPlayer,"wonDM") playerStats[22] = getPlayerData(searchPlayer,"playedDD") playerStats[23] = getPlayerData(searchPlayer,"wonDD") callClientFunction(playerWanted,"setWantedStats",getPlayerName(searchPlayer),playerStats) end end end function onMapStartingHandler(mapInfo) mapType = false if string.find(mapInfo.name,"[DM]",1) then mapType = "DM" elseif string.find(mapInfo.name,"[DD]",1) then mapType = "DD" end for _,thePlayer in pairs(getElementsByType("player")) do if isPlayerLogged(thePlayer) then if getElementData(thePlayer,'currentPVP') then local pvpData = getElementData(thePlayer,'currentPVP') pvpData.started = true setElementData(thePlayer,'currentPVP',pvpData) end addValue(thePlayer,"mapsPlayed",1) if mapType then if mapType == "DM" then addValue(thePlayer,"playedDM",1) elseif mapType == "DD" then addValue(thePlayer,"playedDD",1) end end end end startBettingTime() end addEvent("onMapStarting",true) addEventHandler("onMapStarting",getRootElement(),onMapStartingHandler) function checkPickupedPickup(pickupID,pickupType,pickupModel) if pickupType == "vehiclechange" then if pickupModel == 425 then if isPlayerLogged(source) then hunterReachedHandler(source) end end setPlayerVehicleColors(source) end end addEvent("onPlayerPickUpRacePickup",true) addEventHandler("onPlayerPickUpRacePickup",getRootElement(),checkPickupedPickup) function hunterReachedHandler(thePlayer) if isPlayerLogged(thePlayer) then addValue(thePlayer,"totalHunters",1) addValue(thePlayer,"cash",500) addValue(thePlayer,"EXP",5) outputChatBox("#0088FF[HUNTER]#ffffff You reached hunter and earned {colorCode}5 #ffffff points and {colorCode}$500 #ffffff cash.",thePlayer,255,255,255,true) refreshScoreboard(thePlayer) checkAchievements(thePlayer,3) Link to comment
Moderators Citizen Posted February 13, 2015 Moderators Share Posted February 13, 2015 J'ai pas très bien compris pourquoi tu veux limiter la mapQueue à 1 on peut très bien faire un vote redo sans toucher à la mapQueue. Dans le 1er script, il n'y a rien à toucher, il n'y a rien d’intéressant. Par contre dans le 2ème, je te propose les modifications suivantes: 1 - Modifier la fonction updateMapQueueOnMapStart ligne 92 comme ceci (tu peux copier/coller) function updateMapQueueOnMapStart() randomMap = randomMap + 1 if randomMap ~= 4 then if #mapQueue ~= 0 then if not votedForRedo then table.remove(mapQueue, 1) end votedForRedo = false if #mapQueue > 1 then triggerEvent("onUserpanelWantNextmap", getRootElement(), mapQueue[1]) outputDebugString("Calling next map to race", 1, 255, 255, 255) end end else randomMap = 0 triggerEvent("onUserpanelWantNextmap", getRootElement(), 'Random map') end sentMapQueueToClients() end addEvent("onRaceCallNextMap", true) addEventHandler("onRaceCallNextMap", getRootElement(), updateMapQueueOnMapStart) 2 - Ajouter ce bout de code à la fin de ce fichier (donc juste après la fonction updateMapQueueOnMapStart): local votedForRedo = false addEvent("onVoteRedoSuccess", true) function applyVoteRedo() votedForRedo = true outputChatBox("[REDO] The map will be replayed !", 200, 0, 0) end addEventHandler("onVoteRedoSuccess", root, applyVoteRedo) Explications: L'éxécution de la fonction applyVoteRedo va passer le booléen votedForRedo à true et afficher un message à tout le monde. Ensuite lorsque le serveur appellera updateMapQueueOnMapStart pour connaître la map suivante, j'empêche cette fonction de supprimer la map actuelle si le votedForRedo est à true via ce bout de code: if not votedForRedo then table.remove(mapQueue, 1) end Je n'oublie pas ensuite de remettre votedForRedo à false et je laisse la fonction envoyer la 1ère map de la liste (qui est toujours la même map vu qu'on a évité sa suppression) grâce à cette ligne (qui était déjà là): triggerEvent("onUserpanelWantNextmap", getRootElement(), mapQueue[1]) Je ne sais pas ce que fait exactement l(es) handler(s) de l'event "onUserpanelWantNextmap" mais je suis quasi sûr à 100% que ça définit la map suivante. Donc voilà il ne te reste plus qu'à coder ton vote redo et en cas de succès ... - soit tu appelles directement la fonction applyVoteRedo si tu le codes dans le même fichier, - soit tu trigger l'event "onVoteRedoSuccess" et en cas d'echec (pas assez de vote) tu fais rien à part leur afficher un message comme quoi le vote n'a pas aboutit. Cordialement, Citizen Link to comment
naotriix Posted February 13, 2015 Author Share Posted February 13, 2015 Merci, pour le modifications, toutefois je ne sais pas trop quoi modifier dans le script de voteredo du coup si tu peux m'éclairé. --- VR --- local root = getRootElement() playersVoted = 0 mapRestarted = true cRedo = false getPlayersVR = getElementsByType ("player") for i,playersVR in ipairs(getPlayersVR) do setElementData( playersVR, "hasVoted", "nope" ) end rr,gg,bb = 255,0,0 function PlayerVoted(thePlayer) if mapRestarted then if (getElementData( thePlayer, "hasVoted" ) == "nope") then setElementData( thePlayer, "hasVoted", "voted" ) playersVoted = playersVoted + 1 if playersVoted >= math.floor(getPlayerCount() /2 + 0.5) then rr,gg,bb = 0,255,0 end outputChatBox("' ["..playersVoted.."/".. math.floor(getPlayerCount() /2 + 0.5) .."] ' #1a5eaa~> #c1c1c1Voted For Redo ( #FFFFFF"..getPlayerNametagText(thePlayer).." #C1C1C1)", root, rr, gg, bb, true) if playersVoted >= math.floor(getPlayerCount() /2 + 0.5) then cRedo = true outputChatBox ("#c1c1c1This Map Will Be Restarted By #1a5eaaVote", root, 255, 153, 0, true) end else outputChatBox("#c1c1c1You already #1a5eaaVoted #FFFFFFfor redo !", thePlayer, 255, 0, 0, true) end else outputChatBox("#440000Sorry#ffffff, #c1c1c1This map was restarted by #1a5eaaVote #FFFFFF!", thePlayer, 255, 0, 0, true) end end addCommandHandler ( "vr", PlayerVoted ) addCommandHandler ( "voteredo", PlayerVoted ) ------ Merci Link to comment
naotriix Posted February 16, 2015 Author Share Posted February 16, 2015 J'ai essayé de comprendre et j'ai modifié un peu le vr mais je ne suis pas sur que ca marche: --- VR --- local root = getRootElement() playersVoted = 0 mapRestarted = true cRedo = false getPlayersVR = getElementsByType ("player") for i,playersVR in ipairs(getPlayersVR) do setElementData( playersVR, "hasVoted", "nope" ) end rr,gg,bb = 255,0,0 function PlayerVoted(thePlayer) if mapRestarted then if (getElementData( thePlayer, "hasVoted" ) == "nope") then setElementData( thePlayer, "hasVoted", "voted" ) playersVoted = playersVoted + 1 if playersVoted >= math.floor(getPlayerCount() /2 + 0.5) then rr,gg,bb = 0,255,0 end outputChatBox("' ["..playersVoted.."/".. math.floor(getPlayerCount() /2 + 0.5) .."] ' #1a5eaa~> #c1c1c1Voted For Redo ( #FFFFFF"..getPlayerNametagText(thePlayer).." #C1C1C1)", root, rr, gg, bb, true) if playersVoted >= math.floor(getPlayerCount() /2 + 0.5) then cRedo = true triggerEvent("onVoteRedoSuccess", getRootElement()) outputChatBox ("#c1c1c1This Map Will Be Restarted By #1a5eaaVote", root, 255, 153, 0, true) end else outputChatBox("#c1c1c1You already #1a5eaaVoted #FFFFFFfor redo !", thePlayer, 255, 0, 0, true) end else outputChatBox("#440000Sorry#ffffff, #c1c1c1This map was restarted by #1a5eaaVote #FFFFFF!", thePlayer, 255, 0, 0, true) end end addCommandHandler ( "vr", PlayerVoted ) addCommandHandler ( "voteredo", PlayerVoted ) ------ Link to comment
Moderators Citizen Posted February 16, 2015 Moderators Share Posted February 16, 2015 A mettre à la fin du même fichier que pour mes 2 bouts de code de mon post précédent et après avoir fait le 1 et le 2 de mon post précédent: --- VR --- addEvent("onMapStarting", true) function clearVote() playersVoted = 0 mapRestarting = false for i,playersVR in ipairs(getElementsByType ("player")) do setElementData( playersVR, "hasVoted", "nope" ) end end addEventHandler("onClientResourceStart", resourceRoot, clearVote) addEventHandler("onMapStarting", resourceRoot, clearVote) function voteRedo(thePlayer) if mapRestarting then if (getElementData(thePlayer, "hasVoted" ) == "nope") then setElementData(thePlayer, "hasVoted", "voted" ) playersVoted = playersVoted + 1 local rr,gg,bb = 255,0,0 if playersVoted >= math.floor(getPlayerCount() /2 + 0.5) then rr,gg,bb = 0,255,0 end outputChatBox("' ["..playersVoted.."/".. math.floor(getPlayerCount() /2 + 0.5) .."] ' #1a5eaa~> #c1c1c1Voted For Redo ( #FFFFFF"..getPlayerNametagText(thePlayer).." #C1C1C1)", root, rr, gg, bb, true) if playersVoted >= math.floor(getPlayerCount() /2 + 0.5) then applyVoteRedo() mapRestarting = true outputChatBox ("#c1c1c1This Map Will Be Restarted By #1a5eaaVote", root, 255, 153, 0, true) end else outputChatBox("#c1c1c1You already #1a5eaaVoted #FFFFFFfor redo !", thePlayer, 255, 0, 0, true) end else outputChatBox("#440000Sorry#ffffff, #c1c1c1This map was restarted by #1a5eaaVote #FFFFFF!", thePlayer, 255, 0, 0, true) end end addCommandHandler("vr", voteRedo, false, false) addCommandHandler("voteredo", voteRedo, false, false) ------ Link to comment
naotriix Posted February 16, 2015 Author Share Posted February 16, 2015 Merci, mais ca ne marche toujours pas quand je fais la commande /vr rien ne s'affiche. Link to comment
Valentin3526 Posted February 16, 2015 Share Posted February 16, 2015 Merci, mais ca ne marche toujours pas quand je fais la commande /vr rien ne s'affiche. que dit la commande "/debugscript 2" ? Link to comment
naotriix Posted February 16, 2015 Author Share Posted February 16, 2015 J'ai bidouiller un peu maintenant ca me met Soory, the map was restarted by vote alors que non j'ai rédemmarer le race etc... Dans le debugscript il n'y a propos de ca Link to comment
Valentin3526 Posted February 16, 2015 Share Posted February 16, 2015 Il faudrais le nouveau code, je vais essayer de trouver Link to comment
naotriix Posted February 16, 2015 Author Share Posted February 16, 2015 Voila le code en entier, je te met aussi le race_voting ca peut peut etre se jouer le dedans. function updateMapQueueOnMapStart() randomMap = randomMap + 1 if randomMap ~= 4 then if #mapQueue ~= 0 then if not votedForRedo then table.remove(mapQueue, 1) end votedForRedo = false if #mapQueue > 1 then triggerEvent("onUserpanelWantNextmap", getRootElement(), mapQueue[1]) outputDebugString("Calling next map to race", 1, 255, 255, 255) end end else randomMap = 0 triggerEvent("onUserpanelWantNextmap", getRootElement(), 'Random map') end sentMapQueueToClients() end addEvent("onRaceCallNextMap", true) addEventHandler("onRaceCallNextMap", getRootElement(), updateMapQueueOnMapStart) local votedForRedo = false addEvent("onVoteRedoSuccess", true) function applyVoteRedo() votedForRedo = true outputChatBox("[REDO] The map will be replayed !", 200, 0, 0) end addEventHandler("onVoteRedoSuccess", root, applyVoteRedo) --- VR --- addEvent("onMapStarting", true) function clearVote() playersVoted = 0 mapRestarting = false for i,playersVR in ipairs(getElementsByType ("player")) do setElementData( playersVR, "hasVoted", "nope" ) end end addEventHandler("onClientResourceStart", resourceRoot, clearVote) addEventHandler("onMapStarting", resourceRoot, clearVote) function voteRedo(thePlayer) if mapRestarting then if (getElementData(thePlayer, "hasVoted" ) == "nope") then setElementData(thePlayer, "hasVoted", "voted" ) playersVoted = playersVoted + 1 local rr,gg,bb = 255,0,0 if playersVoted >= math.floor(getPlayerCount() /2 + 0.5) then rr,gg,bb = 0,255,0 end outputChatBox("' ["..playersVoted.."/".. math.floor(getPlayerCount() /2 + 0.5) .."] ' #1a5eaa~> #c1c1c1Voted For Redo ( #FFFFFF"..getPlayerNametagText(thePlayer).." #C1C1C1)", root, rr, gg, bb, true) if playersVoted >= math.floor(getPlayerCount() /2 + 0.5) then applyVoteRedo() mapRestarting = true outputChatBox ("#c1c1c1This Map Will Be Restarted By #1a5eaaVote", root, 255, 153, 0, true) end else outputChatBox("#c1c1c1You already #1a5eaaVoted #FFFFFFfor redo !", thePlayer, 255, 0, 0, true) end else outputChatBox("#440000Sorry#ffffff, #c1c1c1This map was restarted by #1a5eaaVote #FFFFFF!", thePlayer, 255, 0, 0, true) end end addCommandHandler("vr", voteRedo, false, false) addCommandHandler("voteredo", voteRedo, false, false) ------ Race_voting: -- -- racemidvote_server.lua -- -- Mid-race random map vote and -- NextMapVote handled in this file -- local lastVoteStarterName = '' local lastVoteStarterCount = 0 ---------------------------------------------------------------------------- -- displayHilariarseMessage -- -- Comedy gold ---------------------------------------------------------------------------- function displayHilariarseMessage( player ) if not player then lastVoteStarterName = '' else local playerName = getPlayerName(player) local msg = '' if playerName == lastVoteStarterName then lastVoteStarterCount = lastVoteStarterCount + 1 if lastVoteStarterCount == 5 then msg = playerName .. ' started a vote. Hardly a suprise.' elseif lastVoteStarterCount == 10 then msg = 'Guess what! '..playerName .. ' started ANOTHER vote!' elseif lastVoteStarterCount < 5 then msg = playerName .. ' started another vote.' else msg = playerName .. ' continues to abuse the vote system.' end else lastVoteStarterCount = 0 lastVoteStarterName = playerName msg = playerName .. ' started a vote.' end outputRace( msg ) end end ---------------------------------------------------------------------------- -- displayKillerPunchLine -- -- Sewing kits available in the foyer ---------------------------------------------------------------------------- function displayKillerPunchLine( player ) if lastVoteStarterName ~= '' then outputRace( 'Offical news: Everybody hates ' .. lastVoteStarterName ) end end ---------------------------------------------------------------------------- -- startMidMapVoteForRandomMap -- -- Start the vote menu if during a race and more than 30 seconds from the end -- No messages if this was not started by a player ---------------------------------------------------------------------------- function startMidMapVoteForRandomMap(player) -- Check state and race time left if not stateAllowsRandomMapVote() or g_CurrentRaceMode:getTimeRemaining() < 30000 then if player then outputRace( "I'm afraid I can't let you do that, " .. getPlayerName(player) .. ".", player ) end return end displayHilariarseMessage( player ) exports.votemanager:stopPoll() -- Actual vote started here local pollDidStart = exports.votemanager:startPoll { title='Do you want to change to a random map?', percentage=51, timeout=15, allowchange=true, visibleTo=getRootElement(), [1]={'Yes', 'midMapVoteResult', getRootElement(), true}, [2]={'No', 'midMapVoteResult', getRootElement(), false;default=true}, } -- Change state if vote did start if pollDidStart then gotoState('MidMapVote') end end addCommandHandler('new',startMidMapVoteForRandomMap) ---------------------------------------------------------------------------- -- event midMapVoteResult -- -- Called from the votemanager when the poll has completed ---------------------------------------------------------------------------- addEvent('midMapVoteResult') addEventHandler('midMapVoteResult', getRootElement(), function( votedYes ) -- Change state back if stateAllowsRandomMapVoteResult() then gotoState('Running') if votedYes then startRandomMap() else displayKillerPunchLine() end end end ) ---------------------------------------------------------------------------- -- startRandomMap -- -- Changes the current map to a random race map ---------------------------------------------------------------------------- function startRandomMap(ifByDeleteMap) -- Handle forced nextmap setting if maybeApplyForcedNextMap(ifByDeleteMap or false) then return end -- Get a random map chosen from the 10% of least recently player maps, with enough spawn points for all the players (if required) local map = getRandomMapCompatibleWithGamemode( getThisResource(), 10, g_GameOptions.ghostmode and 0 or getTotalPlayerCount() ) if map then g_IgnoreSpawnCountProblems = map -- Uber hack 4000 if not exports.mapmanager:changeGamemodeMap ( map, nil, true ) then problemChangingMap() elseif ifByDeleteMap then deleteThisMap(ifByDeleteMap) end else outputWarning( 'startRandomMap failed' ) end end ---------------------------------------------------------------------------- -- outputRace -- -- Race color is defined in the settings ---------------------------------------------------------------------------- function outputRace(message, toElement) toElement = toElement or g_Root local r, g, b = getColorFromString(string.upper(get("color"))) if getElementType(toElement) == 'console' then outputServerLog(message) else if toElement == rootElement then outputServerLog(message) end if getElementType(toElement) == 'player' then message = '[PM] ' .. message end outputChatBox(message, toElement, r, g, b) end end ---------------------------------------------------------------------------- -- problemChangingMap -- -- Sort it ---------------------------------------------------------------------------- function problemChangingMap() outputRace( 'Changing to random map in 5 seconds' ) local currentMap = exports.mapmanager:getRunningGamemodeMap() TimerManager.createTimerFor("resource","mapproblem"):setTimer( function() -- Check that something else hasn't already changed the map if currentMap == exports.mapmanager:getRunningGamemodeMap() then startRandomMap() end end, math.random(4500,5500), 1 ) end -- -- -- NextMapVote -- -- -- local g_Poll ---------------------------------------------------------------------------- -- startNextMapVote -- -- Start a votemap for the next map. Should only be called during the -- race state 'NextMapSelect' ---------------------------------------------------------------------------- function startNextMapVote() exports.votemanager:stopPoll() -- Handle forced nextmap setting if maybeApplyForcedNextMap() then return end -- Get all maps local compatibleMaps = exports.mapmanager:getMapsCompatibleWithGamemode(getThisResource()) -- limit it to eight random maps if #compatibleMaps > 8 then math.randomseed(getTickCount()) repeat table.remove(compatibleMaps, math.random(1, #compatibleMaps)) until #compatibleMaps == 8 elseif #compatibleMaps < 2 then return false, errorCode.onlyOneCompatibleMap end -- mix up the list order for i,map in ipairs(compatibleMaps) do local swapWith = math.random(1, #compatibleMaps) local temp = compatibleMaps[i] compatibleMaps[i] = compatibleMaps[swapWith] compatibleMaps[swapWith] = temp end local poll = { title="Choose the next map:", visibleTo=getRootElement(), percentage=51, timeout=15, allowchange=true; } for index, map in ipairs(compatibleMaps) do local mapName = getResourceInfo(map, "name") or getResourceName(map) table.insert(poll, {mapName, 'nextMapVoteResult', getRootElement(), map}) end local currentMap = exports.mapmanager:getRunningGamemodeMap() if currentMap then table.insert(poll, {"Play again", 'nextMapVoteResult', getRootElement(), currentMap}) end -- Allow addons to modify the poll g_Poll = poll triggerEvent('onPollStarting', g_Root, poll ) poll = g_Poll g_Poll = nil Link to comment
Valentin3526 Posted February 16, 2015 Share Posted February 16, 2015 à ce que je crois voir, l'erreur peut venir de la fonction "voteRedo" donc faudrais inspecter surtout cette partie: function voteRedo(thePlayer) if mapRestarting then if (getElementData(thePlayer, "hasVoted" ) == "nope") then setElementData(thePlayer, "hasVoted", "voted" ) playersVoted = playersVoted + 1 local rr,gg,bb = 255,0,0 if playersVoted >= math.floor(getPlayerCount() /2 + 0.5) then rr,gg,bb = 0,255,0 end outputChatBox("' ["..playersVoted.."/".. math.floor(getPlayerCount() /2 + 0.5) .."] ' #1a5eaa~> #c1c1c1Voted For Redo ( #FFFFFF"..getPlayerNametagText(thePlayer).." #C1C1C1)", root, rr, gg, bb, true) if playersVoted >= math.floor(getPlayerCount() /2 + 0.5) then applyVoteRedo() mapRestarting = true outputChatBox ("#c1c1c1This Map Will Be Restarted By #1a5eaaVote", root, 255, 153, 0, true) end else outputChatBox("#c1c1c1You already #1a5eaaVoted #FFFFFFfor redo !", thePlayer, 255, 0, 0, true) end else outputChatBox("#440000Sorry#ffffff, #c1c1c1This map was restarted by #1a5eaaVote #FFFFFF!", thePlayer, 255, 0, 0, true) end end En regardant de plus près, je voit que le message affiché est celui-ci: outputChatBox("#440000Sorry#ffffff, #c1c1c1This map was restarted by #1a5eaaVote #FFFFFF!", thePlayer, 255, 0, 0, true) Dit-moi si je me trompe donc personnelement, j'ai pas un assés bon niveau, mais l'erreur vient donc de la partie qui se trouve avant le "else" de l' "outputChatBox" c'est tout ce que je pourrais te dire, essaie de trouver, si jamais tu trouve l'erreur, mais que tu ne sait pas comment la corriger, je ne suis pas sûre de pouvoir t'aider, mais je pense que Citizen a un assés bon niveau pour t'aider. Link to comment
Moderators Citizen Posted February 16, 2015 Moderators Share Posted February 16, 2015 Ouai une erreur dû au code qu'il y avait avant, j'ai changé le nom de la variable en changeant son rôle également et j'ai oublié d'inverser le if. Genre là c'est écrit: Si la map est en train d'être restarté, alors on autorise les votes, sinon on ne les autorise pas. if mapRestarting then -- On autorise les votes else -- On autorise pas end Alors qu'il fallait que j'écrive: Si la map n'est pas en train d'être restarté, alors on autorise les votes, sinon on ne les autorise pas. if not mapRestarting then -- On autorise les votes else -- On autorise pas end Donc je te laisse rajouter le "not" devant "mapRestarting". Cordialement, Citizen. Link to comment
naotriix Posted February 17, 2015 Author Share Posted February 17, 2015 Je viens d'ajouter le not maintenant la commande s'affiche mais sa ne redo pas la map. En debug script sa me met: ERROR: map_queue.lua:138 attempt to perform arthmetic on global 'playersVoted' (a nil value) et aussi: Warning: core_server.lua:1027 bad argument @ 'outputchatbox' expected element at argument 2, got number 200 _outputChatBox(chatString,theElement,colorTable[1],colorTable[2],colorTable[3],true) la ligne. Link to comment
Moderators Citizen Posted February 17, 2015 Moderators Share Posted February 17, 2015 Ouai encore une erreur de copié collé, dsl, change ça: addEventHandler("onMapStarting", resourceRoot, clearVote) en ça addEventHandler("onMapStarting", root, clearVote) Warning: core_server.lua:1027 bad argument @ 'outputchatbox' expected element at argument 2, got number 200 _outputChatBox(chatString,theElement,colorTable[1],colorTable[2],colorTable[3],true) la ligne. ça par contre c'est pas de notre côté vu qu'on a pas touché ce fichier. Et comme c'est un warning, tu peux l'ignorer même même si ça signifie que le serveur voulait output un message dans la chatbox et que ça n'a pas marché. Je pense qu'après cette dernière correction, ça devrait marcher (sauf si l'event "onMapStarting" ne fonctionne pas, mais j'en doute). Cordialement, Citizen Link to comment
naotriix Posted February 17, 2015 Author Share Posted February 17, 2015 J'ai effectué le changement toujours la meme erreur la ligne qui pose pb playersVoted = playersVoted + 1 Link to comment
Moderators Citizen Posted February 17, 2015 Moderators Share Posted February 17, 2015 la ligne qui pose pb playersVoted = playersVoted + 1 Ouai je sais que c'est cette ligne, l'erreur dit qu'il peut pas faire un +1 sur une variable qui n'existe pas. MAIS ! Cette variable est assignée à 0 dans clearVote qui est "normalement" éxécutée lorsque la ressource est démarrée (onResourceStart) et à chaque démarrage de map (onMapStarting). Mais apparemment, aucun des 2 events ne fonctionne. Peut tu me dire le nom du fichier dans lequel on se trouve, le nom de la ressource (race ?) et si c'est un fichier serveur ou client (serveur ?). J'ai comme l'impression qu'on est côté client pour pas que ces events ne fonctionnent. PS: Aussi, si tu pouvais utiliser les balises [lua ][/lua] pour coller ton code Lua au lieu d'utiliser , ça piquerait moins les yeux Cordialement,Citizen Link to comment
naotriix Posted February 17, 2015 Author Share Posted February 17, 2015 Salut, alors le fichier se trouver dans l'userpanel, il s'appelle map_queue.lua donc oui surement client. Je peux t'upload tout le dossier si tu le souhaite aisi que le race, sinon voila le code en entier du fichier: local mapQueue = {} local mapTimers = {} local randomMap = 0 local specialMapCost = 5000 mapBuyDelay = 35 -- Here delay in minutes function addMapToQueue(thePlayer,resourceName) if isPlayerLogged(thePlayer) then local playerCash = getPlayerData(thePlayer,'cash') if playerCash>=shopPrice.map then local errorCode = false if #mapQueue ~= 0 then for i,tableQ in pairs(mapQueue) do if tableQ[4] == resourceName then errorCode = 1 break elseif tableQ[3] == thePlayer then errorCode = 2 break end end end if errorCode then if errorCode == 1 then return displayNotification(thePlayer,"Map queue","This map is already in map queue!",0,100,255) elseif errorCode == 2 then return displayNotification(thePlayer,"Map queue","You have one map in map queue now!",0,100,255) end end local mapQueueTable = {} local map = getResourceFromName(resourceName) if map then local mapQueueTable = { getResourceInfo(map, "name") or resourceName, getPlayerName(thePlayer), thePlayer, resourceName } if not mapTimers[mapQueueTable[4]] then if string.find(mapQueueTable[1],"DD",1) or string.find(mapQueueTable[1],"FUN",1) then if playerCashthen return displayNotification(thePlayer,"Map queue","You dont have enough cash! (Need: $"..specialMapCost..")",0,100,255) end addValue(thePlayer,'specialMaps',1) addValue(thePlayer,'cash',-specialMapCost) else addValue(thePlayer,'cash',-shopPrice.map) addValue(thePlayer,'mapsBought',1) end table.insert(mapQueue,mapQueueTable) if #mapQueue == 1 then triggerEvent("onUserpanelWantNextmap",getRootElement(),mapQueue[1]) end mapTimers[mapQueueTable[4]] = setTimer(resetMapTimer,mapBuyDelay*60000,1,mapQueueTable[4]) displayNotification(thePlayer,"Map queue","You successfully add new map to map queue!",0,100,255) outputChatBox("#0088FF[MAP] #ffffff"..getPlayerName(thePlayer).." #ffffffadd# {colorCode}"..mapQueueTable[1].."#ffffff to map queue.",getRootElement(),255,255,255,true) refreshScoreboard(thePlayer) checkAchievements(thePlayer,4) checkAchievements(thePlayer) else if isTimer(mapTimers[mapQueueTable[4]]) then local rem = getTimerDetails(mapTimers[mapQueueTable[4]]) local rem = math.ceil(rem/60000) displayNotification(thePlayer,"Map queue","You can set this map in: "..rem.." minutes.",0,100,255) end end else displayNotification(thePlayer,"Map queue","Cant find a map!",0,100,255) end else displayNotification(thePlayer,"Map queue","You dont have enough cash!",0,100,255) end end sentMapQueueToClients() end addEvent("onRaceCallNextMapCommand",true) addEventHandler("onRaceCallNextMapCommand",getRootElement(),addMapToQueue) function resetMapTimer(mapString) if isTimer(mapTimers[mapString]) then killTimer(mapTimers[mapString]) end mapTimers[mapString] = nil end function sentMapQueueToClients() callClientFunction(getRootElement(),"updateMapQueue",mapQueue) end function updateMapQueueOnMapStart() randomMap = randomMap + 1 if randomMap ~= 4 then if #mapQueue ~= 0 then if not votedForRedo then table.remove(mapQueue, 1) end votedForRedo = false if #mapQueue > 1 then triggerEvent("onUserpanelWantNextmap", getRootElement(), mapQueue[1]) outputDebugString("Calling next map to race", 1, 255, 255, 255) end end else randomMap = 0 triggerEvent("onUserpanelWantNextmap", getRootElement(), 'Random map') end sentMapQueueToClients() end addEvent("onRaceCallNextMap", true) addEventHandler("onRaceCallNextMap", getRootElement(), updateMapQueueOnMapStart) local votedForRedo = false addEvent("onVoteRedoSuccess", true) function applyVoteRedo() votedForRedo = true outputChatBox("[REDO] The map will be replayed !", 200, 0, 0) end addEventHandler("onVoteRedoSuccess", root, applyVoteRedo) --- VR --- addEvent("onMapStarting", true) function clearVote() playersVoted = 0 mapRestarting = false for i,playersVR in ipairs(getElementsByType ("player")) do setElementData( playersVR, "hasVoted", "nope" ) end end addEventHandler("onClientResourceStart", resourceRoot, clearVote) addEventHandler("onMapStarting", root, clearVote) function voteRedo(thePlayer) if not mapRestarting then if (getElementData(thePlayer, "hasVoted" ) == "nope") then setElementData(thePlayer, "hasVoted", "voted" ) playersVoted = playersVoted + 1 local rr,gg,bb = 255,0,0 if playersVoted >= math.floor(getPlayerCount() /2 + 0.5) then rr,gg,bb = 0,255,0 end outputChatBox("' ["..playersVoted.."/".. math.floor(getPlayerCount() /2 + 0.5) .."] ' #1a5eaa~> #c1c1c1Voted For Redo ( #FFFFFF"..getPlayerNametagText(thePlayer).." #C1C1C1)", root, rr, gg, bb, true) if playersVoted >= math.floor(getPlayerCount() /2 + 0.5) then applyVoteRedo() mapRestarting = true outputChatBox ("#c1c1c1This Map Will Be Restarted By #1a5eaaVote", root, 255, 153, 0, true) end else outputChatBox("#c1c1c1You already #1a5eaaVoted #FFFFFFfor redo !", thePlayer, 255, 0, 0, true) end else outputChatBox("#440000Sorry#ffffff, #c1c1c1This map was restarted by #1a5eaaVote #FFFFFF!", thePlayer, 255, 0, 0, true) end end addCommandHandler("vr", voteRedo, false, false) addCommandHandler("voteredo", voteRedo, false, false) ------ Link to comment
Moderators Citizen Posted February 17, 2015 Moderators Share Posted February 17, 2015 il s'appelle map_queue.lua donc oui surement client. Bah ... regarde dans la meta.xml de la ressource pour savoir. <script src="map_queue.lua" type="???"/> Mais en relisant vite fait le code, on peut voir qu'il y a un getResourceInfo qui est une fonction only server donc nan ça n'a pas l'air d'être du client-side. L'utilises-tu avec le gamemode Race ? parce que normalement, l'event onMapStarting devrait fonctionner Rajoute ça aussi en haut de clearVote (donc juste au-dessus de playerVoted = 0): outputDebugString("clearVote") Et regarde dans la console serveur le nombre de "clearVote" que tu y verras (normalement: une au démarrage de la ressource et une par démarrage de map). Si y en a aucun (ce qui, je pense, va être le cas vu l'erreur que t'as) alors on a un problème dont j'ignore totalement pour l'instant la cause. Link to comment
naotriix Posted February 17, 2015 Author Share Posted February 17, 2015 Tu as raison c'est du server, sinon j'ai rajouté la ligne rien ne s'affiche dans la console ni dans le debugscript 2. Link to comment
naotriix Posted February 17, 2015 Author Share Posted February 17, 2015 sinon j'ai un autre voteredo, celui ci redo bien la map mais du coup y faut refaire les changements car il vire le map queue: -------------------------VOTE REDO----------------------------- local votesRedo = 0 local allowRedo = false local lastMap = "" local requiredVotes = 100 local reqFlag = false local votedPlayers = {} addEvent("onMapStarting", true) function onMapStartResset() votedPlayers = {} if g_ForcedNextMap == false then triggerEvent("onMapSuccessfullyStart", getRootElement()) end end addEventHandler("onMapStarting", getRootElement(), onMapStartResset) function addVotedPlayers(player) votedPlayers[#votedPlayers+1] = getPlayerSerial(player) end function checkVotedPlayer(player) for i=1,#votedPlayers do if (getPlayerSerial(player) == votedPlayers[i])then return true end end return false end function voteRedoManagment(player) if not(checkVotedPlayer(player))then local currentMap = getMapName(exports.mapmanager:getRunningGamemodeMap()) if allowRedo then outputChatBox("#551A8B* #ffffffThis #ff0000Map #ffffffis going to be #ff0000restarted.", player, 255,255,255,true) return end if not(reqFlag)then requiredVotes = tonumber(math.ceil((getPlayerCount()/2))) reqFlag = true end if not(currentMap == lastMap)then votesRedo = votesRedo + 1 addVotedPlayers(player) outputChatBox("#551A8B* #FFFFFFRedo #ff0000votes: (#ff0000"..votesRedo.."#FFFFFF/#ff0000"..requiredVotes.."#FFFFFF) (".. "#ffffff" ..''.. getPlayerName(player)..'#FFFFFF)', getRootElement(), 255, 80, 0, true) if(votesRedo >= requiredVotes)then allowRedo = true end else outputChatBox("#551A8B* #FFFFFFThis #ff0000Map #ffffffwas already #ff0000restarted.", player, 255,255,255,true) end else outputChatBox("#551A8B* #FFFFFFYou Have already #ff0000voted.", player, 255,255,255,true) end end addCommandHandler("voteredo", voteRedoManagment) addCommandHandler("vr", voteRedoManagment) addEventHandler("onMapStarting", getRootElement(), function() votesRedo = 0 allowRedo = false reqFlag = false end) function onGridCountDown (stateName) if stateName == "PostFinish" then lastMap = getMapName(exports.mapmanager:getRunningGamemodeMap()) if(allowRedo)then setTimer(function() voteRedoMap() outputChatBox('#ff0000* #FFFFFFRestarted By #ff0000Vote.', getRootElement(), 255, 80, 0, true) end,500, 1) end end end addEvent("onRaceStateChanging",true) addEventHandler("onRaceStateChanging", getRootElement(), onGridCountDown) --voteRedo function voteRedoMap() local currentMap = exports.mapmanager:getRunningGamemodeMap() if currentMap then if not exports.mapmanager:changeGamemodeMap (currentMap, nil, true) then problemChangingMap() end else outputRace("You can't restart the map because no map is running", getRootElement()) end end Link to comment
Moderators Citizen Posted February 19, 2015 Moderators Share Posted February 19, 2015 Je peux t'upload tout le dossier si tu le souhaite aisi que le race Ouai vas-y parce que là mon code de tête ne fonctionne pas totalement, y a un truc qui coince au niveau du reset du vote. Link to comment
naotriix Posted February 19, 2015 Author Share Posted February 19, 2015 Ok, je t'envoie sa en mp. J'ai remis le race voting de base avec le voteredo dedans. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now