On a Seller NPC project

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
User avatar
Eczarkun
Posts: 9
Joined: Sun Dec 09, 2012 6:48 pm
Location: FRANCE

On a Seller NPC project

Post by Eczarkun »

Hello everyone,

I'm back trying to make script, and understand the work good scripters do. I think the first step is to make gold money piles in order to have enough money drop on the monsters. I'have already found a 3D free model for the vendor (i call him Blaze_gypsy) and integrated the script Adding NPC traders to your dungeon - buy stuff! use Alcoves from Akatana, but before beeing able to buy something, money is needed. So here is my newbie trying:

For the Gold coin, i used the gor gold coin model from Germanny in his grim_vsword_v21-128-2-1.

Then I made a pile in my blender, capture the render for the icon_atlas and integrated it in a custom atlas (sorry for , imported the pile model in GMT to edit the Gold_Coin_pile.model file.

The next step was to define the new object un a gold_coin_pile.lua imported before in my init.lua:
SpoilerShow
-- by Germanny
defineObject{
name = "gor_coin_gold",
class = "Item",
uiName = "Gold Gor Coin",
model = "mod_assets/grim_vsword/models/items/gor_coin_gold.fbx",
description = "Golden Coin of Gor",
gfxAtlas = "mod_assets/grim_vsword/textures/gui/germ_icoatlas.tga",
gfxIndex = 13,
glitterEffect = "glitter_gold",
stackable = true,
weight = 0.031, -- Modified to have a once weight
}

-- Again by Germanny
defineMaterial{
name = "gor_coin_gold",
diffuseMap = "mod_assets/grim_vsword/textures/items/gor_coin_gold_dif.tga",
specularMap = "mod_assets/grim_vsword/textures/items/gor_coin_spec.tga",
normalMap = "mod_assets/grim_vsword/textures/items/gor_coin_normal.tga",
doubleSided = false,
lighting = true,
alphaTest = false,
blendMode = "Opaque",
textureAddressMode = "Wrap",
glossiness = 70,
depthBias = 0,
}

defineObject{
name = "gold_coin_pile",
class = "Item",
uiName = "Gold Coin Pile",
model = "mod_assets/models/items/Gold_coin_pile.fbx",
description = "A small amount of gold coins",
gfxAtlas = "mod_assets/Atlas/icoatlas.tga",
gfxIndex = 31, -- number in my custom atlas
glitterEffect = "glitter_gold",
stackable = false,
weight = 0.5,
onUseItem = function(champion, item)
goldScript.amountGold(item)
end,
}
the script_entity name "goldScript" using check if anybody in your party is carrying a particular type of item by Billick
SpoilerShow
-- INTRODUCE FUNCTION TO CHECK IF THERE IS A SPECIFIC ITEM IN THE PARTY BACKPACK

-- Loop Check for the 4 champions of party
function checkForItemParty(item)
local i = 1
repeat
if checkForItem(party:getChampion(i), item)
then return true
end
i = i + 1
until i == 5
return false
end

-- Check in one champion backpack
function checkForItem(champion, item)
local j = 1
repeat
local itemObj = champion:getItem(j)
if itemObj ~= nil then
if itemObj.name == item
then return true
end
end
j = j+1
until j == 32
return false
end

-- RANDOM GENERATOR PILE OF GOLD COINS

-- Initialize Locals
Amount = 1

function amountGold()
Amount = math.random(25) -- for now on i tried a simple random function but later it may depends on the health of a creature
if checkForItemParty("gold_coin_pile")
then print("We have a gold pile")
spawn("gor_coin_gold", party.level, party.x, party.y, party.facing):setStackSize(Amount) -- here i generate a pile of gor gold coin
else print("We don't have gold pile")
end
end
The effect is a fully generated pile witch create a stack (random(25)) of gold coins,....

But whatever i try, i can't destroy the gold_coin_pile in the party inventory and my spawn of the stack appears on the floor and not in the inventory. I looked the use of Grimq but my understanding of
the ChampionInventoryEx function and replace() subfunction is nearly a desaster...
User avatar
msyblade
Posts: 792
Joined: Fri Oct 12, 2012 4:40 am
Location: New Mexico, USA
Contact:

Re: On a Seller NPC project

Post by msyblade »

don't have my references in front of me right now, but I THINK you are running into the simple problem of scripts differing between inventory and "the world". For instance, to bring an item into existence, you "Spawn" it, but to give to a character, you addItem(not sure if that's correct, but the concept remains.), and if u want to eliminate an object in the world you use "Destroy()", but if a character has the item, the command is removeItem() instead. I'm not familiar with your specific situation or problem, but I have seen this issue affect other modders when scripting. Food for thought! ;)
Oh, n nice ta meet ya! welcome to the Grimrock forums, buddy! :lol:

See this page (ALWAYS!) for reference. (Thanx again jKos, this was a HUGE help to the entire community.)
https://sites.google.com/site/jkosgrimr ... heat-sheet
Currently conspiring with many modders on the "Legends of the Northern Realms"project.

"You have been captured by a psychopathic diety who needs a new plaything to torture."
Hotel Hades
User avatar
Eczarkun
Posts: 9
Joined: Sun Dec 09, 2012 6:48 pm
Location: FRANCE

Re: On a Seller NPC project

Post by Eczarkun »

hy, thanks for your answer

well i also try to define locals as champion_nb and inventory_nb, inserted it in the two loops to be able to memorize the correct implacement (champion, inventory) to be able to use the following
function Steal an item being held or equiped by a party member by Komag : party:getChampion(champion_nb):removeItem(inventory_nb) and of course party:getChampion(champion_nb):insertItem(inventory_nb, spawn(...)) .

But my knowledge of code and the limitation on operators such as "and then" "and if"...etc... get me back silly coordonates so that any function is usefull. Perhaps my placement of these memorize locals was wrong...
User avatar
Wanderer
Posts: 113
Joined: Sat Dec 29, 2012 9:08 pm
Location: Lyramion / Twinlake :)

Re: On a Seller NPC project

Post by Wanderer »

But the Idea to have some sort of Trading-System is great.
I need also some sort of Trading in my Mod (at last to clean-up the Dungeons :mrgreen: ) and I had the same Idea to use Germannys wonderful coins for this. So I am looking forward for your project.

lg Wanderer

Edit: But consider, that there may be "Quest-Items" wich are not to be sold anyway. But at last such common Items like Spears and Shields of the Skeletons to exchange with coins and then buy other things with the coins is a great Idea.
My first LoG-Mod: Abandoned Places 2
User avatar
Eczarkun
Posts: 9
Joined: Sun Dec 09, 2012 6:48 pm
Location: FRANCE

Re: On a Seller NPC project

Post by Eczarkun »

here is the code replacing the script_entity wich ID is goldScript, it is shorter, remove all the piles of gold coins in the inventory of the champions but spawn the random quantity of gold coins on the floor:
i don't know how to use setStackSize(Amount) on the gor_coin_gold in the insertItem(). I took the Return to Inventory topic to get it better.
SpoilerShow
-- RANDOM GENERATOR PILE OF GOLD COINS

-- Initialize Locals
Amount = 1

function amountGold(item,champ,x)
Amount = math.random(25)
for champ = 1,4 do
for slot = 11,31 do
x = party:getChampion(champ):getItem(slot)
if x ~= nil then
if x.name == "gold_coin_pile" then
party:getChampion(champ):removeItem(slot)
spawn("gor_coin_gold", party.level, party.x, party.y, party.facing):setStackSize(Amount) -- Spawn gold stack on the floor
-- party:getChampion(champ):insertItem(slot,y):setStackSize(Amount) -- impossible combination between setStackSize and insertItem
hudprint("You lost some money on the floor")
end
end
end
end
end
User avatar
Eczarkun
Posts: 9
Joined: Sun Dec 09, 2012 6:48 pm
Location: FRANCE

