Jump to content

Ayuda con aritmética.


Tomas

Recommended Posts

Posted

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

Currently developing for International Gaming Community - Join us!

Posted

Postea los errores y en que lineas.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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 -->

Currently developing for International Gaming Community - Join us!

Posted

addCommandHandler no tiene 'source'.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
addCommandHandler no tiene 'source'.

Mmm :/ Me das una ayuda? D:

Entonces puedo hacer por ejemplo

local asd = getLocalPlayer

y cambiar el source por "asd" ? :C

Currently developing for International Gaming Community - Join us!

Posted

Para que queres el comando?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

  • MTA Team
Posted

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); 
  

DevOps Engineer, Cloud Advocate & Security Engineer(Red Team) | Coffee, Containers & Burp

 
Posted
Para que queres el comando?

Mi servidor en este momento está superando su record de jugadores, quiero tirar dinero y que lo agarren C:

Currently developing for International Gaming Community - Join us!

Posted
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

Currently developing for International Gaming Community - Join us!

Posted
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 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
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

Currently developing for International Gaming Community - Join us!

Posted

Pero crea los pickups?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Fijate que valor tiene "money" al tocar el pickup.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

A que te referis con "nada"?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
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. )

Currently developing for International Gaming Community - Join us!

Posted
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:

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
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

Currently developing for International Gaming Community - Join us!

Posted

Ya funciona bien?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
Ya funciona bien?

Si señor D:

Gracias :3

Si quisiera que cada billetito de $10, debo editar el moneyAmmount ya lo se, pero como?

Pongo simplemente 10 ? ._.

Currently developing for International Gaming Community - Join us!

Posted

En lugar de que obtenga el dinero del jugador pones 10.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
En lugar de que obtenga el dinero del jugador pones 10.

Asi solito sin nada? ._. Pobeshito D:

Una preg, para que sirve esto:

# local moneyAmmount = math.floor ( moneyAmmount / 3 )

Divide el dinero? ._.

Currently developing for International Gaming Community - Join us!

  • Recently Browsing   0 members

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