Author Topic: GetSkinName  (Read 2465 times)

rwwpl

  • Full Member
  • ***
  • Posts: 126
  • Karma: +18/-6
  • LU-DM Team
    • View Profile
    • LU-DM Team
GetSkinName
« on: July 21, 2014, 02:25:40 am »
1 Version

Code: [Select]
function GetSkinName(id)
{
switch(id)
{
case 0:   return "Claude";
case 1:   return "Police #1";
case 2:   return "SWAT";
case 3:   return "FBI";
case 4:   return "Army";
case 5:   return "Paramedic";
case 6:   return "Firefighter";
case 7:   return "Wise Guy";
case 8:   return "Taxi";
case 9:   return "Pimp";
case 10:   return "Mafia #1";
case 11:   return "Mafia #2";
case 12:   return "Triad #1";
case 13:   return "Triad #2";
case 14:   return " #1";
case 15:   return " #2";
case 16:   return "Yakuza #1";
case 17:   return "Yakuza #2";
case 18:   return "Yardie #1";
case 19:   return "Yardie #2";
case 20:   return "Colombian Cartel #1";
case 21:   return "Colombian Cartel #2";
case 22:   return "Red Jacks";
case 23:   return "Purple Nines";
case 24:   return "Street Criminal #1";
case 25:   return "Street Criminal #2";
case 30:   return "Male Client";
case 31:   return "Walking Guy #1";
case 32:   return "Vacationist";
case 33:   return "DJ";
case 34:   return "Young Woman #1";
case 35:   return "Young Woman #2";
case 36:   return "Business Woman #1";
case 37:   return "Elder Woman #1";
case 38:   return "Elder Woman #2";
case 39:   return "Prostitute #1";
case 40:   return "Prostitute #2";
case 41:   return "Walking Guy #2";
case 42:   return "Diseased Man";
case 43:   return "Deseased Woman";
case 44:   return "Young Woman #3";
case 45:   return "Walking Old Man #1";
case 46:   return "Walking Guy #3";
case 47:   return "Old Woman #1";
case 48:   return "Old Woman #2";
case 49:   return "Walking Old Man #2";
case 50:   return "Walking Guy #4";
case 51:   return "Old Woman #3";
case 52:   return "Young Woman #4";
case 53:   return "Docks Worker #1";
case 54:   return "Docks Worker #2";
case 55:   return "Male Street Bum";
case 56:   return "Female Street Bum";
case 57:   return "Delivery Guy #1";
case 58:   return "Delivery Guy #2";
case 59:   return "Business Man #1";
case 60:   return "Marty Chonks";
case 61:   return "CIA";
case 62:   return "Female Client #1";
case 63:   return "Young Woman #5";
case 64:   return "Business Woman #2";
case 65:   return "Business Man #2";
case 66:   return "Female Client #2";
case 67:   return "Male Steward";
case 68:   return "Female Steward";
case 69:   return "Male Cocks Fan #1";
case 70:   return "Male Cocks Fan #2";
case 71:   return "Female Cocks Fan";
case 72:   return "Male Paramedics Assistant";
case 73:   return "Female Paramedics Assistant";
case 74:   return "Construction Worker #1";
case 75:   return "Construction Worker #2";
case 76:   return "ZIP Customer";
case 77:   return "Party Woman #1";
case 78:   return "Party Woman #2";
case 79:   return "Male Student";
case 80:   return "Female Student";
case 81:   return "Walking Old Man #3";
case 82:   return "Female Jogger";
case 83:   return "Asuka Kasen";
case 84:   return "Suicide Bomber";
case 85:   return "Butler";
case 86:   return "Catalina";
case 87:   return "Lee Chong";
case 88:   return "Colombian Cartel #3";
case 89:   return "Colombian Cartel #4";
case 90:   return "Colombian Cartel #5";
case 91:   return "Colombian Cartel #6";
case 92:   return "Police #2";
case 93:   return "Curly Bob";
case 94:   return "Phil Cassidy";
case 95:   return "Detective";
case 96:   return "Prison 8-Ball";
case 97:   return "8-Ball";
case 98:   return "Salvatore Leone";
case 99:   return "Mafia #3";
case 100:   return "Mechanic Joey Leone";
case 101:   return "Joey Leone";
case 102:   return "Bar Owner";
case 103:   return "Kenji Kasen";
case 104:   return "Mike Forelli";
case 105:   return "Donald Love";
case 106:   return "Liberty Campus Love";
case 107:   return "Luigi Goterelli";
case 108:   return "Maria Latore";
case 109:   return "Mickey Hamfists";
case 110:   return "Miguel";
case 111:   return "Misty";
case 112:   return "Oriental Gentleman";
case 113:   return "T'ai Chi Oriental Gentleman";
case 114:   return "Prison Oriental Gentleman";
case 115:   return "Ray Machowski";
case 116:   return "Robber Mafia";
case 117:   return "Store Clerk";
case 118:   return "Tanner";
case 119:   return "Toni Cipriani";
case 120:   return "Darkel";
case 121:   return "Chuff Security";
case 122:   return "Prison Claude";
default:   return "Unknown";
}
}

