AI PLAYER, TROOP SPAWN SCRIPT AND MORE
» Siedler Map Source Forum » Siedler DEdK Script Forum » AI PLAYER, TROOP SPAWN SCRIPT AND MORE
Seiten: Zurück 1 2 3 4 5 6 Nächste Seite
Play4FuN
|
#101 15.03.2018 14:26 Beiträge: 704 |
Cavalry Formation Buttons
This should work:
GameCallback_GUI_SelectionChanged_Orig = GameCallback_GUI_SelectionChanged GameCallback_GUI_SelectionChanged = function() GameCallback_GUI_SelectionChanged_Orig() -- Get selected entity local EntityId = GUI.GetSelectedEntity() if Logic.IsLeader( EntityId ) == 1 then if Logic.IsEntityInCategory(EntityId,EntityCategories.CavalryHeavy) == 1 or Logic.IsEntityInCategory(EntityId,EntityCategories.CavalryLight) == 1 then XGUIEng.ShowWidget(gvGUI_WidgetID.SelectionLeader, 1) end end end
paste into a function you call in the FMA or paste it direclty into the FMA.
By the way: use the debugger to see the scripts you can't find in the MapEditor... (Stronghold)
(Just be sure not to define multiple version of the selection changed event, you would run into a stack overflow)
Edit: Version 2 -> battle serf/leader formation fix
function OvrSelectionChanged() GameCallback_GUI_SelectionChanged_Orig = GameCallback_GUI_SelectionChanged GameCallback_GUI_SelectionChanged = function() GameCallback_GUI_SelectionChanged_Orig() -- Get selected entity local EntityId = GUI.GetSelectedEntity() if Logic.IsLeader( EntityId ) == 1 then local EntityType = Logic.GetEntityType( EntityId ) if EntityType == Entities.PU_BattleSerf then XGUIEng.ShowWidget("Commands_Leader", 0) -- bug fix: to display the buttons even when a battle serf has been selected before else XGUIEng.ShowWidget("Commands_Leader", 1) end if Logic.IsEntityInCategory(EntityId,EntityCategories.CavalryHeavy) == 1 or Logic.IsEntityInCategory(EntityId,EntityCategories.CavalryLight) == 1 then XGUIEng.ShowWidget(gvGUI_WidgetID.SelectionLeader, 1) end end end end
____________________
LG Play4FuN
Siedler DEdK Mapping + Scripting Tutorials
Dieser Beitrag wurde von Play4FuN am 17.03.2018 um 14:40 editiert.
polaster64
|
#102 15.03.2018 14:41 Beiträge: 184 |
Zitat von Play4FuN:
This should work:
GameCallback_GUI_SelectionChanged_Orig = GameCallback_GUI_SelectionChanged GameCallback_GUI_SelectionChanged = function() GameCallback_GUI_SelectionChanged_Orig() -- Get selected entity local EntityId = GUI.GetSelectedEntity() if Logic.IsLeader( EntityId ) == 1 then if Logic.IsEntityInCategory(EntityId,EntityCategories.CavalryHeavy) == 1 or Logic.IsEntityInCategory(EntityId,EntityCategories.CavalryLight) == 1 then XGUIEng.ShowWidget(gvGUI_WidgetID.SelectionLeader, 1) end end end
paste into a function you call in the FMA or paste it direclty into the FMA.
By the way: use the debugger to see the scripts you can't find in the MapEditor... (Stronghold)
(Just be sure not to define multiple version of the selection changed event, you would run into a stack overflow)
It works perfectly, thanks very much!
(I just put it in the code, didnt make any function)
Ah I forgot about the debugger, thanks for the tip.
polaster64
|
#103 15.03.2018 22:26 Beiträge: 184 |
Have a look here. I dont have any idea why the entity change their orientation. I tried to change the XD_ScriptEntity orientation but it didnt give any results. Any ideas why it might be like that?
https://imgur.com/a/8NTxR
Play4FuN
|
#104 15.03.2018 22:50 Beiträge: 704 |
Rotating the ScriptEntity can't help because it just gives the position.
You will have to set the orientation in your CreateEntity call. Usually you will set it to 0.
Problem: using CreateEntity will not allow you to set the oritentation:
function CreateEntity(_playerId,_entity,_position,_name) local entityId = Logic.CreateEntity(_entity,_position.X,_position.Y,Logic.GetRandom(360),_playerId) if _name ~= nil then Logic.SetEntityName(entityId,_name) end return entityId end
See the GetRandom(360) there? This is your "problem".
You have to use Logic.CreateEntity here, be careful with the parameters!
____________________
LG Play4FuN
Siedler DEdK Mapping + Scripting Tutorials
polaster64
|
#105 15.03.2018 22:54 Beiträge: 184 |
Zitat von Play4FuN:
Rotating the ScriptEntity can't help because it just gives the position.
You will have to set the orientation in your CreateEntity call. Usually you will set it to 0.
Problem: using CreateEntity will not allow you to set the oritentation:
function CreateEntity(_playerId,_entity,_position,_name) local entityId = Logic.CreateEntity(_entity,_position.X,_position.Y,Logic.GetRandom(360),_playerId) if _name ~= nil then Logic.SetEntityName(entityId,_name) end return entityId end
See the GetRandom(360) there? This is your "problem".
You have to use Logic.CreateEntity here, be careful with the parameters!
So I should just change the 360 to 0?
I dont really get it.. ;/
CreateEntity(1,Entities.PB_Residence3,GetPosition("house7"),GetOrientation_0)
Something like this?
edit does not work
Dieser Beitrag wurde von polaster64 am 15.03.2018 um 23:05 editiert.
Play4FuN
|
#106 16.03.2018 00:37 Beiträge: 704 |
I already said: use the Logic.CreateEntity instead of CreateEntity
____________________
LG Play4FuN
Siedler DEdK Mapping + Scripting Tutorials
polaster64
|
#107 16.03.2018 08:44 Beiträge: 184 |
Zitat von Play4FuN:
I already said: use the Logic.CreateEntity instead of CreateEntity
Okay but should I change the 360 to 0 or leave it alone, just give the position and the entity?
Play4FuN
|
#108 16.03.2018 09:24 Beiträge: 704 |
Logic.CreateEntity(_entity,_position.X,_position.Y,0,_playerId)
____________________
LG Play4FuN
Siedler DEdK Mapping + Scripting Tutorials
polaster64
|
#109 16.03.2018 09:34 Beiträge: 184 |
Zitat von Play4FuN:
Logic.CreateEntity(_entity,_position.X,_position.Y,0,_playerId)
thank you!!!
polaster64
|
#110 16.03.2018 10:53 Beiträge: 184 |
Zitat von Play4FuN:
Logic.CreateEntity(_entity,_position.X,_position.Y,0,_playerId)
Well there goes the problem. I put this in the map script and game crashes when I try to open the map.
Logic.CreateEntity(Entities.PB_Residence3,GetPosition("house7"),0,1)
Dieser Beitrag wurde von polaster64 am 16.03.2018 um 11:00 editiert.
Play4FuN
|
#111 16.03.2018 13:45 Beiträge: 704 |
I guess that you try to create the entity inside another building or a similar blocked area ... this could cause such a crash.
____________________
LG Play4FuN
Siedler DEdK Mapping + Scripting Tutorials
polaster64
|
#112 16.03.2018 14:19 Beiträge: 184 |
Zitat von Play4FuN:
I guess that you try to create the entity inside another building or a similar blocked area ... this could cause such a crash.
yes that is right
It worked with normal CreateEntity but was placed in random direction(orientation).
Dieser Beitrag wurde von polaster64 am 16.03.2018 um 14:31 editiert.
mcb
|
#113 16.03.2018 14:36 Beiträge: 1472 |
Nothing to do with blocking. You didn't split the coordinates into two parameters. This would be correct:
local p = GetPosition("house7") Logic.CreateEntity(Entities.PB_Residence3, p.X, p.Y, 0, 1)
(In your version the x-coordinate gets the random adress of the table, which is most likely to be out of the map which causes a crash. Y-coordinate would be 0, which is ok, i think. Rotation would be 1, ok. Player would be nil, which causes a crash.)
polaster64
|
#114 16.03.2018 14:56 Beiträge: 184 |
Zitat von mcb:
Nothing to do with blocking. You didn't split the coordinates into two parameters. This would be correct:
local p = GetPosition("house7") Logic.CreateEntity(Entities.PB_Residence3, p.X, p.Y, 0, 1)
(In your version the x-coordinate gets the random adress of the table, which is most likely to be out of the map which causes a crash. Y-coordinate would be 0, which is ok, i think. Rotation would be 1, ok. Player would be nil, which causes a crash.)
Works perfectly, thank you very much!
polaster64
|
#115 16.03.2018 17:00 Beiträge: 184 |
TERRAIN
Is there any method to save the terrain from the map? And I dont mean using the copy entity tool.
mcb
|
#116 16.03.2018 18:01 Beiträge: 1472 |
What do you want exactly? You could use the TerrainPatcher to change terrain and entities partway through a map. The Hook also has a function that returns the terrain type and height at a specific location. (But both are nothing for beginners)
polaster64
|
#117 16.03.2018 18:06 Beiträge: 184 |
Zitat von mcb:
What do you want exactly? You could use the TerrainPatcher to change terrain and entities partway through a map. The Hook also has a function that returns the terrain type and height at a specific location. (But both are nothing for beginners)
I want to save the map terrain tho when I lose it I can just load it from the .bin file.
And second question
What is the technology name of the thief sabotage?
ResearchTechnology(Technologies.T_Sabotage, 1)
I tried to guess and of course I got wrong.
How do I make this function to work? Its not called by any of the npcs, I want it to be normal briefing without any npc needed. It works only with StartSimpleJob but I dont want to call it over and over so what should I do? I tried everything and im really out of ideas.. LuaDebugger shows errors everytime but now when I use SimpleJob...
function BriefingPoczatek() -- 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("Dario","Dario","This trip was really long, I think we are close to the SharpPoint", true); ASP("Erek","Erek","We are closer than you think!", true); -- just add as many pages as you need local resolve4 = AP{ tilte = "Erek", text = "Have a look. These are the men we've been searching for, let's help them!", position = GetPosition("Guard"), dialogCamera = false, explore = 1500, } ResolveBriefing(resolve4) StartBriefing(briefing); -- starts the briefing (dont forget this) end
Dieser Beitrag wurde von polaster64 am 16.03.2018 um 20:06 editiert.
mcb
|
#118 16.03.2018 20:50 Beiträge: 1472 |
Ok, so some mapeditor stuff. No idea for that
2:
Technologies.T_ThiefSabotage
Briefing:
That code seems to be correct (except from the ResolveBriefing, which at that point simply is an expensive nop)
What exactly is the error message from the debugger? And please include the code that causes the error.
Did i already link you this here? https://www.lua.org/pil/contents.html It's an english Lua tutorial. It does not cover settlers Lua extensions, but that are mostly libaries and some bugs.
polaster64
|
#119 16.03.2018 22:32 Beiträge: 184 |
Zitat von mcb:
Ok, so some mapeditor stuff. No idea for that
2:
Technologies.T_ThiefSabotage
Briefing:
That code seems to be correct (except from the ResolveBriefing, which at that point simply is an expensive nop)
What exactly is the error message from the debugger? And please include the code that causes the error.
Did i already link you this here? https://www.lua.org/pil/contents.html It's an english Lua tutorial. It does not cover settlers Lua extensions, but that are mostly libaries and some bugs.
Well there is no error message if there is only this:
function BriefingPoczatek() -- 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("Dario","Dario","This trip was really long, I think we are close to the SharpPoint", true); ASP("Erek","Erek","We are closer than you think!", true); -- just add as many pages as you need local resolve4 = AP{ tilte = "Erek", text = "Have a look. These are the men we've been searching for, let's help them!", position = GetPosition("Guard"), dialogCamera = false, explore = 1500, } ResolveBriefing(resolve4) StartBriefing(briefing); -- starts the briefing (dont forget this) end
That part with the map I mean I wanted to somehow copy the entities and all the terrain made.
The error comes out when I add
CreateBriefingPoczatek()
or when I add
BriefingPoczatek()
The briefing starts only when I add
StartSimpleJob("BriefingPoczatek")
but then the briefing goes into the endless loop and thats not what I want.
I wanted to use this new method because its simplier to understand but somehow it does not work and i have no idea why. I tried everything. OR at least I think I tried everything and I possibly forgot the simplest thing but I dont know what is it...
And also I have a question about this:
local p = GetPosition("house7") Logic.CreateEntity(Entities.PB_Residence3, p.X, p.Y, 0, 8)
What should I do if I want to destroy it and spawn the same entity but with the changed player id.
A function like that exists?
function destroyabc() Destroy local p = GetPosition("house7") Logic.CreateEntity(Entities.PB_Residence3, p.X, p.Y, 0, 8) if IsDestroyed(Logic.CreateEntity(Entities.PB_Residence3, p.X, p.Y, 0, 8)then local p = GetPosition("house7") Logic.CreateEntity(Entities.PB_Residence3, p.X, p.Y, 0, 1) end
--Is this possible? Its just an example, it wont work im sure 100%.
local p = GetPosition("house7") Logic.CreateEntity(Entities.PB_Residence3, p.X, p.Y, 0, 1)
Dieser Beitrag wurde von polaster64 am 17.03.2018 um 00:19 editiert.
mcb
|
#120 17.03.2018 00:50 Beiträge: 1472 |
What exactly is the error message? (The line below the yellow - Lua Error - Message)
CreateEntity: Easiest way would be setting a scriptname:
local p = GetPosition("house7") local id = Logic.CreateEntity(Entities.PB_Residence3, p.X, p.Y, 0, 8) SetEntityName(id, "createdHouse7") -- sets the entity scriptname, so you can use it like an entity created with the mapeditor with scriptname
So changing the player would be
ChangePlayer("createdHouse7", 1)
polaster64
|
#121 17.03.2018 11:19 Beiträge: 184 |
Zitat von mcb:
What exactly is the error message? (The line below the yellow - Lua Error - Message)
CreateEntity: Easiest way would be setting a scriptname:
local p = GetPosition("house7") local id = Logic.CreateEntity(Entities.PB_Residence3, p.X, p.Y, 0, 8) SetEntityName(id, "createdHouse7") -- sets the entity scriptname, so you can use it like an entity created with the mapeditor with scriptname
So changing the player would be
ChangePlayer("createdHouse7", 1)
Well if I put
CreateBriefingPoczatek()
or
BriefingPoczatek()
or
StartBriefingPoczatek
or
Start("BriefingPoczatek")
then this is the error message
[string "Map Script"]:110: attempt to call global `StartBriefingPoczatek' (a nil value)
It says that code is outside function.
The briefing only works with the StartSimpleJob as I said before..
With the prelude briefing it works perfect but its "hard to set" style.. Any ideas?
How can I kill npc after briefing? Ex: "Go across that bridge, I wont make it any further"the dialogue) and then npc dies as he said he wont make it any further(you know what i mean xd)
Dieser Beitrag wurde von polaster64 am 17.03.2018 um 12:00 editiert.
mcb
|
#122 17.03.2018 14:39 Beiträge: 1472 |
Seems you got something wrong with the function scope. Can you post the complete Script? (That version with BriefingPoczatek() , that should be correct)
Killing an NPC:
SetHealth("someone", 0)
Should do the job. But some CU entitytypes doesn't have a die animation, so settler crashes if you kill them.
Play4FuN
|
#123 17.03.2018 14:39 Beiträge: 704 |
Kill a settler
use
DestroyEntity(entityID)
to simply remove it OR use
SetHealth(entityID, 0)
to kill it with the death animation
____________________
LG Play4FuN
Siedler DEdK Mapping + Scripting Tutorials
polaster64
|
#124 17.03.2018 15:24 Beiträge: 184 |
function BriefingPoczatek() -- 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("Dario","Dario","This trip was really long, I think we are close to the SharpPoint", true); ASP("Erek","Erek","We are closer than you think!", true); -- just add as many pages as you need local resolve4 = AP{ tilte = "Erek", text = "Have a look. These are the men we've been searching for, let's help them!", position = GetPosition("Guard"), dialogCamera = false, explore = 1500, } ResolveBriefing(resolve4) StartBriefing(briefing); -- starts the briefing (dont forget this) end
that is the code of this briefing.
local p = GetPosition("house7") Logic.CreateEntity(Entities.PB_Residence3, p.X, p.Y, 0, 8) SetEntityName(id, "createdHouse7") local p = GetPosition("house6") Logic.CreateEntity(Entities.PB_Residence3, p.X, p.Y, 0, 8) SetEntityName(id, "createdHouse6") local p = GetPosition("house5") Logic.CreateEntity(Entities.PB_Residence3, p.X, p.Y, 0, 8) SetEntityName(id, "createdHouse5") local p = GetPosition("house4") Logic.CreateEntity(Entities.PB_Residence3, p.X, p.Y, 0, 8) SetEntityName(id, "createdHouse4") local p = GetPosition("house3") Logic.CreateEntity(Entities.PB_Residence3, p.X, p.Y, 0, 8) SetEntityName(id, "createdHouse3") local p = GetPosition("house2") Logic.CreateEntity(Entities.PB_Residence3, p.X, p.Y, 0, 8) SetEntityName(id, "createdHouse2") local p = GetPosition("house1") Logic.CreateEntity(Entities.PB_Residence3, p.X, p.Y, 0, 8) SetEntityName(id, "createdHouse1") local p = GetPosition("kkk3") Logic.CreateEntity(Entities.PB_DarkTower3, p.X, p.Y, 0, 8) SetEntityName(id, "createdkkk3") local p = GetPosition("kkk4") Logic.CreateEntity(Entities.PB_DarkTower3, p.X, p.Y, 0, 8) SetEntityName(id, "createdkkk4") local p = GetPosition("kkk1") Logic.CreateEntity(Entities.CB_Bastille1, p.X, p.Y, 0, 8) SetEntityName(id, "createdkkk1") local p = GetPosition("kkk2") Logic.CreateEntity(Entities.CB_Bastille1, p.X, p.Y, 0, 8) SetEntityName(id, "createdkkk2")
Second problem is this. I set this and everything works but when I come to the other part of the script:
function UsunSkaly1() if IsDestroyed("Skaly") then BriefingBratJan2() ChangePlayer("b1", 1) ChangePlayer("b2", 1) ChangePlayer("b3", 1) ChangePlayer("b4", 1) ChangePlayer("b5", 1) ChangePlayer("b6", 1) ChangePlayer("b7", 1) ChangePlayer("b8", 1) ChangePlayer("b9", 1) ChangePlayer("b10", 1) ChangePlayer("b11", 1) ChangePlayer("b12", 1) ChangePlayer("b13", 1) ChangePlayer("b14", 1) ChangePlayer("b15", 1) ChangePlayer("b16", 1) ChangePlayer("b17", 1) ChangePlayer("b18", 1) ChangePlayer("b19", 1) ChangePlayer("b20", 1) ChangePlayer("b21", 1) ChangePlayer("b22", 1) ChangePlayer("b23", 1) ChangePlayer("b24", 1) ChangePlayer("b25", 1) ChangePlayer("b26", 1) ChangePlayer("b27", 1) ChangePlayer("b28", 1) ChangePlayer("b29", 1) ChangePlayer("b30", 1) ChangePlayer("b31", 1) ChangePlayer("b32", 1) ChangePlayer("b33", 1) ChangePlayer("b34", 1) ChangePlayer("b35", 1) ChangePlayer("b36", 1) ChangePlayer("b37", 1) ChangePlayer("b38", 1) ChangePlayer("b39", 1) ChangePlayer("b45", 1) ChangePlayer("b46", 1) ChangePlayer("b47", 1) ChangePlayer("b48", 1) ChangePlayer("b49", 1) ChangePlayer("b50", 1) ChangePlayer("b51", 1) ChangePlayer("b52", 1) ChangePlayer("b53", 1) ChangePlayer("b54", 1) ChangePlayer("hq1", 1)-- this part ChangePlayer("createdhouse1",1) ChangePlayer("createdhouse2",1) ChangePlayer("createdhouse3",1) ChangePlayer("createdhouse4",1) ChangePlayer("createdhouse5",1) ChangePlayer("createdhouse6",1) ChangePlayer("createdhouse7",1) ChangePlayer("createdkkk1",1) ChangePlayer("createdkkk2",1) ChangePlayer("createdkkk3",1) ChangePlayer("createdkkk4",1)-- to this. -- the entities do not change ID of the player and they still belong to the player 8 which is not what I wanted. AddGold(500) AddClay(200) AddWood(300) AddStone(400) AddIron(100) AddSulfur(300) return true end end
Should I call the
function destroyplayer8buildings() if IsDestroyed("createdhouse7") and ("createdhouse6") and et cetera then local p = GetPosition("house7") Logic.CreateEntity(Entities.PB_Residence3, p.X, p.Y, 0, 1) local p = GetPosition("house6") Logic.CreateEntity(Entities.PB_Residence3, p.X, p.Y, 0, 1) local p = GetPosition("house5") Logic.CreateEntity(Entities.PB_Residence3, p.X, p.Y, 0, 1) local p = GetPosition("house4") Logic.CreateEntity(Entities.PB_Residence3, p.X, p.Y, 0, 1) local p = GetPosition("house3") Logic.CreateEntity(Entities.PB_Residence3, p.X, p.Y, 0, 1) local p = GetPosition("house2") Logic.CreateEntity(Entities.PB_Residence3, p.X, p.Y, 0, 1) local p = GetPosition("house1") Logic.CreateEntity(Entities.PB_Residence3, p.X, p.Y, 0, 1) local p = GetPosition("kkk3") Logic.CreateEntity(Entities.PB_DarkTower3, p.X, p.Y, 0, 1) local p = GetPosition("kkk4") Logic.CreateEntity(Entities.PB_DarkTower3, p.X, p.Y, 0, 1) local p = GetPosition("kkk1") Logic.CreateEntity(Entities.CB_Bastille1, p.X, p.Y, 0, 1) local p = GetPosition("kkk2") Logic.CreateEntity(Entities.CB_Bastille1, p.X, p.Y, 0, 1)
By the way if I change the player of the hq1
Logic.SetModelAndAnimSet(GetID("hq1"), Models.CB_DarkCastle)
the model changes itself to its original form-PB_Headquarters3.
Should I also destroy this entity and then use
local p = GetPosition("hq1") Logic.CreateEntity(Entities.PB_Headquarters3, p.X, p.Y, 0, 1) Logic.SetModelAndAnimSet(GetID("hq1"), Models.CB_DarkCastle)
Would that be a correct move?
mcb
|
#125 17.03.2018 17:51 Beiträge: 1472 |
I wanted you to post the complete script, because most likely you made an error somewhere else in the script.
CreateEntity: You forgot saving the id:
local p = GetPosition("house7") local id = Logic.CreateEntity(Entities.PB_Residence3, p.X, p.Y, 0, 8) SetEntityName(id, "createdHouse7")
hq1: It changes its model back, because it gets replaced by an entity of the same type but another player. Simply calling
Logic.SetModelAndAnimSet(GetID("hq1"), Models.CB_DarkCastle)
again after changing the player should fix this. (The scriptName gets added to the new entity automatically by ChangePlayer and ReplaceEntity)