Addquestscript
Posted: Sat Apr 11, 2009 7:45 am
I've been trying to edit addhitscript.src. Addhitscript works like this, it reads a cfg file with one element and all the paths to the hitscripts, and then sets a prop to the object with a array which contains the path. My problem is that I want a element for each quest. So I've added a foreach which finds all the elements and then searches for the scrippath. This works and it returns all the paths in the end. The problem is when you choose a quest in the gump which the script creates, and check the "Second" quest the script gives the property value of the "Test" quest. The part that gives the quest propertys is untouched, I've only edited the var names, so the error shoulden't lie there. Since the script returns all the elements and script paths I've got no idea what's wrong.
Thanks.
Code: Select all
Quest Test
{
Desc This is a test quest
Script Test :quests:questScripts/testquest
}
Quest Second
{
Desc This is a test quest
Script Second :quests:questScripts/secondquest
}Code: Select all
use uo;
use os;
use cfgfile;
include ":gumps:gumps";
include ":gumps:gumps_ex";
CONST SELECT_START := 0xA00;
CONST OKAY_BTN := 0x1;
program AddQuestScript(who);
SendSysMessage(who, "Select a NPC to add a quest.");
var targ := target(who);
if ( !targ.IsA(POLCLASS_NPC) )
SendSysMessage(who, "Cancelled.");
return 0;
endif
var quest_scripts := GetObjProperty(targ, "QuestScripts");
if ( !quest_scripts )
quest_scripts := array{};
endif
var gump := GFCreateGump();
GFResizePic(gump, 0, 0, GFGetCfgConst("Defaults", "BackGround"), 310, 480);
GFResizePic(gump, 15, 15, GFGetCfgConst("Defaults", "ForeGround"), 280, 450);
GFAddButton(gump, 125, 435, 2128, 2129, GF_CLOSE_BTN, OKAY_BTN);
var config := ReadConfigFile(":quests:questdesc");
var elemname := GetConfigStringKeys(config);
var elem;
var script_list;
var script_keys;
var y_pos := 25;
var match;
foreach key in elemname
elem := FindConfigElem(config, CStr(key));
script_list := GetConfigStringDictionary(elem, "Script");
script_keys := script_list.Keys();
SendSysMessage(who, CStr(script_list));
foreach key in ( script_keys )
match := HasQuestScript(script_list[key], quest_scripts);
GFCheckBox(gump, 20, y_pos, 210, 211, match, _key_iter+SELECT_START);
GFTextLine(gump, 45, y_pos, 2100, key);
y_pos += 20;
SleepMS(2);
endforeach
endforeach
var input := GFSendGump(who, gump);
if ( input[OKAY_BTN] )
quest_scripts.Shrink(0);
foreach key in ( input.keys )
if ( key >= SELECT_START )
var temp := key-SELECT_START;
temp := script_keys[temp];
quest_scripts.Append(script_list[temp]);
endif
SleepMS(2);
endforeach
if ( quest_scripts.Size() < 1 )
EraseObjProperty(targ, "QuestScripts");
else
SetObjProperty(targ, "QuestScripts", quest_scripts);
endif
SendSysMessage(who, "Done.");
else
SendSysMessage(who, "Cancelled.");
endif
return 1;
endprogram
function HasQuestScript(script, byref quest_scripts)
foreach entry in ( quest_scripts )
if ( Lower(script) == Lower(entry) )
return 1;
endif
SleepMS(2);
endforeach
return 0;
endfunction