Darky Posted February 25, 2013 Share Posted February 25, 2013 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 ) Link to comment
PaiN^ Posted February 25, 2013 Share Posted February 25, 2013 You mean you want a specific or random skin on a specific player when he spawn ? Link to comment
Metall Posted February 25, 2013 Share Posted February 25, 2013 function skinW(player) setElementModel(player, modelID) end addEventHandler("onPlayerSpawn", root, skinW) That's it? I didn't really understand your problem. Link to comment
Darky Posted February 25, 2013 Author Share Posted February 25, 2013 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 Link to comment
iPrestege Posted February 25, 2013 Share Posted February 25, 2013 giveWeapon getElementModel setElementModel math.random "onPlayerSpawn" Link to comment
50p Posted February 25, 2013 Share Posted February 25, 2013 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 ) Link to comment
PaiN^ Posted February 25, 2013 Share Posted February 25, 2013 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 ) Link to comment
50p Posted February 25, 2013 Share Posted February 25, 2013 Do you even spawn? Have you updated your code? Link to comment
Anderl Posted February 25, 2013 Share Posted February 25, 2013 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. Link to comment
Darky Posted February 25, 2013 Author Share Posted February 25, 2013 what code is the correct ._. the frist or second Link to comment
Anderl Posted February 25, 2013 Share Posted February 25, 2013 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. Link to comment
Darky Posted February 25, 2013 Author Share Posted February 25, 2013 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 ) Link to comment
Anderl Posted February 25, 2013 Share Posted February 25, 2013 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 Link to comment
50p Posted February 25, 2013 Share Posted February 25, 2013 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 ) Link to comment
Darky Posted February 25, 2013 Author Share Posted February 25, 2013 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 } Link to comment
Darky Posted February 25, 2013 Author Share Posted February 25, 2013 ERROR: weapons/s.lua:25: bad argument#1 to "random" ( interval is empty ) Link to comment
Anderl Posted February 25, 2013 Share Posted February 25, 2013 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. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now