Another script help
Another script help
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)
- GreatEmerald
- CH Staff
- Posts: 3330
- Joined: 24 Jul 2009
- Location: Netherlands
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.
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.
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:
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
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
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?
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?
i found an error:
this combat script freezes the game...any ideas why?
EDIT: i'm a fool, didn't add sleep(20); in the while
but yet the script reports no error but doesn't execte anyway...any idea why?
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;
EDIT: i'm a fool, didn't add sleep(20); in the while
but yet the script reports no error but doesn't execte anyway...any idea why?
Who is online
Users browsing this forum: No registered users and 0 guests