Daily Lucky Numbers:
5
16
19
30
34
45

Battle Mod

Started by Fog, July 10, 2013, 10:14:27 PM

Previous topic - Next topic

Fog

I'm looking for help with the Battle Mod Game that SA and Andrew put together.

I'm not certain if anyone here has ever played the Battle Game so I'm not sure where to begin.

You Battle Monsters with certain attack and def along with health.

As you battle these monsters you gain experience and as you gain experience you can level up.

When you are setting up a monster you can add what level you want it to enter at...

For Example:

You have a weaker monster at level one than you do at level 250.

However you will continue to see those lower level monsters when you get into the upper levels.

And sometime those upper level monsters can still attack you even if you haven't reached their level yet.

So here's what I'm looking to do...

Instead of one input box for the level you want for a monster

Create two input boxes for the lowest level you want the monster to show up and the highest level you want to see the monster.

A Min/Max type of function.


I'll provide screen shot of the admin control panel for editing a monster....

In my case I've converted the monsters into WWII Tanks...



I can provide additional info if requested.

Thanks for any help...I've done lots of PHP code changes with SMF before and had a fix for Simple Portal and their blocks.

Chen Zhen

#1
Fog,

  Imo first you need to edit the language from monster to enemy to make it more appropriate for tanks. 

  So you wish to add a second input box beside the one you have pointed at for a max value and have it save that integer to the data base. Then for the game itself, if the user has a rated power level greater then the max value you want the enemy not to attack?

  I would prefer if the code you need edited was posted so I can show you examples of what needs to be done. Are you able to gather the bits of code from the templates and source files of this mod and post it? I do not mean all of the files but just the area of codes that need to be edited.
ie.

  • the code for the input box from the template file
  • the code from the source file for saving the existing input to the database
  • the code from the source file for battling the enemy/monster that checks the users power level

  Without this information you are asking me to install and peruse the mod whereas the mod author would know best. Has SA given up on its development and support?

Fog

I'm going to start with this one...Battle.Admin.php


