Jump to content

Can anybody get this working??


Recommended Posts

I tried making a bank robbery script but it worked but the timer doesn't, I've never used timers before :P thanks for any help.

function robmarkeronsetup ()
robmarker = createMarker (2277.99, -1729.04, 508.479, "cylinder", 4.5, 255, 0, 0, 128, getRootElement())
setElementInterior (robmarker, 3)
end
addEventHandler("onResourceStart", getRootElement(), robmarkeronsetup)
 
function robm (hitPlayer, matchingDimension)
if (source == robmarker) then
outputChatBox ("****BANK ROB****", hitPlayer, 255, 0, 0, false)
outputChatBox ("Press X To Rob The Bank!", hitPlayer, 255, 0, 0, false)
outputChatBox ("You Must Wait To Get The Cash!", hitPlayer, 255, 0, 0, false)
bindKey (hitPlayer, "x", "down", rob)  
end
end
addEventHandler("onMarkerHit", getRootElement(), robm)
 
bankrob = {}
function rob (thePlayer, key, keystate)
if (key == "x") and (keystate == "down") then
if isTimer(bankrob) then -- Check if timer is running using isTimer (this is an example of its use and all)
end
else
outputChatBox ("***All Police To The Bank "..getPlayerName ( thePlayer ).. " Is Robbing The Bank*** ", getRootElement(), 255, 0, 0, false)
	bankrob = setTimer( robb, 100000, 1 )
function robb()
givePlayerMoney ( thePlayer, math.random(50000, 100000) )
end
end
end
 
function death()
killTimer ( bankrob )
end
addEventHandler ( "onPlayerWasted", getRootElement(), death )

p.s it is very basic at the moment and quickly made.

Edited by Guest
Link to comment

Try this replacement out... no promises, I haven't tested it myself... running a little low on time.

bankrob = {}
function rob (thePlayer, key, keystate)
if (key == "x") and (keystate == "down") then
outputChatBox (***All Police To The Bank "..getPlayerName ( thePlayer ).. " Is Robbing The Bank*** ", getRootElement(), 255, 0, 0, false)
		setPlayerWantedLevel ( thePlayer, 4 )
		bankrob = setTimer( robb, 100000, 1 )
	end
end
 
function robb (thePlayer)
	if (source ~= robmarker) then return else
		givePlayerMoney ( thePlayer, math.random(50000, 100000) )
		setPlayerWantedLevel ( thePlayer, 6 )
	end
end

Also, try adding another event handler to your death function, e.g. "onMarkerLeave"... I'd hate to see you get robbed by a doofus who triggers the robbery in the marker, hops in his Infernus immediately, runs like a girl, and is still richer after 100 seconds. Good luck, man.

Link to comment

before you'll copy bravo351's script copy that: (he messed on quote character)

bankrob = {}
function rob (thePlayer, key, keystate)
if (key == "x") and (keystate == "down") then
outputChatBox ("***All Police To The Bank "..getPlayerName ( thePlayer ).. " Is Robbing The Bank*** ", getRootElement(), 255, 0, 0, false)
setPlayerWantedLevel ( thePlayer, 4 )
     bankrob = setTimer( robb, 100000, 1 )
end
end
 
function robb (thePlayer)
if (source ~= robmarker) then return else
givePlayerMoney ( thePlayer, math.random(50000, 100000) )
setPlayerWantedLevel ( thePlayer, 6 )
end
end

Link to comment
hmm it still dosent work :P im stuck, is there any way to cancel the outputChatBox or hide the marker if there is already a timer if anybody can solve my problem. thanks again.

*edit*

please help people this does not work and I haven't got a clue why.

When you killTimer, it doesn't change value of the timer variable passed to killTimer, so you have to destroy the variable when you kill timer, for instance:

...
killTimer( robbank );
robbank = nil; -- destroy variable
...

It will prevent isTimer from returning true when timer is killed.

There is more bugs in your code which I want you to try and fix them yourself... I'll just point them out and suggest you how to make code more simple:

- Your robbank table is overridden with timer variable (setTimer) - solution: store timer in robbank table with player element as table index

- Whenever player press "x" it will change robbank variable to a new timer - solution: - instead of checking if variable is timer, simply unbindKey to stop players from calling rob function after they called it once

- When you leave the marker, unbind the key - solution: add function to onMarkerLeave event and unbind the key in that function

- (A few more bugs which I forgot about when I was typing about the bugs above --> tired :| )

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