2 Version
Code: [Select]
function GetSkinName(id)
{
if (id == 0)   return "Claude";
else if (id==1)   return "Police #1";
else if (id==2)   return "SWAT";
else if (id==3)   return "FBI";
else if (id==4)   return "Army";
else if (id==5)   return "Paramedic";
else if (id==6)   return "Firefighter";
else if (id==7)  return "Wise Guy";
else if (id==8)   return "Taxi";
else if (id==9)   return "Pimp";
else if (id==10)   return "Mafia #1";
else if (id==11)   return "Mafia #2";
else if (id==12)   return "Triad #1";
else if (id==13)   return "Triad #2";
else if (id==14)   return "Diablo #1";
else if (id==15)   return "Diablo #2";
else if (id==16)   return "Yakuza #1";
else if (id==17)   return "Yakuza #2";
else if (id==18)   return "Yardie #1";
else if (id==19)   return "Yardie #2";
else if (id==20)   return "Colombian Cartel #1";
else if (id==21)   return "Colombian Cartel #2";
else if (id==22)   return "Red Jacks";
else if (id==23)   return "Purple Nines";
else if (id==24)   return "Street Criminal #1";
else if (id==25)   return "Street Criminal #2";
else if (id==30)   return "Male Client";
else if (id==31)   return "Walking Guy #1";
else if (id==32)   return "Vacationist";
else if (id==33)   return "DJ";
else if (id==34)   return "Young Woman #1";
else if (id==35)   return "Young Woman #2";
else if (id==36)   return "Business Woman #1";
else if (id==37)   return "Elder Woman #1";
else if (id==38)   return "Elder Woman #2";
else if (id==39)   return "Prostitute #1";
else if (id==40)   return "Prostitute #2";
else if (id==41)   return "Walking Guy #2";
else if (id==42)   return "Diseased Man";
else if (id==43)   return "Deseased Woman";
else if (id==44)   return "Young Woman #3";
else if (id==45)   return "Walking Old Man #1";
else if (id==46)   return "Walking Guy #3";
else if (id==47)   return "Old Woman #1";
else if (id==48)   return "Old Woman #2";
else if (id==49)   return "Walking Old Man #2";
else if (id==50)   return "Walking Guy #4";
else if (id==51)   return "Old Woman #3";
else if (id==52)   return "Young Woman #4";
else if (id==53)   return "Docks Worker #1";
else if (id==54)   return "Docks Worker #2";
else if (id==55)   return "Male Street Bum";
else if (id==56)   return "Female Street Bum";
else if (id==57)   return "Delivery Guy #1";
else if (id==58)   return "Delivery Guy #2";
else if (id==59)   return "Business Man #1";
else if (id==60)   return "Marty Chonks";
else if (id==61)   return "CIA";
else if (id==62)   return "Female Client #1";
else if (id==63)   return "Young Woman #5";
else if (id==64)   return "Business Woman #2";
else if (id==65)   return "Business Man #2";
else if (id==66)   return "Female Client #2";
else if (id==67)   return "Male Steward";
else if (id==68)   return "Female Steward";
else if (id==69)   return "Male Cocks Fan #1";
else if (id==70)   return "Male Cocks Fan #2";
else if (id==71)   return "Female Cocks Fan";
else if (id==72)   return "Male Paramedics Assistant";
else if (id==73)   return "Female Paramedics Assistant";
else if (id==74)   return "Construction Worker #1";
else if (id==75)   return "Construction Worker #2";
else if (id==76)   return "ZIP Customer";
else if (id==77)   return "Party Woman #1";
else if (id==78)   return "Party Woman #2";
else if (id==79)   return "Male Student";
else if (id==80)   return "Female Student";
else if (id==81)   return "Walking Old Man #3";
else if (id==82)   return "Female Jogger";
else if (id==83)   return "Asuka Kasen";
else if (id==84)   return "Suicide Bomber";
else if (id==85)   return "Butler";
else if (id==86)   return "Catalina";
else if (id==87)   return "Lee Chong";
else if (id==88)   return "Colombian Cartel #3";
else if (id==89)   return "Colombian Cartel #4";
else if (id==90)   return "Colombian Cartel #5";
else if (id==91)   return "Colombian Cartel #6";
else if (id==92)   return "Police #2";
else if (id==93)   return "Curly Bob";
else if (id==94)   return "Phil Cassidy";
else if (id==95)   return "Detective";
else if (id==96)   return "Prison 8-Ball";
else if (id==97)   return "8-Ball";
else if (id==98)   return "Salvatore Leone";
else if (id==99)   return "Mafia #3";
else if (id==100)   return "Mechanic Joey Leone";
else if (id==101)   return "Joey Leone";
else if (id==102)   return "Bar Owner";
else if (id==103)   return "Kenji Kasen";
else if (id==104)   return "Mike Forelli";
else if (id==105)   return "Donald Love";
else if (id==106)   return "Liberty Campus Love";
else if (id==107)   return "Luigi Goterelli";
else if (id==108)   return "Maria Latore";
else if (id==109)   return "Mickey Hamfists";
else if (id==110)   return "Miguel";
else if (id==111)   return "Misty";
else if (id==112)   return "Oriental Gentleman";
else if (id==113)   return "T'ai Chi Oriental Gentleman";
else if (id==114)   return "Prison Oriental Gentleman";
else if (id==115)   return "Ray Machowski";
else if (id==116)   return "Robber Mafia";
else if (id==117)   return "Store Clerk";
else if (id==118)   return "Tanner";
else if (id==119)   return "Toni Cipriani";
else if (id==120)   return "Darkel";
else if (id==121)   return "Chuff Security";
else if (id==122)   return "Prison Claude";
else (!id) return "Unknown";
}
« Last Edit: August 03, 2014, 08:06:16 pm by rwwpl »

Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 531
  • Karma: +27/-16
    • View Profile
