Advertisement
Xetrill

STCS xr_statistic.script

Aug 16th, 2013
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.02 KB | None | 0 0
  1.  
  2. actor_statistic = {
  3.     recieved_quests  = 0,
  4.     completed_quests = 0,
  5.     failed_quests    = 0,
  6.     killed_monsters  = 0,
  7.     killed_stalkers  = 0,
  8.     founded_secrets  = 0,
  9.     recieved_money   = 0,
  10.     spent_money      = 0,
  11. }
  12.  
  13. local killPointsLookup = {
  14.       neutral_novice     = 1, neutral_experienced  = 2, neutral_veteran    = 3, neutral_master  = 4,
  15.       monolith_novice    = 1, monolith_experienced = 2, monolith_veteran   = 3, monolith_master = 4,
  16.       military_novice    = 1, military_experienced = 2, military_veteran   = 3, military_master = 4,
  17.       killer_novice      = 1, killer_experienced   = 2, killer_veteran     = 3, killer_master   = 4,
  18.       ecolog_novice      = 1, ecolog_experienced   = 2, ecolog_veteran     = 3, ecolog_master   = 4,
  19.       dolg_novice        = 1, dolg_experienced     = 2, dolg_veteran       = 3, dolg_master     = 4,
  20.       freedom_novice     = 1, freedom_experienced  = 2, freedom_veteran    = 3, freedom_master  = 4,
  21.       bandit_novice      = 1, bandit_experienced   = 2, bandit_veteran     = 3, bandit_master   = 4,
  22.       zombied_novice     = 1, zombied_experienced  = 2, zombied_veteran    = 3, zombied_master  = 4,
  23.       tushkano_weak      = 1,
  24.       flesh_weak         = 1, flesh_normal         = 2, flesh_strong       = 3,
  25.       boar_weak          = 1, boar_normal          = 2, boar_strong        = 3,
  26.       dog_weak           = 1, dog_normal           = 2, dog_strong         = 3,
  27.       pseudodog_weak     = 1, pseudodog_normal     = 2, pseudodog_strong   = 3,
  28.       psy_dog_weak       = 1, psy_dog_normal       = 2, psy_dog_strong     = 3,
  29.       snork_weak         = 2, snork_normal         = 3, snork_strong       = 4,
  30.       poltergeist_weak   = 2,
  31.       pseudo_gigant_weak = 4,
  32.       controller_weak    = 4,
  33.       bloodsucker_weak   = 1, bloodsucker_normal   = 2, bloodsucker_strong = 3
  34. }
  35.  
  36. local killNameAlias = {
  37.     tushkano_normal      = "tushkano_weak",      tushkano_strong      = "tushkano_weak",
  38.     poltergeist_normal   = "poltergeist_weak",   poltergeist_strong   = "poltergeist_weak",
  39.     pseudo_gigant_normal = "pseudo_gigant_weak", pseudo_gigant_strong = "pseudo_gigant_weak",
  40.     controller_normal    = "controller_weak",    controller_strong    = "controller_weak",
  41.     psy_dog_weak         = "psy_dog",            psy_dog_normal       = "psy_dog",
  42.     psy_dog_strong       = "psy_dog",            rad_psy_dog          = "psy_dog"
  43. }
  44.  
  45. local clsidToMonsterMap = {
  46.     [clsid.tushkano_s    ]    = "tushkano",
  47.     [clsid.flesh_s       ]    = "flesh",
  48.     [clsid.boar_s        ]    = "boar",
  49.     [clsid.dog_s         ]    = "dog",
  50.     [clsid.pseudodog_s   ]    = "pseudodog",
  51.     [clsid.psy_dog_s     ]    = "psy_dog",
  52.     [clsid.psy_dog_phantom_s] = "NIL",
  53.     [clsid.snork_s       ]    = "snork",
  54.     [clsid.poltergeist_s ]    = "poltergeist",
  55.     [clsid.gigant_s      ]    = "pseudo_gigant",
  56.     [clsid.controller_s  ]    = "controller",
  57.     [clsid.bloodsucker_s ]    = "bloodsucker"
  58. }
  59.  
  60. -- This excludes the 'army', which is a special case.
  61. local nonNeutralCommunities = {
  62.     bandit   = true,
  63.     dolg     = true,
  64.     ecolog   = true,
  65.     freedom  = true,
  66.     killer   = true,
  67.     monolith = true,
  68.     zombied  = true
  69. }
  70.  
  71. local IsStalker, rankGetByName, gameStatsAddPoints
  72.     = IsStalker, ranks.get_obj_rank_name, actor_stats.add_points
  73.  
  74. local npcTypeFormat = '%s_%s'
  75.  
  76. local function getNpcType(npc)
  77.     local clsid, rank, community = npc:clsid(), rankGetByName(npc)
  78.     if IsStalker(npc, clsid) then
  79.         community = npc:character_community()
  80.         if community == 'army' then
  81.             community = 'military'
  82.         elseif nonNeutralCommunities[community] == nil then
  83.             community = 'neutral'
  84.         end
  85.  
  86.         return "stalkerkills", npcTypeFormat:format(community, rank)
  87.     else
  88.         community = clsidToMonsterMap[clsid]
  89.         if community == nil then
  90.             abort("[xr_statistic.getNpcType]: Missing clsid-to-monster mapping from clsid '%d' to '%s'.",
  91.                 clsid, npc:section())
  92.         end
  93.  
  94.         if community == "NIL" then
  95.             return nil, nil
  96.         end
  97.  
  98.         return "monsterkills", npcTypeFormat:format(community, rank)
  99.     end
  100. end
  101.  
  102. function addKillCount(npc)
  103.     local statName, section = getNpcType(npc)
  104.     if statName == nil then
  105.         return
  106.     end
  107.  
  108.     local killName = killNameAlias[section]
  109.     if killName == nil then
  110.         killName = section
  111.     end
  112.  
  113.     local points = killPointsLookup[killName]
  114.     if points == nil then
  115.         return
  116.     end
  117.  
  118.     gameStatsAddPoints(statName, killName, 1, points)
  119.  
  120.     local act = db.actor
  121.     act:set_character_rank(act:character_rank() + points)
  122. end
  123.  
  124. function inc_recieved_quests_counter()
  125.     actor_statistic.recieved_quests = actor_statistic.recieved_quests + 1
  126. end
  127.  
  128. function inc_completed_quests_counter()
  129.     actor_statistic.completed_quests = actor_statistic.completed_quests + 1
  130. end
  131.  
  132. function inc_failed_quests_counter()
  133.     actor_statistic.failed_quests = actor_statistic.failed_quests + 1
  134. end
  135.  
  136. function inc_killed_monsters_counter()
  137.     actor_statistic.killed_monsters = actor_statistic.killed_monsters + 1
  138. end
  139.  
  140. function inc_killed_stalkers_counter()
  141.     actor_statistic.killed_stalkers = actor_statistic.killed_stalkers + 1
  142. end
  143.  
  144. function inc_founded_secrets_counter()
  145.     actor_statistic.founded_secrets = actor_statistic.founded_secrets + 1
  146. end
  147.  
  148. function inc_recieved_money_counter(amount)
  149.     actor_statistic.recieved_money = actor_statistic.recieved_money + amount
  150. end
  151.  
  152. function inc_spent_money_counter(amount)
  153.     actor_statistic.spent_money = actor_statistic.spent_money + amount
  154. end
  155.  
  156. function save(package)
  157.     package:w_u16(actor_statistic.recieved_quests)
  158.     package:w_u16(actor_statistic.completed_quests)
  159.     package:w_u16(actor_statistic.failed_quests)
  160.     package:w_u32(actor_statistic.killed_monsters)
  161.     package:w_u32(actor_statistic.killed_stalkers)
  162.     package:w_u16(actor_statistic.founded_secrets)
  163.     package:w_u32(actor_statistic.recieved_money)
  164.     package:w_u32(actor_statistic.spent_money)
  165. end
  166.  
  167. function load(package)
  168.     actor_statistic = {
  169.         recieved_quests  = package:r_u16(),
  170.         completed_quests = package:r_u16(),
  171.         failed_quests    = package:r_u16(),
  172.         killed_monsters  = package:r_u32(),
  173.         killed_stalkers  = package:r_u32(),
  174.         founded_secrets  = package:r_u16(),
  175.         recieved_money   = package:r_u32(),
  176.         spent_money      = package:r_u32()
  177.     }
  178. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement