Jump to content

[MOD] AutoResearch Version 1.0


Cypher

Recommended Posts

Uhm, why exactly are people calling research gambling "wasteful"?

It seems on average it's cheaper to gamble.

3 items: 4.333... quality N to get 1 quality N+1

4 items: 4.75 N to get 1 N+1

5 items: 5 N to get 1 N+1

You can either figure that out from the probabilities/outcomes directly or just calculate -N/+N/+N+1 over 10 trials at perfectly average luck and divide.

This is because you get 1 qual N back on a "loss". If you did't get anything on a loss it'd always be 5 N for 1 N+1, but ... you do.

 

Link to comment
Share on other sites

  • Replies 78
  • Created
  • Last Reply

Top Posters In This Topic

Uhm, why exactly are people calling research gambling "wasteful"?

 

I don't see (and by see, I mean I looked over the thread quickly before recalling that we lived in the wonderful age of technology that allows me to summon forth my control-f to do the looking for me) anyone specifically saying "wasteful", but if I had to categorize it I'd call it "unreliable".

 

Having a 20% chance to produce an upgrade of the same quality level instead of upgrading it  means I'd then have to collect another three before I'd get to try again. I'd rather spend a slight bit more time getting a fifth upgrade and not having a chance I'll have to restart my progress.

 

Good luck with your gambling!

Link to comment
Share on other sites

Loving the mod so far, only upgrading turrets seems to be a bit buggy sometimes.

Not sure if this is because of your mod or an ingame bug, but sometimes with stacks of 10 after researching 5 the old 5 dissapear.

 

Also it would be very nice if the auto research function came with a scalable or configurable cost, this would benefit the economy.

Link to comment
Share on other sites

Hey guys,

Sorry for dropping away last 2 weeks. Some unfortunate events happened in RL which made me unable

to focus on programming last couple of weeks. I'm trying to pick up the pieces again where i left them and

hopefully be able to update the mod with the planned features. I still do plan to implement them, i just

ran into some trouble.

 

I hope i can finish up the new version soon.

 

Greets

Link to comment
Share on other sites

Hey guys,

Sorry for dropping away last 2 weeks. Some unfortunate events happened in RL which made me unable

to focus on programming last couple of weeks. I'm trying to pick up the pieces again where i left them and

hopefully be able to update the mod with the planned features. I still do plan to implement them, i just

ran into some trouble.

 

I hope i can finish up the new version soon.

 

Greets

 

Sorry to hear that. Hopefully the worst is behind you at least.

Thanks for the great mod! Take your time we could all use a bit of practice with patience anyways :D

Link to comment
Share on other sites

  • 2 weeks later...

I dig into this line, and brought the code in a more readable form for further editing on the lines. Problems are still many and one of them is not possible to combine one type of weapon in the stack, the problem with the disappearance of 5 items from the stack if you yourself study.

 

I will be happy if someone helps!

Best regards from DrKirk in rus...

autoresearch.zip

Link to comment
Share on other sites

  • 2 weeks later...

Hi and thanks for that script. this right-click nightmare has ended ;)

 

I've took the originalcode from Cypher and I've edited it a bit to combine the modifiaktions of Guswut and Vaikin.

+ I fixed that bug that happens if you use autoresearch with no rarities checked (in this case the script did not change the research button back to the default one).

 

this script will research 5 (not 3 or 4) items of the same type and rarity and it will not check the subcategories of turrets (e.g. single, doubble, tripple ect.)

 

To use it, install the original files from Cypher's Post and then replace the code in your autoresearch.lua with this one:

package.path=package.path..";data/scripts/entity/merchants/?.lua;"
package.path=package.path..";data/scripts/lib/?.lua;"

local a={[-1]={"Petty",112,112,122,RarityType.Petty},[0]={"Common",255,255,255,RarityType.Common},[1]={"Uncommon",0,208,0,RarityType.Uncommon},[2]={"Rare",0,112,221,RarityType.Rare},[3]={"Exceptional",255,192,64,RarityType.Exceptional},[4]={"Exotic",255,64,16,RarityType.Exotic},[5]={"Legendary",122,0,204,RarityType.Legendary}}
local b={}
local c={}
local d={}
local e={}
local f={}
local g={}
local h=false;

function editUI(i)createColors()
local j=getResolution()
local k=vec2(800,600)
	required:hide()
	optional:hide()
	results:hide()
	button:hide()
