User Tools

Site Tools


scripting:samples:genericschool

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
scripting:samples:genericschool [2023/07/04 03:25] mitscripting:samples:genericschool [2023/07/10 06:42] (current) mit
Line 1: Line 1:
 ===== Generic School Script ===== ===== Generic School Script =====
- +{{http://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 [[Scripting:Samples:SimpleSchool|A simpler scripted school example]] )+\\ 
 +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 [[Scripting:Samples:SimpleSchool|A simpler scripted school example]] )
  
 <code> <code>
 +#include "BaseSchool.mit"    // Include the standard base school functions
  
 $kSchoolStructSize = 7 $kSchoolStructSize = 7
-$kUniversityBuildingNum = 40 
  
 +$kExampleSchoolBuildingNum = 2
 +$kUniversityBuildingNum = 40
  
-$maUniversityList[] =  +$maLessonsList[] =  
-{// cat. skill name  price    learn time    graphic  desc   +{// cat.       skill name  price    learn time    graphic  desc  
- 0, "Engineer",  2000, 20,     "engineer.jpg",    "Manufactory, Engine factory, Tyre factory", 0, + 0, "Lumberjack",    300, 2, "lumberjack.jpg",  "1 Logging site, sawmills, rubber plantations", 0, 
- 0, "Auto manufacturer", 2000, 40, "vehiclefactory.jpg",    "Vehicle factory", 0, + 0, "Farmer",    200, 2, "farmer.jpg",      "Arable farms and vineyards", 0, 
- 0, "Aircraft manufacturer", 2000, 80, "aircraftfactory.jpg",     "Aircraft factory", 0, + 0, "Rancher",    200, 3, "rancher.jpg",     "Livestock farms", 0, 
- 0, "Chemist",  2000, 80, "chemicalplant.jpg",     "Chemical plant", 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  -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" ) Event( "AccessBuilding", "$kUniversityBuildingNum" )
 { {
-    SchoolShowMainOSD( $maUniversityList )+    // Parameter is the skills category to show 
 +    SchoolShowMainOSD( )
 } }
  
-Function SchoolShowMainOSD( $aLessonsList )+//--------------------------------------------------------------------------------------- 
 + 
 +Function SchoolShowMainOSD( $category )
 { {
  if ( $gPlayerNumSkills >= $kMaxNumSkills )  if ( $gPlayerNumSkills >= $kMaxNumSkills )
  {  {
  osdcreate(OSDBUILDING,"SchoolOSD", "School"  osdcreate(OSDBUILDING,"SchoolOSD", "School"
- osdaddat(FADEDTEXT, 50, 5, 500, 25, "", "Here you can acquire new skills. You are limited to 3 skills at any one time.")  + osdadd(FADEDTEXT, 50, 5, 500, 25, "", "Here you can acquire new skills. You are limited to 3 skills at any one time.")  
- osdaddat(FADEDBUTTON, 150, 140, 300, 45, "", "You have the maximum number of skills")  + osdadd(FADEDBUTTON, 150, 140, 300, 45, "", "You have the maximum number of skills")  
- osdaddat(SMALLFADEDTEXT, 100, 250, 400, 25, "", "You can forget any of your existing skills by clicking on them in your Skills list, bottom right."+ 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()   osdactivate() 
  }  }
  else  else
  {  {
-      SchoolShowGenericSkillsOSD( $aLessonsList0, "SelectSkill" )+      SchoolShowGenericSkillsOSD( $maLessonsList$category, "SelectSkill" )
  }  }
 } }
Line 42: Line 62:
 Event( "OSDSelect", "SchoolOSD:SelectSkill" ) Event( "OSDSelect", "SchoolOSD:SelectSkill" )
 { {
- $skillNum = $gParam[1] +    $skillNum = $gParam[1] 
- $price = $gParam[2] +    $price = $gParam[2] 
-        // Unpleasant hack to get the lessons list for a building in later events.. Scripting language should really provide a better way to handle this.. +    SchoolShowBuySkillConfirm( $maLessonsList, $skillNum )
- if ( $gBuildingCode == $kUniversityBuildingNum ) +
-+
- $aLessonsList = $maUniversityList +
-    } +
-    // (** If you want to have multiple school types, you will need to additional else if statements here) +
-    SchoolShowBuySkillConfirm( $aLessonsList, $skillNum )+
 } }
 +</code>
  
 +**BaseSchool.mit** : 
 +<code>
 //----------------------------------------------------------------------- //-----------------------------------------------------------------------
 Function SchoolGetModifiedLearnTime( $baseDays ) Function SchoolGetModifiedLearnTime( $baseDays )
Line 114: Line 131:
  $skillPrice = SchoolGetModifiedPrice( $skillPrice )  $skillPrice = SchoolGetModifiedPrice( $skillPrice )
  
- osdaddat(BIGTEXT, 0, 0, 600, 0, "", "$skillName Skill" ) + osdadd(BIGTEXT, 0, 0, 600, 0, "", "$skillName Skill" ) 
- osdaddat(IMAGE, 50, 60, 200, 200, "", "$imageName"+ osdadd(IMAGE, 50, 60, 200, 200, "", "$imageName"
  $textX = 300  $textX = 300
  
Line 123: Line 140:
  
  $subText = "Allows you to construct and run $desc."  $subText = "Allows you to construct and run $desc."
- osdaddat(FADEDTEXT, $textX, $subtextY, $subtextWidth, 0, "", $subText )+ osdadd(FADEDTEXT, $textX, $subtextY, $subtextWidth, 0, "", $subText )
  $subtextY += 40  $subtextY += 40
  
  $learnTimeText = sysGetRealTimeTextForDays( $learnTimeDays );  $learnTimeText = sysGetRealTimeTextForDays( $learnTimeDays );
- osdaddat(BIGTEXT, $textX, $subtextY, 0, 0, "", "Learn Time: $learnTimeDays gamedays"  )+ osdadd(BIGTEXT, $textX, $subtextY, 0, 0, "", "Learn Time: $learnTimeDays gamedays"  )
  $subtextY += 26  $subtextY += 26
- osdaddat(FADEDTEXT, $textX + 40, $subtextY, 0, 0, "", "(About $learnTimeText realtime)"  )+ osdadd(FADEDTEXT, $textX + 40, $subtextY, 0, 0, "", "(About $learnTimeText realtime)"  )
  $subtextY += 25  $subtextY += 25
- osdaddat(BIGTEXT, $textX, $subtextY, 0, 0, "", "Course price: $priceText"  )+ osdadd(BIGTEXT, $textX, $subtextY, 0, 0, "", "Course price: $priceText"  )
  $subtextY += 30  $subtextY += 30
  
Line 139: Line 156:
  if ( $hasSkill > 0 )  if ( $hasSkill > 0 )
  {  {
- osdaddat(FADEDBUTTON, 300, 245, 270, 30, "", "You already have this skill"+ osdadd(FADEDBUTTON, 300, 245, 270, 30, "", "You already have this skill"
  }  }
  else if ( $isLearning ==  1 )  else if ( $isLearning ==  1 )
  {  {
- osdaddat(FADEDBUTTON, 300, 245, 270, 30, "", "You are already learning this skill"+ osdadd(FADEDBUTTON, 300, 245, 270, 30, "", "You are already learning this skill"
  }  }
  else if ( $gPlayerCash < $skillPrice )  else if ( $gPlayerCash < $skillPrice )
  {  {
- osdaddat(FADEDBUTTON, 300, 245, 270, 30, "", "You don't have enough cash"+ osdadd(FADEDBUTTON, 300, 245, 270, 30, "", "You don't have enough cash"
  }  }
  else  else
  {  {
- osdaddat(EXITBUTTON, 300, 245, 270, 30, "Confirm|$skillNum|$skillPrice|$learnTimeDays", "Purchase Lessons"+ osdadd(EXITBUTTON, 300, 245, 270, 30, "Confirm|$skillNum|$skillPrice|$learnTimeDays", "Purchase Lessons"
  }  }
  
- osdaddat(BUTTON, 200, 330, 200, 30, "Back", "Back"+ osdadd(BUTTON, 200, 330, 200, 30, "Back", "Back"
  osdactivate()   osdactivate() 
 } }
Line 201: Line 218:
  
  $skillPrice = SchoolGetModifiedPrice( $skillPrice )  $skillPrice = SchoolGetModifiedPrice( $skillPrice )
- osdaddat(IMAGE, $imageX, $lineY, 90, 90, "$selectFunc|$skillNum|$skillPrice", "$imageName"+ osdadd(IMAGE, $imageX, $lineY, 90, 90, "$selectFunc|$skillNum|$skillPrice", "$imageName"
  $textY = $lineY + 5  $textY = $lineY + 5
  $priceText = sysGetPriceText( $skillPrice )  $priceText = sysGetPriceText( $skillPrice )
  
- osdaddat(BIGTEXT, $textX, $textY, 0, 0, "", "$skillName" )+ osdadd(BIGTEXT, $textX, $textY, 0, 0, "", "$skillName" )
  $subtextY = $textY + 21  $subtextY = $textY + 21
- osdaddat(TEXT, $textX, $subtextY, 0, 0, "", "Cost: $priceText" )+ osdadd(TEXT, $textX, $subtextY, 0, 0, "", "Cost: $priceText" )
      
  $subtextY = $textY + 40  $subtextY = $textY + 40
  
  $subText = "Allows you to construct and run $desc."  $subText = "Allows you to construct and run $desc."
- osdaddat(FADEDSMALLTEXT, $textX, $subtextY, $subtextWidth, 0, "", "$subText" )+ osdadd(FADEDSMALLTEXT, $textX, $subtextY, $subtextWidth, 0, "", "$subText" )
  
  if ( $numLessons <= 3 )  if ( $numLessons <= 3 )
Line 240: Line 257:
  }  }
  
- osdaddat(BUTTON, 200, 330, 200, 30, "Back", "Back"+ osdadd(BUTTON, 200, 330, 200, 30, "Back", "Back"
  osdactivate()   osdactivate() 
 } }
scripting/samples/genericschool.1688459145.txt.gz · Last modified: 2023/07/04 03:25 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