Tomas Posted March 23, 2014 Posted March 23, 2014 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?
Tomas Posted March 23, 2014 Author Posted March 23, 2014 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:
Tomas Posted March 23, 2014 Author Posted March 23, 2014 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
MTA Team 0xCiBeR Posted March 23, 2014 MTA Team Posted March 23, 2014 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);
Tomas Posted March 23, 2014 Author Posted March 23, 2014 Para que queres el comando? Mi servidor en este momento está superando su record de jugadores, quiero tirar dinero y que lo agarren C:
Tomas Posted March 23, 2014 Author Posted March 23, 2014 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 Ahora que terminó; Gracias
Castillo Posted March 23, 2014 Posted March 23, 2014 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
Tomas Posted March 23, 2014 Author Posted March 23, 2014 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 gracias a los dos :3 EDIT: No da debug pero tampoco da el dinero
Tomas Posted March 23, 2014 Author Posted March 23, 2014 Pero crea los pickups? Sipi, también los destruye al "hit".
Castillo Posted March 23, 2014 Posted March 23, 2014 Fijate que valor tiene "money" al tocar el pickup.
Tomas Posted March 23, 2014 Author Posted March 23, 2014 Fijate que valor tiene "money" al tocar el pickup. Nada...
Tomas Posted March 23, 2014 Author Posted March 23, 2014 A que te referis con "nada"? Que al tocar el pickup o "hitearlo" no sale nada en el debug.
Castillo Posted March 23, 2014 Posted March 23, 2014 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
Tomas Posted March 23, 2014 Author Posted March 23, 2014 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. )
Castillo Posted March 23, 2014 Posted March 23, 2014 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
Tomas Posted March 24, 2014 Author Posted March 24, 2014 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 Este castillo noob haha, okno Te admiro :3
Tomas Posted March 25, 2014 Author Posted March 25, 2014 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 ? ._.
Castillo Posted March 25, 2014 Posted March 25, 2014 En lugar de que obtenga el dinero del jugador pones 10.
Tomas Posted March 25, 2014 Author Posted March 25, 2014 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? ._.
Recommended Posts