Jump to content

Ayuda con aritmética.


Tomas

Recommended Posts

Como dice el título necesito ayuda, yo quiero que al poner un comando X salga un "pickup" de dinero con la cantidad que tenga el que ejecute el comando.

Use de ejemplo el script de Cocodrilo:

  
function createMoney(player) 
   local x, y, z = getElementPosition(player); 
   local x1, y1, x2, y2; 
   x1 = (x-2)+(math.random()*4); 
   y1 = (y-2)+(math.random()*4); 
   x2 = (x-2)+(math.random()*4); 
   y2 = (y-2)+(math.random()*4); 
   local moneyAmmount = getPlayerMoney(player); 
   -- it is not fair too get all the player money. 
   moneyAmmount = math.floor(moneyAmmount/1); 
  
   takePlayerMoney(player, moneyAmmount); 
    
   -- We are going to create 3 pickups, zo we are just cut the ammount in half 
   moneyAmmount = math.floor(moneyAmmount/3); 
  
   -- Create the pickups 
   setElementData(createPickup(x1, y1, z, 3, 1212), "ammount", moneyAmmount); 
   setElementData(createPickup(x2, y2, z, 3, 1212), "ammount", moneyAmmount); 
   setElementData(createPickup(x2, y2, z, 3, 1212), "ammount", moneyAmmount); 
end 
  
function moneyPickupHit(player) 
   local money = getElementData(source, "ammount"); 
   if money then 
      givePlayerMoney(player, money); 
      destroyElement(source); 
   end 
end 
  
  
function playerJustGotDied(ammo, attacker, weapon, bodypart) 
   createMoney(source); 
end 
  
addEventHandler("onPickupUse", getRootElement(), moneyPickupHit); 
addEventHandler("onPlayerWasted", getRootElement(), playerJustGotDied); 
  

Intenté editarlo pero no hay manera, siempre me daba errores de aritmética D:, como podría hacerlo? :S

Link to comment

Edité el codigo para que sea con comando:

  
    function createMoney(player) 
       local x, y, z = getElementPosition(player); 
       local x1, y1, x2, y2; 
       x1 = (x-2)+(math.random()*4); 
       y1 = (y-2)+(math.random()*4); 
       x2 = (x-2)+(math.random()*4); 
       y2 = (y-2)+(math.random()*4); 
       local moneyAmmount = getPlayerMoney(player); 
       -- it is not fair too get all the player money. 
       moneyAmmount = math.floor(moneyAmmount/1); 
             
       -- We are going to create 3 pickups, zo we are just cut the ammount in half 
       moneyAmmount = math.floor(moneyAmmount/3); 
      
       -- Create the pickups 
       setElementData(createPickup(x1, y1, z, 3, 1212), "ammount", moneyAmmount); 
       setElementData(createPickup(x2, y2, z, 3, 1212), "ammount", moneyAmmount); 
       setElementData(createPickup(x2, y2, z, 3, 1212), "ammount", moneyAmmount); 
    end 
      
    function moneyPickupHit(player) 
       local money = getElementData(source, "ammount"); 
       if money then 
          givePlayerMoney(player, money); 
          destroyElement(source); 
       end 
    end 
      
      
    function playerJustGotDied(ammo, attacker, weapon, bodypart) 
       createMoney(source); 
    end 
      
    addEventHandler("onPickupUse", getRootElement(), moneyPickupHit); 
    addCommandHandler("asd123", playerJustGotDied); 
     

Errores:

a><!-- m -->

Link to comment
  • MTA Team

