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

mcb
#51
26.02.2018 20:19
Beiträge: 1472

You have to write your own callback:

CreateChest(GetPosition("chest"), function()
   AddGold(4213)
   Message("You found a chest with 4213 Gold")
end)

polaster64
#52
26.02.2018 20:45
Beiträge: 184

Zitat von mcb:
IsNear: I think your problem are the comments. -- marks the rest of the line as comment.

function foo()
   if bar(1, -- something 2) then
      somethingOther()
   end
end


causes some syntax errors.
This would be better:

function foo()
   if bar(1, 2) then -- something
      somethingOther()
   end
end



Chests:

CreateChestOpener("dario") --first define who can open the chests
CreateChestOpener("erec") -- call it again with all other heroes you need
CreateRandomGoldChest(GetPosition("randomGoldChest")) -- creates a chest with random amount of gold
CreateGoldChest(GetPosition("goldChest")) -- creates a chest with 2000 gold
CreateIronChest(GetPosition("ironChest")) -- creates a chest with 2000 iron
CreateChest(GetPosition("randomChest")) -- creates a chest with 1000 of one random resource or nothing
StartChestQuest() -- start the job that opens the chests, when one defined entity is near a chest


Well the error apperas when I try to create a resource chest, but when I try to create gold chest then there is nothing wrong about it.

2.And if may I ask, how to create a quest in briefing? I mean they talk and the npc says "kill that barbarian" and I want the quest to popup in the quest menu. Is that possible?
Edit:
nevermind, I wrote it after I saw your chest post. Please focus on the second part of the question.

mcb
#53
26.02.2018 21:01
Beiträge: 1472

Create the quest:

questPageExample = AP{
   title = "Scout",
   text = "We need to destroy this tower!",
   position = GetPosition("scout"),
   quest = { -- here the quest
      title = "The Tower", -- quest title
      text = "Destroy the enemy tower.", -- quest text
      type  = MAINQUEST_OPEN, -- or SUBQUEST_OPEN
      id = 1, -- each quest needs its unique id, don't reuse one
   },
}



And when the quest is finished:

 ResolveBriefing(questPageExample) 

polaster64
#54
26.02.2018 21:11
Beiträge: 184

function trapheroes()
if IsDestroyed("Skaly") then
StartSimpleJob("briefingtrap")
CreateArmyTwo()
CreateArmyThree()
return true
end
end
function briefingtrap()

    local briefing = {};
    -- AddPage / AddShortPage functions, used to fill the briefing
    local AP, ASP = AddPages(briefing);
    
    local resolve16 = AP{
       title = "Ari",
       text = "Watch out, its a trap!",
       position = GetPosition("trapheroes2"),
       explore = 2000,
    }


    -- now remove the exploration
    briefing.finished = function()

       ResolveBriefing(resolve16) 
end

    

        
    StartBriefing(briefing); -

end


I dont have any idea why this and only this briefing is getting into the loop, while other dont. And they are also started as SimpleJobs.

mcb
#55
26.02.2018 21:27
Beiträge: 1472

Because you call it as a SimpleJob (means every second).
Just call it normal: briefingtrap()

polaster64
#56
26.02.2018 21:35
Beiträge: 184

Zitat von mcb:
Because you call it as a SimpleJob (means every second).
Just call it normal: briefingtrap()


Well thats strange because other briefings called as SimpleJob dont behave like that.


And I have another question
How to call the lose after all heroes die?

I mean I know

lose()
function lose()
 if isDead("hero1","hero2","hero3" et cetera) then
end
end


and
how to call the lose? Or create the lose condition.

mcb
#57
26.02.2018 21:47
Beiträge: 1472

Defeat()

polaster64
#58
26.02.2018 22:45
Beiträge: 184

Zitat von mcb:
Defeat()


Defeat1()
function Defeat1()
if IsDead("Dario","Ari","Erek","Pielgrzym")then
Defeat(1)--1 means the defeat of the player
return true
end
end


I dont know really how should I build this function, this was my only idea.And the result is predictible - does not work.

polaster64
#59
26.02.2018 23:45
Beiträge: 184

Treasure()
function Treasure()
if IsNear("Dario", "treasure", 3000) then
TreasureBriefing()
    return true
  end
end


It never detects Dario or any other hero, even if I point them to go on exact point, what might be the problem?

polaster64
#60
26.02.2018 23:48
Beiträge: 184

function ArmiaPierwszaDead()
if IsDead("armyOne") then
StartSimpleJob("ArmiaPierwszaSkarbyBriefing")
return true
end
end




function ArmiaPierwszaSkarbyBriefing()
-- this contains all data for the briefing
    local briefing = {};
    -- AddPage / AddShortPage functions, used to fill the briefing
    local AP, ASP = AddPages(briefing);
    ASP("Dario","Dario","Okay, I think we killed them all, lets search the area now.", true);

    local resolve4 = AP{
       title = "Dario",
       text = "The bandits propably hid some treasures in the woods, go search for them!",
       position = GetPosition("woods"),
       explore = 2000,
    }


    -- now remove the exploration
    briefing.finished = function()

       ResolveBriefing(resolve4) -- we remove the exploration