local l=UIVerticalMultiSplitter(i.top,10,10,2)
local m=UIHorizontalSplitter(l:partition(0),10,10,0.5)
	m.padding=6;
local n=m.top;
	n.width=220;
	required=window:createSelection(n,3)
local n=m.bottom;n.width=150;
	optional=window:createSelection(n,2)

for o,p in pairs({required,optional}) do
	p.dropIntoEnabled=1;
	p.entriesSelectable=0;
	p.onReceivedFunction="onRequiredReceived"
	p.onDroppedFunction="onRequiredDropped"
	p.onClickedFunction="onRequiredClicked"
end;
	l.padding=10;
local q=UIOrganizer(l:partition(1))
	q.marginTop=5;
local n=l:partition(1)
	n.width=90;
	n.height=90;
	results=window:createSelection(n,1)
	results.entriesSelectable=0;
	results.dropIntoEnabled=0;
	results.dragFromEnabled=0;
	q:placeElementTop(results)
	q.marginBottom=35;
	button=window:createButton(Rect(),"Research"%_t,"onClickAutoResearch")
	button.width=200;
	button.height=40;
	q:placeElementBottom(button)
	q.marginBottom=0;
	cbAutoResearch=window:createCheckBox(Rect(),"Automatic"%_t,"toggleAutoResearch")
	q:placeElementBottom(cbAutoResearch)
local r=UIOrganizer(l:partition(2))
local s=window:createLabel(vec2(),"AutoResearch Settings"%_t,14)
	s.width=l:partition(2).width;
	s.centered=true;
	r:placeElementTop(s)
local t=UIVerticalMultiSplitter(l:partition(2),10,10,2)
local u=UIOrganizer(t:partition(0))
local v=UIOrganizer(t:partition(1))
local w=UIOrganizer(t:partition(2))
	u.marginTop=10;
	v.marginTop=10;
	w.marginTop=10;
local x=window:createLabel(vec2(),"Rarity"%_t,11)
	x.width=t:partition(0).width;
	x.centered=true;
	u:placeElementTop(x)
local y=window:createLabel(vec2(),"Upgrades"%_t,11)
	y.width=t:partition(1).width;
	y.centered=true;
	v:placeElementTop(y)
local z=window:createLabel(vec2(),"Turrets"%_t,11)
	z.width=t:partition(2).width;
	z.centered=true;
	w:placeElementTop(z)
	u.marginLeft=60;
	u.marginTop=30;
	v.marginTop=30;
	w.marginTop=30;
for A=-1,5 do
	local B=window:createLabel(vec2(),a[A][1]%_t,12)
	local C=window:createCheckBox(Rect(),"","")
	local D=window:createCheckBox(Rect(),"","")
	local E=u.marginTop+25;
		B.width=l:partition(2).width/2;
		B.color=b[A]
		u:placeElementTop(B)
		v:placeElementTop(C)
		w:placeElementTop(D)
		C.width=t:partition(2).width/1.6;
		D.width=t:partition(2).width/1.5;
		c[A]=C;
		d[A]=D;
		u.marginTop=E;
		v.marginTop=E;
		w.marginTop=E
end;
d[-1]:hide()
c[-1].checked=true;
d[0].checked=true
end;

function onClickAutoResearch()
if not cbAutoResearch.checked then onClickResearch() return	end;

autoresearch_on()

local F={c,d}
local G=0;

for A=-1,5 do
	local C=c[A]
	local D=d[A]
	if C.checked then
		G=G+1
	end;
	if D.checked then
		G=G+1
	end
end;

if G==0 then displayChatMessage("You did not select any Rarity types to research!"%_t,Entity().title,1);autoresearch_off(); return end;

updateInventory()

for A=-1,5 do
	local H=a[A][5]
	if c[H].checked then
		local I=getUpgradesByRarity(H)
		if#I>0 then
			local J={}
			for o,K in ipairs(I) do
				if not string.find(K.item.script,"teleporterkey")then
					local L=getUpgradesFromSelection(I,K.item.script)
					if#L>0 then
						-- min number of upgrades for autoresearch
						-- if#L>=3 then
						if#L>=5 then
							local M=#L;
							local N={}
							for A=1,5 do
								if L[A]~=nil then
									table.insert(N,L[A])
								end
							end;
							startAutoResearch(N)
							return
						end
					end
				end
			end
		end
	end
end;

