kuwalda Posted June 1, 2014 Share Posted June 1, 2014 Hello. I have a bit problem with my script: function testejam(thePlayer, command) if ( getElementData ( thePlayer, "dbid" ) == 2 ) then setElementData(thePlayer, "time", getTickCount ()) end local pid = getElementData ( thePlayer, "dbid" ) local ciga = getElementData ( thePlayer, "dbid" ) destroyElement(markeritis) markeritis = createMarker ( blueBerryRally[ciga][1], blueBerryRally[ciga][2], blueBerryRally[ciga][3], "checkpoint", 6, 190, 156, 252, 170 ) if ( #blueBerryRally == ciga ) then outputChatBox("You finished, nice", thePlayer, 255, 255, 0) outputChatBox("Your time:"..(getTickCount () - getElementData( thePlayer, "time" )) / 1000 .."sec.", root, 255, 255, 0) setElementData(thePlayer, "dbid", 1) end setElementData ( thePlayer, "dbid", getElementData ( thePlayer, "dbid" ) + 1 ) addEventHandler( "onMarkerHit", markeritis, testejam ) end addCommandHandler("race", testejam) But I still have some problems I haven`t figured out how to fix them: * when player types /race ,why does everyone sees checkpoints and are allowed to drive through them? I have tried using setElementVisibleTo function but it works only partly.? How to make those checkpoints availabe only for that person, who asked for /race ? * when player finishes race, his time is stored in table, for later use. Lets say i have 3 guys who have raced: x with time 21sec y with time 15sec z with time 17sec How to determen witch one of those was fastest? How to write it in code? * Is it possible to make this script work for multiple people? For that I mean if someone is driving this track and someone else types /race, he gets his own checkpoints and wont disturb other players? And one more question offtopic - how can I make variable, with variable. Like: x = 6 theplayernamex ,so it would be like theplayername6 Link to comment
Den. Posted June 1, 2014 Share Posted June 1, 2014 Here's the edited code for the visibility of the marker: function testejam(thePlayer, command) if ( getElementData ( thePlayer, "dbid" ) == 2 ) then setElementData(thePlayer, "time", getTickCount ()) end local pid = getElementData ( thePlayer, "dbid" ) local ciga = getElementData ( thePlayer, "dbid" ) destroyElement(markeritis) markeritis = createMarker ( blueBerryRally[ciga][1], blueBerryRally[ciga][2], blueBerryRally[ciga][3], "checkpoint", 6, 190, 156, 252, 170, thePlayer ) setElementVisibleTo(markeritis, root, false) setElementVisibleTo(markeritis, thePlayer, true) if ( #blueBerryRally == ciga ) then outputChatBox("You finished, nice", thePlayer, 255, 255, 0) outputChatBox("Your time:"..(getTickCount () - getElementData( thePlayer, "time" )) / 1000 .."sec.", root, 255, 255, 0) setElementData(thePlayer, "dbid", 1) end setElementData ( thePlayer, "dbid", getElementData ( thePlayer, "dbid" ) + 1 ) addEventHandler( "onMarkerHit", markeritis, testejam ) end addCommandHandler("race", testejam) As for the timing and finding out who finished first: --t is the table that holds all the finish times of the players. --It should be in this layout for the function to work: t[thePlayer] = finishtime function findRaceWinner(t) if t and type(t) == 'table' then local time, winner = math.huge for thePlayer, theTime in pairs(t) do if theTime < time then winner, time = thePlayer, theTime end end return winner, time end return false end -Yes it is very possible to make it work for multiple people. Each player should get his own marker now with the visibility fixed, you will probably run into a few issues though. -To make a dynamic variable name, you can utilize a table. --name refers to the player name. -- local x = 6 table[name..x] = value Another way would be to use _G, which is a table of all global variables ( of this resource, I think ). But that will create a GLOBAL dynamic variable, not a local one. local x = 6 _G[name..x] = value Note: I didn't mess with the rest of your script, didn't remove redundancies like pid, etc; You should remove it since you don't need it. 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