end


That also does not work. What is the problem?

mcb
#61
27.02.2018 13:41
Beiträge: 1472

First i should write about the difference between calling a function and registering a job:

foo() -- this calls the function foo, it gets executed immediately (and only this time)
StartSimpleJob("foo") -- this registers the function foo as a job, it don't get immediately executed, instead it gets executed (called) every second until you end the job


So it is importand which one you use, use jobs only if you want to check something every second. (Example: conditions for losing the game, conditions for fullfilling the next quest, controlling armies)

Defeat:
1) Use a Job
2) IsDead uses only one parameter, everything else gets ignored. You have use logical operators to get your result:

 if IsDead("dario") and IsDead("ari") and IsDead("erec") then 


3) Defeat() has no parameter, if you call it the player gets defeated.

Treasure:
1) Use a Job
2) Check if both entities are existing. If one does not exist, the other one can't be near it.

Army:
1) Use a function call to start the briefing.
2) You missed the end of briefing.finished.
3) IsDead can be used to check entities and armies. Use IsDead("entityName" ) for entities and IsDead(armyName) for armies.

polaster64
#62
27.02.2018 21:59
Beiträge: 184

Zitat von mcb:
First i should write about the difference between calling a function and registering a job:

foo() -- this calls the function foo, it gets executed immediately (and only this time)
StartSimpleJob("foo") -- this registers the function foo as a job, it don't get immediately executed, instead it gets executed (called) every second until you end the job


So it is importand which one you use, use jobs only if you want to check something every second. (Example: conditions for losing the game, conditions for fullfilling the next quest, controlling armies)

Defeat:
1) Use a Job
2) IsDead uses only one parameter, everything else gets ignored. You have use logical operators to get your result:

 if IsDead("dario") and IsDead("ari") and IsDead("erec") then 


3) Defeat() has no parameter, if you call it the player gets defeated.

Treasure:
1) Use a Job
2) Check if both entities are existing. If one does not exist, the other one can't be near it.

Army:
1) Use a function call to start the briefing.
2) You missed the end of briefing.finished.
3) IsDead can be used to check entities and armies. Use IsDead("entityName" ) for entities and IsDead(armyName) for armies.


What do you mean with missing the briefing.finished?

Play4FuN
#63
27.02.2018 22:05
Beiträge: 704

There is an "end" missing, you start the briefing.finished function but don't put an end behind it

____________________
LG Play4FuN

Siedler DEdK Mapping + Scripting Tutorials

polaster64
#64
27.02.2018 22:22
Beiträge: 184

Zitat von Play4FuN:
There is an "end" missing, you start the briefing.finished function but don't put an end behind it



function ArmiaPierwszaSkarbyBriefing()
-- this contains all data for the briefing
    local briefing = {};
    -- AddPage / AddShortPage functions, used to fill the briefing
    local AP, ASP = AddPages(briefing);
    ASP("Dario","Dario","Okay, I think we killed them all, lets search the area now.", true);

    local resolve4 = AP{
       title = "Dario",
       text = "The bandits propably hid some treasures in the woods, go search for them!",
       position = GetPosition("woods"),
       explore = 2000,
    }


    -- now remove the exploration
    briefing.finished = function()

       ResolveBriefing(resolve4) -- we remove the exploration
end

    

        
    StartBriefing(briefing); -- starts the briefing (dont forget this)

end



Well I did.

function ArmiaPierwszaDead()
if IsDead("armyOne") and (ArmyOne) then
StartSimpleJob(ArmiaPierwszaSkarbyBriefing)
StartSimpleJob(Treasure)
return true
end
end
function Treasure()
if IsNear("Dario", "treasure", 3000) then

TreasureBriefing()
    return true
  end
end
function TreasureBriefing()
local briefing = {};
    -- AddPage / AddShortPage functions, used to fill the briefing
    local AP, ASP = AddPages(briefing);
    

    local resolve10 = AP{
       title = "Dario",
       text = "Look, thats what I have been talking about!",
       position = GetPosition("zloto"),
       explore = 2000,
    }
    ASP("Ari","Ari","Okay, I think I can open those chests, but we need to remove these rocks.", true);
    ASP("Pilgrim","Pielgrzym","No problem", true);
    -- now remove the exploration
    briefing.finished = function()

       ResolveBriefing(resolve10) -- we remove the exploration
end
      StartBriefing(briefing); -- starts the briefing (dont forget this)


end

function ArmiaPierwszaSkarbyBriefing()
-- this contains all data for the briefing
    local briefing = {};
    -- AddPage / AddShortPage functions, used to fill the briefing
    local AP, ASP = AddPages(briefing);
    ASP("Dario","Dario","Okay, I think we killed them all, lets search the area now.", true);

    local resolve4 = AP{
       title = "Dario",
       text = "The bandits propably hid some treasures in the woods, go search for them!",
       position = GetPosition("woods"),
       explore = 2000,
    }


    -- now remove the exploration
    briefing.finished = function()

       ResolveBriefing(resolve4) -- we remove the exploration