for A=0,5 do
	local H=a[A][5]
	if d[H].checked then
		local O=getTurretsByRarity(H)
		if#O>0 then
			local J={}
			for o,K in ipairs(O) do
				local P=getTurretsFromSelection(O,K.item.itemType,K.item.material,K.item.weaponPrefix,K.item.numWeapons)
				if#P>0 then
					-- min number of turrets for autoresearch
					-- if#P>=3 then
					if#P>=5 then
						local M=#P;
						local N={}
						for A=1,5 do
							if P[A]~=nil then
								table.insert(N,P[A])
							end
						end;
						startAutoResearch(N)
						return
					end
				end
			end
		end
	end
end;

autoresearch_off()
end;

function autoresearch_on()
if not h then
	h=true;
	window.showCloseButton=false;
	window.closeableWithEscape=false;
	window:hide()window:show()button.onPressedFunction="onResearchRunning"
end;
end;
function autoresearch_off()
if h then
	h=false;
	window.showCloseButton=true;
	window.closeableWithEscape=true;
	window:hide()
	window:show()
	button.onPressedFunction="onClickAutoResearch"onShowWindow()
end
end;

function receivedResult()
onClickAutoResearch()
end;

function researchFailed()
if h then
	print("Failed")
	h=false;
	window.showCloseButton=true;
	window.closeableWithEscape=true;
	window:hide()
	window:show()
	button.onPressedFunction="onClickAutoResearch"onShowWindow()
end
end;

function updateInventory()
e={}
f={}
local Q=Player()
for R,S in pairs(Player():getInventory():getItems()) do
	local K=SellableInventoryItem(S.item,R,Q)
	local T=S.item.itemType;
	local U=K.rarity.value;
	if T==InventoryItemType.SystemUpgrade and c[u].checked then
		table.insert(e,K)
	elseif T==InventoryItemType.Turret or itempType==InventoryItemType.TurretTemplate and d[u].checked then
		table.insert(f,K)
	end
end;
table.sort(e,SortSellableInventoryItems)
end;

function getUpgradesByRarity(V)
local M=#e;
local W={}
for A=M,1,-1 do
	if e[A].rarity.value==V then
		table.insert(W,e[A])
	end
end;
return W
end;

function getUpgradesFromSelection(W,X)
local M=#W;
local Y={}
for A=M,1,-1 do
	if W[A].item.script==X then
		table.insert(Y,W[A])
	end
end;
return Y
end;

function getTurretsByRarity(V)
local M=#f;
local W={}
for A=M,1,-1 do
	if f[A].rarity.value==V then
		table.insert(W,f[A])
	end
end;
return W
end;

function getTurretsFromSelection(W,T,Z,_,a0)
local M=#W;
local Y={}
for A=M,1,-1 do
	--change it to use single,double,tripple and quad turrets of the same type in a single research process
	--if W[A].item.itemType==T and W[A].item.material==Z and W[A].item.weaponPrefix==_ and W[A].item.numWeapons==a0 then
	if W[A].item.itemType==T and W[A].item.material==Z and W[A].item.weaponPrefix==_ then
		table.insert(Y,W[A])
	end
end;
return Y
end;

function startAutoResearch(a1)
local a2={}
for o,K in pairs(a1) do
	local a3=a2[K.index]or 0;
	a3=a3+1;
	a2[K.index]=a3
end;
if not checkRarities(a1)then
	displayChatMessage("AutoResearch: rarities too far apart!"%_t,Entity().title,1)
	return
end;
invokeServerFunction("research",a2)
end;

function moveToSelection(a1)
for o,K in ipairs(a1) do
	local a4=getSelectionItem(K)
	onInventoryClicked(inventory.index,a4[1].x,a4[1].y,a4[2],2)
end
end;

function toggleAutoResearch()
for o,p in pairs({required,optional}) do
	p.dropIntoEnabled=not cbAutoResearch.checked;
	button.active=true;
	if cbAutoResearch.checked then
		p.onReceivedFunction="onAutoEnabledTryInteract"
		p.onDroppedFunction="onAutoEnabledTryInteract"
		p.onClickedFunction="onAutoEnabledTryInteract"
		local W=Selection(p.index)
		local K;
		for a5,a6 in pairs(W:getItems()) do
			K=W:getItem(a5)moveItem(K,W,inventory,a5,nil)
		end
	else
		p.onReceivedFunction="onRequiredReceived"
		p.onDroppedFunction="onRequiredDropped"
		p.onClickedFunction="onRequiredClicked"
	end
end;

if cbAutoResearch.checked then
	inventory.onClickedFunction="onAutoEnabledTryInteract"
