Skip to content

General functions

AiTechEye edited this page Sep 23, 2018 · 13 revisions

This list contains some general & usefull functions

Function Desciption
aliveai.kill(self) kill the bot, :remove() works too
aliveai.gethp(object) get hp/health and :get_hp() from bots, mobs and players, no crash risk
aliveai.showhp(self,p) p: nil=green or a randomly value to red
aliveai.showtext(self,text,hexcolor) "ff0000" is red, "00ff00" are green, nil are also green
aliveai.get_dir(self_or_pos,object_or_pos) get bot looking direction
aliveai.nan(number) not a number, no crash risk
aliveai.group(pos, node_group) return get_item_group, no crash risk
aliveai.def(pos,"def") returns registered_nodes[name][def] no crash risk
aliveai.defnode(node_name,"def") returns registered_nodes[name][def] no crash risk
aliveai.known(self,object,"value") add textvalue by bot,player or object name
aliveai.getknown(self,object,type) if the object is known as somthing, eg fight
aliveai.searchhelp(self) call near bots from same team
aliveai.samepos(pos1,pos2) if rounded positions is same
aliveai.roundpos(pos)
aliveai.random_pos(self_or_pos,Min_dis,Max_dis) returns a randomly position where you can stand on
aliveai.get_nodes(self,radio,dencity,filter_num)
aliveai.generate_house(self_or_pos,version) if self/object it returns code or generating a house, version can be 1 (samll) or 2 (big)
aliveai.showpath(pos,number,path) requires aliveai.status=true, number (color) can be 1,2,3 path can be nil
aliveai.showstatus(self,text,color) requires aliveai.status=true, color can be 1,2,3,4 (tempoary change the nametag)
aliveai.team(object,change_to_team) get object team, or use change_to_team to change team, even for players & mobs
aliveai.get_bot_name(object) return botname or ""
aliveai.get_bot_by_name(name) get bot by name, if it exist
aliveai.same_bot(self,object) checks if the bot/object is it self
aliveai.is_bot(object) true or false
aliveai.viewfield(self,object_or_pos) if front of bot
aliveai.visiable(self,pos) if the view not are blocked
aliveai.distance(self_or_pos,po2) distance between 2 positions
aliveai.pointat(self,distance) returns a position front of the bot, distance can be nil
aliveai.is_invisiable(player) check if object is player and is invisiable

Functions for items Description
aliveai.invadd(self,item_name,count,nofeedback) add or remove to to inventory, nofeedback: no autocraft it (can be nil)
aliveai.invhave(self,item,number,getnum) if have in inventory (getnum = get number of the item, can be nil)
aliveai.newneed(self,item,num,search,type) add items the bot need by some reason, item, number, search for type (item or node) search and type can be nil
aliveai.haveneed(self,craft) have items that needs, craft: craft if not have needs
aliveai.spawnpickup(pos,item_name,count) spawn item
aliveai.use(self) use tool by self.tools
aliveai.add_mine(self,nodes,count,need) begin or add to mine (self,table,number,string_or_table)
aliveai.exit_mine(self) exit mine

Random check nodes on generated

aliveai.register_rndcheck_on_generated(table)

Functions mapgen Default Description
node nil node name, eg default:stone
group nil group name, eg spreading_dirt_type (do not write "group:")
run required run when node/group is found
first_only false run 1 time each mapchunk only / first found
miny -500 Min height
maxy 500 Max height
chance 1 Chance to run
mindistance 0 Min distance from nearest run
(the last position is not stored to next serverstart)

Example of usage

aliveai.register_rndcheck_on_generated({
	node="air",
	group="stone",
	maxy=200,
	miny=-20,
	first_only=true,
	chance=500,
	mindistance=1000,
	run=function(pos)
		minetest.place_schematic(pos,".../schematics/ufo.mts", "random", {}, true)
	end
})

aliveai.register_buildings_spawner(name,def)

Used for buildings spawning, collect functions in one tool, instead of lots of them.
on_use and on_place can be defined:

aliveai.register_buildings_spawner("Generate a building",{
	on_use=function(itemstack, user, pointed_thing)
		if pointed_thing.type=="node" then
			local pos=pointed_thing.above
			aliveai.generate_house(pos)
		end
	end
})
```lua
Clone this wiki locally