Por ahí asi:?

  
function createMoney(player) 
       local x, y, z = getElementPosition(player); 
       local x1, y1, x2, y2; 
       x1 = (x-2)+(math.random()*4); 
       y1 = (y-2)+(math.random()*4); 
       x2 = (x-2)+(math.random()*4); 
       y2 = (y-2)+(math.random()*4); 
       local moneyAmmount = getPlayerMoney(player); 
       -- it is not fair too get all the player money. 
       moneyAmmount = math.floor(moneyAmmount/1); 
            
       -- We are going to create 3 pickups, zo we are just cut the ammount in half 
       moneyAmmount = math.floor(moneyAmmount/3); 
      
       -- Create the pickups 
       setElementData(createPickup(x1, y1, z, 3, 1212), "ammount", moneyAmmount); 
       setElementData(createPickup(x2, y2, z, 3, 1212), "ammount", moneyAmmount); 
       setElementData(createPickup(x2, y2, z, 3, 1212), "ammount", moneyAmmount); 
    end 
      
    function moneyPickupHit(player) 
       local money = getElementData(source, "ammount"); 
       if money then 
          givePlayerMoney(player, money); 
          destroyElement(source); 
       end 
    end 
     
function playerJustGotDied(yo) 
       createMoney(yo); 
    end 
      
    addEventHandler("onPickupUse", getRootElement(), moneyPickupHit); 
    addCommandHandler("asd123", playerJustGotDied); 
  

Link to comment
Por ahí asi:?
  
function createMoney(player) 
       local x, y, z = getElementPosition(player); 
       local x1, y1, x2, y2; 
       x1 = (x-2)+(math.random()*4); 
       y1 = (y-2)+(math.random()*4); 
       x2 = (x-2)+(math.random()*4); 
       y2 = (y-2)+(math.random()*4); 
       local moneyAmmount = getPlayerMoney(player); 
       -- it is not fair too get all the player money. 
       moneyAmmount = math.floor(moneyAmmount/1); 
            
       -- We are going to create 3 pickups, zo we are just cut the ammount in half 
       moneyAmmount = math.floor(moneyAmmount/3); 
      
       -- Create the pickups 
       setElementData(createPickup(x1, y1, z, 3, 1212), "ammount", moneyAmmount); 
       setElementData(createPickup(x2, y2, z, 3, 1212), "ammount", moneyAmmount); 
       setElementData(createPickup(x2, y2, z, 3, 1212), "ammount", moneyAmmount); 
    end 
      
    function moneyPickupHit(player) 
       local money = getElementData(source, "ammount"); 
       if money then 
          givePlayerMoney(player, money); 
          destroyElement(source); 
       end 
    end 
     
function playerJustGotDied(yo) 
       createMoney(yo); 
    end 
      
    addEventHandler("onPickupUse", getRootElement(), moneyPickupHit); 
    addCommandHandler("asd123", playerJustGotDied); 
  

Graciassssssss capo :3

Perdona por demorar pero lo probe y me cope e hice el evento xD

Ahora que terminó; Gracias :D

Link to comment
function createMoney ( player ) 
    local x, y, z = getElementPosition ( player ) 
    local x1, y1, x2, y2 
    local x1 = ( x - 2 ) + ( math.random ( ) * 4 ) 
    local y1 = ( y - 2 ) + ( math.random ( ) * 4 ) 
    local x2 = ( x - 2 ) + ( math.random ( ) * 4 ) 
    local y2 = ( y - 2 ) + ( math.random ( ) * 4 ) 
    local moneyAmmount = getPlayerMoney(player); 
    -- it is not fair too get all the player money. 
    local moneyAmmount = math.floor ( moneyAmmount / 1 );  
    -- We are going to create 3 pickups, zo we are just cut the ammount in half 
    local moneyAmmount = math.floor ( moneyAmmount / 3 ) 
    -- Create the pickups 
    setElementData ( createPickup ( x1, y1, z, 3, 1212 ), "amount", moneyAmmount ) 
    setElementData ( createPickup ( x2, y2, z, 3, 1212 ), "amount", moneyAmmount ) 
    setElementData ( createPickup ( x2, y2, z, 3, 1212 ), "amount", moneyAmmount ) 
end 
addCommandHandler ( "tirardinero", createMoney ) 
  
function moneyPickupHit ( player ) 
    local money = getElementData ( source, "amount" ) 
    if ( money ) then 
        givePlayerMoney ( player, money ) 
        destroyElement ( source ) 
    end 
end 

