RedKacsa Posted June 1, 2018 Share Posted June 1, 2018 Robbery Script Animation HELP ME I want to put in a robbery script for an animation for 4-5 seconds, but I do not know how and where to fit it. If someone came to this, he could help. I tried 2-3 things, but none of them worked. Here is my scrip,too, who would like to fit the appropriate script and write it to me, thank you very much! Script: function createRob() Marker = createMarker ( 1788.9731445313,-1123.0570068359,23.5, "cylinder", 1, 255, 0, 0, 5 ) setElementCollisionsEnabled( Marker, false ) bl = createBlipAttachedTo(Marker,45) outputChatBox( "", root, 0, 255, 0 )endaddEventHandler("onResourceStart", resourceRoot,createRob) addEventHandler("onMarkerLeave",root,function ( player ) if ( source ~= Marker ) then return end if ( isPedInVehicle( player ) ) then return end destroyElement( Marker ) destroyElement( bl ) randomMoney = math.random ( 22000, 22000 ) randomWanted = math.random ( 5, 5 ) givePlayerMoney(player,randomMoney) setPlayerWantedLevel ( player, randomWanted ) robPlayer = getPlayerName(player) outputChatBox("",root,0,255,0,true) setTimer( createRob, 600000, 1 ) end) Link to comment
Skully Posted June 1, 2018 Share Posted June 1, 2018 You can achieve this by using the event handler OnMarkerHit, this is triggered whenever a element enters your marker. To make a player/ped do an animation, we can use SetPedAnimation and trigger it on our player that enters the marker. The animation will play for however long you like as specified in the fourth parameter. Here's your finished code. function createRob() Marker = createMarker(1788.9731445313, -1123.0570068359, 23.5, "cylinder", 1, 255, 0, 0, 5) setElementCollisionsEnabled(Marker, false) bl = createBlipAttachedTo(Marker, 45) end addEventHandler("onResourceStart", resourceRoot, createRob) addEventHandler("onMarkerHit", Marker, function(player) -- Attach the event handler to the marker so it detects when a player enters it. if (player) and (getElementType(player) == "player") then -- If the element who entered the marker was a player. setPedAnimation(player, "ROB_BANK", "CAT_SAFE_OPEN", 4000, false, false, false, false) -- Play an animation in the ROB_BANK category for 4000ms. end end) addEventHandler("onMarkerLeave", Marker, function(player) if (source ~= Marker) then return end if (isPedInVehicle(player)) then return end destroyElement(Marker) destroyElement(bl) randomMoney = math.random(22000, 22000) randomWanted = math.random (5, 5) givePlayerMoney(player, randomMoney) setPlayerWantedLevel(player, randomWanted) robPlayer = getPlayerName(player) setTimer(createRob, 600000, 1) end) Link to comment
RedKacsa Posted June 2, 2018 Author Share Posted June 2, 2018 Thanks! I already try it! I inserted it in the script, but it writes something wrong. There are two types of "addEventHandler" problems. Can you help me here? I've noticed in the 8th and 14th line the issue with addEventHandler but I do not know what it is :/ Link to comment
Skully Posted June 3, 2018 Share Posted June 3, 2018 On 6/2/2018 at 17:23, RedKacsa said: Thanks! I already try it! I inserted it in the script, but it writes something wrong. There are two types of "addEventHandler" problems. Can you help me here? I've noticed in the 8th and 14th line the issue with addEventHandler but I do not know what it is What are the errors you're getting? Link to comment
RedKacsa Posted June 13, 2018 Author Share Posted June 13, 2018 "[Time] WARNING: rablas\rob.lua:8: Bad argument @ 'addEventHandler' [Expected element at argument 2, got nill]" "[Time] WARNING: rablas\rob.lua:14: Bad argument @ 'addEventHandler' [Expected element at argument 2, got nill]" Link to comment
MIKI785 Posted June 13, 2018 Share Posted June 13, 2018 That's because Marker is nil when addEventHandler is called. Simply remove the onClientResourceStart, I don't think there is any need for it in this case. Marker = createMarker(1788.9731445313, -1123.0570068359, 23.5, "cylinder", 1, 255, 0, 0, 5) setElementCollisionsEnabled(Marker, false) bl = createBlipAttachedTo(Marker, 45) addEventHandler("onMarkerHit", Marker, function(player) -- Attach the event handler to the marker so it detects when a player enters it. if (player) and (getElementType(player) == "player") then -- If the element who entered the marker was a player. setPedAnimation(player, "ROB_BANK", "CAT_SAFE_OPEN", 4000, false, false, false, false) -- Play an animation in the ROB_BANK category for 4000ms. end end) addEventHandler("onMarkerLeave", Marker, function(player) if (source ~= Marker) then return end if (isPedInVehicle(player)) then return end destroyElement(Marker) destroyElement(bl) randomMoney = math.random(22000, 22000) randomWanted = math.random (5, 5) givePlayerMoney(player, randomMoney) setPlayerWantedLevel(player, randomWanted) robPlayer = getPlayerName(player) setTimer(createRob, 600000, 1) end) Link to comment
RedKacsa Posted June 16, 2018 Author Share Posted June 16, 2018 Now do not make any mistakes! Thank you very much for helping everyone. 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