Jump to content

[HowTo] Redis DB Trader Cleanup


Brunz

Recommended Posts

Hi,

 

I am going to post some scripts which are for Redis DB to solve the following problems.

 

1. Vehicles Stuck in Traders causing low vehicle count on map

2. Traders who are way overstocked

3. Reset all vehicles back to random pos

 

Important Information before starting

1. Shutdown Arma 3 Server

2. Shutdown Redis

3. Backup you DB, then back it up again

4. Understand that you could break your db if you mess up, refer to step 3.

 

Prerequisites

Download redis-cli.exe - https://msopentech.com/opentech-projects/redis/

 

Purge Traders Items

clean_ai_items.lua

local count = 0
local valuelist = redis.call('keys', 'AI_ITEMS:1:*')
if valuelist then
    for i = 1, #valuelist do
        
		--Delete
		redis.call('del', valuelist[i])

		--Set ( Custom Trader loadouts can be set here)
	        --redis.call('set', valuelist[i], '[[],[]]')

		count = count + 1
       
    end
end
return count

Purge Vehicle Spawns ( reset all vehicles and contents )

clean_vehicles.lua

local count = 0
local valuelist = redis.call('keys', 'Vehicle:1:*')
local valueitem
if valuelist then
    for i = 1, #valuelist do
		
                --Purge all vehicles
                count = count + 1
                redis.call('del', valuelist[i]) 

		--Fancy Stuff can go here?
		--valueitem = redis.call('get',valuelist[i])
				
                --if valueitem == '[]' then 
		--  redis.call('del', valuelist[i]) 
		--  count = count + 1
		--end	
        
    end
end
return count

 

Replace Traders Items - Vehicles Only, will replace with specified item

clean_sold_vehicles_only.lua

local VEHICLE_ARRAY =	{"C_Offroad_01_EPOCH","C_Quadbike_01_EPOCH","C_Hatchback_01_EPOCH","C_Hatchback_02_EPOCH","C_SUV_01_EPOCH","C_Rubberboat_EPOCH",
				 "C_Rubberboat_02_EPOCH","C_Rubberboat_03_EPOCH","C_Rubberboat_04_EPOCH","C_Van_01_box_EPOCH","C_Van_01_transport_EPOCH","C_Boat_Civil_01_EPOCH",
				 "C_Boat_Civil_01_police_EPOCH","C_Boat_Civil_01_rescue_EPOCH","B_Heli_Light_01_EPOCH","B_SDV_01_EPOCH","B_MRAP_01_EPOCH",
				 "B_Truck_01_transport_EPOCH","B_Truck_01_covered_EPOCH","B_Truck_01_box_EPOCH","O_Truck_02_covered_EPOCH","O_Truck_02_transport_EPOCH",
				 "O_Truck_03_covered_EPOCH","O_Truck_02_box_EPOCH","I_Heli_light_03_unarmed_EPOCH","O_Heli_Light_02_unarmed_EPOCH","I_Heli_Transport_02_EPOCH",
				 "O_Heli_Transport_04_EPOCH","O_Heli_Transport_04_bench_EPOCH","O_Heli_Transport_04_box_EPOCH","O_Heli_Transport_04_covered_EPOCH",
				 "B_Heli_Transport_03_unarmed_EPOCH","K01","K02","K03","K04","B_G_Offroad_01_F","O_MRAP_02_F","I_MRAP_03_F","O_G_Offroad_01_F",
				 "I_G_Offroad_01_F","I_G_VAN_01_transport_F"}
	
local count = 0
local valuelist = redis.call('keys', 'AI_ITEMS:1:*')
local valueitem
if valuelist then
    for i = 1, #valuelist do
		
		--Clean Vehicles which have been sold
		valueitem = redis.call('get',valuelist[i])
		
		for v = 1, #VEHICLE_ARRAY do
		
			valueitem = string.gsub(valueitem, VEHICLE_ARRAY[v], "EpochRadio0")		
		
		end
		
			  redis.call('set', valuelist[i], valueitem)
			  count = count + 1
		
        
    end
end
return count

 

 

How to Run

 

1. Ensure you have taken backups

2. Shutdown Arma 3 Server

3. Startup REDIS DB

4. Create file above "clean_ai_items.lua" in same directory

4. In the directory where redis-cli.exe is located open a command prompt ( SHIFT + RIGHT CICK --> Open Command WIndows here)

5. Execute below command in command prompt changing inputs to suit your environment, if your unsure what the below flags are run a redis-cli --help for info.

redis-cli -h 127.0.0.1 -p 2456 -a mypass -n 0 --eval clean_ai_items.lua
6. You should get a count outputted of how many traders were purged of there items

7. The changes should save eventually but to do a manual save run the following

redis-cli -h 127.0.0.1 -p 2456 -a mypass -n 0
127.0.0.1:2456> save
OK
127.0.0.1:2456> shutdown
not connected>
8. I recommend taking another db backup

9. Startup DB 

10. Startup Arma 3 Server

11. Enjoy Clean Traders and freed up vehicles

 

Special Notes

