Jump to content

Shop rob


Recommended Posts

Hello guys. I made a very simple shop rob, but i want to make this better.

My idea is i can add more "markers" with a different dimension/interior, in one script, and all marker can be robbed. 

How can i make that? Can anyone help me please? I'm not that best scripter, just started 4/5 month ago..

Thanks any help.

Here is the script:

local settings = {}
function on_shop_start1()
if isElement(created_shopMarker_1) then return end 
    settings.markerX, settings.markerY, settings.markerZ = 369.48327636719, -6.5628895759583, 1001
    settings.dim = 1
    settings.int = 9
    settings.BlipID = 47
    settings.Type = "cylinder"
    settings.size = 1
    settings.R, settings.G, settings.B = 203,150,25
    settings.alpha = 100
    created_shopMarker_1 = createMarker(settings.markerX,settings.markerY,settings.markerZ,settings.Type,settings.size,settings.R, settings.G, settings.B,settings.alpha) 
    AttachBlip = createBlipAttachedTo(created_shopMarker_1,settings.BlipID)
    setElementCollisionsEnabled(created_shopMarker_1,false)
    setElementInterior(created_shopMarker_1,settings.int)
    setElementDimension(created_shopMarker_1,settings.dim)
end
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),on_shop_start1)

function shopROB_1(source)
local playercount = getPlayerCount()
    if isElementWithinMarker(source, created_shopMarker_1) and getElementType(source) == "player" then
        if tonumber(playercount) > 0 then
               setElementFrozen(source, true)
               setPedAnimation(source , "rob_bank", "cat_safe_rob",2*30000, true, true, true, false)
            outputChatBox(getPlayerName(source).."Started robbing the shop.",root,255,255,255,true)             
        setTimer(function()
            setElementFrozen(source,false)
            random = math.random(1500,40000)
            exports["rc_core"]:giveMoney(source,tonumber(random))        
            destroyElement(created_shopMarker_1)
            destroyElement(AttachBlip)
        end,2*30000, 1)
        setTimer(function()
            on_shop_start1()
        end,1800000,1)            
        else
            outputChatBox("Not enough player.",source,255,255,255,true)        
        end
    else
        outputChatBox("You not in a marker",source,255,255,255,true)    
    end
end
addCommandHandler("shoprob",shopROB_1)

 

Edited by TheMOG
Link to comment

So, i think i should use tables for positions(?)

 

something like this:

Table = {

posX, posY,posZ,interiorId,Dimension

posX, posY,posZ,interiorId,Dimension

posX, posY,posZ,interiorId,Dimension

posX, posY,posZ,interiorId,Dimension

posX, posY,posZ,interiorId,Dimension

posX, posY,posZ,interiorId,Dimension

}

then the same thing in the script, but  you can rob all the markers and these markers respawn ..

Edited by TheMOG
Link to comment

It should work.

local shops =
{
	{ name ="Example Shop", x = 369.48327636719, y = -6.5628895759583, z = 1001, dim = 1, int = 9, blip = 47, type = "cylinder", size = 1, r = 203, g = 150, b = 25, a = 100 },
}

function on_shop_start1()
	for i = 1, #shops do
		local theShop = shops[ i ]
		
		theShop[ "marker" ] = createMarker( theShop.x, theShop.y, theShop.z, theShop.type, theShop.size, theShop.r, theShop.g, theShop.b, theShop.a )
		theShop[ "blip" ] = createBlipAttachedTo( theShop[ "markeR" ], theShop.blip )
		setElementCollisionsEnabled( theShop[ "marker" ], false )
		setElementInterior( theShop[ "marker" ], theShop.int )
		setElementDimension( theShop[ "marker" ], theShop.dim )
	end
end
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),on_shop_start1)

