Jump to content

Dudas sobre creación de un Inventario


Recommended Posts

Posted (edited)

Hola, ps como dice el titulo, Como podria obtener todas las Armas que posee un jugador y pasarlas a una gridlist?

Edited by Guest
  • MTA Team
Posted

Usas un for-loop en combinación con getPedWeapon

local cantidadWeapons = 5--Un ejemplo no se cuantos slots hay en total. 
for i=1, cantidadWeapons do 
local weap = getPedWeapon(player,i) 
if not weap == 0 then 
--Obtener nombre y agregar a gridlist 
end 
end 

Posted

Intente esto, Pero no me resulto

local cantidadWeapons = 5 
for i=1, cantidadWeapons do 
local weap = getPedWeapon(localPlayer,i) 
if not weap == 0 then 
local row = guiGridListAddRow ( itemgrid ) 
guiGridListSetItemText ( itemgrid, row, colu, weap, false, false ) 

Posted
Intente esto, Pero no me resulto
local cantidadWeapons = 5 
for i=1, cantidadWeapons do 
local weap = getPedWeapon(localPlayer,i) 
if not weap == 0 then 
local row = guiGridListAddRow ( itemgrid ) 
guiGridListSetItemText ( itemgrid, row, colu, weap, false, false ) 

Postea la función completa.

  • MTA Team
Posted

Además eso solo te va a agregar ID's al gridlist, debes obtener el nombre del arma según ID, si eso es lo que quieres lograr.

Posted
Además eso solo te va a agregar ID's al gridlist, debes obtener el nombre del arma según ID, si eso es lo que quieres lograr.
local cantidadWeapons = 5 
for i=1, cantidadWeapons do 
local weap = getPedWeapon(localPlayer,i) 
if weap ~= getPedWeapon(localPlayer,0) then 
local row = guiGridListAddRow ( itemgrid ) 
guiGridListSetItemText ( itemgrid, row, 1, getWeaponNameFromID(weap), false, false ) 
end 
end 

Posted

Listo, Me funciono, Muchas gracias a todos los que respondieron, Pero tengo otra duda que función podría usar para obtener la cantidad de balas? intente getSlotFromWeapon me funciono pero no me devuelve la cantidad de balas.

Posted
Listo, Me funciono, Muchas gracias a todos los que respondieron, Pero tengo otra duda que función podría usar para obtener la cantidad de balas? intente getSlotFromWeapon me funciono pero no me devuelve la cantidad de balas.

dentro del mismo for loops, usas getPedTotalAmmo.

Posted

Intente con me resulto, perooo, me coloca es todas la cantidad que de balas pero en el arma actual

local cantidadWeapons = 10 
  for i=1, cantidadWeapons do 
   local weap = getPedWeapon(localPlayer,i) 
     if weap ~= getPedWeapon(localPlayer,0) then 
      local row = guiGridListAddRow ( itemgrid ) 
      guiGridListSetItemText ( itemgrid, row, 1,getWeaponNameFromID(weap), false, false ) 
      guiGridListSetItemText ( itemgrid, row, 2,getPedTotalAmmo(localPlayer), false, false ) 

luego al probar esto,se me crashea mta

tidadWeapons do 
   local weap = getPedWeapon(localPlayer,i) 
     if weap ~= getPedWeapon(localPlayer,0) then 
      local row = guiGridListAddRow ( itemgrid ) 
      guiGridListSetItemText ( itemgrid, row, 1,getWeaponNameFromID(weap), false, false ) 
      guiGridListSetItemText ( itemgrid, row, 2,getPedTotalAmmo(localPlayer, weap), false, false ) 

Posted
  
    tidadWeapons do 
       local weap = getPedWeapon(localPlayer,i) 
         if weap ~= getPedWeapon(localPlayer,0) then 
          local row = guiGridListAddRow ( itemgrid ) 
          guiGridListSetItemText ( itemgrid, row, 1,getWeaponNameFromID(weap), false, false ) 
          guiGridListSetItemText ( itemgrid, row, 2,getPedTotalAmmo(localPlayer, i), false, false ) 
  

Posted
  
    tidadWeapons do 
       local weap = getPedWeapon(localPlayer,i) 
         if weap ~= getPedWeapon(localPlayer,0) then 
          local row = guiGridListAddRow ( itemgrid ) 
          guiGridListSetItemText ( itemgrid, row, 1,getWeaponNameFromID(weap), false, false ) 
          guiGridListSetItemText ( itemgrid, row, 2,getPedTotalAmmo(localPlayer, i), false, false ) 
  

Perfecto me funciono gracias, Pero ahora la pregunta del millon, porque i? si me dice que i es igual a 1, no ?

Posted
  
    tidadWeapons do 
       local weap = getPedWeapon(localPlayer,i) 
         if weap ~= getPedWeapon(localPlayer,0) then 
          local row = guiGridListAddRow ( itemgrid ) 
          guiGridListSetItemText ( itemgrid, row, 1,getWeaponNameFromID(weap), false, false ) 
          guiGridListSetItemText ( itemgrid, row, 2,getPedTotalAmmo(localPlayer, i), false, false ) 
  

Perfecto me funciono gracias, Pero ahora la pregunta del millon, porque i? si me dice que i es igual a 1, no ?

es el indice que te otorga el for loops, lo que hiciste para definir todas las armas funciona igual para sus municiones.

Posted

Ése i es igual al índice del loop que se está ejecutando, es decir, puede ser 1, 2, 3, 4 o 5 ( ya que fué el máximo que estipulaste ).

De todas formas, deberías cambiar ese 5 por un 12, ya que hay 12 slots.

Posted

Haaa ok perfecto, ya entendí por esa parte, Use bone_attach para crearle una mochila a el jugador quedándome de la siguiente manera:

jugador = getLocalPlayer() 
mochilero = createObject(371,0,0,0) 
exports.bone_attach:attachElementToBone(mochilero,jugador,3,0,-0.1,0,0,0,0) 

Pero el problema es que debido a que es client, solo se muestra a el jugador no a todo el server, Intente triggearlo desde el server pero no me resulto:

function MochilaPed() 
 triggerClientEvent("alIniciar", resourceRoot) 
end 
addEventHandler("onResourceStart", root, MochilaPed) 

function crearMochila() 
jugador = getLocalPlayer() 
 mochilero = createObject(371,0,0,0) 
 exports.bone_attach:attachElementToBone(mochilero,jugador,3,0,-0.1,0,0,0,0) 
end 
addEvent("alIniciar", true) 
addEventHandler("alIniciar", root, crearMochila) 

  • Recently Browsing   0 members

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