Another script help

Maps and the art of mapmaking.
tofiffe
Peasant
Peasant
Posts: 93
Joined: 21 Mar 2010

Another script help

Unread postby tofiffe » 08 Nov 2010, 18:24

This time i'm just wondering about making the objective, that would count the artifacts you got? I'm trying to make an objective that would count the dragon artifacts(all in one objective)

User avatar
GreatEmerald
CH Staff
CH Staff
Posts: 3330
Joined: 24 Jul 2009
Location: Netherlands

Unread postby GreatEmerald » 08 Nov 2010, 19:08

What game are you talking about?

Franzy
War Dancer
War Dancer
Posts: 362
Joined: 07 Sep 2007
Location: Moscow, Russia
Contact:

Unread postby Franzy » 08 Nov 2010, 19:11

arts={10,21,15,......} -- place here artifacts ids your hero needs to collect

function checkartifacts(hero) --returns 1 if hero has all the required artifacts.

for i=1,length(arts) do
if not HasArtefact(hero,ars) then
return(0);
end

return(1);
end;

--Then you need to call that function, say, at the beginning of each day and then make an Objective complete once the function for the hero returns 1.

tofiffe
Peasant
Peasant
Posts: 93
Joined: 21 Mar 2010

Unread postby tofiffe » 09 Nov 2010, 15:25

would it be the same for doing that for 2 players? or maybe something different?

and about the check for result:
function check()
if checkartifacts==1
SetObjectiveState("objective",OBJECTIVE_COMPLETED,PLAYER_#);
Win(PLAYER_1);
end;
end;

Franzy
War Dancer
War Dancer
Posts: 362
Joined: 07 Sep 2007
Location: Moscow, Russia
Contact:

Unread postby Franzy » 09 Nov 2010, 19:34

You have to supply heroname to checkartifacts.

Like this:

hh = GetPlayerHeroes(PLAYER_1);
for i=1,length(hh) do
if checkartifacts(hh)==1
SetObjectiveState("objective",OBJECTIVE_COMPLETED,PLAYER_1);
Win(PLAYER_1);
end;
end;

tofiffe
Peasant
Peasant
Posts: 93
Joined: 21 Mar 2010

Unread postby tofiffe » 10 Nov 2010, 14:51

thanks!
now for the objective in map editor(i haven't been doing much with that)

do i have to put in multiple objectives for every player i want to get the objective?

and i have signposts with names sign0, sign1...and i need them to display message boxes(textfiles are message.0.txt, message.1.txt...)

is there any way to make a shortcut for writing all the functions?(instead of:
function mb0()
MessageBox("message.0.txt");
end;
Trigger(OBJECT_TOUCH_TRIGGER, "sign0", "mb0");
)?

2. is there any way to set the objective to completed as soon as one has all the arts?
3. when all of them are gathered, nothing happens not even after next day

Franzy
War Dancer
War Dancer
Posts: 362
Joined: 07 Sep 2007
Location: Moscow, Russia
Contact:

Unread postby Franzy » 10 Nov 2010, 20:37

1. Of course. But you should use different naming, like this: sign0,sign1... and sign0msg.txt, sign1msg.txt...

Then you can do the concatenation trick:

function mb(h,obj)
MessageBox(obj.."msg.txt");
end;

for i=0,10 do
Trigger(OBJECT_TOUCH_TRIGGER, "sign"..i, "mb");
end;

--Note that we're using one handler for different objects.

2. For this you have to run it in a thread, like this

function artchecker()
while not nil --infinite loop
hh = GetPlayerHeroes(PLAYER_1);
for i=1,length(hh) do
if checkartifacts(hh)==1
SetObjectiveState("objective",OBJECTIVE_COMPLETED,PLAYER_1);
Win(PLAYER_1);
end;
end;
sleep(100); --checking every 5 seconds
end;
startThread(artchecker);

end

end;

3. Probably just a script error. What does the console say?

tofiffe
Peasant
Peasant
Posts: 93
Joined: 21 Mar 2010

Unread postby tofiffe » 11 Nov 2010, 15:13

ok my mistake...for some reason the player wins as soon as he gets the first artifact specified in arts{}; and a few others...any way to fix this?

EDIT:found the problem, i only mistyped a end; for the loop :P

tofiffe
Peasant
Peasant
Posts: 93
Joined: 21 Mar 2010

Unread postby tofiffe » 02 Dec 2010, 15:15

ok since this topic isn't obsolete yet, i'll ask here :P

can you display messageboxes in combats?

Franzy
War Dancer
War Dancer
Posts: 362
Joined: 07 Sep 2007
Location: Moscow, Russia
Contact:

Unread postby Franzy » 02 Dec 2010, 20:35

Probably not. As far as I know, only functions that start with lowercase are common for adventure and combat modes. You can always try though ^)

tofiffe
Peasant
Peasant
Posts: 93
Joined: 21 Mar 2010

Unread postby tofiffe » 03 Dec 2010, 15:23

actualy it works :D

tofiffe
Peasant
Peasant
Posts: 93
Joined: 21 Mar 2010

Unread postby tofiffe » 04 Dec 2010, 09:20

i found an error:

Code: Select all

path=GetMapDataPath();
EnableAutoFinish(0);
c=GetDefenderCreatures();
while not nil do
   for i=1,length(c) do
   if exist(c)==nil then
      AddCreature( 1, 25, 2);
      MessageBox(path.."mortal/c1.txt");
      break;
   end;
   end;
end;
d=GetAttackerCreatures();
while not nil do
  for i=1,length(d) do
    if exist(d)==nil then
       AddCreature (0, 40, 1);
       MessageBox(path.."mortal/c2.txt");
       EnableAutoFinish(1);
       break;
    end;
  end;
end;
this combat script freezes the game...any ideas why?
EDIT: i'm a fool, didn't add sleep(20); in the while :P
but yet the script reports no error but doesn't execte anyway...any idea why?

Franzy
War Dancer
War Dancer
Posts: 362
Joined: 07 Sep 2007
Location: Moscow, Russia
Contact:

Unread postby Franzy » 04 Dec 2010, 21:23

GetDefenderCreatures() returns not an array but a number of values. Like this:
v1,v2,v3,v4,v5,v6,v7 = GetDefenderCreatures();

tofiffe
Peasant
Peasant
Posts: 93
Joined: 21 Mar 2010

Unread postby tofiffe » 05 Dec 2010, 08:47

realy? ok, seems to be fixed but for some reason the creatures on defender side keep coming up, but attackers aren't...and EnableAutoFinish(0); seems not to work :S

tofiffe
Peasant
Peasant
Posts: 93
Joined: 21 Mar 2010

Unread postby tofiffe » 18 Dec 2010, 09:21

i seem to get a problem when fighting sovereign hero, he has no animations...any way to fix that?


Return to “Mapmaking Guild”

Who is online

Users browsing this forum: No registered users and 7 guests