Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///mining_ai
- switch(aistate)
- {
- case "comefromidle":
- {
- if instance_exists(oStoneBlock)
- {
- rock = findStone(x,y) //Go to nearest rock
- path = path_add()
- direction = point_direction(x,y,rock.x,rock.y)
- mp_grid_clear_cell(global.aigrid,floor(rock.x/32),floor(rock.y/32))
- mp_grid_path(global.aigrid,path,x,y,rock.x,rock.y,true)
- path_start(path,walkspeed,0,true)
- aistate = "goingtorock"
- } else {
- oIRCServer.counts[? CurrentJob] -= 1
- CurrentJob = "Idle"
- }
- break
- }
- case "goingtorock":
- {
- if path_position = 1 //If Path has ended
- {
- aistate = "mining"
- path_delete(path) //Clearing memory
- }
- break
- }
- case "mining":
- {
- if instance_exists(oStoneBlock)
- {
- rock = findStone(x,y)
- if rock.stonehp > 0 //If stone is still alive, hurt him
- {
- rock.stonehp -= 5
- }
- else
- {
- with rock instance_destroy() //If stone is mined, add stone to inv and destroy Stone
- stone += 1
- if stone >= 5
- {
- if instance_exists(oStockpile) //Bring Stone to Stockpile
- {
- stockpile = instance_nearest(x,y,oStockpile)
- path = path_add()
- direction = point_direction(x,y,stockpile.x,stockpile.y)
- mp_grid_clear_cell(global.aigrid,floor(stockpile.x/32),floor(stockpile.y/32))
- mp_grid_path(global.aigrid,path,x,y,stockpile.x,stockpile.y,true)
- path_start(path,walkspeed,0,true)
- aistate = "goingtostockpile"
- }
- } else {
- if instance_exists(oStoneBlock) //Go to next rock
- {
- rock = findStone(x,y)
- path = path_add()
- direction = point_direction(x,y,rock.x,rock.y)
- mp_grid_clear_cell(global.aigrid,floor(rock.x/32),floor(rock.y/32))
- mp_grid_path(global.aigrid,path,x,y,rock.x,rock.y,true)
- path_start(path,walkspeed,0,true)
- aistate = "goingtorock"
- } else {
- stockpile = instance_nearest(x,y,oStockpile) //Bring Stone to Stockpile
- path = path_add()
- direction = point_direction(x,y,stockpile.x,stockpile.y)
- mp_grid_clear_cell(global.aigrid,floor(stockpile.x/32),floor(stockpile.y/32))
- mp_grid_path(global.aigrid,path,x,y,stockpile.x,stockpile.y,true)
- path_start(path,walkspeed,0,true)
- aistate = "goingtostockpile"
- }
- }
- }
- }
- else
- {
- oIRCServer.counts[? CurrentJob] -= 1
- CurrentJob = "Idle"
- }
- break
- }
- case "goingtostockpile":
- {
- if path_position = 1 //If Path has ended
- {
- path_delete(path) //Clearing memory
- global.stone += stone
- stone = 0
- if instance_exists(oStoneBlock) //Mine next stoneblock
- {
- rock = findStone(x,y)
- path = path_add()
- direction = point_direction(x,y,rock.x,rock.y)
- mp_grid_clear_cell(global.aigrid,floor(rock.x/32),floor(rock.y/32))
- mp_grid_path(global.aigrid,path,x,y,rock.x,rock.y,true)
- path_start(path,walkspeed,0,true)
- aistate = "goingtorock"
- }
- else
- {
- oIRCServer.counts[? CurrentJob] -= 1
- CurrentJob = "Idle"
- }
- }
- break
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement