AI PLAYER, TROOP SPAWN SCRIPT AND MORE
» Siedler Map Source Forum » Siedler DEdK Script Forum » AI PLAYER, TROOP SPAWN SCRIPT AND MORE
Seiten: 1 2 3 4 5 6 Nächste Seite
polaster64
|
#1 21.02.2018 19:05 Beiträge: 184 |
AI PLAYER, TROOP SPAWN SCRIPT AND MORE
Hello. Could you help me to setup an AI player?
ScriptExample from ubisoft doesnt help me in anything while making map so I need help of professionals like you guys.
1.How do I make an AI?
Only thing I know is
CreatePlayer2()
How do I make him to repair buildings(serfs) while attacked?
How do I make him to recruit troops and fight?
How can I let the AI to have already 4th level troops and to recruit them constantly?
I want to make him *you know*, really intelligent.
Or even how to make 2 AI's that will fight eachother? Something like the Dartmor
map. Yellowstone vs Dartmor but now exactly in context 2 v 1. More like 1 v 1 and us- real player which has a choice either Dartmor or Yellowstone to destroy as 1st and as 2nd target.
function CreateArmyFour() if ( var < 900 ) then var = var +1 end if ( var == 600 ) then armyFour = {} armyFour.player = 1 armyFour.id = 1 armyFour.strength = 4 armyFour.position = GetPosition("Ziel1") armyFour.rodeLength = 10000 SetupArmy(armyFour) local troopDescription1 = {} troopDescription1.maxNumberOfSoldiers = 8 troopDescription1.minNumberOfSoldiers = 0 troopDescription1.experiencePoints = VERYHIGH_EXPERIENCE troopDescription1.leaderType = Entities.PU_LeaderBow4 for i = 1,4 do EnlargeArmy(armyFour,troopDescription1) end armyFour = {} armyFour.player = 1 armyFour.id = 1 armyFour.strength = 4 armyFour.position = GetPosition("Ziel1") armyFour.rodeLength = 10000 SetupArmy(armyFour) local troopDescription2 = {} troopDescription2.maxNumberOfSoldiers = 8 troopDescription2.minNumberOfSoldiers = 0 troopDescription2.experiencePoints = VERYHIGH_EXPERIENCE troopDescription2.leaderType = Entities.PU_LeaderSword4 for i = 1,4 do EnlargeArmy(armyFour,troopDescription2) end armyFour = {} armyFour.player = 1 armyFour.id = 1 armyFour.strength = 4 armyFour.position = GetPosition("Ziel1") armyFour.rodeLength = 10000 SetupArmy(armyFour) local troopDescription3 = {} troopDescription3.maxNumberOfSoldiers = 3 troopDescription3.minNumberOfSoldiers = 0 troopDescription3.experiencePoints = VERYHIGH_EXPERIENCE troopDescription3.leaderType = Entities.PU_LeaderHeavyCavalry2 for i = 1,2 do EnlargeArmy(armyFour,troopDescription3) end armyFour = {} armyFour.player = 1 armyFour.id = 1 armyFour.strength = 4 armyFour.position = GetPosition("Ziel1") armyFour.rodeLength = 10000 SetupArmy(armyFour) local troopDescription4 = {} troopDescription4.maxNumberOfSoldiers = 3 troopDescription4.minNumberOfSoldiers = 0 troopDescription4.experiencePoints = VERYHIGH_EXPERIENCE troopDescription4.leaderType = Entities.PU_LeaderCavalry2 for i = 1,2 do EnlargeArmy(armyFour,troopDescription4) end armyFour = {} armyFour.player = 1 armyFour.id = 1 armyFour.strength = 4 armyFour.position = GetPosition("Ziel1") armyFour.rodeLength = 10000 SetupArmy(armyFour) local troopDescription5 = {} troopDescription5.maxNumberOfSoldiers = 6 troopDescription5.minNumberOfSoldiers = 0 troopDescription5.experiencePoints = VERYHIGH_EXPERIENCE troopDescription5.leaderType = Entities.PU_LeaderPoleArm4 for i = 1,4 do EnlargeArmy(armyFour,troopDescription5) end var = 0 return end end
2.Now about this script.
How can I make this function to spawn troops only when the troops spawned before died? You know - 1st troop spawn goes to fight and if dies then respawn another portion of troops. How can I do it?
Is there any way for it to be shorter? I dont really know where to cut it because I can see that in every part I put the armyFour.X text and it makes it look big, I know its not needed and I have a problem with cutting it, unfortunately this is the way I only found it working, I know that you are far way better scripters than me and can tell me or edit it to look smaller.
3. How to make cutscenes?
You know - "Look here, this is the enemy of our ally, we need to help him, otherwise he will get smashed"
Im sorry for the chaos but Im really on fire with this game at the moment. Hope you understand everything I wrote here. Best regards!
mcb
|
#2 21.02.2018 21:01 Beiträge: 1472 |
AI: The AI in S5 does provide some basic functionality, but doing anything useful is nothing you can expect from that AI.
To Create an AI you can use this function:
SetupPlayerAi( 2, { -- for player 2 serfLimit = 20, -- buys 20 serfs and rebuys them if they die extracting = 1, -- use serfs to extract resources (0/1) resources = { -- set start resources gold = 2000, wood = 2000, clay = 2000, iron = 2000, stone = 2000, sulfur = 2000 }, refresh = { -- add this resources every updateTime seconds gold = 1000, wood = 0, clay = 0, iron = 0, stone = 0, sulfur = 0, updateTime = 120 }, rebuild = { -- activate rebuild of destroyed buildings after 180 + random(1, 1) seconds delay = 180, randomTime = 1 }, repairing = true, -- serfs repairs damaged buildings constructing = true -- serfs build at placed building sites (repair/buildPlan) })
Anything that you delete from this table gets turned off.
Recruit advanced leaders: You can use GUI.UpgradeSettlerCategory(_ucat, _player) but this only works for Leaders buyed at these buildings, but this generally don't work wery well. For spawned Troops just insert the fitting Leaders.
Respawning Armies: You could use a TroopSpawnGenerator or a SimpleJob with an IsDead condition.
Army = { player = 2, -- which player id = 1, -- id of the army (allowed are 0-9) strength = 8, -- max position = GetPosition("EnemySpawn"), -- start position of the army rodeLength = 4000, --range where the army searches enemys -- now data for the respawn generator spawnTypes = { -- leaders that get spawned with number of soldiers. {Entities.PU_LeaderPoleArm4, 8}, {Entities.PU_LeaderPoleArm4, 8}, {Entities.PU_LeaderSword4, 8}, {Entities.PU_LeaderSword4, 8}, }, endless = true, --after the last leader got spawned the list begins again with the first spawnPos = GetPosition("EnemySpawn"), -- the position where the leaders should spawn spawnGenerator = "EnemyHQ", -- the building that spawns the troops. if it gets destroyed, no more spawning respawnTime = 10, -- time between respawns in seconds refresh = true, --refill soldiers maxSpawnAmount = 3, -- spawn this amount of leaders max at one time noEnemy = true, -- if set, there must be no enemy near the spawnGenerator for spawning noEnemyDistance = 2000, -- distance for noEnemy } SetupArmy(Army) -- initializes army SetupAITroopSpawnGenerator("EnemyArmy", Army) -- initializes the TroopSpawnGenerator. "EnemyArmy" is an unique name you choose for the generator.
You still need to controll your army and say what it should do.
Cutscenes: Real cutscenes are somewhat difficult, because you need to pack some additional data in your .s5x. You can define cutscenes in the LuaDebugger.
polaster64
|
#3 21.02.2018 21:20 Beiträge: 184 |
Zitat von mcb:
AI: The AI in S5 does provide some basic functionality, but doing anything useful is nothing you can expect from that AI.
To Create an AI you can use this function:
SetupPlayerAi( 2, { -- for player 2 serfLimit = 20, -- buys 20 serfs and rebuys them if they die extracting = 1, -- use serfs to extract resources (0/1) resources = { -- set start resources gold = 2000, wood = 2000, clay = 2000, iron = 2000, stone = 2000, sulfur = 2000 }, refresh = { -- add this resources every updateTime seconds gold = 1000, wood = 0, clay = 0, iron = 0, stone = 0, sulfur = 0, updateTime = 120 }, rebuild = { -- activate rebuild of destroyed buildings after 180 + random(1, 1) seconds delay = 180, randomTime = 1 }, repairing = true, -- serfs repairs damaged buildings constructing = true -- serfs build at placed building sites (repair/buildPlan) })
Anything that you delete from this table gets turned off.
Recruit advanced leaders: You can use GUI.UpgradeSettlerCategory(_ucat, _player) but this only works for Leaders buyed at these buildings, but this generally don't work wery well. For spawned Troops just insert the fitting Leaders.
Respawning Armies: You could use a TroopSpawnGenerator or a SimpleJob with an IsDead condition.
Army = { player = 2, -- which player id = 1, -- id of the army (allowed are 0-9) strength = 8, -- max position = GetPosition("EnemySpawn"), -- start position of the army rodeLength = 4000, --range where the army searches enemys -- now data for the respawn generator spawnTypes = { -- leaders that get spawned with number of soldiers. {Entities.PU_LeaderPoleArm4, 8}, {Entities.PU_LeaderPoleArm4, 8}, {Entities.PU_LeaderSword4, 8}, {Entities.PU_LeaderSword4, 8}, }, endless = true, --after the last leader got spawned the list begins again with the first spawnPos = GetPosition("EnemySpawn"), -- the position where the leaders should spawn spawnGenerator = "EnemyHQ", -- the building that spawns the troops. if it gets destroyed, no more spawning respawnTime = 10, -- time between respawns in seconds refresh = true, --refill soldiers maxSpawnAmount = 3, -- spawn this amount of leaders max at one time noEnemy = true, -- if set, there must be no enemy near the spawnGenerator for spawning noEnemyDistance = 2000, -- distance for noEnemy } SetupArmy(Army) -- initializes army SetupAITroopSpawnGenerator("EnemyArmy", Army) -- initializes the TroopSpawnGenerator. "EnemyArmy" is an unique name you choose for the generator.
You still need to controll your army and say what it should do.
Cutscenes: Real cutscenes are somewhat difficult, because you need to pack some additional data in your .s5x. You can define cutscenes in the LuaDebugger.
Wow, applaus man. You are very helpful. Thanks for all the --text so I know how everything works. And how do I control the army? is it something like this down below?
StartSimpleJob("ControlArmySix") function ControlArmyTwo() Defend(armyTwo) end
And if correct, then how to set the army to move between the 2 points? Something like the patrol function.
function ControlArmyThree() Attack( armyThree, GetPosition("example") ) end
Is it possible to set it as
Attack( armyThree, Player1 )
?
mcb
|
#4 21.02.2018 21:40 Beiträge: 1472 |
Something like this. There are some Functions special for moving armies. But they all must be periodically called from a SimpleJob.
Just Defend the spawn area:
function ControlArmy() if Counter.Tick2("ControlArmy", 10) then -- just one command every 10 seconds Defend(Army) -- if someone is near, attack him with the whole army, else move back end end
Attack the nearest enemy:
function ControlArmy() if Counter.Tick2("ControlArmy", 10) then Advance(Army) -- moves the army coordinated to the next enemy end end
(You could also use FrontalAttack(Army) but this can separate the troops)
Patrol between 2 Points, i really don't know if there is an easy solution. Maybe with AI.Army_AddWaypoint(_player, _armyId, _entityId) (but wrong paramerters will likely crash S5)
I don't use anything of this standard AI "features", so i just translated some stuff from the Wiki
daniBIGdani
|
#5 21.02.2018 21:55 Beiträge: 153 |
Patrol troops
Patrol troops is possible e.g. with:
-- create a bowtroop at position "pos_bowtroop" local X, Y = Logic.GetEntityPosition(Logic.GetEntityIDByName("pos_bowtroop")) bowTroop1ID = GlobalMissionScripting.CreateGroup(1, Entities.PU_LeaderBow4, 8, X, Y, 0 ) -- the troop patrols between "pos_bowtroop", "patrol_wp1", "patrol_wp2", "patrol_wp3" and "pos_bowtroop" local X, Y = Logic.GetEntityPosition(Logic.GetEntityIDByName("patrol_wp1")) Logic.GroupPatrol(bowTroop1ID, X, Y) Logic.GroupAddPatrolPoint(bowTroop1ID, Logic.GetEntityPosition (Logic.GetEntityIDByName("patrol_wp2"))) Logic.GroupAddPatrolPoint(bowTroop1ID, Logic.GetEntityPosition (Logic.GetEntityIDByName("patrol_wp3"))) -- the troop guards entity "hero"(could be another troop): Logic.GroupGuard(bowTroop1ID,Logic.GetEntityIDByName("hero"))
daniBIGdani
polaster64
|
#7 21.02.2018 22:15 Beiträge: 184 |
Zitat von mcb:
Something like this. There are some Functions special for moving armies. But they all must be periodically called from a SimpleJob.
Just Defend the spawn area:
function ControlArmy() if Counter.Tick2("ControlArmy", 10) then -- just one command every 10 seconds Defend(Army) -- if someone is near, attack him with the whole army, else move back end end
Attack the nearest enemy:
function ControlArmy() if Counter.Tick2("ControlArmy", 10) then Advance(Army) -- moves the army coordinated to the next enemy end end
(You could also use FrontalAttack(Army) but this can separate the troops)
Patrol between 2 Points, i really don't know if there is an easy solution. Maybe with AI.Army_AddWaypoint(_player, _armyId, _entityId) (but wrong paramerters will likely crash S5)
I don't use anything of this standard AI "features", so i just translated some stuff from the Wiki
Is it possible to set a specific enemy to attack? Or I will just have to place the AIs near eachother.
mcb
|
#8 22.02.2018 00:28 Beiträge: 1472 |
Easiest way would be just moving the army with
Redeploy(Army, GetPosition("something"))
polaster64
|
#9 22.02.2018 23:07 Beiträge: 184 |
SetupPlayerAi( 3, { -- for player 2 serfLimit = 20, -- buys 20 serfs and rebuys them if they die extracting = 4, -- use serfs to extract resources (0/1) resources = { -- set start resources gold = 20000, wood = 20000, clay = 20000, iron = 20000, stone = 20000, sulfur = 20000 }, refresh = { -- add this resources every updateTime seconds gold = 10000, wood = 10000, clay = 10000, iron = 10000, stone = 10000, sulfur = 10000, updateTime = 120 }, rebuild = { -- activate rebuild of destroyed buildings after 180 + random(1, 1) seconds delay = 180, randomTime = 1 }, repairing = true, -- serfs repairs damaged buildings constructing = true -- serfs build at placed building sites (repair/buildPlan) })
I used this fucntion to create AI but nothing happens. Is there something I forgot to use? All AI player buildings have set correct ID, I dont know why the player3 doesnt recruit any troops, did I forget about something?
mcb
|
#10 23.02.2018 13:15 Beiträge: 1472 |
Yes, because the AI can not do something useful alone.
You can activate SetupAITroopGenerator which works similar to then SetupAITroopSpawnGenerator you used.
Army.AllowedTypes = { UpgradeCategories.LeaderSword, UpgradeCategories.LeaderBow, } SetupAITroopGenerator("Army", Army)
But which Troops you get is random and there will be troops standing unused in front of ther recruiting building.
polaster64
|
#11 23.02.2018 21:21 Beiträge: 184 |
Zitat von mcb:
Yes, because the AI can not do something useful alone.
You can activate SetupAITroopGenerator which works similar to then SetupAITroopSpawnGenerator you used.
Army.AllowedTypes = { UpgradeCategories.LeaderSword, UpgradeCategories.LeaderBow, } SetupAITroopGenerator("Army", Army)
But which Troops you get is random and there will be troops standing unused in front of ther recruiting building.
Okay so I used random map generator, got some buildings, added resources etc you know and SetHostile(1,2)
MapEditor_SetupAI(2, 3, 1000000, 3, "janusz1", 3, 0)
Well the AI is quite stupid. I attack the building and it does nothing. I take back all my army and then it attacks with its army, but when I kill some of its troops the Leaders with like 5 of 8 soldiers go back and refill. Is there possibility to make them go rambo all the time?
This is the whole script right here
-------------------------------------------------------------------------------- -- MapName: XXX -- -- Author: XXX -- -------------------------------------------------------------------------------- -- Include main function Script.Load( Folders.MapTools.."Main.lua" ) IncludeGlobals("MapEditorTools") --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -- This function is called from main script to initialize the diplomacy states function InitDiplomacy() SetHostile(1,2) end --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -- This function is called from main script to init all resources for player(s) function InitResources() -- set some resources AddGold (100000) AddSulfur(200000) AddIron (300000) AddWood (400000) AddStone (500000) AddClay (600000) AddGold (2,100000) AddSulfur(2,100000) AddIron (2,100000) AddWood (2,100000) AddStone (2,100000) AddClay (2,100000) end --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -- This function is called to setup Technology states on mission start function InitTechnologies() ResearchTechnology(Technologies.GT_Mercenaries, 1) --> Wehrpflicht ResearchTechnology(Technologies.GT_StandingArmy, 1) --> stehendes Heer ResearchTechnology(Technologies.GT_Tactics, 1) --> Taktiken ResearchTechnology(Technologies.GT_Strategies, 1) --> Pferdezucht ResearchTechnology(Technologies.GT_Construction, 1) --> Konstruktion ResearchTechnology(Technologies.GT_ChainBlock, 1) --> Flaschenzug ResearchTechnology(Technologies.GT_GearWheel, 1) --> Zahnräder ResearchTechnology(Technologies.GT_Architecture, 1) --> Architektur ResearchTechnology(Technologies.GT_Alchemy, 1) --> Alchimie ResearchTechnology(Technologies.GT_Alloying, 1) --> Legierungen ResearchTechnology(Technologies.GT_Metallurgy, 1) --> Metallurgie ResearchTechnology(Technologies.GT_Chemistry, 1) --> Chemie ResearchTechnology(Technologies.GT_Literacy, 1) --> Bildung ResearchTechnology(Technologies.GT_Printing, 1) --> Buchdruck ResearchTechnology(Technologies.GT_Trading, 1) --> Handelswesen ResearchTechnology(Technologies.GT_Library, 1) --> Büchereien ResearchTechnology(Technologies.GT_Mathematics, 1) --> Mathematik ResearchTechnology(Technologies.GT_Binocular, 1) --> Ferngläser ResearchTechnology(Technologies.GT_Matchlock, 1) --> Luntenschloss ResearchTechnology(Technologies.GT_PulledBarrel, 1) --> gezogener Lauf ResearchTechnology(Technologies.T_BetterChassis, 1) ResearchTechnology(Technologies.T_BetterTrainingArchery, 1) ResearchTechnology(Technologies.T_BetterTrainingBarracks, 1) ResearchTechnology(Technologies.T_Shoeing, 1) -- Schmiede etc. ResearchTechnology(Technologies.T_BodkinArrow, 1) -- Bodkin-Pfeile ResearchTechnology(Technologies.T_ChainMailArmor, 1) -- Kettenhemd ResearchTechnology(Technologies.T_FleeceArmor, 1) ResearchTechnology(Technologies.T_FleeceLinedLeatherArmor, 1) ResearchTechnology(Technologies.T_Fletching, 1) -- Befiederung ResearchTechnology(Technologies.T_IronCasting, 1) -- Eisengießen ResearchTechnology(Technologies.T_LeadShot, 1) ResearchTechnology(Technologies.T_LeatherArcherArmor, 1) ResearchTechnology(Technologies.T_LeatherMailArmor, 1) ResearchTechnology(Technologies.T_PaddedArcherArmor, 1) ResearchTechnology(Technologies.T_PlateMailArmor, 1) ResearchTechnology(Technologies.T_Sights, 1) ResearchTechnology(Technologies.T_SoftArcherArmor, 1) ResearchTechnology(Technologies.T_Turnery, 1) ResearchTechnology(Technologies.T_WoodAging, 1) ResearchTechnology(Technologies.T_TownGuard, 1) ResearchTechnology(Technologies.T_MasterOfSmithery, 1) ResearchTechnology(Technologies.T_Tracking, 1) ResearchTechnology(Technologies.T_UpgradeSword1, 1) ResearchTechnology(Technologies.T_UpgradeSword2, 1) ResearchTechnology(Technologies.T_UpgradeSword3, 1) ResearchTechnology(Technologies.T_UpgradeSpear1, 1) ResearchTechnology(Technologies.T_UpgradeSpear2, 1) ResearchTechnology(Technologies.T_UpgradeSpear3, 1) ResearchTechnology(Technologies.T_UpgradeBow1, 1) ResearchTechnology(Technologies.T_UpgradeBow2, 1) ResearchTechnology(Technologies.T_UpgradeBow3, 1) ResearchTechnology(Technologies.T_UpgradeRifle1, 1) ResearchTechnology(Technologies.T_UpgradeLightCavalry1, 1) ResearchTechnology(Technologies.T_UpgradeHeavyCavalry1, 1) end --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -- This function is called on game start and after save game is loaded, setup your weather gfx -- sets here function InitWeatherGfxSets() SetupNormalWeatherGfxSet() end --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -- This function is called on game start you should setup your weather periods here function InitWeather() AddPeriodicSummer(10) end --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -- This function is called on game start and after save game to initialize player colors function InitPlayerColorMapping() end --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -- This function is called on game start after all initialization is done function FirstMapAction() CreateArmyThree() local VictoryConditionType = 2 if VictoryConditionType == 1 then MapEditor_SetupResourceVictoryCondition( 1000, 1000, 1000, 1000, 1000, 1000 ) elseif VictoryConditionType == 2 then MapEditor_SetupDestroyVictoryCondition(2) end -- Level 0 is deactivated...ignore MapEditor_SetupAI(2, 3, 1000000, 3, "janusz1", 3, 180) SetupPlayerAi( 2, {constructing = true, extracting = 0, repairing = true, serfLimit = 8} ) SetPlayerName ( 2 , "JasonDerulo" ) MapEditor_SetupAI(4, 0, 0, 0, "", 0, 0) MapEditor_SetupAI(5, 0, 0, 0, "", 0, 0) MapEditor_SetupAI(6, 0, 0, 0, "", 0, 0) MapEditor_SetupAI(7, 0, 0, 0, "", 0, 0) MapEditor_SetupAI(8, 0, 0, 0, "", 0, 0) -- HQ Defeat Condition MapEditor_CreateHQDefeatCondition() end function CreateArmyThree() armyThree = { player = 2, id = 3, strength = 20, position = GetPosition("armyThree"), rodeLength = 20000 } SetupArmy(armyThree) local troopDescription = { maxNumberOfSoldiers = 8, minNumberOfSoldiers = 0, experiencePoints = MEDIUM_EXPERIENCE, leaderType = Entities.PU_LeaderSword4 } for i = 1, 5 do EnlargeArmy(armyThree, troopDescription) end local troopDescription = { maxNumberOfSoldiers = 8, minNumberOfSoldiers = 0, experiencePoints = LOW_EXPERIENCE, leaderType = Entities.PU_LeaderBow4 } for i = 1, 5 do EnlargeArmy(armyThree, troopDescription) end local troopDescription = { maxNumberOfSoldiers = 8, minNumberOfSoldiers = 0, experiencePoints = LOW_EXPERIENCE, leaderType = Entities.PU_LeaderPoleArm4 } for i = 1, 1 do EnlargeArmy(armyThree, troopDescription) end StartSimpleJob("ControlArmyThree") end function ControlArmyThree() Defend(armyThree) end -- Quest data MapEditor_QuestTitle = "Destroy the enemy!" MapEditor_QuestDescription = "Do it, we need peace!"
What should I add to make AI more intelligent etc? Its just the beggining and the design of the map is also the beggining because its really crap and I will take care of that later on. But lets get to the point. I want the AI players(I will add more of them soon, but first of all I need to make them clever)
And, what seeds are best for map generating? Its quite annoying when u get sand map with a lot of sh*t in there.
Or is there a program which can generate cool maps?
And How do I add briges? I mean the bridge build plan, didnt find it in doodads.
mcb
|
#12 23.02.2018 22:59 Beiträge: 1472 |
You have to write everything yourself. Detect when the AI is under attack, respond to it and attack itself.
I'm currently working on my own AI, but that script has some 1000 lines of code (and is not finished yet).
For map Geneation: I think nobody uses the random option. Everything is made per hand. (But don't ask my how, i have no idea )
Bridges: There is an option somewhere that insers a whole bridge with neccesary terrain height.
polaster64
|
#13 23.02.2018 23:48 Beiträge: 184 |
Zitat von mcb:
You have to write everything yourself. Detect when the AI is under attack, respond to it and attack itself.
I'm currently working on my own AI, but that script has some 1000 lines of code (and is not finished yet).
For map Geneation: I think nobody uses the random option. Everything is made per hand. (But don't ask my how, i have no idea )
Bridges: There is an option somewhere that insers a whole bridge with neccesary terrain height.
But like how to do it? I know completely nothing about this all scripting and I learn from other maps scripts and somehow they work and mine doesnt work and thats kinda frustrating isnt it?
I dont know anything about scripting and the "script book" is in deutsch and I cant understand any god damn thing!
PS Are you some kind of ubisoft ex employee? You know this LUA stuff perfectly and thats really interesting
mcb
|
#14 24.02.2018 01:22 Beiträge: 1472 |
I'm a bit too young to be employee of Ubisoft. At the moment i'm a student at a german university. And my knowledge about Lua is far from perfect.
First start to Lua might be: https://www.lua.org/pil/contents.html It is generally about Lua and coding (but not about S5)
But i did already knew something about Java, so learning another language is far easier than learning the first one.
So a real AI that responds to any possible situation is a lot of code, which translates in a lot of time or a lot of money, which might be the reason why almost no strategy game has a good AI.
(If you add self-learning you also need a ridiculous amount of computing power, at least another top GPU only for AI.)
So what you can do is: Think what the AI should do on this specific map, and then spawn (or recruit some armies) and write control jobs for them. I can help you by telling you how to write this control job, if you know what it should do.
Example: If the player attacks, the AI should defend itself. If the player moves something near a specific clay mine, attack it. If nothing of the above cases, just attack somewhere.
polaster64
|
#15 24.02.2018 11:28 Beiträge: 184 |
Zitat von mcb:
I'm a bit too young to be employee of Ubisoft. At the moment i'm a student at a german university. And my knowledge about Lua is far from perfect.
First start to Lua might be: https://www.lua.org/pil/contents.html It is generally about Lua and coding (but not about S5)
But i did already knew something about Java, so learning another language is far easier than learning the first one.
So a real AI that responds to any possible situation is a lot of code, which translates in a lot of time or a lot of money, which might be the reason why almost no strategy game has a good AI.
(If you add self-learning you also need a ridiculous amount of computing power, at least another top GPU only for AI.)
So what you can do is: Think what the AI should do on this specific map, and then spawn (or recruit some armies) and write control jobs for them. I can help you by telling you how to write this control job, if you know what it should do.
Example: If the player attacks, the AI should defend itself. If the player moves something near a specific clay mine, attack it. If nothing of the above cases, just attack somewhere.
Well you have given me the whole spawn army script and bless you for that 1000 times. But I dont know anything about this recruit troops thing. And how do I compare the range of the AI to the map size? Is there any addon that shows how far AI has the "look" of the map?
Play4FuN
|
#16 24.02.2018 13:04 Beiträge: 704 |
The AI does not care about the fog of war, they just "sense" where their next (closest) enemy is.
To get the map size you can use
WorldSizeX, WorldSizeY = Logic.WorldGetSize()
To get a feeling how to set the range of the AI in their setup you can use ambients in the MapEditor and adjust their radius. Always multiply the radius of the ambient with 100 for your scripting. Having an ambient of radius 60 which seems to be fair for an AI range means that you use 6000 in your script as AI range.
By the way. Use the LuaDebugger not only for your own maps, also check out other players map scripts to see how they make their troops spawn or how they control their armys. As mcb said it is mostly the best to setup a "normal" "AI" and use a control job for their armys - which is quite easy once you understand its functionality.
____________________
LG Play4FuN
Siedler DEdK Mapping + Scripting Tutorials
polaster64
|
#17 24.02.2018 14:21 Beiträge: 184 |
Zitat von Play4FuN:
The AI does not care about the fog of war, they just "sense" where their next (closest) enemy is.
To get the map size you can use
WorldSizeX, WorldSizeY = Logic.WorldGetSize()
To get a feeling how to set the range of the AI in their setup you can use ambients in the MapEditor and adjust their radius. Always multiply the radius of the ambient with 100 for your scripting. Having an ambient of radius 60 which seems to be fair for an AI range means that you use 6000 in your script as AI range.
By the way. Use the LuaDebugger not only for your own maps, also check out other players map scripts to see how they make their troops spawn or how they control their armys. As mcb said it is mostly the best to setup a "normal" "AI" and use a control job for their armys - which is quite easy once you understand its functionality.
Well if we talking about ambients, what is their goal? I didnt find out that and Im using editor like 3-4 hours a day and still didnt get it.
And about LuaDebugger. I dont really know how to use it, but I checked on someone's map the AI range and it was only 512, when I set that on my test map it didnt do anything, Im really curious what it depends on.
polaster64
|
#18 24.02.2018 15:39 Beiträge: 184 |
Is there any script that lets the player to open and close the gates? I downloaded over 50 maps and didnt find anything.
mcb
|
#19 24.02.2018 16:03 Beiträge: 1472 |
Gates: I have seen such a map, but this has some disadvantages.
1) The AI doesn't care about walls. They just stand in front of them and do nothing.
2) If a Leader has some Ordes to move through a Gate and you close it, S5 could crash.
XS_Ambient: Plays an ambient sound near a position.
LuaDebugger: Download it and start it. Then you can start S5 through its GUI. The just start your Map, Alt-Tab out and you have a 2nd window that shows all loaded scripts/lua errors and a lua console.
polaster64
|
#20 24.02.2018 16:40 Beiträge: 184 |
Zitat von mcb:
Gates: I have seen such a map, but this has some disadvantages.
1) The AI doesn't care about walls. They just stand in front of them and do nothing.
2) If a Leader has some Ordes to move through a Gate and you close it, S5 could crash.
XS_Ambient: Plays an ambient sound near a position.
LuaDebugger: Download it and start it. Then you can start S5 through its GUI. The just start your Map, Alt-Tab out and you have a 2nd window that shows all loaded scripts/lua errors and a lua console.
I already did that but I dont seem it very useful for me right now as my scripting knowledge is on the level of nothing.
And how do I create the prelude briefing situation?
You know, ask npc about something and the talk is going on and he gives us a quest or thanks us for saving him and gives us something. How to do that? I am reading the scriptology from other map and dont really get it how its done.
mcb
|
#21 24.02.2018 18:56 Beiträge: 1472 |
You can just run your map with debugger active. Then you get the exact reason and location, in case of a script error.
For briefings there are 2 "styles":
1) The old one (used in BB original Maps and their Scripting tutorial)
function CreatePreludeBriefing() -- wie das Kind heißt ist egal. Nur so weiß man welches Briefing das ist. preludeBriefing = {} -- Das ist auch egal wie es heißt. Nur so geschrieben ist es eine globale Variable, -- die immer Speicherplatzt belegt besser : local preludeBriefing = {} -- bis hier sind beide formen gleich local page = 0 -- hier wird eine locale Variable angelegt, die page heißt page = page + 1 -- bei jeder neuen Seite müssen wir die Variable um eins erhöhen. preludeBriefing[page] = {} -- hier machen wir nichts anderes wie table.insert(preludeBriefing,{}) preludeBriefing[page].title = "Dario" -- ab hier kommen einige Variable zu dem table preludeBriefing[page] preludeBriefing[page].explore = 1000 preludeBriefing[page].text = "Dann schaun wir mal" preludeBriefing[page].position = GetPosition("Dario") preludeBriefing[page].dialogCamera = true preludeBriefing[page].quest = {} --hier wird eine Variable des tables wieder ein table preludeBriefing[page].quest.id = 1 -- ab hier werden dem table preludeBriefing[page].quest neue Variable zugewiesen preludeBriefing[page].quest.type = MAINQUEST_OPEN preludeBriefing[page].quest.title = "1. Auftrag" preludeBriefing[page].quest.text = "Sucht euren Vater auf!" preludeBriefing[page].action = function() StartDelayFunc( function() IrgendEine(); end ) end; -- hier noch ne Action page = page + 1 -- Noch ne Seite. preludeBriefing[page] = {} preludeBriefing[page].title = "Ottokar" preludeBriefing[page].text = "Anna ick liebe dir" StartBriefing(preludeBriefing) -- Und jetzt ab die Post end
(Yust, so you have seen it once)
2) The new one:
function SpecialBriefing() -- this contains all data for the briefing local briefing = {}; -- AddPage / AddShortPage functions, used to fill the briefing local AP, ASP = AddPages(briefing); -- ASP( _name, _title, _text, _dialog); -- _name: Script name of the target entity. camera will centered at this entity -- _title: Page title -- _text: Page text -- _dialog: set to true to move the camera closer, else just leave it out ASP("scout","Scout","I heared you destroyed this tower?", true); ASP("erec","Erec","Yes, that was planned."); ASP("scout","Scout","Ok, then its fine!", true); -- just add as many pages as you need StartBriefing(briefing); -- starts the briefing (dont forget this) end You need this functions in your script: [code]function AddPages( _briefing ) local AP = function(_page) table.insert(_briefing, _page); return _page; end local ASP = function(_entity, _title, _text, _dialog) return AP(CreateShortPage(_entity, _title, _text, _dialog)); end return AP, ASP; end function CreateShortPage( _entity, _title, _text, _dialog) local page = { title = _title, text = _text, position = GetPosition( _entity ), dialogCamera = _dialog }; return page; end
In comparison, the new style is much shorter and has less global variables.
polaster64
|
#22 24.02.2018 19:25 Beiträge: 184 |
Zitat von mcb:
2) The new one:
function SpecialBriefing() -- this contains all data for the briefing local briefing = {}; -- AddPage / AddShortPage functions, used to fill the briefing local AP, ASP = AddPages(briefing); -- ASP( _name, _title, _text, _dialog); -- _name: Script name of the target entity. camera will centered at this entity -- _title: Page title -- _text: Page text -- _dialog: set to true to move the camera closer, else just leave it out ASP("scout","Scout","I heared you destroyed this tower?", true); ASP("erec","Erec","Yes, that was planned."); ASP("scout","Scout","Ok, then its fine!", true); -- just add as many pages as you need StartBriefing(briefing); -- starts the briefing (dont forget this) end You need this functions in your script: [code]function AddPages( _briefing ) local AP = function(_page) table.insert(_briefing, _page); return _page; end local ASP = function(_entity, _title, _text, _dialog) return AP(CreateShortPage(_entity, _title, _text, _dialog)); end return AP, ASP; end function CreateShortPage( _entity, _title, _text, _dialog) local page = { title = _title, text = _text, position = GetPosition( _entity ), dialogCamera = _dialog }; return page; end
In comparison, the new style is much shorter and has less global variables.
How do I use the second style with the npc?
And how to create this npc?
For example:
We right click on the NPC and we speak with him and he says: look here (and the script shows the location of the map and says to go there)
How to do that with 2nd method?
I cant see this in the code you've given me or I just dont get it.
mcb
|
#23 24.02.2018 19:48 Beiträge: 1472 |
Just use the briefing function as callback at the NPC:
function CreateNpcScout() local npc = { name = "scout", -- name of the npc callback = SpecialBriefing, -- what should be called, when the npc gets spoken with } CreateNPC(npc) end
polaster64
|
#24 24.02.2018 20:53 Beiträge: 184 |
Zitat von mcb:
Just use the briefing function as callback at the NPC:
function CreateNpcScout() local npc = { name = "scout", -- name of the npc callback = SpecialBriefing, -- what should be called, when the npc gets spoken with } CreateNPC(npc) end
function SpecialBriefing() -- this contains all data for the briefing local briefing = {}; -- AddPage / AddShortPage functions, used to fill the briefing local AP, ASP = AddPages(briefing); -- ASP( _name, _title, _text, _dialog); -- _name: Script name of the target entity. camera will centered at this entity -- _title: Page title -- _text: Page text -- _dialog: set to true to move the camera closer, else just leave it out ASP("scout","Scout","I heared you destroyed this tower?", true); ASP("erec","Erec","Yes, that was planned."); ASP("scout","Scout","Ok, then its fine!", true); -- just add as many pages as you need StartBriefing(briefing); -- starts the briefing (dont forget this) end You need this functions in your script: [code]function AddPages( _briefing ) local AP = function(_page) table.insert(_briefing, _page); return _page; end local ASP = function(_entity, _title, _text, _dialog) return AP(CreateShortPage(_entity, _title, _text, _dialog)); end return AP, ASP; end function CreateShortPage( _entity, _title, _text, _dialog) local page = { title = _title, text = _text, position = GetPosition( _entity ), dialogCamera = _dialog }; return page; end
can I create
function SpecialBriefing1() function SpecialBriefing2()
et cetera? Or it will only work with
function SpecialBriefing()
hmm?
Because I wanna do over a dozen or so briefings, so here is the question:
Will it work?
polaster64
|
#25 24.02.2018 22:12 Beiträge: 184 |
Zitat von polaster64:
Zitat von mcb:
Just use the briefing function as callback at the NPC:
function CreateNpcScout() local npc = { name = "scout", -- name of the npc callback = SpecialBriefing, -- what should be called, when the npc gets spoken with } CreateNPC(npc) end
function SpecialBriefing() -- this contains all data for the briefing local briefing = {}; -- AddPage / AddShortPage functions, used to fill the briefing local AP, ASP = AddPages(briefing); -- ASP( _name, _title, _text, _dialog); -- _name: Script name of the target entity. camera will centered at this entity -- _title: Page title -- _text: Page text -- _dialog: set to true to move the camera closer, else just leave it out ASP("scout","Scout","I heared you destroyed this tower?", true); ASP("erec","Erec","Yes, that was planned."); ASP("scout","Scout","Ok, then its fine!", true); -- just add as many pages as you need StartBriefing(briefing); -- starts the briefing (dont forget this) end You need this functions in your script: [code]function AddPages( _briefing ) local AP = function(_page) table.insert(_briefing, _page); return _page; end local ASP = function(_entity, _title, _text, _dialog) return AP(CreateShortPage(_entity, _title, _text, _dialog)); end return AP, ASP; end function CreateShortPage( _entity, _title, _text, _dialog) local page = { title = _title, text = _text, position = GetPosition( _entity ), dialogCamera = _dialog }; return page; end
can I create
function SpecialBriefing1() function SpecialBriefing2()
et cetera? Or it will only work with
function SpecialBriefing()
hmm?
Because I wanna do over a dozen or so briefings, so here is the question:
Will it work?
https://imgur.com/a/SyOke
Look here. Everytime I use CreateArmyOne() or CreateANYFUNCTION
there goes an error and I dont know where is the problem because down below the function is called without any mistakes so I dont really know where is the problem god damnit