end

    

        
    StartBriefing(briefing); -- starts the briefing (dont forget this)

end


This is the part of the code that does not work. I dont have any other idea for it,

mcb
#65
28.02.2018 13:38
Beiträge: 1472

I see 2 problems here (at ArmiaPierwszaDead):
1)

if IsDead("armyOne") and (ArmyOne) then


What do you want to do here? At the moment you check, if the entity "armyOne" is dead and the global variable ArmyOne is set.
The check, if the army stored in armyOne is dead would look so:

if IsDead(ArmyOne) then



2)

StartSimpleJob(ArmiaPierwszaSkarbyBriefing)
StartSimpleJob(Treasure)


As i already said, starting a briefing is not areason for a SimpleJob, because after you want to start it, it gets startet every second again. Also to start a SimpleJob you have give the parameter as string:

StartSimpleJob("Treasure")



Also, is ArmiaPierwszaDead started as SimpleJob?

polaster64
#66
28.02.2018 15:34
Beiträge: 184

Zitat von mcb:
I see 2 problems here (at ArmiaPierwszaDead):
1)

if IsDead("armyOne") and (ArmyOne) then


What do you want to do here? At the moment you check, if the entity "armyOne" is dead and the global variable ArmyOne is set.
The check, if the army stored in armyOne is dead would look so:

if IsDead(ArmyOne) then



2)

StartSimpleJob(ArmiaPierwszaSkarbyBriefing)
StartSimpleJob(Treasure)


As i already said, starting a briefing is not areason for a SimpleJob, because after you want to start it, it gets startet every second again. Also to start a SimpleJob you have give the parameter as string:

StartSimpleJob("Treasure")



Also, is ArmiaPierwszaDead started as SimpleJob?


Yes, it is.

polaster64
#67
10.03.2018 21:20
Beiträge: 184

I didnt turn on my pc for a week because I was out of town and I come back and I cant open my map file. Is there any way to get the script back? I dont want to do it again..

Play4FuN
#68
10.03.2018 22:19
Beiträge: 704

First, what exactly prevents you from opening the map? Is there any error message?
Maybe you use the wrong editor? (wrong addon)


Second, please save your scripts external, at least not only inside your map file! Make a seperate scripts folder for your map scripts.

____________________
LG Play4FuN

Siedler DEdK Mapping + Scripting Tutorials

polaster64
#69
10.03.2018 23:10
Beiträge: 184

Zitat von Play4FuN:
First, what exactly prevents you from opening the map? Is there any error message?
Maybe you use the wrong editor? (wrong addon)


Second, please save your scripts external, at least not only inside your map file! Make a seperate scripts folder for your map scripts.


the error message is "couldnt load map file"

mcb
#70
10.03.2018 23:52
Beiträge: 1472

Can you start the map? You could also try to open it with the bba-tool.

polaster64
#71
11.03.2018 10:47
Beiträge: 184

Zitat von mcb:
Can you start the map? You could also try to open it with the bba-tool.


I cant start it. It dissapeared from the maps I had put in the user folder. I mean it is in there but the game does not see it.

polaster64
#72
11.03.2018 10:49
Beiträge: 184

Zitat von polaster64:

Zitat von mcb:
Can you start the map? You could also try to open it with the bba-tool.


I cant start it. It dissapeared from the maps I had put in the user folder. I mean it is in there but the game does not see it.


Opened it with bba tool and guess what.
"Error. Not a SettlersHoK archive.

mcb
#73
11.03.2018 14:44
Beiträge: 1472

Seems your file is broken. (What is the filesize? Just out of curiosity.) There is an autosave file (Documents/The Settlers HOK/MapEditor/Autosave) maybe you can use it.

Play4FuN
#74
11.03.2018 14:57
Beiträge: 704

Maybe I got it: it happend to me a whiel ago. I could not open a map file but play the map...

It happend as I had the game AND MapEditor open and unluckily tried to save the map file which did not work because the game was running... I closed the game and saved my map file and the next time I tried to open it I had the same error. I had to use the autosave file as mcb said. So be carefull not to save while having the game open!

____________________
LG Play4FuN

Siedler DEdK Mapping + Scripting Tutorials

polaster64
#75
11.03.2018 17:55
Beiträge: 184

Zitat von mcb:
Seems your file is broken. (What is the filesize? Just out of curiosity.) There is an autosave file (Documents/The Settlers HOK/MapEditor/Autosave) maybe you can use it.


File size is normal. 3.379 KB. The autosave file doesnt work as yesterday I tried to open this map in different ways.

Seiten: Zurück 1 2 3 4 5 6 Nächste Seite

SiteEngine v1.5.0 by nevermind, ©2005-2007
Design by SpiderFive (www.siedler-games.de) - English translation by juja

Impressum