<?phpif (!defined('SMF'))	die('Hacking attempt...');	function battleAdmin() { 	global $context, $sourcedir, $txt;		//require_once($sourcedir . '/ManageServer.php');	    //Set title and default sub-action.	loadTemplate('Battle_Admin');	//Load the language strings	loadLanguage('Battle');	//Are you allowed to administrate Battle?	isAllowedTo('admin_battle');    $context['page_title'] = $txt['battle_adminmmc'];			$context[$context['admin_menu_name']]['tab_data']['title'] = $txt['battle_adminmm'];	$context[$context['admin_menu_name']]['tab_data']['description'] = $txt['battle_adminmmd'];	$subActions = array(	    'main' => 'battle_main',		'config' => 'battle_settings',		'shop' => 'battle_shop',		'add_item' => 'battle_shop_add_edit',		'edit_item' => 'battle_shop_add_edit',		'save_item' => 'battle_shop_add_edit',		'shop_del' => 'battle_shop_item_delete',			'bmem' => 'battle_members',			'monsterlist' => 'battle_monsterlist',		'editm' => 'battle_monster',		'monster' => 'battle_monster',		'savemonster' => 'battle_monster',		'del' => 'battle_monster_delete',		'quest_edit' => 'battle_quest_add_edit',        'quest_save' => 'battle_quest_add_edit',	        'quest_add' => 'battle_quest_add_edit',			'quest' => 'battle_quest',			'quest_del' => 'battle_quest_delete',	        'custom' => 'battle_custom',	        'custom_del' => 'battle_cust_delete',	        'custom_edit' => 'battle_cust_add_edit',        'custom_save' => 'battle_cust_add_edit',	        'custom_add' => 'battle_cust_add_edit',	        'maintain' => 'battle_maintain',	        'reset' => 'battle_reset',	        'dshout' => 'battle_reset_shouts',	        'dhist' => 'battle_reset_hist',						);	$_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'main';	$subActions[$_REQUEST['sa']]();	}function battle_main(){}function battle_maintain(){global $txt, $context;$context['sub_template'] = 'maintain';$context['page_title'] = $txt['battle_tabaman'];	}function battle_reset_hist() {global  $smcFunc;$smcFunc['db_query']('', '		TRUNCATE {db_prefix}battle_history',			array());				redirectexit('action=admin;area=battle;sa=maintain;dhist=done');	}function battle_reset_shouts() {global  $smcFunc;$smcFunc['db_query']('', '		TRUNCATE {db_prefix}battle_shouts',			array());		   redirectexit('action=admin;area=battle;sa=maintain;dshout=done');		}function battle_reset(){global $db_prefix, $modSettings, $txt, $sourcedir, $smcFunc;	$smcFunc['db_query']('','UPDATE {db_prefix}members             SET 			 gold = {int:gold},			 hp = {int:hp},			 max_hp = {int:max_hp},			 atk = {int:atk},			 max_atk = {int:max_atk},			 def = {int:def},			 max_def = {int:max_def},			 energy = {int:energy},			 max_energy = {int:max_energy},			 stamina = {int:stamina},			 max_stamina = {int:max_stamina},			 level = {int:level},			 exp = {int:exp},			 max_exp = {int:max_exp},			 mon_slays = {int:mon_slays},			 mem_slays = {int:mem_slays},			 is_dead = {int:is_dead}',			array(				'gold' => $modSettings['battle_gold_reg'],				'hp' => $modSettings['battle_hp_reg'],				'max_hp' => $modSettings['battle_hp_max_reg'],				'atk' => $modSettings['battle_atk_reg'],				'max_atk' => $modSettings['battle_atk_max_reg'],				'def' => $modSettings['battle_def_reg'],				'max_def' => $modSettings['battle_def_max_reg'],				'energy' => $modSettings['battle_energy_reg'],				'max_energy' => $modSettings['battle_energy_max_reg'],				'stamina' => $modSettings['battle_stamina_reg'],				'max_stamina' => $modSettings['battle_stamina_max_reg'],				'level' => 0,				'exp' => 0,				'max_exp' => $modSettings['exp_bef_level'],				'mon_slays' => 0,				'mem_slays' => 0,				'is_dead' => 0,				)			);						// emtyp the quest history		$smcFunc['db_query']('', '		TRUNCATE {db_prefix}battle_quest_hist',			array());				//empty the grave yard		$smcFunc['db_query']('', '		TRUNCATE {db_prefix}battle_graveyard',			array());				//reset quest plays to zero		//make it a value between 1 and 0 checked = 1 		$_POST['is_final'] = isset($_POST['is_final'])? 1 : 0;		$smcFunc['db_query']('', '		UPDATE {db_prefix}battle_quest		SET 		plays = {int:play}',		array(			'play' => 0,		));		        if($modSettings['enable_battle_hist']) 	    {		require_once($sourcedir . '/Battle/Battle_Shouts.php');		$content = '<span class="error"><strong>'.$txt['battle_hist28'].'</strong></span>';        add_to_battle_hist($content);		}				    redirectexit('action=admin;area=battle;sa=maintain;reset=done');}function battle_cust_add_edit(){	global $smcFunc, $context, $txt;	isAllowedTo('admin_battle');	$context['cust']['id'] = !empty($_REQUEST['cust']) ? (int) $_REQUEST['cust'] : 0;	if (!empty($_POST['submit']))	{		checkSession();		$fields = array('outcome1', 'outcome1_reward', 'outcome1_action', 'outcome2', 'outcome2_reward', 'outcome2_action', 'start','price');		foreach ($fields as $field)		{			if (empty($_POST[$field]))				fatal_error($field . ' left empty!', false);			else				$_POST[$field] = $smcFunc['htmlspecialchars']($_POST[$field], ENT_QUOTES);		}		if (empty($context['cust']['id']))		{			$smcFunc['db_insert']('',				'{db_prefix}battle_explore',				array('outcome1' => 'string', 'outcome2' => 'string',	'outcome1_reward' => 'string', 'outcome2_reward' => 'string', 'outcome1_action' => 'string', 'outcome2_action' => 'string', 'start' => 'string', 'price' => 'string'),				array($_POST['outcome1'], $_POST['outcome2'], $_POST['outcome1_reward'], $_POST['outcome2_reward'], $_POST['outcome1_action'], $_POST['outcome2_action'], $_POST['start'], $_POST['price']),				array()			);		}		else		{			$smcFunc['db_query']('', '				UPDATE {db_prefix}battle_explore				SET					outcome1 = {string:outcome1},					outcome2 = {string:outcome2},					outcome1_reward = {string:outcome1_reward},					outcome2_reward = {string:outcome2_reward},					outcome1_action = {string:outcome1_action},				    outcome2_action = {string:outcome2_action},					start = {string:start},					price = {string:price}				WHERE id_explore = {int:id_cust}',			array(				'id_cust' => $context['cust']['id'],					'outcome1' => $_POST['outcome1'],					'outcome2' => $_POST['outcome2'],					'outcome1_reward' => $_POST['outcome1_reward'],					'outcome2_reward' => $_POST['outcome2_reward'],					'outcome1_action' => $_POST['outcome1_action'],					'outcome2_action' => $_POST['outcome2_action'],					'start' => $_POST['start'],					'price' => $_POST['price'],				)			);		}		redirectexit('action=admin;area=battle;sa=custom');	}	if (!empty($context['cust']['id']))	{		$request = $smcFunc['db_query']('', '			SELECT id_explore, outcome1, outcome1_reward, outcome2, outcome2_reward, outcome2_action, outcome1_action, start, price			FROM {db_prefix}battle_explore			WHERE id_explore = {int:id_cust}',			array(					'id_cust' => $context['cust']['id'],			)		);		while ($row = $smcFunc['db_fetch_assoc']($request))		{			$context['cust'] += array(				'id_explore' => $row['id_explore'],				'outcome1' => $row['outcome1'],				'outcome1_reward' => $row['outcome1_reward'],				'outcome2' => $row['outcome2'],				'outcome2_reward' => $row['outcome2_reward'],				'outcome2_action' => $row['outcome2_action'],				'outcome1_action' => $row['outcome1_action'],				'start' => $row['start'],				'price' => $row['price']			);		}		$smcFunc['db_free_result']($request);	}	else	{		$context['cust'] += array(		        'id_explore' => '',				'outcome1' => '',				'outcome2' => '',				'outcome1_reward' => '',				'outcome2_reward' => '',				'outcome1_action' => '',				'outcome2_action'=> '',				'start' => '',				'price' => '',		);	}	$context['sub_template'] = 'custEdit_Add';	$context['page_title'] = $txt['battle_ce'];	}function battle_cust_delete(){global $smcFunc;	$cust_id = !empty($_REQUEST['cust']) ? (int) $_REQUEST['cust'] : 0;	   $smcFunc['db_query']('', '		DELETE FROM {db_prefix}battle_explore		WHERE id_explore = {int:q_id}',	array(		'q_id' => $cust_id,	));			redirectexit('action=admin;area=battle;sa=custom');	}function battle_custom(){	global $context, $txt, $smcFunc, $scripturl;			$context['page_title'] = 'Custom Actions';	$context['sub_template'] = 'battle_custom';    $context['battle_cust'] = array();		$request = $smcFunc['db_query']('', '		SELECT COUNT(*)		FROM {db_prefix}battle_explore',			array());	list ($quest) = $smcFunc['db_fetch_row']($request);	$smcFunc['db_free_result']($request);		// Now create the page index.	$context['page_index'] = constructPageIndex($scripturl . '?action=admin;area=battle;sa=custom;sort=' . $_REQUEST['start'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $quest, 10);	$context['start'] = $_REQUEST['start'];				$request = $smcFunc['db_query']('', '			SELECT id_explore, start			FROM {db_prefix}battle_explore			ORDER BY id_explore DESC			LIMIT {int:start}, 10',			array(				'start' => $context['start'],							)		);		// Loop through all results	while ($row = $smcFunc['db_fetch_assoc']($request))			// And add them to the list			$context['battle_cust'][] = array(				'id_explore' => $row['id_explore'],				'start' => $row['start']				);					$smcFunc['db_free_result']($request);		}function battle_quest(){	global $context, $txt, $smcFunc, $scripturl;			$context['page_title'] = $txt['battle_Quest'];	$context['sub_template'] = 'battle_quest';    $context['battle_quest'] = array();		$request = $smcFunc['db_query']('', '		SELECT COUNT(*)		FROM {db_prefix}battle_quest',			array());	list ($quest) = $smcFunc['db_fetch_row']($request);	$smcFunc['db_free_result']($request);		// Now create the page index.	$context['page_index'] = constructPageIndex($scripturl . '?action=admin;area=battle;sa=quest;sort=' . $_REQUEST['start'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $quest, 10);	$context['start'] = $_REQUEST['start'];				$request = $smcFunc['db_query']('', '			SELECT b.id_quest, b.gold, b.itext, b.stext, b.ftext, b.stext, b.exp, b.level,			b.success, b.name, b.plays, b.energy			FROM {db_prefix}battle_quest AS b			ORDER BY id_quest DESC			LIMIT {int:start}, 10',			array(				'start' => $context['start'],							)		);		// Loop through all results	while ($row = $smcFunc['db_fetch_assoc']($request))			// And add them to the list			$context['battle_quest'][] = array(				'id_quest' => $row['id_quest'],				'name' => $row['name'],				'itext' => $row['itext'],				'ftext' => $row['ftext'],				'stext' => $row['stext'],				'exp' => $row['exp'],				'level' => $row['level'],				'success' => $row['success'],				'gold' => $row['gold'],				'plays' => $row['plays'],				'energy' => $row['energy']				);					$smcFunc['db_free_result']($request);		}function battle_quest_delete(){// Gotta global it other wise thing dont work properlyglobal $smcFunc;	$quest_id = !empty($_REQUEST['quest']) ? (int) $_REQUEST['quest'] : 0;	   $smcFunc['db_query']('', '		DELETE FROM {db_prefix}battle_quest		WHERE id_quest = {int:q_id}',	array(		'q_id' => $quest_id,	));			redirectexit('action=admin;area=battle;sa=quest');	}function battle_quest_add_edit(){	global $smcFunc, $context, $txt;	isAllowedTo('admin_battle');	$context['quest']['id'] = !empty($_REQUEST['quest']) ? (int) $_REQUEST['quest'] : 0;	if (!empty($_POST['submit']))	{		checkSession();		$fields = array('name', 'gold', 'itext', 'stext', 'ftext','exp', 'energy', 'success');		foreach ($fields as $field)		{			if (empty($_POST[$field]))				fatal_error($field . ' left empty!', false);			else				$_POST[$field] = $smcFunc['htmlspecialchars']($_POST[$field], ENT_QUOTES);		}// Make it a value between 1 and 0 checked = 1 		$_POST['is_final'] = isset($_POST['is_final'])? 1 : 0;		if (empty($context['quest']['id']))		{			$smcFunc['db_insert']('',				'{db_prefix}battle_quest',				array('name' => 'string', 'gold' => 'string',	'itext' => 'string', 'stext' => 'string', 'ftext' => 'string', 'exp' => 'string', 'energy' => 'string', 'success' => 'string', 'level' => 'string', 'is_final' => 'string'),				array($_POST['name'], $_POST['gold'], $_POST['itext'], $_POST['stext'], $_POST['ftext'], $_POST['exp'], $_POST['energy'], $_POST['success'], $_POST['level'], $_POST['is_final']),				array()			);		}		else		{			$smcFunc['db_query']('', '				UPDATE {db_prefix}battle_quest				SET					name = {string:name},					gold = {string:gold},					itext = {string:itext},					stext = {string:stext},					ftext = {string:ftext},					exp = {string:exp},					energy = {string:energy},					success = {string:success},					level = {string:level},					is_final = {int:is_final}				WHERE id_quest = {int:id_quest}',			array(				'id_quest' => $context['quest']['id'],					'name' => $_POST['name'],					'gold' => $_POST['gold'],					'itext' => $_POST['itext'],					'stext' => $_POST['stext'],					'ftext' => $_POST['ftext'],					'exp' => $_POST['exp'],					'energy' => $_POST['energy'],					'success' => $_POST['success'],					'level' => $_POST['level'],					'is_final' => $_POST['is_final'],				)			);		}		redirectexit('action=admin;area=battle;sa=quest');	}	if (!empty($context['quest']['id']))	{		$request = $smcFunc['db_query']('', '			SELECT b.id_quest, b.gold, b.itext, b.stext, b.ftext, b.stext, 			b.exp, b.level, b.success, b.name, b.plays, b.energy, b.is_final			FROM {db_prefix}battle_quest AS b			WHERE id_quest = {int:id_quest}',			array(					'id_quest' => $context['quest']['id'],			)		);		while ($row = $smcFunc['db_fetch_assoc']($request))		{			$context['quest'] += array(				'id_quest' => $row['id_quest'],				'name' => $row['name'],				'itext' => $row['itext'],				'ftext' => $row['ftext'],				'stext' => $row['stext'],				'exp' => $row['exp'],				'level' => $row['level'],				'success' => $row['success'],				'gold' => $row['gold'],				'plays' => $row['plays'],				'energy' => $row['energy'],				'is_final' => $row['is_final'],			);		}		$smcFunc['db_free_result']($request);	}	else	{		$context['quest'] += array(		        'id_quest' => '',				'name' => '',				'itext' => '',				'ftext' => '',				'stext' => '',				'exp' => '',				'level'=> '',				'success' => '',				'gold' => '',				'plays' => '',				'energy' => '',				'is_final' => '',		);	}	$context['sub_template'] = 'questEdit_Add';	$context['page_title'] = $txt['battle_Quest'];	}function battle_monster(){	global $smcFunc, $context, $txt;	isAllowedTo('admin_forum');	$context['monster']['id'] = !empty($_REQUEST['monster']) ? (int) $_REQUEST['monster'] : 0;	if (!empty($_POST['submit']))	{		checkSession();		$fields = array('atk', 'def', 'name', 'hp', 'img', 'max_hp','mon_range');		foreach ($fields as $field)		{			if (empty($_POST[$field]))			fatal_error($field . ' left empty!', false);		else			$_POST[$field] = $smcFunc['htmlspecialchars']($_POST[$field], ENT_QUOTES);		}		if (empty($context['monster']['id']))		{			$smcFunc['db_insert']('',				'{db_prefix}battle_monsters',				array('atk' => 'string', 'def' => 'string', 'name' => 'string', 'hp' => 'string', 'img' => 'string', 'max_hp' => 'string', 'mon_range' => 'string'),				array($_POST['atk'], $_POST['def'], $_POST['name'], $_POST['hp'], $_POST['img'], $_POST['max_hp'], $_POST['mon_range']),				array()			);		}		else		{			$smcFunc['db_query']('', '				UPDATE {db_prefix}battle_monsters				SET				name = {string:name},				atk = {string:atk},				def = {string:def},				hp = {string:hp},				img = {string:img},				max_hp = {string:max_hp},				mon_range = {string:mon_range}				WHERE id_monster = {int:id_monster}',				array(				'id_monster' => $context['monster']['id'],				'name' => $_POST['name'],				'atk' => $_POST['atk'],				'def' => $_POST['def'],				'hp' => $_POST['hp'],				'img' => $_POST['img'],				'max_hp' => $_POST['max_hp'],				'mon_range' => $_POST['mon_range'],				)			);		}	redirectexit('action=admin;area=battle;sa=monsterlist');	} if (!empty($context['monster']['id'])) {	$request = $smcFunc['db_query']('', '	SELECT name, atk, def, hp, img, max_hp, mon_range	FROM {db_prefix}battle_monsters	WHERE id_monster = {int:id_monster}',	array(		'id_monster' => $context['monster']['id'],	));  while ($row = $smcFunc['db_fetch_assoc']($request))  {	$context['monster'] += array(	'name' => $row['name'],    'atk' => $row['atk'],    'def' => $row['def'],    'hp' => $row['hp'],    'img' => $row['img'],    'max_hp' => $row['max_hp'],    'mon_range' => $row['mon_range'],   );  }  $smcFunc['db_free_result']($request); } else {	$context['monster'] += array(   'name' => '',   'atk' => '',   'def' => '',   'hp' => '',   'img' => '',   'max_hp' => '',   'mon_range' => '',  ); } $context['sub_template'] = 'monsterEdit_Add'; $context['page_title'] = $txt['battle_monsters'];}function getImageList(){	global $settings;	// Start with an empty array	$imageList = array();	// Try to open the images directory		if ($handle = opendir($settings['default_theme_dir'] . '/' . basename($settings['default_images_url']) . '/battle/monsters'))	{		// For each file in the directory...		while (false !== ($file = readdir($handle)))		{			// ...if it's a valid file, add it to the list			if (!in_array($file, array('.', '..', 'blank.gif')))				$imageList[] = $file;		}		// Sort the list		sort($imageList);		return $imageList;	}	// Otherwise, if directory inaccessible, show an error	else	{		fatal_lang_error('cannot_open_images');	}}function battle_monster_delete(){global $smcFunc, $txt;	$monster_id = !empty($_REQUEST['monster']) ? (int) $_REQUEST['monster'] : 0;	if (empty($monster_id))fatal_error($txt['battle_nomon'], false);	   $smcFunc['db_query']('', '		DELETE FROM {db_prefix}battle_monsters		WHERE id_monster = {int:mon_id}',	array(		'mon_id' => $monster_id,	));			redirectexit('action=admin;area=battle;sa=monsterlist');	}function battle_monsterlist() {// Must global it otherwise we get erros   global $smcFunc, $scripturl, $txt, $request, $context;  $context['sub_template'] = 'battle_admin_monsters'; $context['page_title'] = $txt['battle_monsters'];	 	// Get the total amount of entries.	$request = $smcFunc['db_query']('', '		SELECT COUNT(*)		FROM {db_prefix}battle_monsters',			array(						)		);	list ($totalmonsters) = $smcFunc['db_fetch_row']($request);	$smcFunc['db_free_result']($request);			// Create the page index.	$context['page_index'] = constructPageIndex($scripturl . '?action=admin;area=battle;sa=monsterlist;sort=' . $_REQUEST['start'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $totalmonsters, 10);	$context['start'] = $_REQUEST['start'];		// Get the data.	$request = $smcFunc['db_query']('', '		SELECT id_monster, atk, def, hp, name, img, max_hp		FROM {db_prefix}battle_monsters		ORDER BY atk DESC		LIMIT {int:start}, 10',			array(				'start' => $context['start'],			)		);	// Set the value of the callback function.	$context['get_monsters'] = 'getmonstersEntry';}function getmonstersEntry($reset = false){	// Gotta global it other wise thing dont work properly	global $smcFunc, $request;	if ($request == false)		return false;	if (!($row = $smcFunc['db_fetch_assoc']($request)))		return false;	$output = array(		'id_monster' => $row['id_monster'],		'name' => $row['name'],		'atk' => $row['atk'],		'def' => $row['def'],		'hp' => $row['hp'],		'img' => $row['img'],		'max_hp' => $row['max_hp'],				);	return $output;		}function battle_shop_item_delete(){global $smcFunc;	$item_id = !empty($_REQUEST['item']) ? (int) $_REQUEST['item'] : 0;	if (empty($item_id))fatal_error('No Item Selected', false);	   $smcFunc['db_query']('', '		DELETE FROM {db_prefix}battle_shop		WHERE id_item = {int:item_id}',	array(		'item_id' => $item_id,	));			redirectexit('action=admin;area=battle;sa=shop');	}function battle_shop_add_edit(){global $smcFunc, $context, $txt;	isAllowedTo('admin_battle');	$context['item']['id'] = !empty($_REQUEST['item']) ? (int) $_REQUEST['item'] : 0;	if (!empty($_POST['submit']))	{		checkSession();		$fields = array('name', 'price', 'act', 'img', 'description', 'amount');		foreach ($fields as $field)		{			if (empty($_POST[$field]))				fatal_error($field . ' left empty!', false);			else				$_POST[$field] = $smcFunc['htmlspecialchars']($_POST[$field], ENT_QUOTES);		}		if (empty($context['item']['id']))		{			$smcFunc['db_insert']('',				'{db_prefix}battle_shop',				array('name' => 'string', 'price' => 'int',	'action' => 'string', 'img' => 'string', 'description' => 'string', 'amount' => 'int'),				array($_POST['name'], $_POST['price'], $_POST['act'], $_POST['img'], $_POST['description'], $_POST['amount']),				array()			);		}		else		{			$smcFunc['db_query']('', '				UPDATE {db_prefix}battle_shop				SET					name = {string:name},					price = {int:price},					action = {string:action},					img = {string:img},					description = {string:description},					amount = {int:amount}				WHERE id_item = {int:id_item}',			array(				'id_item' => $context['item']['id'],					'name' => $_POST['name'],					'price' => $_POST['price'],					'action' => $_POST['act'],					'img' => $_POST['img'],					'description' => $_POST['description'],					'amount' => $_POST['amount'],				)			);		}		redirectexit('action=admin;area=battle;sa=shop');	}	if (!empty($context['item']['id']))	{		$request = $smcFunc['db_query']('', '		SELECT id_item, name, price, action, img, description, amount		FROM {db_prefix}battle_shop			WHERE id_item = {int:id_item}',			array(					'id_item' => $context['item']['id'],			)		);		while ($row = $smcFunc['db_fetch_assoc']($request))		{			$context['item'] += array(				'id_item' => $row['id_item'],				'name' => $row['name'],				'price' => $row['price'],				'action' => $row['action'],				'img' => $row['img'],				'description' => $row['description'],				'amount' => $row['amount'],							);		}		$smcFunc['db_free_result']($request);	}	else	{		$context['item'] += array(		        'id_item' => '',				'name' => '',				'price' => '',				'action' => '',				'img' => '',				'description' => '',				'amount'=> '',		);	}	$context['sub_template'] = 'shopEdit_Add';	$context['page_title'] = $txt['battle_shop_item'];	}function getshopImageList(){	global $settings;	// Start with an empty array	$imageList = array();	// Try to open the images directory		if ($handle = opendir($settings['default_theme_dir'] . '/' . basename($settings['default_images_url']) . '/battle/shop'))	{		// For each file in the directory...		while (false !== ($file = readdir($handle)))		{			// ...if it's a valid file, add it to the list			if (!in_array($file, array('.', '..', 'blank.gif')))				$imageList[] = $file;		}		// Sort the list		sort($imageList);		return $imageList;	}	// Otherwise, if directory inaccessible, show an error	else	{		fatal_lang_error('cannot_open_images');	}}function battle_shop(){global  $smcFunc, $scripturl, $txt, $context;$context['sub_template'] = 'battle_shop';$context['page_title'] = $txt['battle_shop_item'];	$context['shop'] = array();  		$request = $smcFunc['db_query']('', '		SELECT COUNT(*)		FROM {db_prefix}battle_shop',			array(							)		);	list ($shop) = $smcFunc['db_fetch_row']($request);	$smcFunc['db_free_result']($request);		// Now create the page index.	$context['page_index'] = constructPageIndex($scripturl . '?action=admin;area=battle;sa=shop;sort=' . $_REQUEST['start'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $shop, 10);	$context['start'] = $_REQUEST['start'];	  		$battleQ = $smcFunc['db_query']('', '				SELECT id_item, name, price, action, img, description, amount				FROM {db_prefix}battle_shop				LIMIT {int:start}, 10',			array(				'start' => $context['start'],							)		);				while ($row = $smcFunc['db_fetch_assoc']($battleQ))			// And add them to the list			$context['shop'][] = array(				'id_item' => $row['id_item'],				'name' => $row['name'],				'price' => $row['price'],				'action' => $row['action'],				'img' => $row['img'],				'amount' => $row['amount'],				'description' => $row['description'],			);					$smcFunc['db_free_result']($battleQ);}function battle_settings($return_config = false){    // Must global it otherwise we get erros	global $txt, $scripturl, $context, $sourcedir, $modSettings;		// We need this 	require_once($sourcedir.'/ManageServer.php');	$context['sub_template'] = 'show_settings';	$txt['battle_add_amount'] = sprintf($txt['battle_add_amount'],$modSettings['battle_time']);	$config_vars = array(		array('check', 'enable_battle'),		array('check', 'enable_img_menu'),		array('check', 'enable_battle_shoutbox'),		array('check', 'enable_show_who_battle'),		array('check', 'enable_battle_hist'),		array('check', 'enable_sts_post'),		array('check', 'enable_sts_pm'),		array('check', 'enable_sts_profile'),		//'',		array('text', 'bcash'),		'',			array('int', 'battle_map_across'),		array('int', 'battle_map_down'),		'',		array('int', 'exp_bef_level'),		array('int', 'exp_stat_level'),		'',		array('int', 'exp_def_mem'),		array('int', 'exp_def_mon'),		'',		array('int', 'battle_time'),		array('int', 'battle_add_amount'),		'',		array('int', 'battle_how_much_reviv_user'),		array('int', 'battle_how_much_hp'),		'',		array('int', 'battle_gold_reg'),		array('int', 'battle_hp_reg'),		array('int', 'battle_hp_max_reg'),		array('int', 'battle_atk_reg'),		array('int', 'battle_atk_max_reg'),		array('int', 'battle_def_reg'),		array('int', 'battle_def_max_reg'),		array('int', 'battle_energy_reg'),		array('int', 'battle_energy_max_reg'),		array('int', 'battle_stamina_reg'),		array('int', 'battle_stamina_max_reg'),		);		if (isset($_GET['save']))	{		saveDBSettings($config_vars);		redirectexit('action=admin;area=battle;sa=config');	}	$context['post_url'] = $scripturl .'?action=admin;area=battle;save;sa=config';	$context['settings_title'] = $txt['battle_config'];	prepareDBSettingContext($config_vars);	}function battle_members() {	global 	$context, $smcFunc, $b, $txt, $userid;		$context['sub_template'] = 'bmembers';	$context['page_title'] = $txt['battle_mem'];	$_POST['thename'] = !empty($_POST['thename']) ? $smcFunc['htmlspecialchars']($_POST['thename'], ENT_QUOTES) : '';		if(isset($_REQUEST['next']) && isset($_POST['thename']))	{		$userid = battle_UserId($_POST['thename']);		if(!isset($userid)) 		{			$b['b_message'] = $txt['battle_mem_error'];		}	}	if(isset($_REQUEST['update']))	{		//check the users session		checkSession();		$cash = !empty($_POST['cash']) ? (int) $_POST['cash'] : 0;		$atk = !empty($_POST['atk']) ? (int) $_POST['atk'] : 0;		$def = !empty($_POST['def']) ? (int) $_POST['def'] : 0;		$stam = !empty($_POST['stam']) ? (int) $_POST['stam'] : 0;		$max_stam = !empty($_POST['max_stam']) ? (int) $_POST['max_stam'] : 0;		$hp = !empty($_POST['hp']) ? (int) $_POST['hp'] : 0;		$max_hp = !empty($_POST['max_hp']) ? (int) $_POST['max_hp'] : 0;		$energy = !empty($_POST['energy']) ? (int) $_POST['energy'] : 0;		$level = !empty($_POST['level']) ? (int) $_POST['level'] : 0;		$exp = !empty($_POST['exp']) ? (int) $_POST['exp'] : 0;		$max_land = !empty($_POST['max_land']) ? (int) $_POST['max_land'] : 0;		$max_atk = !empty($_POST['max_atk']) ? (int) $_POST['max_atk'] : 0;		$max_def = !empty($_POST['max_def']) ? (int) $_POST['max_def'] : 0;		$max_energy = !empty($_POST['max_energy']) ? (int) $_POST['max_energy'] : 0;		$userid = $_POST['thename'];		battle_do_gold($userid, $cash);		battle_do_atk($userid, $atk);		battle_do_def($userid, $def);		battle_do_hp($userid, $hp);		battle_do_max_hp($userid, $max_hp);		battle_do_level($userid, $level);		battle_do_exp($userid, $exp);		battle_do_max_atk($userid, $max_atk);		battle_do_max_def($userid, $max_def);		battle_do_stam($userid, $stam);		battle_do_max_stam($userid, $max_stam);		battle_do_energy($userid, $energy);		battle_do_max_energy($userid, $max_energy);	}}function battle_do_stam($userid, $stam) {	updateMemberData($userid, array('stamina' => $stam));		}function battle_do_energy($userid, $energy) {	updateMemberData($userid, array('energy' => $energy));		}function battle_do_max_energy($userid, $max_energy) {	updateMemberData($userid, array('max_energy' => $max_energy));		}function battle_do_max_stam($userid, $max_stam) {	updateMemberData($userid, array('max_stamina' => $max_stam));		}		function battle_do_max_def($userid, $max_def) {updateMemberData($userid, array('max_def' => $max_def));		}function battle_do_max_atk($userid, $max_atk) {	updateMemberData($userid, array('max_atk' => $max_atk));		}function battle_do_exp($userid, $exp) {	updateMemberData($userid, array('exp' => $exp));		}function battle_do_level($userid, $level) {updateMemberData($userid, array('level' => $level));		}		function battle_do_hp($userid, $hp) {updateMemberData($userid, array('hp' => $hp));		}function battle_do_max_hp($userid, $max_hp) {updateMemberData($userid, array('max_hp' => $max_hp));	}function battle_do_def($userid, $def) {updateMemberData($userid, array('def' => $def));	}function battle_do_gold($userid, $cash) {global $modSettings;	updateMemberData($userid, array($modSettings['bcash'] => $cash));		}function battle_do_atk($userid, $atk) {updateMemberData($userid, array('atk' => $atk));}function battle_UserId($nameid) {	global $smcFunc;	$result = $smcFunc['db_query']('','		SELECT id_member		FROM {db_prefix}members		WHERE member_name = {string:nameid}		LIMIT 1',			array(			'nameid' => $nameid,				)			);;	$row =  $smcFunc['db_fetch_assoc']($result);	$smcFunc['db_free_result']($result);	return $row['id_member'];}function battle_gold($userid) {	global $modSettings, $smcFunc;		$result = $smcFunc['db_query']('', '				SELECT {raw:cash} 				FROM {db_prefix}members 				WHERE id_member = {int:userid}				LIMIT 1',			array(			'userid' => $userid,			'cash' => $modSettings['bcash'],				)			);	$row = $smcFunc['db_fetch_assoc']($result);	$smcFunc['db_free_result']($result);	return $row[$modSettings['bcash']];}function battle_atk($userid) {	global $smcFunc;		$result = $smcFunc['db_query']('', '				SELECT atk 				FROM {db_prefix}members 				WHERE id_member = {int:userid}				LIMIT 1',			array(			'userid' => $userid,				)			);	$row = $smcFunc['db_fetch_assoc']($result);	$smcFunc['db_free_result']($result);	return $row['atk'];}function battle_max_atk($userid) {	global $smcFunc;		$result = $smcFunc['db_query']('', '				SELECT max_atk 				FROM {db_prefix}members 				WHERE id_member = {int:userid}				LIMIT 1',			array(			'userid' => $userid,				)			);	$row = $smcFunc['db_fetch_assoc']($result);	$smcFunc['db_free_result']($result);	return $row['max_atk'];}function battle_max_def($userid) {	global $smcFunc;		$result = $smcFunc['db_query']('', '				SELECT max_def								FROM {db_prefix}members 				WHERE id_member = {int:userid}				LIMIT 1',			array(			'userid' => $userid,				)			);	$row = $smcFunc['db_fetch_assoc']($result);	$smcFunc['db_free_result']($result);	return $row['max_def'];}function battle_def($userid) {	global $smcFunc;		$result = $smcFunc['db_query']('', '				SELECT def								FROM {db_prefix}members 				WHERE id_member = {int:userid}				LIMIT 1',			array(			'userid' => $userid,				)			);	$row = $smcFunc['db_fetch_assoc']($result);	$smcFunc['db_free_result']($result);	return $row['def'];}function battle_energy($userid) {	global $smcFunc;		$result = $smcFunc['db_query']('', '				SELECT energy								FROM {db_prefix}members 				WHERE id_member = {int:userid}				LIMIT 1',			array(			'userid' => $userid,				)			);	$row = $smcFunc['db_fetch_assoc']($result);	$smcFunc['db_free_result']($result);	return $row['energy'];}function battle_max_energy($userid) {	global $smcFunc;		$result = $smcFunc['db_query']('', '				SELECT max_energy								FROM {db_prefix}members 				WHERE id_member = {int:userid}				LIMIT 1',			array(			'userid' => $userid,				)			);	$row = $smcFunc['db_fetch_assoc']($result);	$smcFunc['db_free_result']($result);	return $row['max_energy'];}function battle_stamina($userid) {	global $smcFunc;		$result = $smcFunc['db_query']('', '				SELECT stamina								FROM {db_prefix}members 				WHERE id_member = {int:userid}				LIMIT 1',			array(			'userid' => $userid,				)			);	$row = $smcFunc['db_fetch_assoc']($result);	$smcFunc['db_free_result']($result);	return $row['stamina'];}function battle_max_stamina($userid) {	global $smcFunc;		$result = $smcFunc['db_query']('', '				SELECT max_stamina								FROM {db_prefix}members 				WHERE id_member = {int:userid}				LIMIT 1',			array(			'userid' => $userid,				)			);	$row = $smcFunc['db_fetch_assoc']($result);	$smcFunc['db_free_result']($result);	return $row['max_stamina'];}function battle_hp($userid) {	global $smcFunc;		$result = $smcFunc['db_query']('', '				SELECT hp								FROM {db_prefix}members 				WHERE id_member = {int:userid}				LIMIT 1',			array(			'userid' => $userid,				)			);	$row = $smcFunc['db_fetch_assoc']($result);	$smcFunc['db_free_result']($result);	return $row['hp'];}function battle_max_hp($userid) {	global $smcFunc;		$result = $smcFunc['db_query']('', '				SELECT max_hp							FROM {db_prefix}members 				WHERE id_member = {int:userid}				LIMIT 1',			array(			'userid' => $userid,				)			);	$row = $smcFunc['db_fetch_assoc']($result);	$smcFunc['db_free_result']($result);	return $row['max_hp'];}function battle_level($userid) {	global $smcFunc;		$result = $smcFunc['db_query']('', '				SELECT level								FROM {db_prefix}members 				WHERE id_member = {int:userid}				LIMIT 1',			array(			'userid' => $userid,				)			);	$row = $smcFunc['db_fetch_assoc']($result);	$smcFunc['db_free_result']($result);	return $row['level'];}?>

Fog

I've edited a bit of text to reflect Tanks instead of tanks on my site...I struggle to keep from typing Tanks instead of Monsters...LOL


Chen Zhen

#4
Fog,

  I asked for the part of the code that is needed for edit & not the whole file. You should have just posted the function for editing monsters/enemies from that file.

This is the function you need to edit:

function battle_monster()

{

   global $smcFunc, $context, $txt;

   isAllowedTo('admin_forum');

   $context['monster']['id'] = !empty($_REQUEST['monster']) ? (int) $_REQUEST['monster'] : 0;

   if (!empty($_POST['submit']))

   {

      checkSession();

      $fields = array('atk', 'def', 'name', 'hp', 'img', 'max_hp','mon_range');

      foreach ($fields as $field)

      {

         if (empty($_POST[$field]))

         fatal_error($field . ' left empty!', false);

      else

         $_POST[$field] = $smcFunc['htmlspecialchars']($_POST[$field], ENT_QUOTES);

      }

      if (empty($context['monster']['id']))

      {

         $smcFunc['db_insert']('',

            '{db_prefix}battle_monsters',

            array('atk' => 'string', 'def' => 'string', 'name' => 'string', 'hp' => 'string', 'img' => 'string', 'max_hp' => 'string', 'mon_range' => 'string'),

            array($_POST['atk'], $_POST['def'], $_POST['name'], $_POST['hp'], $_POST['img'], $_POST['max_hp'], $_POST['mon_range']),

            array()

         );

      }

      else

      {

         $smcFunc['db_query']('', '

            UPDATE {db_prefix}battle_monsters

            SET

            name = {string:name},

            atk = {string:atk},

            def = {string:def},

            hp = {string:hp},

            img = {string:img},

            max_hp = {string:max_hp},

            mon_range = {string:mon_range}

            WHERE id_monster = {int:id_monster}',

            array(

            'id_monster' => $context['monster']['id'],

            'name' => $_POST['name'],

            'atk' => $_POST['atk'],

            'def' => $_POST['def'],

            'hp' => $_POST['hp'],

            'img' => $_POST['img'],

            'max_hp' => $_POST['max_hp'],

            'mon_range' => $_POST['mon_range'],

            )

         );

      }

   redirectexit('action=admin;area=battle;sa=monsterlist');

   }

if (!empty($context['monster']['id']))

{

   $request = $smcFunc['db_query']('', '

   SELECT name, atk, def, hp, img, max_hp, mon_range

   FROM {db_prefix}battle_monsters

   WHERE id_monster = {int:id_monster}',

   array(

      'id_monster' => $context['monster']['id'],

   )

);

  while ($row = $smcFunc['db_fetch_assoc']($request))

  {

   $context['monster'] += array(

   'name' => $row['name'],

    'atk' => $row['atk'],

    'def' => $row['def'],

    'hp' => $row['hp'],

    'img' => $row['img'],

    'max_hp' => $row['max_hp'],

    'mon_range' => $row['mon_range'],

   );

  }

  $smcFunc['db_free_result']($request);

}

else

{

   $context['monster'] += array(

   'name' => '',

   'atk' => '',

   'def' => '',

   'hp' => '',

   'img' => '',

   'max_hp' => '',

   'mon_range' => '',

  );

}

$context['sub_template'] = 'monsterEdit_Add';

$context['page_title'] = $txt['battle_monsters'];

}







I need the admin template code before you can commence the following edits to that function...


function battle_monster()

{

   global $smcFunc, $context, $txt;

   isAllowedTo('admin_forum');

   $context['monster']['id'] = !empty($_REQUEST['monster']) ? (int) $_REQUEST['monster'] : 0;

   if (!empty($_POST['submit']))

   {

      checkSession();

      $fields = array('atk', 'def', 'name', 'hp', 'img', 'max_hp','mon_range', 'mon_max_range');

      foreach ($fields as $field)

      {

         if (empty($_POST[$field]))

         fatal_error($field . ' left empty!', false);

      else

         $_POST[$field] = $smcFunc['htmlspecialchars']($_POST[$field], ENT_QUOTES);

      }

      if (empty($context['monster']['id']))

      {

         $smcFunc['db_insert']('',

            '{db_prefix}battle_monsters',

            array('atk' => 'string', 'def' => 'string', 'name' => 'string', 'hp' => 'string', 'img' => 'string', 'max_hp' => 'string', 'mon_range' => 'string', 'mon_max_range' => 'int'),

            array($_POST['atk'], $_POST['def'], $_POST['name'], $_POST['hp'], $_POST['img'], $_POST['max_hp'], $_POST['mon_range'], $_POST['mon_max_range']),

            array()

         );

      }

      else

      {

         $smcFunc['db_query']('', '

            UPDATE {db_prefix}battle_monsters

            SET

            name = {string:name},

            atk = {string:atk},

            def = {string:def},

            hp = {string:hp},

            img = {string:img},

            max_hp = {string:max_hp},

            mon_range = {string:mon_range},
           
            mon_max_range = {int:mon_max_range}

            WHERE id_monster = {int:id_monster}',

            array(

            'id_monster' => $context['monster']['id'],

            'name' => $_POST['name'],

            'atk' => $_POST['atk'],

            'def' => $_POST['def'],

            'hp' => $_POST['hp'],

            'img' => $_POST['img'],

            'max_hp' => $_POST['max_hp'],

            'mon_range' => $_POST['mon_range'],
           
            'mon_max_range' => $_POST['mon_max_range'],

            )

         );

      }

   redirectexit('action=admin;area=battle;sa=monsterlist');

   }

if (!empty($context['monster']['id']))

{

   $request = $smcFunc['db_query']('', '

   SELECT name, atk, def, hp, img, max_hp, mon_range, mon_max_range

   FROM {db_prefix}battle_monsters

   WHERE id_monster = {int:id_monster}',

   array(

      'id_monster' => $context['monster']['id'],

   )

);

  while ($row = $smcFunc['db_fetch_assoc']($request))

  {

   $context['monster'] += array(

   'name' => $row['name'],

    'atk' => $row['atk'],

    'def' => $row['def'],

    'hp' => $row['hp'],

    'img' => $row['img'],

    'max_hp' => $row['max_hp'],

    'mon_range' => $row['mon_range'],
   
    'mon_max_range' => $row['mon_max_range'],

   );

  }

  $smcFunc['db_free_result']($request);

}

else

{

   $context['monster'] += array(

   'name' => '',

   'atk' => '',

   'def' => '',

   'hp' => '',

   'img' => '',

   'max_hp' => '',

   'mon_range' => '',
   
   'mon_max_range' => '',

  );

}

$context['sub_template'] = 'monsterEdit_Add';

$context['page_title'] = $txt['battle_monsters'];

}


  Without the admin template that displays the input boxes you may get an error therefore I need you to post that part of the admin template.  Also I need to see the part of code for the install that creates the tables & columns because you now need to create an int(10) column in the battle_monsters table named mon_max_range unless you want to create that manually.


Fog

Thanks Underdog...I'll work on that when I get home from work.

Chen Zhen

#6
These are the steps you need to take to accomplish your task:


  • Installation: Add int(10) mon_max_range to battle_monsters table
  • Add settings for manipulating mon_max_range column in source file (shown in last post)
  • Add input to the form in that mods admin template for mon_max_range value
  • Adjust source file appropriately for battling/meeting enemies/monsters

Step 2 is shown above and you need to apply the others.

I see you are having issues when attempting to attach files. This is due to the free hosting environment used here on this site.
Simply follow the instructions from this link to accomplish that: http://webdevelop.comli.com/index.php?topic=4.msg44#msg44
It will allow up to 50MB per file which Imo is more than enough for website files.

Fog

I got the battle admin template modified with another input field...

I manually enters a new table on my DB.

But I haven't been able to link them together...I'm guessing thats where step two is important.

Fog

Here's the install part

$smcFunc['db_add_column']('{db_prefix}battle_monsters',
array(
'name' => 'mon_range',
'type' => 'varchar',
'size' => '255',
'null' => false
)
);

Chen Zhen

#9
Fog,

Here is the admin template code. I fixed up the html a bit as it was broken (errors). I am not sure if it looks proper atm as I am not able to test it.


function template_monsterEdit_Add()
{
global $context, $scripturl, $settings, $txt;

$context['battle_images'] = getImageList();

echo '
<form action="', $scripturl, '?action=admin;area=battle;save;sa=savemonster" method="post" name="theAdminForm" accept-charset="', $context['character_set'], '">
<table border="0" width="80%" align="center" cellspacing="1" cellpadding="3" class="tborder windowbg2">
<tr class="titlebg">
<td>'.$txt['battle_monsters'].'</td>
</tr>
<tr>
<td style="text-align: right;">'.$txt['battle_monsters_name'].'</td>
<td><input type="text" name="name" value="', $context['monster']['name'], '" /></td>
</tr>
<tr>
<td style="text-align: right;">'.$txt['battle_monsters_atk'].'</td>
<td><input type="text" name="atk" value="', $context['monster']['atk'], '" /></td>
</tr>
<tr>
<td style="text-align: right;">'.$txt['battle_monsters_def'].'</td>
<td><input type="text" name="def" value="', $context['monster']['def'], '" /></td>
</tr>
<tr>
<td style="text-align: right;">'.$txt['battle_monsters_hp'].'</td>
<td><input type="text" name="hp" value="', $context['monster']['hp'], '" /></td>
</tr>
<tr>
<td style="text-align: right;">'.$txt['battle_monsters_m_hp'].'</td>
<td><input type="text" name="max_hp" value="', $context['monster']['max_hp'], '" /></td>
</tr>
<tr>
<td style="text-align: right;">'.$txt['battle_monsters_range'].'</td>
<td>
<span>
<input type="text" name="mon_range" size="6" maxlength="5" value="', $context['monster']['mon_range'], '" />
</span>
<span style="position:relative;left:10px;">
<input type="text" name="mon_max_range" size="6" maxlength="5" value="', $context['monster']['mon_max_range'], '" />
</span>
</td>
</tr>
<tr>
<td style="text-align: right;">'.$txt['battle_monsters_img'] .'</td>
<td>
<script type="text/javascript" language="javascript"><!-- // --><![CDATA[
function show_image()
{
if (document.theAdminForm.icon.value !== "none")
{
// TODO: Should this detect the sources URL, rather than just assume?
var image_url = "', $settings['images_url'], '/battle/monsters/" + document.theAdminForm.icon.value;
document.images["icon"].src = image_url;
}
else
{
document.images["icon"].src = "', $settings['images_url'], '/battle/monsters/blank.gif";
}
}
// ]]></script>
<select name="img" id="icon" onchange="show_image()">
<option value="blank.gif"', ($context['monster']['img'] == 'blank.gif' ? ' selected="selected"' : ''), '>
', $txt['battle_none'], '
</option>';

// Get all images for the dropdown list
foreach ($context['battle_images'] as $image)
echo '
<option value="', $image, '"', ($context['monster']['img'] == $image ? ' selected="selected"' : ''), '>
', $image, '
</option>';

echo '
</select>';

if (empty ($context['monster']['img']))
echo '
<img name="icon" src="', $settings['images_url'], '/battle/monsters/blank.gif" border="1" alt="" />';
else
echo '
<img name="icon" src="', $settings['images_url'], '/battle/monsters/', $context['monster']['img'], '" border="1"  alt="" />';

echo '
<br />
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center;">
<input type="submit" name="submit" value="'.$txt['battle_save'].'" />
</td>
</tr>
</table>
<input type="hidden" name="monster" value="', $context['monster']['id'], '" />
<input type="hidden" name="sc" value="', $context['session_id'], '" />
</form>';
}


Chen Zhen

#10
For the install you need to add this code in that file perhaps under the code you just posted from that file:

$smcFunc['db_add_column']('{db_prefix}battle_monsters',
array(
'name' => 'mon_max_range',
'type' => 'int',
'size' => '10',
'null' => false
)
);


also in the language file you need to change the text of the $txt variable.
ie.

$txt['battle_monsters_range'] = 'Battle Monster Range (Min/Max)';


Also I corrected the last code as I left an extra input by mistake.. please copy and paste it anew.

Chen Zhen

Fog,

  If you like your template editing then just make sure the input field for the addition is something like this:

<input type="text" name="mon_max_range" value="', $context['monster']['mon_max_range'], '" />


... and it should work for allowing the input.

Fog

$smcFunc['db_add_column']('{db_prefix}battle_monsters',
array(
'name' => 'mon_range',
'type' => 'varchar',
'size' => '255',
'null' => false
)
);
   

Fog

which code...sorry


I thought you meant my last one.

Fog

Quote from: underdog on July 11, 2013, 10:12:37 PM
Fog,

Here is the admin template code. I fixed up the html a bit as it was broken (errors). I am not sure if it looks proper atm as I am not able to test it.


function template_monsterEdit_Add()
{
global $context, $scripturl, $settings, $txt;

$context['battle_images'] = getImageList();

echo '
<form action="', $scripturl, '?action=admin;area=battle;save;sa=savemonster" method="post" name="theAdminForm" accept-charset="', $context['character_set'], '">
<table border="0" width="80%" align="center" cellspacing="1" cellpadding="3" class="tborder windowbg2">
<tr class="titlebg">
<td>'.$txt['battle_monsters'].'</td>
</tr>
<tr>
<td style="text-align: right;">'.$txt['battle_monsters_name'].'</td>
<td><input type="text" name="name" value="', $context['monster']['name'], '" /></td>
</tr>
<tr>
<td style="text-align: right;">'.$txt['battle_monsters_atk'].'</td>
<td><input type="text" name="atk" value="', $context['monster']['atk'], '" /></td>
</tr>
<tr>
<td style="text-align: right;">'.$txt['battle_monsters_def'].'</td>
<td><input type="text" name="def" value="', $context['monster']['def'], '" /></td>
</tr>
<tr>
<td style="text-align: right;">'.$txt['battle_monsters_hp'].'</td>
<td><input type="text" name="hp" value="', $context['monster']['hp'], '" /></td>
</tr>
<tr>
<td style="text-align: right;">'.$txt['battle_monsters_m_hp'].'</td>
<td><input type="text" name="max_hp" value="', $context['monster']['max_hp'], '" /></td>
</tr>
<tr>
<td style="text-align: right;">'.$txt['battle_monsters_range'].'</td>
<td>
<span>
<input type="text" name="mon_range" size="6" maxlength="5" value="', $context['monster']['mon_range'], '" />
</span>
<span style="position:relative;left:10px;">
<input type="text" name="mon_max_range" size="6" maxlength="5" value="', $context['monster']['mon_max_range'], '" />
</span>
</td>
</tr>
<tr>
<td style="text-align: right;">'.$txt['battle_monsters_img'] .'</td>
<td>
<script type="text/javascript" language="javascript"><!-- // --><![CDATA[
function show_image()
{
if (document.theAdminForm.icon.value !== "none")
{
// TODO: Should this detect the sources URL, rather than just assume?
var image_url = "', $settings['images_url'], '/battle/monsters/" + document.theAdminForm.icon.value;
document.images["icon"].src = image_url;
}
else
{
document.images["icon"].src = "', $settings['images_url'], '/battle/monsters/blank.gif";
}
}
// ]]></script>
<select name="img" id="icon" onchange="show_image()">
<option value="blank.gif"', ($context['monster']['img'] == 'blank.gif' ? ' selected="selected"' : ''), '>
', $txt['battle_none'], '
</option>';

// Get all images for the dropdown list
foreach ($context['battle_images'] as $image)
echo '
<option value="', $image, '"', ($context['monster']['img'] == $image ? ' selected="selected"' : ''), '>
', $image, '
</option>';

echo '
</select>';

if (empty ($context['monster']['img']))
echo '
<img name="icon" src="', $settings['images_url'], '/battle/monsters/blank.gif" border="1" alt="" />';
else
echo '
<img name="icon" src="', $settings['images_url'], '/battle/monsters/', $context['monster']['img'], '" border="1"  alt="" />';

echo '
<br />
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center;">
<input type="submit" name="submit" value="'.$txt['battle_save'].'" />
</td>
</tr>
</table>
<input type="hidden" name="monster" value="', $context['monster']['id'], '" />
<input type="hidden" name="sc" value="', $context['session_id'], '" />
</form>';
}


Are you suggesting I should replace the whole admin template code with the one you have posted?

Just making sure...