When my script has only option to buy 1 gun, it usually works:
Spoiler
npcs = {
{type = 'weapon', x = 235, y = 121, cost = 1, weapon = 6, name = 'Five-Seven', npcname = 'Vendedor de Armas'}
}
addhook('usebutton', 'usebuttonHook')
function usebuttonHook(id, x, y)
for npc = 1, #npcs do
if x == npcs[npc].x and y == npcs[npc].y then
if player(id, 'money') >= npcs[npc].cost then
if npcs[npc].type == 'food' then
parse('sethealth '..id..' '..(player(id, 'health') + npcs[npc].heal))
elseif npcs[npc].type == 'weapon' then
parse('equip '..id..' '..npcs[npc].weapon)
end
parse('setmoney '..id..' '..(player(id, 'money') - npcs[npc].cost))
msg2(id, "Voce adquiriu um item.")
end
end
end
end
{type = 'weapon', x = 235, y = 121, cost = 1, weapon = 6, name = 'Five-Seven', npcname = 'Vendedor de Armas'}
}
addhook('usebutton', 'usebuttonHook')
function usebuttonHook(id, x, y)
for npc = 1, #npcs do
if x == npcs[npc].x and y == npcs[npc].y then
if player(id, 'money') >= npcs[npc].cost then
if npcs[npc].type == 'food' then
parse('sethealth '..id..' '..(player(id, 'health') + npcs[npc].heal))
elseif npcs[npc].type == 'weapon' then
parse('equip '..id..' '..npcs[npc].weapon)
end
parse('setmoney '..id..' '..(player(id, 'money') - npcs[npc].cost))
msg2(id, "Voce adquiriu um item.")
end
end
end
end
If I put the same I put below, the script does not recognize neither the first gun.
Spoiler
npcs = {
{type = 'weapon', x = 235, y = 121, cost = 1, weapon = 6, name = 'Five-Seven', npcname = 'Vendedor de Armas'}
{type = 'weapon2', x = 236, y = 121, cost = 1, weapon = 5, name = 'Elite', npcname = 'Vendedor de Armas2'}
{type = 'weapon3', x = 237, y = 121, cost = 1, weapon = 2, name = 'Glock', npcname = 'Vendedor de Armas3'}
{type = 'weapon4', x = 238, y = 121, cost = 1, weapon = 3, name = 'Deagle', npcname = 'Vendedor de Armas4'}
{type = 'weapon5', x = 245, y = 121, cost = 1, weapon = 10, name = 'M3', npcname = 'Vendedor de Armas5'}
{type = 'weapon6', x = 246, y = 121, cost = 1, weapon = 11, name = 'XM1014', npcname = 'Vendedor de Armas6'}
{type = 'weapon7', x = 247, y = 121, cost = 1, weapon = 35, name = 'AWP', npcname = 'Vendedor de Armas7'}
{type = 'weapon8', x = 248, y = 121, cost = 1, weapon = 34, name = 'SCOUT', npcname = 'Vendedor de Armas8'}
{type = 'weapon9', x = 235, y = 113, cost = 1, weapon = 31, name = 'SG552', npcname = 'Vendedor de Armas9'}
{type = 'weapon10', x = 236, y = 113, cost = 1, weapon = 33, name = 'AUG32', npcname = 'Vendedor de Armas10'}
{type = 'weapon11', x = 237, y = 113, cost = 1, weapon = 37, name = 'SG550', npcname = 'Vendedor de Armas11'}
{type = 'weapon12', x = 238, y = 113, cost = 1, weapon = 36, name = 'G3SG1', npcname = 'Vendedor de Armas12'}
{type = 'weapon13', x = 245, y = 113, cost = 1, weapon = 32, name = 'M4A1', npcname = 'Vendedor de Armas13'}
{type = 'weapon14', x = 246, y = 113, cost = 1, weapon = 30, name = 'AK-47', npcname = 'Vendedor de Armas14'}
{type = 'weapon15', x = 247, y = 113, cost = 1, weapon = 22, name = 'P90', npcname = 'Vendedor de Armas15'}
{type = 'weapon16', x = 248, y = 113, cost = 1, weapon = 38, name = 'Galil', npcname = 'Vendedor de Armas16'}
{type = 'weapon17', x = 235, y = 105, cost = 1, weapon = 76, name = 'Air-Strike', npcname = 'Vendedor de Armas17'}
{type = 'weapon18', x = 236, y = 105, cost = 1, weapon = 72, name = 'Gas-Grenade', npcname = 'Vendedor de Armas18'}
{type = 'weapon19', x = 237, y = 105, cost = 1, weapon = 73, name = 'Molotov Cocktail', npcname = 'Vendedor de Armas19'}
{type = 'weapon20', x = 238, y = 105, cost = 1, weapon = 51, name = 'HE', npcname = 'Vendedor de Armas20'}
{type = 'weapon21', x = 245, y = 105, cost = 1, weapon = 41, name = 'Tactical Shield', npcname = 'Vendedor de Armas21'}
{type = 'weapon22', x = 246, y = 105, cost = 1, weapon = 69, name = 'Machete', npcname = 'Vendedor de Armas22'}
{type = 'weapon23', x = 247, y = 105, cost = 1, weapon = 60, name = 'Gas Mask', npcname = 'Vendedor de Armas23'}
{type = 'weapon24', x = 248, y = 105, cost = 1, weapon = 82, name = 'Medic Armor', npcname = 'Vendedor de Armas24'}
{type = 'weapon25', x = 235, y = 97, cost = 1, weapon = 77, name = 'Mine', npcname = 'Vendedor de Armas25'}
{type = 'weapon26', x = 236, y = 97, cost = 1, weapon = 86, name = 'Gut Bomb', npcname = 'Vendedor de Armas26'}
{type = 'weapon27', x = 237, y = 97, cost = 1, weapon = 87, name = 'Laser Mine', npcname = 'Vendedor de Armas27'}
{type = 'weapon28', x = 238, y = 97, cost = 1, weapon = 89, name = 'Satchel Charge', npcname = 'Vendedor de Armas28'}
{type = 'weapon29', x = 245, y = 97, cost = 1, weapon = 90, name = 'M134', npcname = 'Vendedor de Armas29'}
{type = 'weapon30', x = 246, y = 97, cost = 1, weapon = 91, name = 'FN F2000', npcname = 'Vendedor de Armas30'}
{type = 'weapon31', x = 247, y = 97, cost = 1, weapon = 85, name = 'Chainsaw', npcname = 'Vendedor de Armas31'}
{type = 'weapon32', x = 248, y = 97, cost = 1, weapon = 40, name = 'M249', npcname = 'Vendedor de Armas32'}
}
addhook('usebutton', 'usebuttonHook')
function usebuttonHook(id, x, y)
for npc = 1, #npcs do
if x == npcs[npc].x and y == npcs[npc].y then
if player(id, 'money') >= npcs[npc].cost then
if npcs[npc].type == 'food' then
parse('sethealth '..id..' '..(player(id, 'health') + npcs[npc].heal))
elseif npcs[npc].type == 'weapon' then
parse('equip '..id..' '..npcs[npc].weapon)
end
parse('setmoney '..id..' '..(player(id, 'money') - npcs[npc].cost))
msg2(id, "Voce adquiriu um item.")
end
end
end
end
{type = 'weapon', x = 235, y = 121, cost = 1, weapon = 6, name = 'Five-Seven', npcname = 'Vendedor de Armas'}
{type = 'weapon2', x = 236, y = 121, cost = 1, weapon = 5, name = 'Elite', npcname = 'Vendedor de Armas2'}
{type = 'weapon3', x = 237, y = 121, cost = 1, weapon = 2, name = 'Glock', npcname = 'Vendedor de Armas3'}
{type = 'weapon4', x = 238, y = 121, cost = 1, weapon = 3, name = 'Deagle', npcname = 'Vendedor de Armas4'}
{type = 'weapon5', x = 245, y = 121, cost = 1, weapon = 10, name = 'M3', npcname = 'Vendedor de Armas5'}
{type = 'weapon6', x = 246, y = 121, cost = 1, weapon = 11, name = 'XM1014', npcname = 'Vendedor de Armas6'}
{type = 'weapon7', x = 247, y = 121, cost = 1, weapon = 35, name = 'AWP', npcname = 'Vendedor de Armas7'}
{type = 'weapon8', x = 248, y = 121, cost = 1, weapon = 34, name = 'SCOUT', npcname = 'Vendedor de Armas8'}
{type = 'weapon9', x = 235, y = 113, cost = 1, weapon = 31, name = 'SG552', npcname = 'Vendedor de Armas9'}
{type = 'weapon10', x = 236, y = 113, cost = 1, weapon = 33, name = 'AUG32', npcname = 'Vendedor de Armas10'}
{type = 'weapon11', x = 237, y = 113, cost = 1, weapon = 37, name = 'SG550', npcname = 'Vendedor de Armas11'}
{type = 'weapon12', x = 238, y = 113, cost = 1, weapon = 36, name = 'G3SG1', npcname = 'Vendedor de Armas12'}
{type = 'weapon13', x = 245, y = 113, cost = 1, weapon = 32, name = 'M4A1', npcname = 'Vendedor de Armas13'}
{type = 'weapon14', x = 246, y = 113, cost = 1, weapon = 30, name = 'AK-47', npcname = 'Vendedor de Armas14'}
{type = 'weapon15', x = 247, y = 113, cost = 1, weapon = 22, name = 'P90', npcname = 'Vendedor de Armas15'}
{type = 'weapon16', x = 248, y = 113, cost = 1, weapon = 38, name = 'Galil', npcname = 'Vendedor de Armas16'}
{type = 'weapon17', x = 235, y = 105, cost = 1, weapon = 76, name = 'Air-Strike', npcname = 'Vendedor de Armas17'}
{type = 'weapon18', x = 236, y = 105, cost = 1, weapon = 72, name = 'Gas-Grenade', npcname = 'Vendedor de Armas18'}
{type = 'weapon19', x = 237, y = 105, cost = 1, weapon = 73, name = 'Molotov Cocktail', npcname = 'Vendedor de Armas19'}
{type = 'weapon20', x = 238, y = 105, cost = 1, weapon = 51, name = 'HE', npcname = 'Vendedor de Armas20'}
{type = 'weapon21', x = 245, y = 105, cost = 1, weapon = 41, name = 'Tactical Shield', npcname = 'Vendedor de Armas21'}
{type = 'weapon22', x = 246, y = 105, cost = 1, weapon = 69, name = 'Machete', npcname = 'Vendedor de Armas22'}
{type = 'weapon23', x = 247, y = 105, cost = 1, weapon = 60, name = 'Gas Mask', npcname = 'Vendedor de Armas23'}
{type = 'weapon24', x = 248, y = 105, cost = 1, weapon = 82, name = 'Medic Armor', npcname = 'Vendedor de Armas24'}
{type = 'weapon25', x = 235, y = 97, cost = 1, weapon = 77, name = 'Mine', npcname = 'Vendedor de Armas25'}
{type = 'weapon26', x = 236, y = 97, cost = 1, weapon = 86, name = 'Gut Bomb', npcname = 'Vendedor de Armas26'}
{type = 'weapon27', x = 237, y = 97, cost = 1, weapon = 87, name = 'Laser Mine', npcname = 'Vendedor de Armas27'}
{type = 'weapon28', x = 238, y = 97, cost = 1, weapon = 89, name = 'Satchel Charge', npcname = 'Vendedor de Armas28'}
{type = 'weapon29', x = 245, y = 97, cost = 1, weapon = 90, name = 'M134', npcname = 'Vendedor de Armas29'}
{type = 'weapon30', x = 246, y = 97, cost = 1, weapon = 91, name = 'FN F2000', npcname = 'Vendedor de Armas30'}
{type = 'weapon31', x = 247, y = 97, cost = 1, weapon = 85, name = 'Chainsaw', npcname = 'Vendedor de Armas31'}
{type = 'weapon32', x = 248, y = 97, cost = 1, weapon = 40, name = 'M249', npcname = 'Vendedor de Armas32'}
}
addhook('usebutton', 'usebuttonHook')
function usebuttonHook(id, x, y)
for npc = 1, #npcs do
if x == npcs[npc].x and y == npcs[npc].y then
if player(id, 'money') >= npcs[npc].cost then
if npcs[npc].type == 'food' then
parse('sethealth '..id..' '..(player(id, 'health') + npcs[npc].heal))
elseif npcs[npc].type == 'weapon' then
parse('equip '..id..' '..npcs[npc].weapon)
end
parse('setmoney '..id..' '..(player(id, 'money') - npcs[npc].cost))
msg2(id, "Voce adquiriu um item.")
end
end
end
end
edited 1×, last 22.06.14 06:43:25 pm