Jump to content
Brunz

[HowTo] Redis DB Trader Cleanup

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

Share this post


Link to post
Share on other sites

Does this wipe the traders every time it is run?

 

Yes, It will wipe everything on a trader once its executed. Not a thing i would ever do. But just an example you can execute when needed

Share this post


Link to post
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/

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

@Tophi Redis Desktop currently can only update one value at a time manually. if you want to do a bulk update please read the first post carefully and use redis-cli.exe with the lua script

 

thank you. i will try it

Share this post


Link to post
Share on other sites

Hi,

an update has been added to the original post.

Instead of cleaning the whole trader of all items i have added a script which will replace only those vehicles you specify with a item of your choosing.

See - clean_sold_vehicles_only.lua

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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

Share this post


Link to post
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/

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

Share this post


Link to post
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 :-)

Share this post


Link to post
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:

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Advertisement
  • Supporters
  • Discord

×
×
  • Create New...