Jump to content

[HELP] givePlayerMoney onMarkerHit with timer


Recommended Posts

Posted (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 by Guest
Posted
local moneymarker = createMarker (2505.2, -1672.5, 12, "cylinder", 2, 60, 240, 32, 200) 
  
function giveMoney () 
    givePlayerMoney (source, 10) 
end 
addEventHandler ("onMarkerHit", moneymarker, giveMoney) 

Posted
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) 

Posted
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?

Posted
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?

Posted
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.

Posted
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) 

Posted (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 by Guest
Posted
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" :P

Posted (edited)

[quote name=..:D&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" :P

#Fixed. Thank's :D

Edited by Guest
Posted
[quote name=..:D&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" :P

#Fixed. Thank's :D

You might also want to take the 'local' from "theTimer' off, so it can be triggered outside the 'if' it is in.

Posted

[quote name=..:D&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 :)

Posted
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 

Posted

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 ;)

Posted
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?

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...