GetTypeIndexFromClothes: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
Line 24: Line 24:
   local clothesIndex = 1
   local clothesIndex = 1
   if ( currentTexture ) then -- if he had clothes of that type
   if ( currentTexture ) then -- if he had clothes of that type
     clothesType, clothesIndex = getTypeIndexFromClothes ( currentTexture, currentModel ) -- get the type and index of these clothes, so we can decrease and get the previous
     local tempA, tempB = getTypeIndexFromClothes ( currentTexture, currentModel ) -- get the type and index for these clothes, so we can decrease and get the previous in the list
    if ( tempA and tempB ) then -- if we found them
      clothesType, clothesIndex = tempA, tempB
    end
   end
   end
   clothesIndex = clothesIndex - 1
   clothesIndex = clothesIndex - 1
   local texture, model = getClothesByTypeIndex ( clothesType, clothesIndex ) -- get the new texture and model
   local texture, model = getClothesByTypeIndex ( clothesType, clothesIndex ) -- get the new texture and model
   if ( texture ) then -- if the clothes exist
   if ( texture == false ) then -- if we've reached the end of the list
     addPlayerClothes ( thePlayer, texture, model, clothesType )
     removePlayerClothes ( thePlayer, clothesType )
  else addPlayerClothes ( thePlayer, texture, model, clothesType )
   end
   end
end
end
addCommandHandler ( "previousClothes", scriptPreviousClothes )
addCommandHandler ( "previousClothes", scriptPreviousClothes )
</syntaxhighlight>
</syntaxhighlight>

Revision as of 15:24, 13 August 2007

Dialog-information.png This article needs checking.

Reason(s): Required argument catalogues not present (notice red links)

This function is used to get the clothes type and index from the texture and model. (Scans through the list of clothes for the specific type).

Syntax

int int getTypeIndexFromClothes ( string clothesTexture, string clothesModel )

Required Arguments

  • clothesTexture: A string determining the clothes texture that you wish to retrieve the type and index from. See clothes textures.
  • clothesModel: A string determining the corresponding clothes model that you wish to retrieve the type and index from. See clothes models.

Returns

This function returns two integers, type and index respectively, false if invalid arguments were passed to the function.

Example

This example gets the current clothes of a certain type on a player, then swaps with the previous in the clothes list.

function scriptPreviousClothes ( thePlayer, key, clothesType )
  local currentTexture, currentModel = getPlayerClothes ( thePlayer, clothesType ) -- get the current clothes on this slot
  local clothesIndex = 1
  if ( currentTexture ) then -- if he had clothes of that type
    local tempA, tempB = getTypeIndexFromClothes ( currentTexture, currentModel ) -- get the type and index for these clothes, so we can decrease and get the previous in the list
    if ( tempA and tempB ) then -- if we found them
      clothesType, clothesIndex = tempA, tempB
    end
  end
  clothesIndex = clothesIndex - 1
  local texture, model = getClothesByTypeIndex ( clothesType, clothesIndex ) -- get the new texture and model
  if ( texture == false ) then -- if we've reached the end of the list
    removePlayerClothes ( thePlayer, clothesType )
  else addPlayerClothes ( thePlayer, texture, model, clothesType )
  end
end
addCommandHandler ( "previousClothes", scriptPreviousClothes )

See Also