Jump to content

[HELP] How can I make this work?


Recommended Posts


local greenzone = createColRectangle ( 1995.224609375, 1516.697265625, 11, 45 )
local greenzoneradar = createRadarArea ( 1993.91796875, 1567.671875, 50, -100, 255, 255, 0, 150 )
local playerSource = getLocalPlayer

function getThatMoney ( playerSource, matchingDimension )
    local getmoney = getPlayerMoney ( playerSource )
        if (getElementType(playerSource) == "player") then
                outputChatBox( "#FFFFFF* #00FF00You've entered the money zone!", playerSource, 255, 255, 109, true )
                setRadarAreaFlashing ( greenzoneradar, true )
			setPlayerMoney ( playerSource, getmoney +50 )
			local setMoney = setPlayerMoney ( playerSource, getmoney + 5 )
			setTimer (setMoney, 1000, 0)
        end
end
addEventHandler ( "onColShapeHit", root, getThatMoney )


function getThatMoneyExit ( playerSource, matchingDimension )
        if (getElementType(playerSource) == "player") then
                        outputChatBox ( "#FFFFFF* #FF0000You've left the money zone!", playerSource, 255, 255, 109, true )
                        setRadarAreaFlashing ( greenzoneradar, false )
        end
end
addEventHandler ( "onColShapeLeave", greenzone, getThatMoneyExit )

-------------------------------------------------------------------------------------------------------------------------------------------------------

Hi everyone, I'm new to scripting but been playing the game off and on for 10 years and now wanting to get into learning more about scripting, so this script probably looks horrible to most.

 This script is supposed to have a green zone in a certain area and as the player stays in said zone should get $5 everyone second but I can't figure out the arguments on the setTimer, any help explaining what I'm doing wrong will be so helpful, thank you!

 

Edited by Ryan167
Link to comment

Try this

 

local greenzone = createColRectangle ( 1995.224609375, 1516.697265625, 11, 45 )
local greenzoneradar = createRadarArea ( 1993.91796875, 1567.671875, 50, -100, 255, 255, 0, 150 )

function Col_Enter ( thePlayer, matchingDimension )
        if getElementType ( thePlayer ) == "player" then
		setElementData(thePlayer, "isInGreenZone", true)
		setRadarAreaFlashing ( greenzoneradar, true )
		outputChatBox( "#FFFFFF* #00FF00You've entered the money zone!", thePlayer, 255, 255, 109, true )
        end
end
addEventHandler ( "onColShapeHit", greenzone, Col_Enter )

function Col_Exit ( thePlayer, matchingDimension )
		if getElementType ( thePlayer ) == "player" then
		setElementData(thePlayer, "isInGreenZone", false)
		setRadarAreaFlashing ( greenzoneradar, false )
		outputChatBox ( "#FFFFFF* #FF0000You've left the money zone!", playerSource, 255, 255, 109, true )
        end
end
addEventHandler ( "onColShapeLeave", greenzone, Col_Exit )

setTimer(function() 
for i,v in ipairs(getElementsByType("player")) do
if getElementData(v, "isInGreenZone") == false then return false end
givePlayerMoney(v, 5)
end
end, 1000, 1)

 

Link to comment
22 minutes ago, Ryan167 said:

I appreciate the fast response thank you, but that still doesn't work.

I didn't try to code at first
But I made some change, I think it will work now
I've changed the col location to test, you can change it later
Try this one server side
 

greenzone = createColRectangle ( 1400.2144775391,1425.1593017578, 100, 100 )
greenzoneradar = createRadarArea ( 1400.2144775391,1425.1593017578, 100, 100, 255, 255, 0, 150 )

function Col_Enter ( thePlayer, matchingDimension )
        if getElementType ( thePlayer ) == "player" then
		setElementData(thePlayer, "isInGreenZone", true)
		setRadarAreaFlashing ( greenzoneradar, true )
		setTimer(giveMoneyToPlayers, 1000, 0, thePlayer)
		outputChatBox( "#FFFFFF* #00FF00You've entered the money zone!", thePlayer, 255, 255, 109, true )
        end
end
addEventHandler ( "onColShapeHit", greenzone, Col_Enter )

function Col_Exit ( thePlayer, matchingDimension )
		if getElementType ( thePlayer ) == "player" then
		setElementData(thePlayer, "isInGreenZone", false)
		setRadarAreaFlashing ( greenzoneradar, false )
		outputChatBox ( "#FFFFFF* #FF0000You've left the money zone!", playerSource, 255, 255, 109, true )
        end
end
addEventHandler ( "onColShapeLeave", greenzone, Col_Exit )


function giveMoneyToPlayers (thePlayer)
	if getElementData(thePlayer, "isInGreenZone") == false then return false end
	givePlayerMoney(thePlayer, 5)
	end

 

I've re-checked the code and found an issue
Try this version I hope it helps you
 

greenzone = createColRectangle ( 1400.2144775391,1425.1593017578, 100, 100 )
greenzoneradar = createRadarArea ( 1400.2144775391,1425.1593017578, 100, 100, 255, 255, 0, 150 )

function Col_Enter ( thePlayer, matchingDimension )
        if getElementType ( thePlayer ) == "player" then
		setElementData(thePlayer, "isInGreenZone", true)
		setRadarAreaFlashing ( greenzoneradar, true )
		outputChatBox( "#FFFFFF* #00FF00You've entered the money zone!", thePlayer, 255, 255, 109, true )
        end
end
addEventHandler ( "onColShapeHit", greenzone, Col_Enter )

function Col_Exit ( thePlayer, matchingDimension )
		if getElementType ( thePlayer ) == "player" then
		setElementData(thePlayer, "isInGreenZone", false)
		setRadarAreaFlashing ( greenzoneradar, false )
		outputChatBox ( "#FFFFFF* #FF0000You've left the money zone!", playerSource, 255, 255, 109, true )
		resetTimer(timer)
        end
end
addEventHandler ( "onColShapeLeave", greenzone, Col_Exit )


timer = setTimer(function(thePlayer)
		for i, v in ipairs(getElementsByType("player")) do
		if getElementData(v, "isInGreenZone") == false then return false end
		givePlayerMoney(v, 5)
		end
	end
	,1000, 0, thePlayer)

 

Link to comment

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