Alexs Posted July 15, 2012 Share Posted July 15, 2012 Hola a Todos, este es el script de envio de dinero que yo uso: function giveSomeoneMoney(player, cmd, target, amount) if target then if amount then local money = getPlayerMoney(player) local targetplayer = getPlayerFromName(target) amount = tonumber(amount) if targetplayer then if money >= amount then givePlayerMoney(targetplayer, amount) takePlayerMoney(player, amount) outputChatBox(getPlayerName(player).." dio "..amount.." a "..getPlayerName(targetplayer), getRootElement(), 205, 092, 092, true) else outputChatBox("No tienes suficiente dinero!", player, 205, 092, 092) end else outputChatBox("Error: Player no encontrado", player, 205, 092, 092) end else outputChatBox("Error: /dardinero [Jugador] [Monto]", player, 205, 092, 092) end else outputChatBox("Error: /dardinero [Jugador] [Monto]", player, 205, 092, 092) end end addCommandHandler("dardinero", giveSomeoneMoney) Pero descubri un bug, al poner un numero negativo el script le roba a otro, te da a ti y le quita al otro, como puedo evitar que el argumento "amount" comienze con un signo negativo? Link to comment
Castillo Posted July 15, 2012 Share Posted July 15, 2012 Verifica si "amount" es mayor que 0. Link to comment
Alexs Posted July 15, 2012 Author Share Posted July 15, 2012 Lo puse asi: function giveSomeoneMoney(player, cmd, target, amount) if target then if amount then local money = getPlayerMoney(player) local targetplayer = getPlayerFromName(target) amount = tonumber(amount) if targetplayer then if amount > 0 then --agregue esto! if money >= amount then givePlayerMoney(targetplayer, amount) takePlayerMoney(player, amount) outputChatBox(getPlayerName(player).." dio "..amount.." a "..getPlayerName(targetplayer), getRootElement(), 205, 092, 092, true) else outputChatBox("No tienes suficiente dinero!", player, 205, 092, 092) end else outputChatBox("Error: Player no encontrado", player, 205, 092, 092) end else outputChatBox("Error: /dardinero [Jugador] [Monto]", player, 205, 092, 092) end else outputChatBox("Error: /dardinero [Jugador] [Monto]", player, 205, 092, 092) end end end addCommandHandler("dardinero", giveSomeoneMoney) Pero dice: Error: /dardinero [Jugador] [Monto] Link to comment
Castillo Posted July 15, 2012 Share Posted July 15, 2012 function giveSomeoneMoney ( player, cmd, target, amount ) if ( target ) and ( amount ) then local money = getPlayerMoney ( player ) local targetplayer = getPlayerFromName ( target ) local amount = tonumber ( amount ) if ( targetplayer ) then if ( amount > 0 ) then --agregue esto! if ( money >= amount ) then givePlayerMoney ( targetplayer, amount ) takePlayerMoney ( player, amount ) outputChatBox ( getPlayerName ( player ) .." dio "..amount.." a ".. getPlayerName ( targetplayer ), getRootElement(), 205, 092, 092, true ) else outputChatBox ( "No tienes suficiente dinero!", player, 205, 092, 092 ) end else outputChatBox ( "Error: El monto debe ser mayor que 0!", player, 205, 092, 092 ) end else outputChatBox ( "Error: Player no encontrado", player, 205, 092, 092 ) end else outputChatBox ( "Error: /dardinero [Jugador] [Monto]", player, 205, 092, 092 ) end end addCommandHandler ( "dardinero", giveSomeoneMoney ) Link to comment
Recommended Posts