User Tools

Site Tools


scripting:samples:genericschool

Generic School Script

theuniversal.net_worldmanual_images_genericschoolscript.jpg

Standard school script used on lovelace (etc). Table at the top defines the skills available, graphics are hosted on a webpage specified in the script.
(Alternatively, try A simpler scripted school example )

#include "BaseSchool.mit"    // Include the standard base school functions

$kSchoolStructSize = 7

$kExampleSchoolBuildingNum = 2
$kUniversityBuildingNum = 40

$maLessonsList[] = 
{// cat.       skill name	 price    learn time    graphic			 desc		
	0,	"Lumberjack",	   300,		2,	"lumberjack.jpg",  "1 Logging site, sawmills, rubber plantations",		0,
	0,	"Farmer",	   200,		2,	"farmer.jpg",      "Arable farms and vineyards",							0,
	0,	"Rancher",	   200,		3,	"rancher.jpg",     "Livestock farms",										0,
	0,	"Poultry Farmer",  200,		3,	"poultry.jpg",     "Poultry farms",										0,
							 
	1,	"Engineer",	 2000,		20,	"engineer.jpg",    "Manufactory, Engine factory, Tyre factory",	0,
	1,	"Auto manufacturer",	 2000,	40,	"vehiclefactory.jpg",	   "Vehicle factory",							0,
	1,	"Aircraft manufacturer", 2000,	80,	"aircraftfactory.jpg",     "Aircraft factory",							0,
	1,	"Chemist",		 2000,	80,	"chemicalplant.jpg",     "Chemical plant",								0,
	-1,		"",		-1, -1, "", ""  // eol
}

//---------------------------------------------------------------------------------------
// Building Access functions.. add these for each school type

Event( "AccessBuilding", "$kExampleSchoolBuildingNum" )
{
    // Parameter is the skills category to show
    SchoolShowMainOSD( 0 )
}

Event( "AccessBuilding", "$kUniversityBuildingNum" )
{
    // Parameter is the skills category to show
    SchoolShowMainOSD( 1 )
}

//---------------------------------------------------------------------------------------

Function	SchoolShowMainOSD( $category )
{
	if ( $gPlayerNumSkills >= $kMaxNumSkills )
	{
		osdcreate(OSDBUILDING,"SchoolOSD", "School" ) 
		osdadd(FADEDTEXT, 50, 5, 500, 25, "", "Here you can acquire new skills. You are limited to 3 skills at any one time.") 
		osdadd(FADEDBUTTON, 150, 140, 300, 45, "", "You have the maximum number of skills") 
		osdadd(SMALLFADEDTEXT, 100, 250, 400, 25, "", "You can forget any of your existing skills by clicking on them in your Skills list, bottom right.") 
		osdactivate() 
	}
	else
	{
	     SchoolShowGenericSkillsOSD( $maLessonsList, $category, "SelectSkill" )
	}
}

Event( "OSDSelect", "SchoolOSD:SelectSkill" )
{
    $skillNum = $gParam[1]
    $price = $gParam[2]
    SchoolShowBuySkillConfirm( $maLessonsList, $skillNum )
}

BaseSchool.mit :

//-----------------------------------------------------------------------
Function	SchoolGetModifiedLearnTime( $baseDays )
{
    // Add logic here to modify the return value if you want your school system to change the learn time
    // for skill based on player specific factors, e.g. Lovelace makes skills take longer to learn based 
    // on the number of skills the player has learnt previously
    return( $baseDays )
}


Function	SchoolGetModifiedPrice( $basePrice )
{
    // Add logic here to modify the return value if you want your school system to change price
    // for the skill based on player specific factors, e.g. Lovelace makes skills cost more based 
    // on the number of skills the player has learnt previously
    return( $basePrice )
}

Function	SchoolFindSkillDetails( $aLessonsList, $skillNum )
{
	$index = 1

	while( $aLessonsList[$index] >= 0 )
	{
		$skillName = $aLessonsList[$index+1]
		$listSkillNum = sysGetSkillNum( $skillName )
		if ( $listSkillNum == $skillNum )
		{
			return( $index )
		}
		$index += $kSchoolStructSize
	}
	$index = -1
	return( $index )
}