else
	inventory.onClickedFunction="onInventoryClicked"
	refreshButton()
end
end;

function onAutoEnabledTryInteract()
displayChatMessage("Turn of Automatic to use these manually again!"%_t,Entity().title,1)
end;

function onResearchRunning()
displayChatMessage("Research is currently running please wait!"%_t,Entity().title,3)
end;

function createColors()
for A=-1,5 do
	local a7=Color()
	a7.r=a[A][2]/255;
	a7.g=a[A][3]/255;
	a7.b=a[A][4]/255;
	a7.a=255/255;
	b[A]=a7
end
end

 

You may use notepad++ for that, but I think the win editor should do it also.

Link to comment
Share on other sites

  • 2 months later...
  • 2 weeks later...
  • 2 weeks later...

Simple request, probably not a simple response.

Can the script be modified to do 3 for petty and common, 4 for uncommon and rare and 5 for the rest?

 

Either way, this works brilliantly.

I love scavenging so much lol

Link to comment
Share on other sites

  • 4 weeks later...

Script doesnt work any more?

I tried few times.. result:

1) in research window no icons of turrets/systems stored in inventory = cant choose manually

2) on choosing grades (grey, white, green) - button research become active only after activation of auto-research function

3) Auto research making only one round, then stop....and no any other actions can be done, no "research function" on research station any longer..till reload of galaxy

Please advice.

 

Link to comment
Share on other sites

Script doesnt work any more?

I tried few times.. result:

1) in research window no icons of turrets/systems stored in inventory = cant choose manually

2) on choosing grades (grey, white, green) - button research become active only after activation of auto-research function

3) Auto research making only one round, then stop....and no any other actions can be done, no "research function" on research station any longer..till reload of galaxy

Please advice.

 

Same here.  I think it has something to do with the Alliance upgrade.

 

[EDIT]

Looks like there's a bug thats triggered when the window gets opened.

 

2017-07-31 03-03-52| could not execute function 'onShowWindow' in '"data/scripts/entity/merchants/researchstation.lua"':

2017-07-31 03-03-52| data/scripts/entity/merchants/researchstation.lua:250: attempt to call global 'SelectionItem' (a nil value)

2017-07-31 03-03-52| stack traceback:

2017-07-31 03-03-52| data/scripts/entity/merchants/researchstation.lua:250: in function <data/scripts/entity/merchants/researchstation.lua:219>

 

Link to comment
Share on other sites

2017-08-02 19-40-26| could not execute function 'onShowWindow' in '"data/scripts/entity/merchants/researchstation.lua"':
2017-08-02 19-40-26| data/scripts/entity/merchants/researchstation.lua:250: attempt to call global 'SelectionItem' (a nil value)
2017-08-02 19-40-26| stack traceback:
2017-08-02 19-40-26| 	data/scripts/entity/merchants/researchstation.lua:250: in function <data/scripts/entity/merchants/researchstation.lua:219>

 

I have the same problem.

I'm trying to fix it just for fun but I am having very little success :P

Link to comment
Share on other sites

Ok, fixed it :)

I only tested in single player, but should not have issues in MP.

I also added alliance support (it will upgrade turrets/systems that are in the alliance inventory if you are in an alliance ship and part of the alliance).

All credit goes to the original developer, I just updated the API.

AutoResearch_0.12.zip

Link to comment
Share on other sites

Ok, I did quite a few changes now.

  • Moved the configuration to /configs/autoresearch for convenience
  • Added the option to enable/disable merging of turrets with different amounts of barrels
  • Added the option to disable research for specific tiers of weaponry/systems
  • Added the option to set a specific amount to use when researching a tier (ex: use 3 for common, 5 for legendary)

 

I am not quite happy with the code status but will work on it a bit more when I have more time :)

autoresearch.zip

Link to comment
Share on other sites

  • 1 month later...

I'm new to modding this game and I was wondering how exactly am I supposed to install the changes you have made. I know I'm supposed to copy the data folder from download into the Avorion directory but where am I supposed to put this config folder? Just put it inside the data folder as well?

Link to comment
Share on other sites

tried to use this on the beta branch version and the UI/menu is there but none of my inventory shows up in the research station when the menu is loaded. I really enjoyed this mod, shame its not working anymore. May possibly be on my end only if it is still working for everyone else. If any one has a working version for the beta branch version of the game could you please attach to your reply? i'd really appreciate it! Thank you

 

EDIT: .14 beta branch version

 

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

×
×
  • Create New...