Skip to content

Posts from Scripts

4.8 (8 ratings)
User Avatar
#1292
Auto-translated

hp = random(1);
dp = random(1);
tep = random(1);

function politica()
while 1 do
if dp == 1 then
SetPlayerTeam(2,1);
print("Demon is on you!");
sleep(5);
else
SetPlayerTeam(2,2);
print("Demon is not on you");
sleep(5);
end;
if hp == 1 then
SetPlayerTeam(3,1);
print("Human is on you!");
sleep(5);
else
SetPlayerTeam(3,3);
print("Human is not on you");
sleep(5);
end;
if tep == 1 then
SetPlayerTeam(4,1);
print("Dark elf is on you!");
sleep(5);
else
SetPlayerTeam(2,2);
print("Dark elf is not on you");
sleep(5);
end;
end;
end;

startThread(politica);
1) How can I prevent the `print` function from constantly displaying the same messages?
2) The values of `hp`, `dp`, and `tep` are constantly equal to 0. Is this a script error or a quirk of the random function?
502 Bad Gateway
__________________________________
nginx/0.8.54
User Avatar
#1293
Auto-translated
sorry, wrong place (I'm editing, I'll delete it if needed)

Added 1 minute ago
Warrior, loop... (I'll insert the function here) stop

Whatever
User Avatar
#1294
Auto-translated
I also need an answer to the second question.
502 Bad Gateway
__________________________________
nginx/0.8.54
User Avatar
#1295
Auto-translated
regarding breake: I stepped in, I fixed it. if you need only the part that works with a variable to be disabled, then put any other parameter together with the if statement where the variable is. example: a = 0
b = 0
c = 0
hp = random(1);
dp = random(1);
tep = random(1);

function politica()
while 1 do
if dp == 1 and a == 0 then
a = 1
SetPlayerTeam(2,1);
print("Demon is on you!");
sleep(5);
else
SetPlayerTeam(2,2);
print("Demon is not on you");
sleep(5);
end;
if hp == 1 and b == 0 then
b = 1
SetPlayerTeam(3,1);
print("Human is on you!");
sleep(5);
else
SetPlayerTeam(3,3);
print("Human is not on you");
sleep(5);
end;
if tep == 1 and c == 0 then
c = 1
SetPlayerTeam(4,1);
print("Dark elf is on you!");
sleep(5);
else
SetPlayerTeam(2,2);
print("Dark elf is not on you");
sleep(5);
end;

end;
end;

startThread(politica);

Whatever
User Avatar
#1296
Auto-translated
As far as I know, does `break` completely stop a `while` loop, or not?
502 Bad Gateway
__________________________________
nginx/0.8.54
User Avatar
#1297
Auto-translated
breake fixed

Second question: random(1) returns numbers from 0 to (number in parentheses) - 1

therefore, your random number is generated from 0 to 1-1 = 0

but it should be random(2) = either 0 or 1 is generated

Whatever
User Avatar
#1298
Auto-translated
Dude, you can highlight the script with the `
` tag, otherwise it will be inconvenient to paste it.
502 Bad Gateway
__________________________________
nginx/0.8.54
In reply to Warrior777
User Avatar
#1299
Auto-translated
Warrior777

hp = random(1);
dp = random(1);
tep = random(1);

function politica()
while 1 do
if dp == 1 then
SetPlayerTeam(2,1);
print("Demon is on you!");
sleep(5);
else
SetPlayerTeam(2,2);
print("Demon is not on you");
sleep(5);
end;
if hp == 1 then
SetPlayerTeam(3,1);
print("Human is on you!");
sleep(5);
else
SetPlayerTeam(3,3);
print("Human is not on you");
sleep(5);
end;
if tep == 1 then
SetPlayerTeam(4,1);
print("Dark elf is on you!");
sleep(5);
else
SetPlayerTeam(2,2);
print("Dark elf is not on you");
sleep(5);
end;
end;
end;

startThread(politica);
1) How can I make it so that print doesn't constantly output the same messages?
2) The values of hp, dp, and tep are constantly equal to 0. Is this a script error or just random chance?
Read the Manuals to learn how random works.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
User Avatar
#1300
Auto-translated
Break removed, code fixed. Too many messages at once.

Whatever
In reply to Heroist
User Avatar
#1301
Auto-translated
Heroist
aaa... damn, I messed up. Thanks.
By the way, I've made some changes to the campaign function that recalculates the number of defeated enemies. But now it works strangely. Can you tell me what's wrong?
What exactly do you need it to do?
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
User Avatar
#1302
Auto-translated
Added 1 minute ago
RedHeavenHero
What exactly do you need from it?


Well, after the battle with the hero 'Berein', if he wins, the number of enemy creatures killed should be displayed, and he should receive 100% of the best bones as a reward :smile51: :smile51: :smile51:

Whatever
In reply to Heroist
User Avatar
#1303
Auto-translated
Heroist
Added 1 minute ago


Well, after a battle with the hero 'Berein', if he wins, the number of enemy creatures killed should be displayed, and he should receive 100% of their bones:smile51: :smile51: :smile51:
Trigger( COMBAT_RESULTS_TRIGGER, "combat_results" )

function combat_results(c)
local we = -1
if GetSavedCombatArmyPlayer(c, 1) == PLAYER_1 then we = 1 end
if GetSavedCombatArmyPlayer(c, 0) == PLAYER_1 then we = 0 end
if we ~= -1 then
local they = 1 - we
if GetSavedCombatArmyHero(c,we) == "Berein" then
local stackscount = GetSavedCombatArmyCreaturesCount(c, they)
for i=0,stackscount-1 do
local creature, creaturescount, died = GetSavedCombatArmyCreatureInfo(c, they, i)
if died > 0 then
AddHeroCreatures('Berein', 29, died)
end
end
end
end
end
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
User Avatar
#1304
Auto-translated
Added 1 minute ago
It seems everything is clear, except for one thing:

What does we ~= -1 actually mean? Doesn't it become equal to 1/0?

Whatever
In reply to Heroist
User Avatar
#1305
Auto-translated
Heroist
Added 1 minute ago
It seems everything is clear, except for one thing:

What does we ~= -1 actually mean? Doesn't it become equal to 1/0?
In case player 1 didn't participate in the battle.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
User Avatar
#1306
Auto-translated
Okay, I understand now. Thank you very much.

Whatever

Statistics

Welcome our newest member: leyu