function shopROB_1(source)
local playercount = getPlayerCount()
	for i = 1, #shops do
		local theShop = shops[ i ]
		if ( theShop[ "marker" ] ) then
			if ( ( isElementWithinMarker( source, theShop[ "marker" ] ) ) and ( ( getElementType( source ) ) == "player" ) ) then
				if ( ( tonumber( playercount ) ) > 0 ) then
					setElementFrozen( source, true )
					setPedAnimation( source, "rob_bank", "cat_safe_rob", 2 * 30000, true, true, true, false )
					outputChatBox( getPlayerName( source ) .. " started robbing the " .. theShop[ "name" ], source, 0, 255, 0 )
					
					setTimer( function( source, theShopID )
						local theShop = shops[ theShopID ]
						setElementFrozen( source, false )
						local random_var = math.random( 1500, 400000 )
						exports.rc_core:giveMoney( source, random_var )
						destroyElement( theShop[ "marker" ] )
						destroyElement( theShop[ "blip" ] )
					end, 60000, 1, source, i )
					
					setTimer( function( theShopID )
						local theShop = shops[ theShopID ]
						theShop[ "marker" ] = createMarker( theShop.x, theShop.y, theShop.z, theShop.type, theShop.size, theShop.r, theShop.g, theShop.b, theShop.a )
						theShop[ "blip" ] = createBlipAttachedTo( theShop[ "marker" ], theShop.blip )
					end, 1800000, 1, i )
				else
					outputChatBox( "Not enough players!", source, 255, 0, 0, true )
				end
				
				break
			end
		end
	end
end
addCommandHandler("shoprob",shopROB_1)

 

Edited by Uknown.
  • Like 1
Link to comment

Thank you very much. Its working, i get some debug, but i can fix that. 

Only problem is, when i rob 1 marker, after the timer its not "respawning".

Only the second marker respawning

also, there is an error: bad argumet @ 'isElementWithinMarker' [Expected marker at argument 2]

Edited by TheMOG
Link to comment
local shops =
{
	{ name ="Example Shop", x = 369.48327636719, y = -6.5628895759583, z = 1001, dim = 1, int = 9, blip = 47, type = "cylinder", size = 1, r = 203, g = 150, b = 25, a = 100 },
}

function on_shop_start1()
	for i = 1, #shops do
		local theShop = shops[ i ]
		
		theShop[ "marker" ] = createMarker( theShop.x, theShop.y, theShop.z, theShop.type, theShop.size, theShop.r, theShop.g, theShop.b, theShop.a )
		theShop[ "blip" ] = createBlipAttachedTo( theShop[ "markeR" ], theShop.blip )
		setElementCollisionsEnabled( theShop[ "marker" ], false )
		setElementInterior( theShop[ "marker" ], theShop.int )
		setElementDimension( theShop[ "marker" ], theShop.dim )
	end
end
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),on_shop_start1)

function shopROB_1(source)
local playercount = getPlayerCount()
	for i = 1, #shops do
		local theShop = shops[ i ]
		if ( theShop[ "marker" ] ) then
			if ( ( isElement( theShop[ "marker" ] ) ) and ( isElementWithinMarker( source, theShop[ "marker" ] ) ) and ( ( getElementType( source ) ) == "player" ) ) then
				if ( ( tonumber( playercount ) ) > 0 ) then
					setElementFrozen( source, true )
					setPedAnimation( source, "rob_bank", "cat_safe_rob", 2 * 30000, true, true, true, false )
					outputChatBox( getPlayerName( source ) .. " started robbing the " .. theShop[ "name" ], source, 0, 255, 0 )
					
					setTimer( function( source, theShopID )
						local theShop = shops[ theShopID ]
						setElementFrozen( source, false )
						local random_var = math.random( 1500, 400000 )
						exports.rc_core:giveMoney( source, random_var )
						destroyElement( theShop[ "marker" ] )
						destroyElement( theShop[ "blip" ] )
					end, 60000, 1, source, i )
					
					setTimer( function( theShopID )
						local theShop = shops[ theShopID ]
						theShop[ "marker" ] = createMarker( theShop.x, theShop.y, theShop.z, theShop.type, theShop.size, theShop.r, theShop.g, theShop.b, theShop.a )
						theShop[ "blip" ] = createBlipAttachedTo( theShop[ "marker" ], theShop.blip )
					end, 1800000, 1, i )
				else
					outputChatBox( "Not enough players!", source, 255, 0, 0, true )
				end
				
				break
			end
		end
	end
end
addCommandHandler("shoprob",shopROB_1)

 

  • Like 1
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...