SkullBreaker Posted March 10, 2015 Posted March 10, 2015 (edited) Hi guys! I would like to add a timer on this script. (for example: if you stand in the marker, you get 50$ every 10 seconds.) This is my script: local moneymarker = createMarker (2505.2, -1672.5, 12, "cylinder", 2, 60, 240, 32, 200) function giveMoney(player) if getElementType(player) == "player" then givePlayerMoney(player, 10) end end addEventHandler("onMarkerHit", moneymarker, giveMoney) I'll be glad if you could help me out FIXED, THANKYOU! This is my script now: local moneymarker = createMarker(2505.2, -1672.5, 12, "cylinder", 5, 60, 240, 32, 200) function giveMoney(player) if getElementType(player) == "player" then theTime = setTimer (function() givePlayerMoney(player, 50) end, 10000, 0) end end addEventHandler("onMarkerHit", moneymarker, giveMoney) function killTime() if isTimer(theTime) then killTimer(theTime) end end addEventHandler("onMarkerLeave", moneymarker, killTime) Edited March 11, 2015 by Guest
Tekken Posted March 10, 2015 Posted March 10, 2015 local moneymarker = createMarker (2505.2, -1672.5, 12, "cylinder", 2, 60, 240, 32, 200) function giveMoney () givePlayerMoney (source, 10) end addEventHandler ("onMarkerHit", moneymarker, giveMoney)
TAPL Posted March 10, 2015 Posted March 10, 2015 local moneymarker = createMarker (2505.2, -1672.5, 12, "cylinder", 2, 60, 240, 32, 200) function giveMoney(player) if getElementType(player) == "player" then givePlayerMoney(player, 10) end end addEventHandler("onMarkerHit", moneymarker, giveMoney)
SkullBreaker Posted March 10, 2015 Author Posted March 10, 2015 local moneymarker = createMarker (2505.2, -1672.5, 12, "cylinder", 2, 60, 240, 32, 200) function giveMoney () givePlayerMoney (source, 10) end addEventHandler ("onMarkerHit", moneymarker, giveMoney) doesn't work and what happened to the timer?
SkullBreaker Posted March 10, 2015 Author Posted March 10, 2015 local moneymarker = createMarker (2505.2, -1672.5, 12, "cylinder", 2, 60, 240, 32, 200) function giveMoney(player) if getElementType(player) == "player" then givePlayerMoney(player, 10) end end addEventHandler("onMarkerHit", moneymarker, giveMoney) Works! thanks! but how to make it on a timer?
Tekken Posted March 10, 2015 Posted March 10, 2015 local moneymarker = createMarker (2505.2, -1672.5, 12, "cylinder", 2, 60, 240, 32, 200) function giveMoney(player) if getElementType(player) == "player" then givePlayerMoney(player, 10) end end addEventHandler("onMarkerHit", moneymarker, giveMoney) Works! thanks! but how to make it on a timer? Wath do you mean by timer ? it's give money on player hit marker.
SkullBreaker Posted March 10, 2015 Author Posted March 10, 2015 I mean that if you stand in a random marker, colshape or something like that, you get for example $50 every 10 seconds.
..:D&G:.. Posted March 10, 2015 Posted March 10, 2015 local moneymarker = createMarker (2505.2, -1672.5, 12, "cylinder", 2, 60, 240, 32, 200) function giveMoney(player) if getElementType(player) == "player" then setTimer ( function() givePlayerMoney(player, 50) outputChatBox("Cash money! Cash money!", player, 0, 255, 0) end, 10000, 1 ) --10000 = miliseconds = 10 seconds end end addEventHandler("onMarkerHit", moneymarker, giveMoney)
Tekken Posted March 10, 2015 Posted March 10, 2015 (edited) This will give 50 $ every 10 seconds if player is in marker. local moneymarker = createMarker (2505.2, -1672.5, 12, "cylinder", 2, 60, 240, 32, 200) function giveMoney(player) if getElementType(player) == "player" then local theTime = setTimer ( function() givePlayerMoney(player, 50) end, 10000, 0 ) end end addEventHandler("onMarkerHit", moneymarker, giveMoney) function killTime() if isTimer(theTime) then killTimer(theTime) end end addEventHandler("onMarkerLeave", moneymarker, killTime) Edited March 10, 2015 by Guest
..:D&G:.. Posted March 10, 2015 Posted March 10, 2015 This will give 50 $ every 10 seconds if player is in marker. local moneymarker = createMarker (2505.2, -1672.5, 12, "cylinder", 2, 60, 240, 32, 200) function giveMoney(player) if getElementType(player) == "player" then local theTime setTimer ( function() givePlayerMoney(player, 50) end, 10000, 0 ) end end addEventHandler("onMarkerHit", moneymarker, giveMoney) function killTime() if isTimer(theTime) then killTimer(theTime) end end addEventHandler("onMarkerLeave", moneymarker, killTime) You forgot the '=' between "theTimer" and "setTimer"
Tekken Posted March 10, 2015 Posted March 10, 2015 (edited) [quote name=..&G:..] This will give 50 $ every 10 seconds if player is in marker. local moneymarker = createMarker (2505.2, -1672.5, 12, "cylinder", 2, 60, 240, 32, 200) function giveMoney(player) if getElementType(player) == "player" then theTime setTimer ( function(player) givePlayerMoney(player, 50) end, 10000, 0 ) end end addEventHandler("onMarkerHit", moneymarker, giveMoney) function killTime() if isTimer(theTime) then killTimer(theTime) end end addEventHandler("onMarkerLeave", moneymarker, killTime) You forgot the '=' between "theTimer" and "setTimer" #Fixed. Thank's Edited March 10, 2015 by Guest
..:D&G:.. Posted March 10, 2015 Posted March 10, 2015 [quote name=..&G:..]This will give 50 $ every 10 seconds if player is in marker. local moneymarker = createMarker (2505.2, -1672.5, 12, "cylinder", 2, 60, 240, 32, 200) function giveMoney(player) if getElementType(player) == "player" then local theTime setTimer ( function() givePlayerMoney(player, 50) end, 10000, 0 ) end end addEventHandler("onMarkerHit", moneymarker, giveMoney) function killTime() if isTimer(theTime) then killTimer(theTime) end end addEventHandler("onMarkerLeave", moneymarker, killTime) You forgot the '=' between "theTimer" and "setTimer" #Fixed. Thank's You might also want to take the 'local' from "theTimer' off, so it can be triggered outside the 'if' it is in.
Tekken Posted March 10, 2015 Posted March 10, 2015 [quote name=..&G:..] You might also want to take the 'local' from "theTimer' off, so it can be triggered outside the 'if' it is in. Hmm, i didn't know that thanks
TAPL Posted March 10, 2015 Posted March 10, 2015 player is not defined inside the timer, also you should use table.
iMr.TZ[W]ER Posted March 10, 2015 Posted March 10, 2015 player is not defined inside the timer, also you should use table. why he should use a table ?
TAPL Posted March 10, 2015 Posted March 10, 2015 player is not defined inside the timer, also you should use table. why he should use a table ? MTA isn't single player, you can't just use one variable for more than one player. Actually there's no need for using the event onMarkerHit and onMarkerLeave. Use one timer and loop all players in the marker and give them money. getElementColShape getElementsWithinColShape
SkullBreaker Posted March 11, 2015 Author Posted March 11, 2015 Thanks for your replies! I am going to try some out
SkullBreaker Posted March 11, 2015 Author Posted March 11, 2015 It worked perfectly! This is what I got now: local moneymarker = createMarker(2505.2, -1672.5, 12, "cylinder", 5, 60, 240, 32, 200) function giveMoney(player) if getElementType(player) == "player" then theTime = setTimer (function() givePlayerMoney(player, 50) end, 10000, 0) end end addEventHandler("onMarkerHit", moneymarker, giveMoney) function killTime() if isTimer(theTime) then killTimer(theTime) end end addEventHandler("onMarkerLeave", moneymarker, killTime) Thanks for your help
SkullBreaker Posted March 11, 2015 Author Posted March 11, 2015 player is not defined inside the timer, also you should use table. why he should use a table ? MTA isn't single player, you can't just use one variable for more than one player. Actually there's no need for using the event onMarkerHit and onMarkerLeave. Use one timer and loop all players in the marker and give them money. getElementColShape getElementsWithinColShape What exactly is a "colshape" and what can I do with it?
..:D&G:.. Posted March 11, 2015 Posted March 11, 2015 Colshape is an invisible area, a square or any other shape. You can use that instead of a marker, more realistic.,
SkullBreaker Posted March 11, 2015 Author Posted March 11, 2015 [quote name=..&G:..]Colshape is an invisible area, a square or any other shape. You can use that instead of a marker, more realistic., Okay Thanks!
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