Function	SchoolShowBuySkillConfirm( $aLessonsList, $skillNum )
{
	$index = SchoolFindSkillDetails( $aLessonsList, $skillNum )

	if ( $index == -1 )
	{
		*msg %PLAYER% Error locating skill $skillNum in script lessons lists
		return
	}
	
	osdcreate(OSDBUILDING,"SchoolOSD", "State School" ) 
	osdadditem(HTTPSET, "", "http://gfmcontent.b-cdn.net/gamecontent/zion3/menus/" )
	$lineY = 10

	$skillName = $aLessonsList[$index+1]
	$skillNum = sysGetSkillNum( $skillName )
	$skillPrice = $aLessonsList[$index+2]
	$learnTimeDays = $aLessonsList[$index+3]
	$imageName = $aLessonsList[$index+4]
	$desc = $aLessonsList[$index+5]
	$extraInvestBuildNum = $aLessonsList[$index+6]

	$learnTimeDays = SchoolGetModifiedLearnTime( $learnTimeDays )
	$skillPrice = SchoolGetModifiedPrice( $skillPrice )

	osdadd(BIGTEXT, 0, 0, 600, 0, "", "$skillName Skill" )
	osdadd(IMAGE, 50, 60, 200, 200, "", "$imageName") 
	$textX = 300

	$priceText = sysGetPriceText( $skillPrice )
	$subtextY = 50
	$subtextWidth = 290

	$subText = "Allows you to construct and run $desc."
	osdadd(FADEDTEXT, $textX, $subtextY, $subtextWidth, 0, "", $subText )
	$subtextY += 40

	$learnTimeText = sysGetRealTimeTextForDays( $learnTimeDays );
	osdadd(BIGTEXT, $textX, $subtextY, 0, 0, "", "Learn Time: $learnTimeDays gamedays"  )
	$subtextY += 26
	osdadd(FADEDTEXT, $textX + 40, $subtextY, 0, 0, "", "(About $learnTimeText realtime)"  )
	$subtextY += 25
	osdadd(BIGTEXT, $textX, $subtextY, 0, 0, "", "Course price: $priceText"  )
	$subtextY += 30

	$isLearning = sysPlayerIsLearningSkill( $skillName )
	$hasSkill = sysPlayerSkillLevel( $skillName )

	if ( $hasSkill > 0 )
	{
		osdadd(FADEDBUTTON, 300, 245, 270, 30, "", "You already have this skill") 
	}
	else if ( $isLearning ==  1 )
	{
		osdadd(FADEDBUTTON, 300, 245, 270, 30, "", "You are already learning this skill") 
	}
	else if ( $gPlayerCash < $skillPrice )
	{
		osdadd(FADEDBUTTON, 300, 245, 270, 30, "", "You don't have enough cash") 
	}
	else
	{
		osdadd(EXITBUTTON, 300, 245, 270, 30, "Confirm|$skillNum|$skillPrice|$learnTimeDays", "Purchase Lessons") 
	}

	osdadd(BUTTON, 200, 330, 200, 30, "Back", "Back") 
	osdactivate() 
}


Function	SchoolShowGenericSkillsOSD( $aLessonsList, $category, $selectFunc )
{
	$index = 1
	$numLessons = 0
	while( $aLessonsList[$index] >= 0 )
	{
		if ( $aLessonsList[$index] == $category )
		{
			$numLessons += 1
		}
		$index += $kSchoolStructSize
	}
	
	osdcreate(OSDBUILDING,"SchoolOSD", "" ) 
	osdadditem(HTTPSET, "", "http://gfmcontent.b-cdn.net/gamecontent/zion3/menus/" )
	$lineY = 10
	if ( $numLessons > 3 )
	{
		$imageX = 10
		$textX = 105
		$subtextWidth = 180
	}
	else
	{
		$imageX = 100
		$textX = 200
		$subtextWidth = 300
	}

	$index = 1
	$count = 0
	while( $aLessonsList[$index] >= 0 )
	{
		if ( $aLessonsList[$index] == $category )
		{
			$skillName = $aLessonsList[$index+1]
			$skillNum = sysGetSkillNum( $skillName )
			$skillPrice = $aLessonsList[$index+2]
			$imageName = $aLessonsList[$index+4]
			$desc = $aLessonsList[$index+5]

			$skillPrice = SchoolGetModifiedPrice( $skillPrice )
			osdadd(IMAGE, $imageX, $lineY, 90, 90, "$selectFunc|$skillNum|$skillPrice", "$imageName") 
			$textY = $lineY + 5
			$priceText = sysGetPriceText( $skillPrice )

			osdadd(BIGTEXT, $textX, $textY, 0, 0, "", "$skillName" )
			$subtextY = $textY + 21
			osdadd(TEXT, $textX, $subtextY, 0, 0, "", "Cost: $priceText" )
			 
			$subtextY = $textY + 40

			$subText = "Allows you to construct and run $desc."
			osdadd(FADEDSMALLTEXT, $textX, $subtextY, $subtextWidth, 0, "", "$subText" )

			if ( $numLessons <= 3 )
			{
				$lineY += 100
			}
			else
			{
				$mod = $count / 2
				$mod *= 2
				// Move on to second column
				if ( $mod == $count )
				{
					$textX = 405
					$imageX = 305
				}
				else
				{
					$textX = 110
					$imageX = 10
					$lineY += 100
				}
			}
			$count += 1
		}
		$index += $kSchoolStructSize
	}

	osdadd(BUTTON, 200, 330, 200, 30, "Back", "Back") 
	osdactivate() 
}


Event( "OSDSelect", "SchoolOSD:Confirm" )
{
	$skillNum = $gParam[1]
	$price = $gParam[2]
	$learnTimeDays = $gParam[3]

	if ( $gPlayerCash >= $price )
	{
		$skillName = sysGetSkillName( $skillNum )
		$hasSkill = sysPlayerSkillLevel( $skillName )

		if ( $hasSkill == 0 )
		{
			$amountPaid = sysRemoveWealth( $price, "Education Fees")
			if ( $amountPaid > 0 )
			{
				$newSkillCount = $gPlayerVar[$kPlayerVarNumSkillsLearnt] + 1
				$gPlayerVar[$kPlayerVarNumSkillsLearnt] = $newSkillCount
				*addskill %PLAYER% $skillNum $learnTimeDays

				if ( $gBuildingOwnerID >= 2 )
				{
					// If less than 100 sheckles, owner gets 10%
					if ( $price < 10000 )
					{
						$schoolProfit = $amountPaid * 10
						$schoolProfit /= 100
					}
					else
					{				
						// Otherwise, owner gets 5%
						$schoolProfit = $amountPaid * 5
						$schoolProfit /= 100
					}
					*addtoinvestment $gBuildingNum $schoolProfit
				}
			}
			return
		}		
		else
		{
			*msg %PLAYER% You already have this skill
		}
	}
	else
	{
		*msg %PLAYER% You don't have enough cash to purchase this skill
	}
}

scripting/samples/genericschool.txt · Last modified: 2023/07/10 06:42 by mit

Except where otherwise noted, content on this wiki is licensed under the following license: Public Domain
Public Domain Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki