Connection ErrorBad RequestSession ExpiredSign in requiredForbiddenNot FoundToo Many RequestsServer ErrorBad GatewayService UnavailableGateway TimeoutHTTP Version Not Supported
Session Expired
Your session has expired. Please log in to continue.
Sign in required
You need an account to do that. Sign in or create one — it only takes a minute.
Request Failed
We encountered an issue while processing your request.
Please check your internet connection and try again.
Hmm, that's a shame. So, the problem lies elsewhere...
Why is it a shame? Why does the problem lie elsewhere? The problem is precisely in this. The number, although seemingly non-negative, still causes an error in functions such as AddObjectCreatures, RemoveObjectCreatures, and so on.
I didn't finish reading your message. I basically expected that. Well, it's fixable. Thank you!
Whatever
metufonaStatistics
Registered:
Posts:4
Auto-translated
Good people, please help me with some advice. I really want to set up a strong army to guard the dwarven treasure. I made the object inactive and added a trigger on touch with the question "Are you ready to fight the guardian?". If the answer is yes, a message should appear, and a battle should begin. The message appears, but the battle doesn't happen. I would like to understand why. I will be grateful for any help, because I'm tired of tinkering with it.
```
dir = GetMapDataPath()
Trigger(OBJECT_TOUCH_TRIGGER, "tres1", "tres1F")
function tres1F (heroName)
number=GetCurrentPlayer()
QuestionBoxForPlayers(number,dir.."Capture.txt", "captureF", "nocaptureF")
end
function captureF (heroName)
number=GetCurrentPlayer()
MessageBoxForPlayers(number,dir.."gettreasure.txt")
StartCombat (heroName, nil, 2,
CREATURE_THANE, 20,
CREATURE_WARLORD, 20, nil)
end
function alreadyCapturedF (heroName)
number=GetCurrentPlayer()
MessageBoxForPlayers(number,dir.."alreadyCaptured.txt")
end
function nocaptureF (heroName)
number=GetCurrentPlayer()
MessageBoxForPlayers(number,dir.."Coward.txt")
end
SetObjectEnabled("tres1", false)
MentStatistics
Registered:
Posts:31,055
Auto-translated
The script looks good; it's strange that it doesn't work. Have you checked the console? And this... I doubt it will help, but I would try adding three more "nil" values at the end of StartCombat. There's just this thing where, by default, the value of the variable that comes first in the function is set, and it might be causing a bug where a required variable isn't set, and the default value is set in such a way...
Hello everyone, please help me with some advice. I really want to set up a strong army guarding the Dwarven treasure. I made the object inactive and added a trigger on touch with a question: "Are you ready to fight the guardian?". If the answer is yes, a message should appear, and a battle should begin. The message appears, but the battle doesn't start. I would like to understand why. I will be grateful for any help, because I'm tired of tinkering with it.
dir = GetMapDataPath() Trigger(OBJECT_TOUCH_TRIGGER, "tres1", "tres1F"); function tres1F (heroName) number=GetCurrentPlayer(); QuestionBoxForPlayers(number,dir.."Capture.txt", "captureF", "nocaptureF"); end; function captureF (heroName) number=GetCurrentPlayer(); MessageBoxForPlayers(number,dir.."gettreasure.txt"); StartCombat (heroName, nil, 2, CREATURE_THANE, 20, CREATURE_WARLORD, 20, nil); end; function alreadyCapturedF (heroName) number=GetCurrentPlayer(); MessageBoxForPlayers(number,dir.."alreadyCaptured.txt"); end; function nocaptureF (heroName) number=GetCurrentPlayer(); MessageBoxForPlayers(number,dir.."Coward.txt"); end; SetObjectEnabled("tres1", false);
I took a quick look and already found the error. In the QuestionBoxForPlayers function, you specify a function that will be called when the "Yes" answer is given. This function does not take any parameters, i.e., in the line function captureF (heroName), the parentheses should be empty. There is a solution, for example, like this: before this entire block, define a global variable, i.e., write a line like hero=''. Then, in the function where QuestionBox is written, assign the hero's name to this variable like this: hero= heroName. And already in the StartCombat function, use this variable. It will look something like this:
dir = GetMapDataPath() hero=''; Trigger(OBJECT_TOUCH_TRIGGER, "tres1", "tres1F"); function tres1F (heroName) number=GetCurrentPlayer(); hero=heroName; QuestionBoxForPlayers(number,dir.."Capture.txt", "captureF", "nocaptureF"); end; function captureF () number=GetCurrentPlayer(); MessageBoxForPlayers(number,dir.."gettreasure.txt"); StartCombat (hero, nil, 2, CREATURE_THANE, 20, CREATURE_WARLORD, 20, nil); end; function alreadyCapturedF (heroName) number=GetCurrentPlayer(); MessageBoxForPlayers(number,dir.."alreadyCaptured.txt"); end; function nocaptureF () number=GetCurrentPlayer(); hero=''; MessageBoxForPlayers(number,dir.."Coward.txt"); end; SetObjectEnabled("tres1", nil);
I would also like to note that it would be good to add a function to the StartCombat function that will be called after the battle. Thanks to it, you can reward the hero, remove the trigger from the building, etc.
These functions can be passed parameters in a slightly unconventional way; instead of writing "captureF," you can write "captureF('"..heroName.."')". Also, MessageBoxForPlayers takes the player's filter GetPlayerFilter(number) as its first parameter, not the player itself. The difference won't be noticeable if there are only 1-2 players, but errors will occur with more than 2. It would also be good to add a check to see if the player is a computer-controlled player or not.
I took a quick look and already found a mistake. In the QuestionBoxForPlayers function, you define a function that will be called when the "Yes" answer is given. This function does not accept any parameters, i.e., in the line function captureF (heroName), the parentheses should be empty. There is a solution, for example, like this: before this entire block, define a global variable, i.e., write a line like hero=''. Then, in the function where QuestionBox is written, assign the hero's name to this variable like this: hero= heroName. And then use this variable in the StartCombat function. It will look something like this:
dir = GetMapDataPath() hero=''; Trigger(OBJECT_TOUCH_TRIGGER, "tres1", "tres1F"); function tres1F (heroName) number=GetCurrentPlayer(); hero=heroName; QuestionBoxForPlayers(number,dir.."Capture.txt", "captureF", "nocaptureF"); end; function captureF () number=GetCurrentPlayer(); MessageBoxForPlayers(number,dir.."gettreasure.txt"); StartCombat (hero, nil, 2, CREATURE_THANE, 20, CREATURE_WARLORD, 20, nil); end; function alreadyCapturedF (heroName) number=GetCurrentPlayer(); MessageBoxForPlayers(number,dir.."alreadyCaptured.txt"); end; function nocaptureF () number=GetCurrentPlayer(); hero=''; MessageBoxForPlayers(number,dir.."Coward.txt"); end; SetObjectEnabled("tres1", nil);
I'd also like to note that it would be good to add a function to the StartCombat function that will be called after the battle. Thanks to it, you can reward the hero, remove the trigger from the building, etc.
Thank you very much, now everything works! I will keep in mind for the future that such functions should be written without parameters. I was already planning to add a function after the battle in StartCombat, I'm just doing everything in stages so as not to get confused.
RedHeavenHero
Yes, and MessageBoxForPlayers takes not the player as the first parameter, but its filter GetPlayerFilter(number). There will be no visible difference if there are 1-2 players, but errors will occur for >2. It is also desirable to add a check to see if the player is a computer or not.
Only one player will have access to this object. Therefore, I'd rather leave it as is. But I will keep it in mind for the future, thank you!
RedHeavenHeroStatistics
Registered:
Posts:2,380
Auto-translated
Only one player will have access to this object. Therefore, I'd rather leave it as is. But I'll keep it in mind for the future, thanks!