Hi all, ive been messing about with a universal shop script, which ties in with other currency to make it all blend in nicely, i have it working up to the point of the weapon being added to the players inventory e.g arrows, bolts etc . Problem is nothing is being added, i can buy ok using the right currency but no arrows added. Here's the code
--key to cycle left
local left = "o"
--key to cycle right
local right = "p"
--key to purchase item
local confirm = "["
--distance to shop (to interact)
local shop = 120
--variable used for in game currency
g_RPG_Gold = 0
local pressed = 0
local item = 1
local item_name = {}
local max_item = 15
local item_number = {}
local cost = {}
function shop_init(e)
item_name[1] = "Bow"
item_name[2] = "Arrows"
item_name[3] = "Crossbow"
item_name[4] = "Bolts"
item_name[5] = ""
--set item number here of items to be sold (if weapon or ammo etc - if not a real item then enter 0)
item_number[1] = 680
item_number[2] = 681
item_number[3] = 682
item_number[4] = 683
item_number[5] = 0
--set cost of each item here
cost[1] = 2000
cost[2] = 150
cost[3] = 2000
cost[4] = 200
cost[5] = 0
--folder containing images
--LoadImages("shop",1)
end
function shop_main(e)
--if player near shop
if GetPlayerDistance(e) <= shop then
if pressed == 0 then
if GetInKey() == confirm then
--check player has enough to purchase item
if g_RPG_Gold >= cost[item] then
--update money and give item
g_RPG_Gold = g_RPG_Gold - cost[item]
PlaySound(e,0)
AddPlayerWeapon(item_number[item])
pressed = 1
end
end
--cycle through items
if GetInKey() == right then
pressed = 1
if item < max_item then
item = item + 1
else
item = 1
end
elseif GetInKey() == left then
pressed = 1
if item > 1 then
item = item - 1
else
item = max_item
end
end
--show prompt while near shop
Prompt(item_name[item] .. " Costs " .. cost[item] .. " , You have " .. g_RPG_Gold .. "Gold")
else
--reset input if key's are released
if GetInKey() ~= left and GetInKey() ~= right and GetInKey() ~= confirm then
pressed = 0
end
end
--update images
SetImageAlignment(0)
SetImagePosition(50,50)
ShowImage(item)
else
HideImage(item)
end
end
Any ideas as to why? im using the entity number from the bottom of the editor