Kenix Posted December 21, 2010 Share Posted December 21, 2010 That it for an error help to solve it. not work function onTimeElapsed() and announcementText ERROR: attempt to compare two userdata values. teamSurvivor = createTeam ( "Survivors", 0, 255, 0 ) teamzombie = createTeam ( "Zombies", 255, 0, 0 ) g_Root = getRootElement() local g_TimeLimit,g_MissionTimer local mapTimers = {} local announcementText local defaults = { timeLimit = 300, } function zmMapStart(resource,mapRoot) local resourceName = getResourceName ( resource ) g_TimeLimit = (tonumber(get(resourceName..".time_limit")) and math.floor(tonumber(get(resourceName..".time_limit"))) or defaults.timeLimit)*1000 g_MissionTimer = exports.missiontimer:createMissionTimer (g_TimeLimit,true,true,0.5,20,true,"default-bold",1) addEventHandler ( "onMissionTimerElapsed", g_MissionTimer, onTimeElapsed ) end addEventHandler ( "onGamemodeMapStart", g_Root, zmMapStart ) addEventHandler ( "onPlayerJoin", g_Root, function() if announcementText then announcementText:sync(source) end end) function Endgame(winner,draw) for i,timer in ipairs(mapTimers) do if isTimer ( timer ) then killTimer ( timer ) end end outputChatBox ( "debug; 2;" ) mapTimers = {} destroyElement(g_MissionTimer) setTimer ( reboot, 1000, 1 ) if not winner then if draw then for i,player in ipairs(getElementsByType"player") do toggleAllControls(player,true,true,false) fadeCamera(player,false,10,0,0,0) end outputChatBox ( "debug; 3;" ) triggerClientEvent ( "onzombiewin", getRootElement()) outputChatBox("Выживших не осталось. Зомби победили!") announcementText:visible(true) announcementText:text("Выживших не осталось. Зомби победили!") announcementText:color(255,255,255,255) announcementText:sync() return else return end end outputChatBox ( "debug; 4;" ) for i,player in ipairs(getElementsByType"player") do if team ~= winner then setCameraTarget(player,winner) toggleAllControls(player,true,true,false) end fadeCamera(player,false,10,0,0,0) end outputChatBox ( "debug; 5;" ) triggerClientEvent ( "onsurwin", getRootElement()) outputChatBox("Выжившие победили! Они пережили нападение") announcementText:visible(true) announcementText:text(getTeamName(winner).."Выжившие победили! Они пережили нападение") announcementText:color(getTeamColor(winner)) announcementText:sync() outputChatBox ( "debug; wintext;" ) end function reboot() announcementText:visible(false) announcementText:sync() exports.mapmanager:changeGamemode( getResourceFromName('zombie_mod') ) end function isTimer ( timer ) for i,v in ipairs(getTimers()) do if timer == v then return true end end outputChatBox ( "debug; 7;" ) return false end function onTimeElapsed() local teamSurvivor = getElementsByType"team" local teamzombie = getElementsByType"team" table.sort ( teamSurvivor, sortingfunction ) table.sort ( teamzombie, sortingfunction ) if getElementData ( teamSurvivor,teamzombie[1], "Score" ) == getElementData ( teamSurvivor,teamzombie[2], "Score" ) then Endgame ( false, true ) return end Endgame(teamSurvivor,teamzombie[1],false) end Link to comment
Aibo Posted December 21, 2010 Share Posted December 21, 2010 announcementText is not a function, it's an object this is nonsense: getElementsByType"team" you forgot the parentheses getElementData() takes only one element. whole onTimeElapsed() function is almost random code. what is sortingfunction? and indentation is horrible. and it looks like you dont really know what you're doing Link to comment
Kenix Posted December 21, 2010 Author Share Posted December 21, 2010 Question : announcementText is not a function, it's an object. answer : I was mistaken it I know Question : whole onTimeElapsed() function is almost random code. answer: Read more attentively. addEventHandler ( "onMissionTimerElapsed", g_MissionTimer, onTimeElapsed ) Question : what is sortingfunction? answer: local function sortingFunction (a,b) return (getElementData(a,"Score") or 0) > (getElementData(b,"Score") or 0) end and it looks like you dont really know what you're doing. answer : I want to make that was shown team which won. The zombie or survived. Link to comment
Aibo Posted December 21, 2010 Share Posted December 21, 2010 line 58: for i,player in ipairs(getElementsByType"player") do again no parentheses line 59: if team ~= winner then where's team? line 60: setCameraTarget(player,winner) idk if you even can set camera target to a team, because here "winner" is supposed to be a team line 84: function isTimer ( timer ) MTA already has built-in function isTimer PS: if you know what you want to do, it doesnt mean you know what you're doing. for someone who uses OOP in Lua you're making a lot of errors. Link to comment
Kenix Posted December 21, 2010 Author Share Posted December 21, 2010 Thanks already helped the timer works and shows who won and start next map, but now the bug only team wins zombie. but it must be right if the surviving are kept, they win. P.s many thanks dude) Link to comment
Castillo Posted December 22, 2010 Share Posted December 22, 2010 don't double-post! just wait for another member to answer. Link to comment
Aibo Posted December 22, 2010 Share Posted December 22, 2010 help please =( have you fixed anything i've posted? i dont know how you want to determine the winner, from what i can see you're trying to sort teams by points. well for the team with most points to be a winner: function onTimeElapsed() local teamSurvivor = getElementsByType("team") -- you were getting same teams in both tables table.sort ( teamSurvivor, sortingFunction ) -- sortingFunction i suppose if getElementData ( teamSurvivor[1], "Score" ) == getElementData ( teamSurvivor[2], "Score" ) then Endgame(false, true) -- your "draw" return end Endgame(teamSurvivor[1],false) -- send the team with most points to Endgame() function end Link to comment
Kenix Posted December 22, 2010 Author Share Posted December 22, 2010 I've corrected the script but it still does not work = ( still zombies win = ( teamSurvivor = createTeam ( "Survivors", 0, 255, 0 ) teamzombie = createTeam ( "Zombies", 255, 0, 0 ) g_Root = getRootElement() local g_TimeLimit,g_MissionTimer local mapTimers = {} local announcementText local defaults = { timeLimit = 300, } local function sortingfunction (a,b) return (getElementData(a,"Score") or 0) > (getElementData(b,"Score") or 0) end function zmMapStart(resource,mapRoot) local resourceName = getResourceName ( resource ) g_TimeLimit = (tonumber(get(resourceName..".time_limit")) and math.floor(tonumber(get(resourceName..".time_limit"))) or defaults.timeLimit)*1000 g_MissionTimer = exports.missiontimer:createMissionTimer (g_TimeLimit,true,true,0.5,20,true,"default-bold",1) addEventHandler ( "onMissionTimerElapsed", g_MissionTimer, onTimeElapsed ) end addEventHandler ( "onGamemodeMapStart", g_Root, zmMapStart ) addEventHandler ( "onPlayerJoin", g_Root, function() if announcementText then announcementText:sync(source) end end) function Endgame(winner,draw) for i,timer in ipairs(mapTimers) do if isTimer ( timer ) then killTimer ( timer ) end end outputChatBox ( "debug; 2;" ) mapTimers = {} destroyElement(g_MissionTimer) setTimer ( reboot, 6100, 1 ) if not winner then if draw then for i,player in ipairs(getElementsByType("player")) do -- add ( ) toggleAllControls(player,true,true,false) fadeCamera(player,false,10,0,0,0) end outputChatBox ( "debug; 3;" ) triggerClientEvent ( "onzombiewin", getRootElement()) outputChatBox("Выживших не осталось. Зомби победили!") announcementText:visible(true) announcementText:text("Выживших не осталось. Зомби победили!") announcementText:color(255,255,255,255) announcementText:sync() return else return end end outputChatBox ( "debug; 4;" ) for i,player in ipairs(getElementsByType("player")) do -- add ( ) if player ~= winner then -- fix setCameraTarget(player,winner) toggleAllControls(player,true,true,false) end fadeCamera(player,false,10,0,0,0) end outputChatBox ( "debug; 5;" ) triggerClientEvent ( "onsurwin", getRootElement()) outputChatBox("Выжившие победили! Они пережили нападение") announcementText:visible(true) announcementText:text(getTeamName(winner).."Выжившие победили! Они пережили нападение") announcementText:color(getTeamColor(winner)) announcementText:sync() outputChatBox ( "debug; wintext;" ) end function reboot() announcementText:visible(false) announcementText:sync() exports.mapmanager:changeGamemode( getResourceFromName('zombie_mod') ) end function isTimer ( timer ) for i,v in ipairs(getTimers()) do if timer == v then return true end end outputChatBox ( "debug; 7;" ) return false end function onTimeElapsed() local teamSurvivor = getElementsByType("team") -- you were getting same teams in both tables table.sort ( teamSurvivor, sortingfunction ) -- sortingFunction i suppose if getElementData ( teamSurvivor[1], "Score" ) == getElementData ( teamSurvivor[2], "Score" ) then Endgame(false, true) -- your "draw" return end Endgame(teamSurvivor[1],false) -- send the team with most points to Endgame() function end Link to comment
Aibo Posted December 22, 2010 Share Posted December 22, 2010 if player ~= winner then -- fix winner is team here. Link to comment
Kenix Posted December 22, 2010 Author Share Posted December 22, 2010 Hasn't understood. Link to comment
Kenix Posted December 24, 2010 Author Share Posted December 24, 2010 not working zombies won! teamSurvivor = createTeam ( "Survivors", 0, 255, 0 ) teamzombie = createTeam ( "Zombies", 255, 0, 0 ) g_Root = getRootElement() local g_TimeLimit,g_MissionTimer local mapTimers = {} local announcementText local defaults = { timeLimit = 300, } local function sortingfunction (a,b) return (getElementData(a,"Score") or 0) > (getElementData(b,"Score") or 0) end function zmMapStart(resource,mapRoot) local resourceName = getResourceName ( resource ) g_TimeLimit = (tonumber(get(resourceName..".time_limit")) and math.floor(tonumber(get(resourceName..".time_limit"))) or defaults.timeLimit)*1000 g_MissionTimer = exports.missiontimer:createMissionTimer (g_TimeLimit,true,true,0.5,20,true,"default-bold",1) addEventHandler ( "onMissionTimerElapsed", g_MissionTimer, onTimeElapsed ) end addEventHandler ( "onGamemodeMapStart", g_Root, zmMapStart ) addEventHandler ( "onPlayerJoin", g_Root, function() if announcementText then announcementText:sync(source) end end) function Endgame(winner,draw) for i,timer in ipairs(mapTimers) do if isTimer ( timer ) then killTimer ( timer ) end end outputChatBox ( "debug; 2;" ) mapTimers = {} destroyElement(g_MissionTimer) setTimer ( reboot, 6100, 1 ) if not winner then if draw then for i,player in ipairs(getElementsByType("player")) do -- add ( ) toggleAllControls(player,true,true,false) fadeCamera(player,false,10,0,0,0) end outputChatBox ( "debug; 3;" ) triggerClientEvent ( "onzombiewin", getRootElement()) outputChatBox("Выживших не осталось. Зомби победили!") announcementText:visible(true) announcementText:text("Выживших не осталось. Зомби победили!") announcementText:color(255,255,255,255) announcementText:sync() return else return end end outputChatBox ( "debug; 4;" ) for i,player in ipairs(getElementsByType("player")) do -- add ( ) if Survivors~= winner then -- changed setCameraTarget(player,winner) toggleAllControls(player,true,true,false) end fadeCamera(player,false,10,0,0,0) end outputChatBox ( "debug; 5;" ) triggerClientEvent ( "onsurwin", getRootElement()) outputChatBox("Выжившие победили! Они пережили нападение") announcementText:visible(true) announcementText:text(getTeamName(winner).."Выжившие победили! Они пережили нападение") announcementText:color(getTeamColor(winner)) announcementText:sync() outputChatBox ( "debug; wintext;" ) end function reboot() announcementText:visible(false) announcementText:sync() exports.mapmanager:changeGamemode( getResourceFromName('zombie_mod') ) end function isTimer ( timer ) for i,v in ipairs(getTimers()) do if timer == v then return true end end outputChatBox ( "debug; 7;" ) return false end function onTimeElapsed() local teamSurvivor = getElementsByType("team") -- you were getting same teams in both tables table.sort ( teamSurvivor, sortingfunction ) -- sortingFunction i suppose if getElementData ( teamSurvivor[1], "Score" ) == getElementData ( teamSurvivor[2], "Score" ) then Endgame(false, true) -- your "draw" return end Endgame(teamSurvivor[1],false) -- send the team with most points to Endgame() function end Link to comment
Aibo Posted December 24, 2010 Share Posted December 24, 2010 teamSurvivor = createTeam ( "Survivors", 0, 255, 0 ) teamzombie = createTeam ( "Zombies", 255, 0, 0 ) g_Root = getRootElement() local g_TimeLimit,g_MissionTimer local mapTimers = {} local announcementText local defaults = { timeLimit = 300, } local function sortingfunction (a,b) return (getElementData(a,"Score") or 0) > (getElementData(b,"Score") or 0) end function zmMapStart(resource,mapRoot) local resourceName = getResourceName ( resource ) g_TimeLimit = (tonumber(get(resourceName..".time_limit")) and math.floor(tonumber(get(resourceName..".time_limit"))) or defaults.timeLimit)*1000 g_MissionTimer = exports.missiontimer:createMissionTimer (g_TimeLimit,true,true,0.5,20,true,"default-bold",1) addEventHandler("onMissionTimerElapsed", g_MissionTimer, onTimeElapsed) end addEventHandler("onGamemodeMapStart", g_Root, zmMapStart) addEventHandler ( "onPlayerJoin", g_Root, function() if announcementText then announcementText:sync(source) end end) function Endgame(winner,draw) for i,timer in ipairs(mapTimers) do if isTimer ( timer ) then killTimer ( timer ) end end outputChatBox ( "debug; 2;" ) mapTimers = {} destroyElement(g_MissionTimer) setTimer ( reboot, 6100, 1 ) if not winner then if draw then for i,player in ipairs(getElementsByType("player")) do -- add ( ) toggleAllControls(player,true,true,false) fadeCamera(player,false,10,0,0,0) end outputChatBox ( "debug; 3;" ) triggerClientEvent ( "onzombiewin", getRootElement()) outputChatBox("Выживших не осталось. Зомби победили!") announcementText:visible(true) announcementText:text("Выживших не осталось. Зомби победили!") announcementText:color(255,255,255,255) announcementText:sync() return else return end end outputChatBox ( "debug; 4;" ) for i,player in ipairs(getElementsByType("player")) do if Survivors ~= winner then -- what is survivors now? setCameraTarget(player,winner) -- winner is TEAM toggleAllControls(player,true,true,false) end fadeCamera(player,false,10,0,0,0) end outputChatBox ( "debug; 5;" ) triggerClientEvent ( "onsurwin", getRootElement()) outputChatBox("Выжившие победили! Они пережили нападение") announcementText:visible(true) announcementText:text(getTeamName(winner).." - Выжившие победили! Они пережили нападение") announcementText:color(getTeamColor(winner)) announcementText:sync() outputChatBox ( "debug; wintext;" ) end function reboot() announcementText:visible(false) announcementText:sync() exports.mapmanager:changeGamemode( getResourceFromName('zombie_mod') ) end function onTimeElapsed() local teamSurvivor = getElementsByType("team") -- you were getting same teams in both tables table.sort(teamSurvivor, sortingfunction) -- sortingFunction i suppose if getElementData ( teamSurvivor[1], "Score" ) == getElementData ( teamSurvivor[2], "Score" ) then Endgame(false, true) -- your "draw" return end if getTeamName(teamSurvivor[1]) == "Zombies" then Endgame(false,false) -- Zombies have the Score, sending no winner else Endgame(teamSurvivor[1],false) -- send the Survivors to Endgame() function end end Link to comment
Kenix Posted December 24, 2010 Author Share Posted December 24, 2010 if teamSurvivor ~= winner then setCameraTarget(teamSurvivor,winner) Link to comment
Kenix Posted December 26, 2010 Author Share Posted December 26, 2010 read 28 line function onTimeElapsed() local teamSurvivor = getElementsByType("team") -- you were getting same teams in both tables table.sort(teamSurvivor, sortingfunction) -- sortingFunction i suppose if getElementData ( teamSurvivor[1], "Score" ) == getElementData ( teamSurvivor[2], "Score" ) then Endgame(false, true) -- your "draw" return outputChatBox ( "debug; zombie draw1;" ) end if Endgame(teamzombie,false) then else Endgame(teamSurvivor[1],false) -- send the Survivors to Endgame() function outputChatBox ( "debug; zombie draw;" ) --end end end function Endgame(winner,draw) for i,timer in ipairs(mapTimers) do if isTimer ( timer ) then killTimer ( timer ) end end outputChatBox ( "debug; 2;" ) mapTimers = {} destroyElement(g_MissionTimer) setTimer ( reboot, 6100, 1 ) if not teamSurvivor == winner then --------------- if you put a ~ = a surviving will win and if you put a zombie == how to fix it?? if draw then for i,player in ipairs(getElementsByType("player")) do -- add ( ) toggleAllControls(player,true,true,false) fadeCamera(player,false,10,0,0,0) end outputChatBox ( "debug; 3;" ) triggerClientEvent ( "onzombiewin", getRootElement()) outputChatBox("Выживших не осталось. Зомби победили!") announcementText:visible(true) announcementText:text("Выживших не осталось. Зомби победили!") announcementText:color(255,255,255,255) announcementText:sync() return else return end end outputChatBox ( "debug; 4;" ) for i,player in ipairs(getElementsByType("player")) do if teamSurvivor ~= winner then -- what is survivors now? outputChatBox ( "debug; sur;" ) setCameraTarget(player,winner) -- winner is TEAM toggleAllControls(player,true,true,false) end fadeCamera(player,false,10,0,0,0) end outputChatBox ( "debug; 5;" ) triggerClientEvent ( "onsurwin", getRootElement()) outputChatBox("Выжившие победили! Они пережили нападение") announcementText:visible(true) announcementText:text(getTeamName(winner).." - Выжившие победили! Они пережили нападение") announcementText:color(getTeamColor(winner)) announcementText:sync() outputChatBox ( "debug; wintext;" ) end Link to comment
Aibo Posted December 26, 2010 Share Posted December 26, 2010 explain exactly how you want to determine the winner. Link to comment
Kenix Posted December 26, 2010 Author Share Posted December 26, 2010 Look survivors must hold out until the deadline if they do not hold on a zombie won and if they held out to win. P.s I badly write in English. EDIT.here's the problem with the test team won or not = ( Link to comment
Discord Moderators Zango Posted December 26, 2010 Discord Moderators Share Posted December 26, 2010 Aiboforcen is russian I think, you can ask in the russian section instead, currently a standard mind can barely comprehend the meaning of your request son 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