#Dv^ Posted June 29, 2016 Share Posted June 29, 2016 Hola, había hecho este scritp para que te de un arma random al escribir el comando te da un arma random El problema es cuando pongo /arma solo sale en el chat "Ha obtenido un arma" local weapons = { 12, 14, 15, 20, 30, 31 } local weapID = getWeaponNameFromID ( weapName ) function arma ( thePlayer, weapName ) giveWeapon ( thePlayer, weapons[ math.random( #weapons ) ] ) -- Gives the M4 weapon with 200 ammo outputChatBox("Ha obtenido una ".. weapName, playerSource ) end addCommandHandler("arma", arma) Agradezco la ayuda Link to comment
DBY Posted June 29, 2016 Share Posted June 29, 2016 addCommandHandler("arma", function(thePlayer) local weapons = {12, 14, 15, 20, 30, 31} local weaponID = weapons[math.random(#weapons)] if giveWeapon(thePlayer, weaponID) then outputChatBox("Ha obtenido una ".. getWeaponNameFromID(weaponID), thePlayer ) end end ) Link to comment
Tomas Posted June 29, 2016 Share Posted June 29, 2016 local weapons = { 12, 14, 15, 20, 30, 31 } local weapID = getWeaponNameFromID ( weapName ) function arma ( thePlayer ) local wepId = weapons[ math.random( #weapons ) ] giveWeapon ( thePlayer, wepId ) -- Gives the M4 weapon with 200 ammo outputChatBox("Ha obtenido una ".. getWeaponNameFromID(wepId), thePlayer ) end addCommandHandler("arma", arma) Link to comment
#Dv^ Posted June 29, 2016 Author Share Posted June 29, 2016 ¿Y si quiero que salga cuanta municion obtuvo? ¿Se usa getWeaponAmmo ? Muchas gracias Link to comment
aka Blue Posted June 29, 2016 Share Posted June 29, 2016 ¿Quieres que la munición también sea aleatoria? Link to comment
aka Blue Posted June 29, 2016 Share Posted June 29, 2016 local weapons = { 12, 14, 15, 20, 30, 31 } addCommandHandler ( "arma", function ( player, commandName ) local municionRandom = math.random ( 15, 50 ) -- Municion random desde 15 hasta 50 local weapon = weapons[ math.random( #weapons ) ] giveWeapon ( player, weapon, municionRandom ) outputChatBox ( "Ha obtenido una "..getWeaponNameFromID ( weapon ).." con "..municionRandom.." de munición.", player ) end ) Link to comment
#Dv^ Posted June 29, 2016 Author Share Posted June 29, 2016 Muchas Gracias por tu ayuda y la de todos, Saludos. Link to comment
Tomas Posted June 29, 2016 Share Posted June 29, 2016 local weapons = { 12, 14, 15, 20, 30, 31 } addCommandHandler ( "arma", function ( player, commandName ) local municionRandom = math.random ( 15, 50 ) -- Municion random desde 15 hasta 50 local weapon = weapons[ math.random( #weapons ) ] giveWeapon ( player, weapon, municionRandom ) outputChatBox ( "Ha obtenido una "..getWeaponNameFromID ( weapon ).." con "..municionRandom.." de munición.", player ) end ) No es necesario nombrar los argumentos de las funciones que no utilizarás, es innecesario y pierdes memoria Link to comment
aka Blue Posted June 30, 2016 Share Posted June 30, 2016 • playerSource: The player who triggered the command. If not triggered by a player (e.g. by admin), this will be false. • commandName: The name of the command triggered. This is useful if multiple commands go through one function. • arg1, arg2, ...: Each word after command name in the original command is passed here in a seperate variable. If there is no value for an argument, its variable will contain nil. You can deal with a variable number of arguments using the vararg expression, as shown in Server Example 2 below. Me basé en eso Link to comment
Recommended Posts