Link to comment
function createMoney ( player ) 
    local x, y, z = getElementPosition ( player ) 
    local x1, y1, x2, y2 
    local x1 = ( x - 2 ) + ( math.random ( ) * 4 ) 
    local y1 = ( y - 2 ) + ( math.random ( ) * 4 ) 
    local x2 = ( x - 2 ) + ( math.random ( ) * 4 ) 
    local y2 = ( y - 2 ) + ( math.random ( ) * 4 ) 
    local moneyAmmount = getPlayerMoney(player); 
    -- it is not fair too get all the player money. 
    local moneyAmmount = math.floor ( moneyAmmount / 1 );  
    -- We are going to create 3 pickups, zo we are just cut the ammount in half 
    local moneyAmmount = math.floor ( moneyAmmount / 3 ) 
    -- Create the pickups 
    setElementData ( createPickup ( x1, y1, z, 3, 1212 ), "amount", moneyAmmount ) 
    setElementData ( createPickup ( x2, y2, z, 3, 1212 ), "amount", moneyAmmount ) 
    setElementData ( createPickup ( x2, y2, z, 3, 1212 ), "amount", moneyAmmount ) 
end 
addCommandHandler ( "tirardinero", createMoney ) 
  
function moneyPickupHit ( player ) 
    local money = getElementData ( source, "amount" ) 
    if ( money ) then 
        givePlayerMoney ( player, money ) 
        destroyElement ( source ) 
    end 
end 

Ahora el tuyo no me tira debug xD gracias a los dos :3

EDIT: No da debug pero tampoco da el dinero xD

Link to comment

No me referia a eso, pone este codigo y postea el resultado:

function createMoney ( player ) 
    local x, y, z = getElementPosition ( player ) 
    local x1, y1, x2, y2 
    local x1 = ( x - 2 ) + ( math.random ( ) * 4 ) 
    local y1 = ( y - 2 ) + ( math.random ( ) * 4 ) 
    local x2 = ( x - 2 ) + ( math.random ( ) * 4 ) 
    local y2 = ( y - 2 ) + ( math.random ( ) * 4 ) 
    local moneyAmmount = getPlayerMoney(player); 
    -- it is not fair too get all the player money. 
    local moneyAmmount = math.floor ( moneyAmmount / 1 ); 
    -- We are going to create 3 pickups, zo we are just cut the ammount in half 
    local moneyAmmount = math.floor ( moneyAmmount / 3 ) 
    -- Create the pickups 
    setElementData ( createPickup ( x1, y1, z, 3, 1212 ), "amount", moneyAmmount ) 
    setElementData ( createPickup ( x2, y2, z, 3, 1212 ), "amount", moneyAmmount ) 
    setElementData ( createPickup ( x2, y2, z, 3, 1212 ), "amount", moneyAmmount ) 
end 
addCommandHandler ( "tirardinero", createMoney ) 
  
function moneyPickupHit ( player ) 
    local money = getElementData ( source, "amount" ) 
    if ( money ) then 
outputChatBox ( "DATA IS: ".. tostring ( money ) ) 
        givePlayerMoney ( player, money ) 
        destroyElement ( source ) 
    end 
end 

Link to comment
No me referia a eso, pone este codigo y postea el resultado:
function createMoney ( player ) 
    local x, y, z = getElementPosition ( player ) 
    local x1, y1, x2, y2 
    local x1 = ( x - 2 ) + ( math.random ( ) * 4 ) 
    local y1 = ( y - 2 ) + ( math.random ( ) * 4 ) 
    local x2 = ( x - 2 ) + ( math.random ( ) * 4 ) 
    local y2 = ( y - 2 ) + ( math.random ( ) * 4 ) 
    local moneyAmmount = getPlayerMoney(player); 
    -- it is not fair too get all the player money. 
    local moneyAmmount = math.floor ( moneyAmmount / 1 ); 
    -- We are going to create 3 pickups, zo we are just cut the ammount in half 
    local moneyAmmount = math.floor ( moneyAmmount / 3 ) 
    -- Create the pickups 
    setElementData ( createPickup ( x1, y1, z, 3, 1212 ), "amount", moneyAmmount ) 
    setElementData ( createPickup ( x2, y2, z, 3, 1212 ), "amount", moneyAmmount ) 
    setElementData ( createPickup ( x2, y2, z, 3, 1212 ), "amount", moneyAmmount ) 
