|
Post by macceba on Mar 15, 2012 14:02:59 GMT 1
Hello guys, i am trying to make a one script which could detect commander in many scripdid areas. There are 10 areas (100-109) and ten scirpid units(100-109). I would like to change player ScriptId unit when comander enter to area. But not succes up to now. Thanks Martin
function HTanksG1() local commander = 1000; local i = 0; local X = {100,101,102,103,104,105,106,107,108,109}; repeat if (GetNScriptUnitsInArea (commander, "X") == 1) then ChangePlayer (X, 0); i = i + 1; until(i > 10); Suicide (); end; end;
|
|
|
Post by danzig70 on Mar 15, 2012 23:33:28 GMT 1
I think the script area should be in quotes like GetNScriptUnitsInArea("commander", ScriptID);
I havent used an array in place of the ScriptID before though.
|
|
|
Post by Major Pain on Mar 16, 2012 2:38:25 GMT 1
You may need to send the ChangePlayer command out to another Function.
function HTanksG1() local commander = 1000; local i = 0; local X = {100,101,102,103,104,105,106,107,108,109}; repeat if (GetNScriptUnitsInArea (commander, "X") == 1) then RunScript("SideChange",5000); i = i + 1; until(i > 10); Suicide (); end; end;
function SideChange() ChangePlayer (X, 0); Suicide(); end;
You should also recheck which ones have already changed so they don't pass through function again.
What seems to occur in some scripts when trying to perform ChangePlayer, Move, Stop and Check Locations, is the function bugs out. The argument might be true but it falis to perform all commands.
It is best to separate these commands. In the case of Arrays, you can easily pass the variables between functions to achieve the same goal with only a few functions.
Also, use 'DisplayTrace' whereever you can to verify that that part of the script is operating.
I hope this helps...
|
|
|
Post by macceba on Mar 16, 2012 9:16:23 GMT 1
Many thanks guys, i have thought about it. dont know how Lua works in "GetNScriptUnitsInArea" and probably even generaly.........with numerals and characters......... Maybe the script is looking for script id area "x " name. But first i am going to try Major advice. Thanks Martin
|
|
|
Post by Major Pain on Mar 16, 2012 12:30:19 GMT 1
I didn't realize you had named the Locations as a number. They must be in String Form.
You also need to declare the Array and use a variable name other than "x". You should use a descriptive variable name.
GMAP {}
GMap = {"100","101","102","103","104","105","106","107","108","109"};
The If - then becomes
if (GetNScriptUnitsInArea (commander, GMap) == 1) then
If you are checking several commanders, you will have to use a separate function to check these...
For instance...
Add the "i" to the Commander Script ID.
commandertest = 1000 + i
Since I don't have the entire script, I can't see exactly what you are trying to accomplish. Hopefully, this will give you some help.
MP
|
|
|
Post by macceba on Sept 21, 2012 13:31:57 GMT 1
Hi, i have found an old scirpt on bkportal archive....... well dont truly understand some part. It is very clever/smart heavy matrix script, but maybe someone could know ...... RED Lines i have trouble to understand function LR(x) LandReinforcement(x); end; function Rad(x) return RandomInt(x); end; function IPP(x) return IsPlayerPresent(x); end; function OHP(x) return GetObjectHPs(x); end; function NUA(x, y) return GetNUnitsInArea(x, y;); end; function Reinf() LR(step + std_reinf) std_reinf = std_reinf + 1 if std_reinf > max_reinf then Suicide(); end; end; function Factory() local i = 1; while area do --loop through areas if IPP(owner) == 1 then --owner check if NUA(owner, area) > 0 then --labor check if OHP(id_o) >= hp_o * (100 - dmg_perc) / 100 then --office hitpoints check if OHP(id_w) >= hp_w * (100 - dmg_perc) / 100 then --factory hitpoints check if Office[owner] == rf then --production progress check if ind == 0 and NUA(owner, area) >= 2 then x = 2 else x = 1 end; for j = 1, x do LR(id_r + Rad(rd)) end; Office[owner] = 0 else Office[owner] = Office[owner] + 1 end; end; end; end; end; i = i + 1 end; end;
function Init() tf_min = 1/4; --length of production check interval (minutes); production time (min) = tf_min * reinf_factor dmg_perc = 50; --how much can production buildings be damaged tr_min = 10; max_reinf = 6; std_reinf = 1; step = 100; ------------------------------------------------------- tf_ms = tf_min * 60 * 1000; tr_ms = tr_min * 60 * 1000; ------------------------------------------------------- player = {0, 1, 2, 3}; area = {"FA01", "FA02", "FA03", "FA11", "FA12", "FA13", "FA21", "FA22", "FA23", "FA31", "FA32", "FA33"}; --office area desc owner = {0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3}; --office owner id ind = {0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0}; --special reinf indicator id_o = {1501, 1511, 1521, 1601, 1611, 1621, 1701, 1711, 1721, 1801, 1811, 1821}; --office id id_w = {1500, 1510, 1520, 1600, 1610, 1620, 1700, 1710, 1720, 1800, 1810, 1820}; --factory id id_r = {1000, 1020, 1010, 1100, 1120, 1110, 1200, 1220, 1210, 1300, 1320, 1310}; --base reinf id hp_o = {500, 500, 500, 500, 750, 500, 500, 500, 500, 500, 500, 500}; --office hitpoints (max) hp_w = {750, 750, 500, 750, 1000, 500, 1000, 750, 500, 750, 1000, 500}; --factory hitpoints (max) rf = {24, 48, 24, 24, 48, 24, 24, 48, 24, 24, 48, 24}; --reinf factor (when reinf initiate) rd = {2, 2, 2, 2, 2, 2, 4, 1, 2, 4, 1, 2}; --number of diff units available in factory ------------------------------------------------------- Office = {}; --production counter i = 1; while area do Office = {} j = 1 while player[j] do Office[player[j]] = 0 j = j + 1 end; i = i + 1 end; ------------------------------------------------------- RunScript("Info0", 10000); RunScript("Info1", 20000); RunScript("Info2", 30000); RunScript("Reinf", tr_ms); RunScript("Factory", tf_ms); end;
|
|