If you want to get fancy and do preloaded traders then you can use the commented section in the clean_ai_items.lua file

Link to comment
Share on other sites

When I call the clean_ai_items.lua comes only

<integer> 0

Hi,

 

That basically means it found no results from the keys lookup, check your EpochServer.ini and see what is your InstanceID, you may need to modify the keys lookup pattern to match.

 

eg.. where it has 1 change it to your instanceid

local valuelist = redis.call('keys', 'AI_ITEMS:1:*')

local valuelist = redis.call('keys', 'AI_ITEMS:MyInstanceID:*')

You can check the keys look up is working by doing below

 

replace the below parameters to suit your environment and then run the below in the command prompt.

1. Connect to DB using redis-cli

redis-cli -h 127.0.0.1 -p 2456 -a mypass -n 0

2. List keys using a pattern

127.0.0.1:2456> keys AI_ITEMS:MyInstanceID:*
1) "AI_ITEMS:MyInstanceID:87"
2) "AI_ITEMS:MyInstanceID:26"
etc.....

if all else fails try to connect using http://redisdesktop.com/

Link to comment
Share on other sites

Hi,

 

That basically means it found no results from the keys lookup, check your EpochServer.ini and see what is your InstanceID, you may need to modify the keys lookup pattern to match.

 

eg.. where it has 1 change it to your instanceid

local valuelist = redis.call('keys', 'AI_ITEMS:1:*')

local valuelist = redis.call('keys', 'AI_ITEMS:MyInstanceID:*')

You can check the keys look up is working by doing below

 

replace the below parameters to suit your environment and then run the below in the command prompt.

1. Connect to DB using redis-cli

redis-cli -h 127.0.0.1 -p 2456 -a mypass -n 0

2. List keys using a pattern

127.0.0.1:2456> keys AI_ITEMS:MyInstanceID:*
1) "AI_ITEMS:MyInstanceID:87"
2) "AI_ITEMS:MyInstanceID:26"
etc.....

if all else fails try to connect using http://redisdesktop.com/

 

i'm connected with redisdesktop, and i'm connected to my database but not clue how to enter the code in it.... any advice

Link to comment
Share on other sites

  • 1 month later...

Brunz, I ran the clean script, removing all vendor items, and I added 'start up' items for the vendors. When I look in RedisDesktop, I see the items and amounts, however, in game, I do not see them, the vendors have nothing.

 

Is there something I am missing?

 

Thanks

 

Tal

Link to comment
Share on other sites

I rebooted the server, and it worked. Don't know why it didn't the first time. I had the DB running, ran the script, checked the data, then started the Arma server, and nothing was changed. I closed the Arma server, ran the script again, and started the Arma server and it showed the change.

 

I am assuming you can set this to run at say server shutdown, or start up. I am new to Arma coding and our admins were looking at a way to have the vendors restock each reboot, and to clear out items so they don't get clunky.

 

Thanks

Link to comment
Share on other sites

  • 3 weeks later...

Hi,

 

That basically means it found no results from the keys lookup, check your EpochServer.ini and see what is your InstanceID, you may need to modify the keys lookup pattern to match.

 

eg.. where it has 1 change it to your instanceid

local valuelist = redis.call('keys', 'AI_ITEMS:1:*')

local valuelist = redis.call('keys', 'AI_ITEMS:MyInstanceID:*')

You can check the keys look up is working by doing below

 

replace the below parameters to suit your environment and then run the below in the command prompt.

1. Connect to DB using redis-cli

redis-cli -h 127.0.0.1 -p 2456 -a mypass -n 0

2. List keys using a pattern

127.0.0.1:2456> keys AI_ITEMS:MyInstanceID:*
1) "AI_ITEMS:MyInstanceID:87"
2) "AI_ITEMS:MyInstanceID:26"
etc.....

if all else fails try to connect using http://redisdesktop.com/

Hi Brunz, I have the same problem with <integer> 0

 

When I followed your instructions above changing my DB instance ID to 0 which is what I have against DB in my EpochServer.ini file, I get this:

<empty list or set>

Can't work out what I'm doing wrong, any ideas?

 

Thanks

Link to comment
Share on other sites

Hi Brunz, I have the same problem with <integer> 0

 

When I followed your instructions above changing my DB instance ID to 0 which is what I have against DB in my EpochServer.ini file, I get this:

<empty list or set>

Can't work out what I'm doing wrong, any ideas?

 

Thanks

 

Hello, DB = 0 from epochserver.ini is wrong. U must change to NA123, which is default if you not change it.

Look for InstanceID in epochserver.ini

local valuelist = redis.call('keys', 'AI_ITEMS:NA123:*')  is what u need :-)

Link to comment
Share on other sites

Hello, DB = 0 from epochserver.ini is wrong. U must change to NA123, which is default if you not change it.

Look for InstanceID in epochserver.ini

local valuelist = redis.call('keys', 'AI_ITEMS:NA123:*')  is what u need :-)

Thanks dude. Can't believe I didn't spot that and was trying to use the DB number instead of instance... :mellow:

Link to comment
Share on other sites

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
  • Advertisement
  • Discord

×
×
  • Create New...