Jump to content

source for skin table


Darky

Recommended Posts

Posted

i have a question , i am learning in this and i don't know if i can change the "element" ( source ) and replace this for a skin tablet or a specific skin

example:

local Skin = { 9,12 } 
  
    function skinW (  ) 
      giveWeapon ( Skin , 2 , 1, true ) 
       end 
   addEventHandler ( "onPlayerSpawn", getRootElement(), SkinW  ) 
  

Posted
function skinW(player) 
    setElementModel(player, modelID) 
end 
addEventHandler("onPlayerSpawn", root, skinW) 

That's it? I didn't really understand your problem.

Posted

I have a server, when you enter gives you a random skin,I try to get the skin 287 or 286, the server give me a M4 but if hi have the skin 285 give me a Colt

Posted

Maybe this is what you want...

addEventHandler( "onPlayerSpawn", root, 
    function( ) 
        local playerSkin = getElementModel( source ); 
        if( playerSkin == 287 ) then 
            giveWeapon( source, 31, 100 ); 
        elseif( playerSkin == 286 ) then 
            giveWeapon( source, 22, 100 ); 
        end 
    end 
) 

Posted
Maybe this is what you want...
addEventHandler( "onPlayerSpawn", root, 
    function( ) 
        local playerSkin = getElementModel( source ); 
        if( playerSkin == 287 ) then 
            giveWeapon( source, 31, 100 ); 
        elseif( playerSkin == 286 ) then 
            giveWeapon( source, 22, 100 ); 
        end 
    end 
) 

addEventHandler( "onPlayerSpawn", root, 
    function( ) 
        local playerSkin = getElementModel( source ); 
        if( playerSkin == 287 or 286 ) then 
            giveWeapon( source, 31, 100 ); 
        elseif( playerSkin == 285 ) then 
            giveWeapon( source, 22, 100 ); 
        end 
    end 
) 

Posted
Maybe this is what you want...
addEventHandler( "onPlayerSpawn", root, 
    function( ) 
        local playerSkin = getElementModel( source ); 
        if( playerSkin == 287 ) then 
            giveWeapon( source, 31, 100 ); 
        elseif( playerSkin == 286 ) then 
            giveWeapon( source, 22, 100 ); 
        end 
    end 
) 

addEventHandler( "onPlayerSpawn", root, 
    function( ) 
        local playerSkin = getElementModel( source ); 
        if( playerSkin == 287 or 286 ) then 
            giveWeapon( source, 31, 100 ); 
        elseif( playerSkin == 285 ) then 
            giveWeapon( source, 22, 100 ); 
        end 
    end 
) 

Your code is wrong.

Posted

50p's code is correct, but you have to add "or playerSkin == 286" after "playerSkin == 287" if you want to give that specific weapon for both 287 and 286 skins.

Posted

and other question, i can create a list which all skins? or something that looks

example

     
  
    local Weapons = {31 , 30 } 
    local skins = { 287 , 286 } 
  
addEventHandler( "onPlayerSpawn", root, 
        function( ) 
            local playerSkin = getElementModel( source ); 
            if( playerSkin == skins ) then 
                giveWeapon( source, Weapons[ math.random ( #Weapons ) ], 100 ); 
            elseif( playerSkin == 285 ) then 
                giveWeapon( source, 22, 100 ); 
            end 
        end 
    ) 
  
  
  

Posted

This:

local Weapons = {31 , 30 } 
local skins = { 287 , 286 } 

Change to:

local Weapons = { [31] = true, [30] = true }; 
local skins = { [287] = true, [286] = true }; 

And this:

if( playerskin == skins ) then 

Change to:

if ( skins[ playerSkin ] ) then 

Posted

You can have weapon ID assigned to skin ID

  
local weaponIDBySkin = {  
[287] = 31, -- skin ID 287 will have weapon 31 
[286] = 31, 
[285] = 22 
} 
  
addEventHandler( "onPlayerSpawn", root, 
    function( ) 
        local playerSkin = getElementModel( source ); 
        if( skins[ playerSkin ] ) then -- check if playerSkin is inside the table 
            giveWeapon( source, weaponIDBySkin[ playerSkin ], 100 ); 
        end 
    end 
) 
  
  
  

Posted

good , now works nice , thanks Andrel , 50p and all for time and help. :B

Andrel , i use these and give me error.

local Weapons = { [31] = true, [30] = true }; 

but i change for these again , and work good

local Weapons = {31 , 30 } 

Posted

Ah, yes, my bad. math.random will not work with non-indexed arrays (that are not in order). You could do a function to get a random index from the array even not being in order, but it's easier to use 50p's code.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...