Tadpole Posted March 15, 2009 Share Posted March 15, 2009 ok so im wondering me and my friend is working on a dragstrip race wt the airport in SF and i wanna no if i can set onMarkerHit to out put chatbox like (name has won the race) then after he gits passed marker a next (name has finished second) and so on up to six people is this possible thx for reply's Link to comment
Tadpole Posted March 16, 2009 Author Share Posted March 16, 2009 Okay thanks for the reply *EDIT* ok so i got to a point were i need help! im a bit of a noob at lua but this is what i have so far enter3 = createMarker ( -1148.4782, 345.7957, 13.6835, "cylinder", 30, 125, 0, 0, 155, getRootElement() ) function MarkerHit ( hitPlayer, matchingDimension ) outputChatBox ( "sourcePlayer() has won the race!" ) end addEventHandler("onMarkerHit", enter3, MarkerHit) function MarkerHit ( hitPlayer, matchingDimension ) outputChatBox ( "thePlayer finished second!" ) end addEventHandler ("onMarkerHit", enter3, MarkerHit) Link to comment
devil666 Posted March 17, 2009 Share Posted March 17, 2009 Here it is for when u hit the marker sorry it took me so long to get it.....0o0o0o0 and i still dont know how to stop it from saying it again when someone hits it after u enter3 = createMarker ( -1148.4782, 345.7957, 13.6835, "cylinder", 30, 125, 0, 0, 155, getRootElement() ) function MarkerHit ( player, hitPlayer, matchingDimension ) username = getClientName ( player ) outputChatBox ( username, player, 255, 0, 0 ) outputChatBox ( "Has Won The Race!", 255, 0, 0 ) end addEventHandler("onMarkerHit", enter3, MarkerHit) Link to comment
robhol Posted March 17, 2009 Share Posted March 17, 2009 If you want real "ranking" by order, this would be better: ranking = 1; -- start at one, of couse... addEventHandler("onPlayerMarkerHit", theMarker, function () -- there are two arguments, but we won't use any of them. outputChatBox( getPlayerName(source) .. " finished as #" .. tostring(ranking) .. "!"); ranking = ranking + 1; -- count upwards. end ) Erm... I think I used a 1.0-only function, it's likely to be the getPlayerName. If you use DP2.3 and the server nags you about an attempt to call a nil value, replace getPlayerName with the valid function from DP2.3, i think it's getClientName. Also, although this is DEAD obvious, I didn't make the marker, that's up to you. Link to comment
[DKR]silverfang Posted March 17, 2009 Share Posted March 17, 2009 (edited) Okay thanks for the reply *EDIT* ok so i got to a point were i need help! im a bit of a noob at lua but this is what i have so far original code function startRace () position = 1 enter3 = createMarker ( -1148.4782, 345.7957, 13.6835, "cylinder", 30, 125, 0, 0, 155, getRootElement() ) addEventHandler("onMarkerHit", enter3, MarkerHit) end addCommandHandler("race", startRace) function MarkerHit ( hitPlayer, matchingDimension ) if position = 1 then outputChatBox ( getClientName(hitPlayer).. " has won the race!" ) position = position + 1 elseif position = 2 then outputChatBox ( getClientName(hitPlayer).. " has come second!" ) position = position + 1 elseif position = 3 then outputChatBox ( getClientName(hitPlayer).. " has come third!" ) --remove event handler so this function doesn't get called again! removeEventHandler("onMarkerHit", enter3,MarkerHit) destroyElement(enter3) end end I've edited it a bit so it'll do exactly what you want for dp2.3 Edited March 17, 2009 by Guest Link to comment
DutchCaffeine Posted March 17, 2009 Share Posted March 17, 2009 function startRace () position = 1 enter3 = createMarker ( -1148.4782, 345.7957, 13.6835, "cylinder", 30, 125, 0, 0, 155, getRootElement() ) addEventHandler("onMarkerHit", enter3, MarkerHit) end addCommandHandler("race", startRace) function MarkerHit ( hitPlayer, matchingDimension ) if position = 1 then outputChatBox ( getClientName(hitPlayer).. " has won the race!" ) -- add one to position (can't remember if this works for LUA as I've not been scripting in it for a while... Damn project work) -- if position++ doesn't work use position = position + 1 instead position++ elseif position = 2 then outputChatBox ( getClientName(hitPlayer).. " has come second!" ) position++ elseif position = 3 then outputChatBox ( getClientName(hitPlayer).. " has come third!" ) --remove event handler so this function doesn't get called again! removeEventHandler("onMarkerHit", enter3,MarkerHit) destroyElement(enter3) end end I've edited it a bit so it'll do exactly what you want for dp2.3 That aint going to work. variable++; -- is like php. variable = variable + 1; -- That is lua. Link to comment
[DKR]silverfang Posted March 17, 2009 Share Posted March 17, 2009 That aint going to work. variable++; -- is like php. variable = variable + 1; -- That is lua. Yeah, I've been using alot of PHP lately and if you'd read my code you would have seen that I wasn't sure if it worked in LUA or not... Have edited the snippet now... 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