Re: GetSkinName
« Reply #1 on: July 22, 2014, 06:03:47 pm »
Version 1 is the better. It would be nice to add a default value like "Unknown" to be sure it actually returns something even if you enter a invalid id.

Vortrex

  • Full Member
  • ***
  • Posts: 267
  • Karma: +54/-73
    • View Profile
Re: GetSkinName
« Reply #2 on: July 30, 2014, 04:31:55 am »
There's a third way ... Make an array of all the skins and just use something like:
Code: [Select]
return SkinNames[ skinid ]

Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 531
  • Karma: +27/-16
    • View Profile
Re: GetSkinName
« Reply #3 on: July 31, 2014, 11:03:12 pm »
There's a third way ... Make an array of all the skins and just use something like:
Code: [Select]
return SkinNames[ skinid ]
Uses more memory since it needs to load the whole array in order to return one index. The switch method is better in this case.

rwwpl

  • Full Member
  • ***
  • Posts: 126
  • Karma: +18/-6
  • LU-DM Team
    • View Profile
    • LU-DM Team
Re: GetSkinName
« Reply #4 on: August 03, 2014, 08:05:43 pm »
I fixed small bug

Old:
Code: [Select]
case 108:   return "Luigi Goterelli";
case 108:   return "Maria Latore";

New:
Code: [Select]
case 107:   return "Luigi Goterelli";
case 108:   return "Maria Latore";

Vortrex

  • Full Member
  • ***
  • Posts: 267
  • Karma: +54/-73
    • View Profile
Re: GetSkinName
« Reply #5 on: August 03, 2014, 10:16:47 pm »
There's a third way ... Make an array of all the skins and just use something like:
Code: [Select]
return SkinNames[ skinid ]
Uses more memory since it needs to load the whole array in order to return one index. The switch method is better in this case.

If you only need to use this function minimally, then yes, you would be correct. However, if you have to use this function often, then no.

I'm pretty sure the array is the better choice. Just keep it on the root table and access it when needed. Accessing a specific index of an array is much lighter on memory. With the switch method, you are pretty much doing the same thing as a loop. A switch statement runs through all the options until it finds what it needs. Not only is the switch statement slower, it consumes processing that could be used elsewhere.

I'm not sure if this next part is correct, but I'm pretty sure there is one core linear process, in which the current processing needs to finish before the next is started. Unless you are using threads, I think that this would be held up by a switch statement needing to do its thing.

Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 531
  • Karma: +27/-16
    • View Profile
Re: GetSkinName
« Reply #6 on: August 04, 2014, 09:37:56 pm »
I haven't thought of keeping the array saved in the root table. In that case you are correct.
It takes the switch method 1550ms to get skin 61 (middle one) a million times, while the array does it in 200ms. Point taken, I was wrong.

 

© Liberty Unleashed Team.