kuwalda Posted June 16, 2014 Share Posted June 16, 2014 Hello. I kinda bad with tables, so I don`t know how to correctly write them, but I hope you will understand my problem. First of all I want to store all players, that have accepted their participation into race, into table: raceName[playername] = unfinished or finishtime And after, when my timer ticks out, I want to call function on all of those players: setTimer ( endRace, 10000, 1, raceMap ) function endRace(raceToEnd) outputChatBox("Lets end this map:"..raceToEnd.."", root, 0, 255, 255) --run loop for every player in table --*arguments to end race* --end loop end So what I am asking - how to make this loop? I know it`s something like for x,y in pairs(table) do ,but I don`t really understand how it works. I would be really greatful to anyone who could type this loop for me and explain it for me, so I know how to use it next time. Also, I am having question - I have function function raceConsider( ) if getPlayerCount() >= 1 and raceActive["aktivs"] == false then raceActive["aktivs"] = true setTimer ( needRaceGUI, 5000, 1) outputChatBox("DEBUG:[1]", root, 255, 255, 0) end end addEventHandler ( "onPlayerJoin", getRootElement(), raceConsider ) addCommandHandler("gorace", raceConsider) I can active it by joining the server, or typing command /gorace. How can I determinate what activated this function and if it was activated by command, I want to skip that IF statement check. Is it possible or I have to type another function? Link to comment
aintaro Posted June 16, 2014 Share Posted June 16, 2014 to loop through all the players is like this : local players = getElementsByType ( "player" ) -- Get every player for k, player in ipairs ( players ) do -- For every player do the following... account = getPlayerAccount ( player ) -- Get every player's account if ( not isGuestAccount ( account ) ) then -- For every player that's logged in.... outputChatBox("this is a message to all the players", player) end end Link to comment
kuwalda Posted June 16, 2014 Author Share Posted June 16, 2014 function endRace(raceToEnd) outputChatBox("We would end this race:"..raceToEnd..".", root, 0, 255, 255) --this shows, but nothing more function findRaceWinner(blueBerryRallyP) if blueBerryRallyP and type(blueBerryRallyP) == 'table' then local time, winner = math.huge for thePlayer, theTime in pairs(blueBerryRallyP) do if theTime < time then winner, time = thePlayer, theTime outputChatBox("TEST: "..winner.."", root, 0, 255, 255) outputChatBox("TEST: "..time.."", root, 0, 255, 255) outputChatBox("TEST: "..tostring(winner).."", root, 0, 255, 255) outputChatBox("TEST: "..tostring(time).."", root, 0, 255, 255) end end return winner, time end return false end end why this is not working, when this is: function sexyinfo(thePlayer, command) outputChatBox(""..tostring(blueBerryRallyP[thePlayer]).."", thePlayer, 255, 255, 0) end addCommandHandler("fancy", sexyinfo) Link to comment
Gtagasje Posted June 17, 2014 Share Posted June 17, 2014 function raceConsider(thePlayer, cmd) if thePlayer and cmd and cmd == "gorace" then -- It was activated by command else -- It was not activated by command if getPlayerCount() >= 1 and raceActive["aktivs"] == false then raceActive["aktivs"] = true setTimer ( needRaceGUI, 5000, 1) outputChatBox("DEBUG:[1]", root, 255, 255, 0) end end end addEventHandler ( "onPlayerJoin", getRootElement(), raceConsider ) addCommandHandler("gorace", raceConsider) 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