GetValidPedModels: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (removed needs example)
(5 intermediate revisions by 5 users not shown)
Line 13: Line 13:
==Example==
==Example==
This example will get if the specified skin is a valid skin or not.
This example will get if the specified skin is a valid skin or not.
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function isValidSkin( thePlayer, command, specifiedSkin )  -- Define the function
function isValidSkin( thePlayer, command, specifiedSkin )  -- Define the function
Line 21: Line 22:
             if skin == tonumber( specifiedSkin ) then -- If skin equals specified one, it is valid
             if skin == tonumber( specifiedSkin ) then -- If skin equals specified one, it is valid
                 result = skin -- So set it as result
                 result = skin -- So set it as result
                break --stop looping through a table after we found the skin
             end
             end
         end
         end
         if ( result ) then -- If we got results
         if ( result ) then -- If we got results
             outputChatBox( tostring( skin ) .. " is a valid skin ID.", thePlayer, 0, 255, 0 ) -- It is valid, output it
             outputChatBox( result .. " is a valid skin ID.", thePlayer, 0, 255, 0 ) -- It is valid, output it
         else -- If we didn't get results
         else -- If we didn't get results
             outputChatBox( specifiedSkin .. " is not a valid skin ID.", thePlayer, 0, 255, 0 ) -- No result, it is not valid
             outputChatBox( specifiedSkin .. " is not a valid skin ID.", thePlayer, 0, 255, 0 ) -- No result, it is not valid
Line 34: Line 36:
addCommandHandler("checkskin",isValidSkin) -- bind 'checkskin' command to 'isValidSkin' function
addCommandHandler("checkskin",isValidSkin) -- bind 'checkskin' command to 'isValidSkin' function
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Ped functions}}
{{Ped functions}}
[[pl:GetValidPedModels]]

Revision as of 11:48, 13 February 2018

This function returns all valid ped models.

Syntax

table getValidPedModels ( )

Returns

Returns a table with all valid ped models.

Example

This example will get if the specified skin is a valid skin or not.

Click to collapse [-]
Server
function isValidSkin( thePlayer, command, specifiedSkin )  -- Define the function
    if ( specifiedSkin ) then -- If skin specified
        local allSkins = getValidPedModels ( ) -- Get valid skin IDs
        local result = false -- Define result, it is currently false
        for key, skin in ipairs( allSkins ) do -- Check all skins
            if skin == tonumber( specifiedSkin ) then -- If skin equals specified one, it is valid
                result = skin -- So set it as result
                break --stop looping through a table after we found the skin
            end
        end
        if ( result ) then -- If we got results
            outputChatBox( result .. " is a valid skin ID.", thePlayer, 0, 255, 0 ) -- It is valid, output it
        else -- If we didn't get results
            outputChatBox( specifiedSkin .. " is not a valid skin ID.", thePlayer, 0, 255, 0 ) -- No result, it is not valid
        end
    else -- If no skin specified
        outputChatBox( "Please specify a skin ID to check!", thePlayer, 255, 0, 0 ) -- Tell it to the player
    end
end
addCommandHandler("checkskin",isValidSkin) -- bind 'checkskin' command to 'isValidSkin' function

See Also