<?PHP
$npc['storage'] = 123;
$npc['storageKill'] = 124;
$missions = array();
$mission = array();
$mission['id'] = 0;
$mission['name'] = 'NaMe';
$mission['comment'] = 'CoMMeNt';
$mission['text'] = array();
$mission['text'][0] = array();
$mission['text'][0]['text'] = '0.0._ hello. mission? {yes}?';
$mission['text'][0]['answers'] = array();
$mission['text'][0]['answers'][0] = array();
$mission['text'][0]['answers'][0]['words'] = array();
$mission['text'][0]['answers'][0]['words'][0] = '0.0.0.yes';
$mission['text'][0]['answers'][0]['words'][1] = '0.0.0.mission';
$mission['text'][0]['answers'][0]['requirements'] = array();
$mission['text'][0]['answers'][0]['actions'] = array();
$mission['text'][0]['answers'][0]['actions'][0] = array();
$mission['text'][0]['answers'][0]['actions'][0]['type'] = '2';
$mission['text'][0]['answers'][0]['actions'][0]['params'] = array();
$mission['text'][1] = array();
$mission['text'][1]['text'] = '0.1._ can you bring me item 333? {yes}?';
$mission['text'][1]['answers'] = array();
$mission['text'][1]['answers'][0] = array();
$mission['text'][1]['answers'][0]['words'] = array();
$mission['text'][1]['answers'][0]['words'][0] = '0.1.0.yes';
$mission['text'][1]['answers'][0]['words'][1] = '0.1.0.of course';
$mission['text'][1]['answers'][0]['requirements'] = array();
$mission['text'][1]['answers'][0]['actions'] = array();
$mission['text'][1]['answers'][0]['actions'][0] = array();
$mission['text'][1]['answers'][0]['actions'][0]['type'] = '4';
$mission['text'][1]['answers'][0]['actions'][0]['params'] = array();
$mission['text'][1]['answers'][1] = array();
$mission['text'][1]['answers'][1]['words'] = array();
$mission['text'][1]['answers'][1]['words'][0] = '0.1.1.no way';
$mission['text'][1]['answers'][1]['words'][1] = '0.1.1.fuck"you';
$mission['text'][1]['answers'][1]['requirements'] = array();
$mission['text'][1]['answers'][1]['actions'] = array();
$mission['text'][1]['answers'][1]['actions'][0] = array();
$mission['text'][1]['answers'][1]['actions'][0]['type'] = '1';
$mission['text'][1]['answers'][1]['actions'][0]['params'] = array();
$mission['text'][1]['answers'][1]['actions'][0]['params'][1] = '0.1.1.answer.Come back when you will be interested.';
$mission['text'][1]['answers'][1]['actions'][1] = array();
$mission['text'][1]['answers'][1]['actions'][1]['type'] = '8';
$mission['text'][1]['answers'][1]['actions'][1]['params'] = array();
$missions[0] = $mission;
$mission = array();
$mission['id'] = 1;
$mission['name'] = 'NaMe2';
$mission['comment'] = 'CoMMeNt2';
$mission['text'] = array();
$mission['text'][0] = array();
$mission['text'][0]['text'] = '1.0._ hello. are you here because you done {mission} ? {yes}?';
$mission['text'][0]['answers'] = array();
$mission['text'][0]['answers'][0] = array();
$mission['text'][0]['answers'][0]['words'] = array();
$mission['text'][0]['answers'][0]['words'][0] = '1.0.0.yes';
$mission['text'][0]['answers'][0]['words'][1] = '1.0.0.mission';
$mission['text'][0]['answers'][0]['words'][2] = '1.0.0.some shits';
$mission['text'][0]['answers'][0]['requirements'] = array();
$mission['text'][0]['answers'][0]['actions'] = array();
$mission['text'][0]['answers'][0]['actions'][0] = array();
$mission['text'][0]['answers'][0]['actions'][0]['type'] = '2';
$mission['text'][0]['answers'][0]['actions'][0]['params'] = array();;
$mission['text'][1] = array();
$mission['text'][1]['text'] = '1.1._ do you have item 333 with you? {ye}?';
$mission['text'][1]['answers'] = array();
$mission['text'][1]['answers'][0] = array();
$mission['text'][1]['answers'][0]['words'] = array();
$mission['text'][1]['answers'][0]['words'][0] = '1.1.0.ye';
$mission['text'][1]['answers'][0]['words'][1] = '1.1.0.of course';
$mission['text'][1]['answers'][0]['requirements'] = array();
$mission['text'][1]['answers'][0]['requirements'][0] = array();
$mission['text'][1]['answers'][0]['requirements'][0]['type'] = '6';
$mission['text'][1]['answers'][0]['requirements'][0]['params'] = array();
$mission['text'][1]['answers'][0]['requirements'][0]['params'][1] = '333';
$mission['text'][1]['answers'][0]['requirements'][0]['params'][2] = '>=';
$mission['text'][1]['answers'][0]['requirements'][0]['params'][3] = '1';
$mission['text'][1]['answers'][0]['requirements'][0]['failActions'] = array();
$mission['text'][1]['answers'][0]['requirements'][0]['failActions'][0] = array();
$mission['text'][1]['answers'][0]['requirements'][0]['failActions'][0]['type'] = '1';
$mission['text'][1]['answers'][0]['requirements'][0]['failActions'][0]['params'] = array();
$mission['text'][1]['answers'][0]['requirements'][0]['failActions'][0]['params'][1] = '1.1.0.failanswer.You do not have item 333.';
$mission['text'][1]['answers'][0]['requirements'][0]['failActions'][1] = array();
$mission['text'][1]['answers'][0]['requirements'][0]['failActions'][1]['type'] = '8';
$mission['text'][1]['answers'][0]['requirements'][0]['failActions'][1]['params'] = array();
$mission['text'][1]['answers'][0]['actions'] = array();
$mission['text'][1]['answers'][0]['actions'][0] = array();
$mission['text'][1]['answers'][0]['actions'][0]['type'] = '1';
$mission['text'][1]['answers'][0]['actions'][0]['params'] = array();
$mission['text'][1]['answers'][0]['actions'][0]['params'][1] = '1.1.0.answer.Mission done. No more missions gzzz.';
// add reward
//
$mission['text'][1]['answers'][1] = array();
$mission['text'][1]['answers'][1]['words'] = array();
$mission['text'][1]['answers'][1]['words'][0] = '1.1.1.no way';
$mission['text'][1]['answers'][1]['words'][1] = '1.1.1.fuck"you';
$mission['text'][1]['answers'][1]['requirements'] = array();
$mission['text'][1]['answers'][1]['actions'] = array();
$mission['text'][1]['answers'][1]['actions'][0] = array();
$mission['text'][1]['answers'][1]['actions'][0]['type'] = '1';
$mission['text'][1]['answers'][1]['actions'][0]['params'] = array();
$mission['text'][1]['answers'][1]['actions'][0]['params'][1] = '1.1.1.answer.Come back when you will have item 333.';
$mission['text'][1]['answers'][1]['actions'][1] = array();
$mission['text'][1]['answers'][1]['actions'][1]['type'] = '8';
$mission['text'][1]['answers'][1]['actions'][1]['params'] = array();
$missions[1] = $mission;
$nl = '<br />';
$tab = ' ';
function t($times)
{
$ret = '';
for($i = 0; $i < $times; $i++)
{
$ret .= ' ';
}
return $ret;
}
function printActions($missions, $actions, $missionID, $textID, $answerID, $tabCount)
{
foreach($actions as $action)
{
// zmianiec next na dane ID
}
$realActions = array();
foreach($actions as $action)
{
//var_dump($action);
switch($action['type'])
{
case 1: // say
echo t($tabCount) . 'selfSay("' . str_replace('"', '\"', $action['params'][1]) . '", cid)' . $GLOBALS['nl'];
break;
case 2: // Go to next text
echo t($tabCount) . 'talkStates[getPlayerGUID(cid)] = ' . ($textID+1) . $GLOBALS['nl'];
echo t($tabCount) . 'selfSay("' . str_replace('"', '\"', $missions[$missionID]['text'][($textID+1)]['text']) . '", cid)' . $GLOBALS['nl'];
// show text
break;
case 3: // Go to next mission
echo t($tabCount) . 'talkStates[getPlayerGUID(cid)] = 1' . $GLOBALS['nl'];
echo t($tabCount) . 'doCreatureSetStorage(cid, ' . $GLOBALS['npc']['storage'] . ', ' . ($missionID+1) . ')' . $GLOBALS['nl'];
break;
case 4: // Go to next mission and show it's text
echo t($tabCount) . 'talkStates[getPlayerGUID(cid)] = 1' . $GLOBALS['nl'];
echo t($tabCount) . 'doCreatureSetStorage(cid, ' . $GLOBALS['npc']['storage'] . ', ' . ($missionID+1) . ')' . $GLOBALS['nl'];
echo t($tabCount) . 'selfSay("' . str_replace('"', '\"', $missions[($missionID+1)]['text'][1]['text']) . '", cid)' . $GLOBALS['nl'];
break;
case 5: // Go to text <X_1> and show text // in same mission
echo t($tabCount) . 'talkStates[getPlayerGUID(cid)] = ' . $action['params'][1] . $GLOBALS['nl'];
echo t($tabCount) . 'selfSay("' . str_replace('"', '\"', $missions[$missionID]['text'][$action['params'][1]]['text']) . '", cid)' . $GLOBALS['nl'];
break;
case 6: // Go to mission <X_1> <X_2> // mission X, text X
echo t($tabCount) . 'doCreatureSetStorage(cid, ' . $GLOBALS['npc']['storage'] . ', ' . $action['params'][1] . ')' . $GLOBALS['nl'];
echo t($tabCount) . 'talkStates[getPlayerGUID(cid)] = ' . $action['params'][2] . $GLOBALS['nl'];
break;
case 7: // Go to mission <X_1> <X_2> and show text// mission X, text X
echo t($tabCount) . 'doCreatureSetStorage(cid, ' . $GLOBALS['npc']['storage'] . ', ' . $action['params'][1] . ')' . $GLOBALS['nl'];
echo t($tabCount) . 'talkStates[getPlayerGUID(cid)] = ' . $action['params'][2] . $GLOBALS['nl'];
echo t($tabCount) . 'selfSay("' . str_replace('"', '\"', $missions[$action['params'][1]]['text'][$action['params'][2]]['text']) . '", cid)' . $GLOBALS['nl'];
break;
case 8: // Go to start of NPC // talkstate = 1
echo t($tabCount) . 'talkStates[getPlayerGUID(cid)] = 0' . $GLOBALS['nl'];
break;
case 9: //
break;
}
}
echo t($tabCount) . 'return true' . $GLOBALS['nl'];
}
/*
actionsAvailable[0] = Array("None", "");
actionsAvailable[1] = Array("Say", '<input type="type" value="" name="param1" />');
actionsAvailable[2] = Array("Go to next text", ""); // wait for answer from next 'text'
actionsAvailable[3] = Array("Go to next mission", ""); // go to next mission
actionsAvailable[4] = Array("Go to next mission and show text", ""); // go to next mission and show text
actionsAvailable[5] = Array("Go to text and show it's text", '<input type="type" value="1" name="param1" />'); // go to text X and show it's text
actionsAvailable[6] = Array("Go to mission", 'MissionID <input type="type" value="" name="param1" />, TextID <input type="type" value="1" name="param2" />'); // go to mission X, text X
actionsAvailable[7] = Array("Go to mission and show text", 'MissionID <input type="type" value="" name="param1" />, TextID <input type="type" value="1" name="param2" />'); // go to mission X, text X and show text
actionsAvailable[8] = Array("Go to start of NPC", ""); // talkstate = 1
*/
echo '<pre>';
echo t(0) . 'function npcGreet(cid)' . $nl;
echo t(1) . 'if(cid ~= 0) then' . $nl;
echo t(2) . 'NPCtalkState[getPlayerGUID(cid)] = 0' . $nl;
echo t(2) . 'if(getCreatureStorage(cid, ' . $npc['storage'] . ') == -1) then' . $nl;
echo t(3) . 'doCreatureSetStorage(cid, ' . $npc['storage'] . ', 0)' . $nl;
echo t(2) . 'end' . $nl;
echo t(2) . 'npcHandler:addFocus(cid)' . $nl;
echo t(2) . 'local missionID = getCreatureStorage(cid, ' . $npc['storage'] . ')' . $nl;
foreach($missions as $mission)
{
echo t(2) . 'if(missionID == ' . $mission['id'] . ') then' . $nl;
echo t(3) . 'npcSay("' . str_replace('"', '\"', $mission['text'][0]['text']) . '")' . $nl;
echo t(3) . 'npcSay("' . str_replace('"', '\"', $mission['text'][0]['text']) . '", cid)' . $nl;
echo t(3) . 'return false' . $nl;
echo t(2) . 'end' . $nl;
}
echo t(1) . 'end' . $nl;
echo t(1) . 'return false' . $nl;
echo t(0) . 'end' . $nl;
echo t(0) . 'npcHandler:setCallback(CALLBACK_GREET, npcGreet)' . $nl . $nl;
echo 'function npcTalkAboutMission(cid, type, msg)' . $nl;
echo t(1) . 'if(not npcHandler:isFocused(cid)) then' . $nl;
echo t(2) . 'return false' . $nl;
echo t(1) . 'end' . $nl;
echo t(1) . 'local missionID = getCreatureStorage(cid, ' . $npc['storage'] . ')' . $nl;
echo t(1) . 'local talkState = talkStates[getPlayerGUID(cid)]' . $nl;
foreach($missions as $mission)
{
echo t(1) . 'if(missionID == ' . $mission['id'] . ') then' . $nl;
//echo '-----------';
foreach($mission['text'] as $textID => $text)
{
echo t(2) . (($textID > 0) ? 'else' : '') . 'if(talkState == ' . $textID . ') then' . $nl;
foreach($text['answers'] as $answerID => $answer)
{
echo t(3) . (($answerID > 0) ? 'else' : '') . 'if(';
$answerWords = array();
foreach($answer['words'] as $word)
$answerWords[] = 'messageContains(msg, "' . str_replace('"', '\"', $word) . '")';
echo implode(' or ', $answerWords) . ') then' . $nl;
$anyVocation = false;
foreach($answer['requirements'] as $require)
{
switch($require['type'])
{
case 1: // level
echo t(4) . 'if(not (getPlayerLevel(cid) ' . $require['params'][1] . ' ' . $require['params'][2] . ')) then' . $nl;
printActions($missions, $require['failActions'], $mission['id'], $textID, $answerID, 5);
echo t(4) . 'end' . $nl;
break;
case 2: // magic level
echo t(4) . 'if(not (getPlayerMagLevel(cid) ' . $require['params'][1] . ' ' . $require['params'][2] . ')) then' . $nl;
printActions($missions, $require['failActions'], $mission['id'], $textID, $answerID, 5);
echo t(4) . 'end' . $nl;
break;
case 3: // skill level
echo t(4) . 'if(not (getPlayerSkillLevel(cid, ' . $require['params'][1] . ') ' . $require['params'][2] . ' ' . $require['params'][3] . ')) then' . $nl;
printActions($missions, $require['failActions'], $mission['id'], $textID, $answerID, 5);
echo t(4) . 'end' . $nl;
break;
// todo all below
case 4: // vocation is
$vocations = explode(';', $require['params'][1]);
echo t(4) . 'if(not (getPlayerMagLevel(cid) ' . $require['params'][1] . ' ' . $require['params'][2] . ')) then' . $nl;
printActions($missions, $require['failActions'], $mission['id'], $textID, $answerID, 5);
echo t(4) . 'end' . $nl;
break;
case 5: // vocation is not
echo t(4) . 'if(not (getPlayerMagLevel(cid) ' . $require['params'][1] . ' ' . $require['params'][2] . ')) then' . $nl;
printActions($missions, $require['failActions'], $mission['id'], $textID, $answerID, 5);
echo t(4) . 'end' . $nl;
break;
case 6: // item count
echo t(4) . 'if(not (getPlayerItemCount(cid, ' . $require['params'][1] . ') ' . $require['params'][2] . ' ' . $require['params'][3] . ')) then' . $nl;
printActions($missions, $require['failActions'], $mission['id'], $textID, $answerID, 5);
echo t(4) . 'end' . $nl;
break;
case 7: // item slot
echo t(4) . 'if(not (getPlayerItemCount(cid, ' . $require['params'][1] . ') ' . $require['params'][2] . ' ' . $require['params'][3] . ')) then' . $nl;
printActions($missions, $require['failActions'], $mission['id'], $textID, $answerID, 5);
echo t(4) . 'end' . $nl;
break;
}
}
printActions($missions, $answer['actions'], $mission['id'], $textID, $answerID, 4);
//getPlayerSkillLevel(cid, skill
//getPlayerVocation(cid)
/*
requirementsAvailable[0] = Array("None", "");
requirementsAvailable[1] = Array("Level", '<select name="param1">' + compareNumberOptions + '</select><input type="text" name="param2" value="0" />');
requirementsAvailable[2] = Array("Magic Level", '<select name="param1">' + compareNumberOptions + '</select><input type="text" name="param2" value="0" />');
requirementsAvailable[3] = Array("Skill Level", '<select name="param1">' + skillOptions + '</select><select name="param2">' + compareNumberOptions + '</select><input type="text" name="param3" value="0" />');
requirementsAvailable[4] = Array("Vocation IS", '<select name="param1">' + compareNumberOptions + '</select><input type="text" name="param2" value="0" />');
requirementsAvailable[5] = Array("Vocation IS NOT", '<select name="param1">' + compareNumberOptions + '</select><input type="text" name="param2" value="0" />');
requirementsAvailable[6] = Array("Item Count", 'Item ID: <input type="text" name="param1" size="5" value="0" /> Count: <select name="param2">' + compareNumberOptions + '</select><input type="text" name="param3" value="0" />');
requirementsAvailable[7] = Array("Item Slot", 'Item Slot <select name="param1">' + slotOptions + '</select> ItemID <input type="text" name="param2" size="5" value="0" /> Attributes <input type="text" size="60" name="param3" value="" />');
*/
if($answerID+1 == count($text['answers']))
{
echo t(3) . 'end' . $nl;
}
}
if($textID+1 == count($mission['text']))
{
echo t(2) . 'end' . $nl;
}
}
echo t(1) . 'end' . $nl;
}
echo t(0) . 'end' . $nl;
echo '</pre>';
?>