end 
addCommandHandler ( "tirardinero", createMoney ) 
  
function moneyPickupHit ( player ) 
    local money = getElementData ( source, "amount" ) 
    if ( money ) then 
outputChatBox ( "DATA IS: ".. tostring ( money ) ) 
        givePlayerMoney ( player, money ) 
        destroyElement ( source ) 
    end 
end 

Acabo de hacerlo: No pasa nada.

( Si ya se que es al agarrar el pickup, no pasa nada. )

Link to comment
function createMoney ( player ) 
    local x, y, z = getElementPosition ( player ) 
    local x1, y1, x2, y2 
    local x1 = ( x - 2 ) + ( math.random ( ) * 4 ) 
    local y1 = ( y - 2 ) + ( math.random ( ) * 4 ) 
    local x2 = ( x - 2 ) + ( math.random ( ) * 4 ) 
    local y2 = ( y - 2 ) + ( math.random ( ) * 4 ) 
    local moneyAmmount = getPlayerMoney(player); 
    -- it is not fair too get all the player money. 
    local moneyAmmount = math.floor ( moneyAmmount / 1 ); 
    -- We are going to create 3 pickups, zo we are just cut the ammount in half 
    local moneyAmmount = math.floor ( moneyAmmount / 3 ) 
    -- Create the pickups 
    setElementData ( createPickup ( x1, y1, z, 3, 1212 ), "amount", moneyAmmount ) 
    setElementData ( createPickup ( x2, y2, z, 3, 1212 ), "amount", moneyAmmount ) 
    setElementData ( createPickup ( x2, y2, z, 3, 1212 ), "amount", moneyAmmount ) 
end 
addCommandHandler ( "tirardinero", createMoney ) 
  
function moneyPickupHit ( player ) 
    local money = getElementData ( source, "amount" ) 
    if ( money ) then 
        givePlayerMoney ( player, money ) 
        destroyElement ( source ) 
    end 
end 
addEventHandler ( "onPickupHit", root, moneyPickupHit ) 

Me habia olvidado del event handler de onPickupHit :oops:

Link to comment
function createMoney ( player ) 
    local x, y, z = getElementPosition ( player ) 
    local x1, y1, x2, y2 
    local x1 = ( x - 2 ) + ( math.random ( ) * 4 ) 
    local y1 = ( y - 2 ) + ( math.random ( ) * 4 ) 
    local x2 = ( x - 2 ) + ( math.random ( ) * 4 ) 
    local y2 = ( y - 2 ) + ( math.random ( ) * 4 ) 
    local moneyAmmount = getPlayerMoney(player); 
    -- it is not fair too get all the player money. 
    local moneyAmmount = math.floor ( moneyAmmount / 1 ); 
    -- We are going to create 3 pickups, zo we are just cut the ammount in half 
    local moneyAmmount = math.floor ( moneyAmmount / 3 ) 
    -- Create the pickups 
    setElementData ( createPickup ( x1, y1, z, 3, 1212 ), "amount", moneyAmmount ) 
    setElementData ( createPickup ( x2, y2, z, 3, 1212 ), "amount", moneyAmmount ) 
    setElementData ( createPickup ( x2, y2, z, 3, 1212 ), "amount", moneyAmmount ) 
end 
addCommandHandler ( "tirardinero", createMoney ) 
  
function moneyPickupHit ( player ) 
    local money = getElementData ( source, "amount" ) 
    if ( money ) then 
        givePlayerMoney ( player, money ) 
        destroyElement ( source ) 
    end 
end 
addEventHandler ( "onPickupHit", root, moneyPickupHit ) 

Me habia olvidado del event handler de onPickupHit :oops:

Este castillo noob haha, okno xD

Te admiro :3

Link to comment
  • Recently Browsing   0 members

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