Re: On a Seller NPC project

Post by Eczarkun »

sorry i found a little mistake on the previous post : it's hudPrint nor hudprint. Also i saw the random loot system by Jkos in the topic Set up for Randomized Loot in dungeon or monster drops. I added a new Itemlist category "money" in his random_loot script entity.
SpoilerShow
money = { "gold_coin_pile"},
I also tried it on a monster by adding his define the following lines:
SpoilerShow
onDie = function(item)
random_loot.addRandomLoot(monstername_monsternumber,{'money'})
end,
It's work perfectly (with always the drop of the money on the floor) but is limited to a monstername_monsternumber not a category of monster... but the work on the new Randomized Loot in dungeon or monster drops is terrific!
Thanks
User avatar
Eczarkun
Posts: 9
Joined: Sun Dec 09, 2012 6:48 pm
Location: FRANCE

Re: On a Seller NPC project

Post by Eczarkun »

hello again,

well i have an evolution to the command in any monster definition:
SpoilerShow
onDie = function(self,item)
--[[ fully function with the entry money = { "gor_coin_gold"}, with amountmin=0 amountmax=exp/20 It may be better to introduce a local but i failed extracting the exp stat as the same way as the health stat ]]
random_loot.addRandomLoot(self,{'money'},0,15)
end,
I'm now working on a widgets, thanks to Jkos Grimwidgets and the use of the addrandomloot list to edit a list of buy price & sell price, with also an icon of the things a vendor can sell. But i have another problem with the .dds file generated by gimp to make a record goldsack in the same system as the grimwidgets compass, i simply tried there to replace the image of the compass with my image file. Even if i change the BC1/DXT1 to BC3/DXT5 because the import of object icons are with transparent background. The error file says:
SpoilerShow
[string "Gui.lua"]:0: D3DError - CreateTexture failed: D3DERR_INVALIDCALL
stack traceback:
[C]: in function 'load'
[string "Gui.lua"]: in function 'drawImage'
#compass:13: in function 'drawCompass'
#compass:19: in function 'callback'
#gw:47: in function '_processKeyHooks'
#gw:11: in function '_drawGUI'
mod_assets/Bonus/Grimwidgets/Scripts/grimwidgets.lua:16: in function 'onDrawGui'
[string "Party.lua"]: in main chunk
[string "Map.lua"]: in function 'sendMessage'
[string "GameMode.lua"]: in function 'update'
[string "DungeonEditor.lua"]: in main chunk
[C]: in function 'xpcall'
[string "DungeonEditor.lua"]: in function 'preview'
[string "DungeonEditor.lua"]: in function 'update'
[string "Grimrock.lua"]: in main chunk
stack traceback:
[C]: in function 'error'
[string "DungeonEditor.lua"]: in function 'handleError'
[string "DungeonEditor.lua"]: in function 'preview'
[string "DungeonEditor.lua"]: in function 'update'
[string "Grimrock.lua"]: in main chunk

OS Version 6.1

OEM ID: 0
Number of processors: 2
Page size: 4096
Processor type: 586

Total memory: 4095 MB
Free memory: 1306 MB

Display device 0:
Device name: \\.\DISPLAY1
Device string: NVIDIA GeForce GTS 450
State flags: 00000005

Display device 1:
Device name: \\.\DISPLAY2
Device string: NVIDIA GeForce GTS 450
State flags: 00000000

Display device 2:
Device name: \\.\DISPLAYV1
Device string: RDPDD Chained DD
State flags: 00200008

Display device 3:
Device name: \\.\DISPLAYV2
Device string: RDP Encoder Mirror Driver
State flags: 00200008

Display device 4:
Device name: \\.\DISPLAYV3
Device string: RDP Reflector Display Driver
State flags: 00200008
well, again i feel lost, it's the same error when i try another image for the image-sample to edit a npc seller/buyer on place of the eob dwarf image... Perhaps someone can explain me?
Thanks in advance
Post Reply