Skip to content

Posts from Scripts

4.8 (8 ratings)
In reply to }{0TT@6bI4
User Avatar
5 years ago
Auto-translated
Hello. Mapmakers, can you tell me how to create a quest with questions, similar to a "yes" or "no" format, but where the question is only displayed if the hero's army has a specific number of creatures?
User Avatar
5 years ago
Auto-translated
Hmm...
(Attempting to fix the topic)
User Avatar
5 years ago
Auto-translated
Hello.
Obviously: if there are creatures, display a QuestionBox; if not, display a MessageBox.
In reply to }{0TT@6bI4
User Avatar
5 years ago
Auto-translated
Hello, dear mapmakers. Can you tell me which command can be used to remove some objects from the map and place new ones?
User Avatar
5 years ago
Auto-translated
Hello! RemoveObject (for static objects) / RazeBuilding (for buildings) Conversely: CreateStatic / CreateArtifact / ...
User Avatar
5 years ago
Auto-translated
Hello, working class. The problem is this: I need to track the activation of a quest – the conditions are the story coefficient and whether the player has captured a city. Here's the code. I start the thread at the beginning of the script, but the game gives an error in the console when loading. What's wrong? Other threads run normally, but this one...
Value was NIL when getting global with name 'ActFinalSQ'
ERROR: StartThread first parameter must be a function
startThread(ActFinalSQ)

function ActFinalSQ()
if A == 2 and SetObjectOwner('humanTown2', 1) then
MessageBox("/Maps/SingleMissions/ChoiseOTW1/ActFSQ0.txt")
SetObjectPosition('AratF', 67, 67, 0)
SetObjectPosition('AstridaF', 69, 70, 0)
SetObjectPosition('LoggensF', 65, 70, 0)
sleep(2)
MoveCamera(67, 67, 0, 2, 1, 285, 1, 0)
sleep(10)
MessageBox("/Maps/SingleMissions/ChoiseOTW1/ActFSQ1.txt")
GetObjectiveState('FSQ', 1, OBJECTIVE_ACTIVE)
end
end


Added 39 minutes ago
And here's my second question. I don't understand how QuestionBox works. I'll present the code below. What I want is for dialogs to appear when interacting with an object, and these dialogs change depending on the in-game coefficient. At one point, a question box should be presented to the player, but at the same time, the function that is assigned to the question box when "OK" is pressed is executed, then the function for "CANCEL", and then, in addition, the action that is performed for a different coefficient. I'm already getting a headache because everything seems to work – the functions are executed, but not as they should! Please help me solve these problems – what needs to be changed?
function Ensleg() --dialog function
if B == 1 then -- first official meeting, dialog
MessageBox("/Maps/SingleMissions/ChoiseOTW1/ED1.txt")
sleep(2)
MessageBox("/Maps/SingleMissions/ChoiseOTW1/ED2.txt")
sleep(2)
MessageBox("/Maps/SingleMissions/ChoiseOTW1/ED3.txt")
sleep(2)
B = 5
if B == 5 then --asks about teleporting to the crypt
QuestionBox("/Maps/SingleMissions/ChoiseOTW1/EQ.txt", AEY(), AEN())
if B == 0 then -- meeting when the quest is not active.
MessageBox("/Maps/SingleMissions/ChoiseOTW1/ED0.txt")
if B == 2 then -- meeting after the fight in the crypt
SQFinal()
if B == 3 then -- meeting after completing the quest
MessageBox("/Maps/SingleMissions/ChoiseOTW1/EE.txt")
if B == 4 then -- if the player started a dialog near the crypt, it asks about returning.
QuestionBox("/Maps/SingleMissions/ChoiseOTW1/EQ2.txt", AEY2(), AEN())
end
end
end
end
end
end

Trigger(OBJECT_TOUCH_TRIGGER, "ensleg", "Ensleg");

function AEY() -- answer YES - teleport to the crypt
MessageBox("/Maps/SingleMissions/ChoiseOTW1/EN1.txt")
sleep(1)
MessageBox("/Maps/SingleMissions/ChoiseOTW1/EN2.txt")
sleep(1)
MessageBox("/Maps/SingleMissions/ChoiseOTW1/EN21.txt")
sleep(1)
MessageBox("/Maps/SingleMissions/ChoiseOTW1/EN3.txt")
sleep(2)
ETP()
end

function AEY2() --teleport home
SetObjectPosition('Ohtarig', 100, 84, 0, 2)
SetObjectPosition('ensleg', 102, 89, 0)
B = 5
end

function ETP() --refusal to teleport
SetObjectPosition('Ohtarig', 80, 169, 0, 2)
SetObjectPosition('ensleg', 80, 167, 0)
B = 4
end


Added 2 minutes ago
There's an incorrect comment at the very bottom – ETP – teleport to the crypt.
User Avatar
5 years ago
Auto-translated
When specifying a callback function in QuestionBox, it should be a string. "AYE", "AEN"
In reply to }{0TT@6bI4
User Avatar
5 years ago
Auto-translated
Indeed – removing the parentheses fixed the issue, and everything now works as expected. However, I have another question regarding the same code snippet. Now, the object doesn't respond to subsequent interactions, only the first one. I haven't reset the trigger anywhere. What did I do wrong?

Added 18 minutes later
Oh, I solved the problem by replacing "if" with "elseif." When I was looking for a solution to the first error, I fixed it, but I forgot to revert the change! Now, the question is still related to the topic – there are no more errors, everything loads, but when the conditions are met, nothing happens...
User Avatar
5 years ago
Auto-translated
Hello, my sleepy friends! I have a new question, and I have no idea how to implement it! The task: before certain battles, save the hero's current army, and at the end, after the battle, restore it. How can I track this process? And, importantly, don't add units; simply, if I had 100 Synods and 15 Hydras, after the battle, I should still have 100 Synods and 15 Hydras. Figuratively speaking.
In reply to OrnsteinDragonslayer
User Avatar
5 years ago
Auto-translated
Hello! I've encountered what seems like a simple problem. I can't get the quest stage check to work. Can you tell me what I'm doing wrong?
progress = GetObjectiveProgress("obj_alh", 1);

function func_alh_complite ()
  if (progress == 1)
   then MessageBox ("/Maps/SingleMissions/Vayshan0_1/mess_alh_complite.txt");
   SetObjectiveProgress("obj_alh", OBJECTIVE_COMPLETED);
   Trigger(REGION_ENTER_AND_STOP_TRIGGER, "reg_alh_complite", nil);
  end;
end;
Trigger(REGION_ENTER_AND_STOP_TRIGGER, "reg_alh_complite", "func_alh_complite");
User Avatar
5 years ago
Auto-translated
The SetObjectiveProgress function is used to determine the progress of a quest, not its state. You need to use the SetObjectiveState/GetObjectiveState function.
In reply to }{0TT@6bI4
User Avatar
5 years ago
Auto-translated
Oh, I saw everything, but I didn't even notice that it said "Progress" there, thanks.

Added 10 hours and 52 minutes ago
I'm trying to implement a check to see if a hero has a creature. The logs say that GetHeroCreature is an undefined script, so it's being replaced with nil. I haven't seen this script in any of the maps, so it seems like the official guide has an incorrect script for checking for creatures. This raises a legitimate question: what script should I use for the check?
zog = GetHeroCreature("Ohtarig", 129)

function func_log ()
if (zog == 1)
then MessageBox("/Maps/SingleMissions/Vayshan0_1/mess_log1.txt");
SetObjectiveState("obj_log", OBJECTIVE_ACTIVE);
Trigger(REGION_ENTER_AND_STOP_TRIGGER, "reg_log", "func_log");
else MessageBox("/Maps/SingleMissions/Vayshan0_1/mess_log.txt");
sleep(1);
StartCombat("Ohtarig", nil, 1, 129, 1, nil,"func_remove_log",nil, not nil);
Trigger(REGION_ENTER_AND_STOP_TRIGGER, "reg_log", nil);
end;
end;
Trigger(REGION_ENTER_AND_STOP_TRIGGER, "reg_log", "func_log");
User Avatar
5 years ago
GetHeroCreatures
In reply to }{0TT@6bI4
5 years ago
Auto-translated
Esteemed comrades,

I would like to ask you to share your thoughts.
function BindTriggerToObject(object, handler)
Trigger(OBJECT_TOUCH_TRIGGER, object, handler)
end

RPGEngine.Init = function()
for i, player in players do
for j, object in player.RPG.BUILDINGS do
local handler = 'EnterBuilding('..player.key..", "..'"'..object.key..'")'
BindTriggerToObject(object.name, handler)
end
end
end

 

player is a table that needs to be passed as a parameter to the handler. The handler for the object_touch trigger is currently passed as a string (as in the example).

That is, for certain global tables, a field is added with a string containing the exact name of the table, and it is then substituted into the handler (i.e., for the table player1 = {key='player1'}).

However, there are quite a few smaller tables, and writing a key for each one is quite tedious. Wrapping the handler in an anonymous function is pointless - closures are not supported here, and a local function does not have access to the external environment.

If anyone understands this, please let me know.

User Avatar
5 years ago
Auto-translated
Oooooh, object-oriented Lua?!
Regarding tables, I only used them once, I think, but it was a trivial case, and I didn't invent anything particularly clever to simplify things.
the023, please tell us what this RPGEngine is and what you use it for; it's very, very interesting. Is this the library?

Statistics

Welcome our newest member: recijeb

Users Online 3 users 1552 guests