gschool_randperson 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # gschool_randperson
  2. !! arguments: <gender> <excluded_first_name> <grupTipeEnabled>...
  3. !! gender : 0 for male, 1 for female
  4. !! excluded_first_name : can be '' or you can provide result of previous invocation, so you can compose non-repeating pairs of people
  5. !! <grupTipeEnabled>... : 1 if you include grupTipe, 0 otherwise, look at examples below
  6. !!
  7. !! example:
  8. !! $rand_girl = func('gschool_randperson', 1, '', 1, 1, 0, 1, 0, 0)
  9. !! $rand_girl1 = func('gschool_randperson', 1, $rand_girl, 1, 1, 0, 1)
  10. !!
  11. !! Having grupTipes (social groups)
  12. !! 1 - cool kids
  13. !! 2 - jocks
  14. !! 3 - nerds
  15. !! 4 - Gopnik
  16. !! 5 - outcasts
  17. !! 6 - teachers
  18. !! examples above instruct to choose random person from: cool kids, jocks and gopniks
  19. !! NOTE that in $rand_girl1 zero values for outcasts and teachers are not defined - undefined values will be zero by language
  20. !! Thanks to that you can include new social group and you don''t need to make changes in all places
  21. rand_person_ind = 0
  22. rand_filtered_ind = 0
  23. :filter_loop
  24. rand_person_ind = rand_person_ind + 1
  25. if rand_person_ind >= ARRSIZE('grupTipe') : jump 'outside_filter_loop'
  26. genderMatches = ARGS[0] = npcPol[rand_person_ind]
  27. nameIsNotRepeated = ARGS[1] <> $npc_firstname[$school_static_num[rand_person_ind]]
  28. grupTipeIsLegal = grupTipe[rand_person_ind] > 0
  29. grupTipeMatches = ARGS[grupTipe[rand_person_ind] + 1] = 1
  30. if genderMatches and nameIsNotRepeated and grupTipeIsLegal and grupTipeMatches :
  31. rand_filtered[rand_filtered_ind] = rand_person_ind
  32. rand_filtered_ind = rand_filtered_ind + 1
  33. end
  34. jump 'filter_loop'
  35. :outside_filter_loop
  36. if ARRSIZE('rand_filtered') > 0 :
  37. random_person = rand_filtered[rand(0,ARRSIZE('rand_filtered'))]
  38. $RESULT = $npc_firstname[$school_static_num[random_person]]
  39. else
  40. $rand_gender = IIF (ARGS[0] = 0, 'boy', 'girl')
  41. $RESULT = '<<$rand_gender>> you don''t know'
  42. end
  43. KILLVAR 'rand_person_ind'
  44. KILLVAR 'rand_filtered_ind'
  45. KILLVAR 'rand_filtered'
  46. KILLVAR '$rand_gender'
  47. KILLVAR 'random_person'
  48. KILLVAR 'genderMatches'
  49. KILLVAR 'nameIsNotRepeated'
  50. KILLVAR 'grupTipeIsLegal'
  51. KILLVAR 'grupTipeMatches'
  52. --- gschool_randperson ---------------------------------