[script] OnDeath item spawning

Hi,

what would be the method to spawn a specific object on a creature death ?
So many things a lacking on the script front it seems :undecided:

I dont want to use the DBR system, because I want the spawn of item to be “skill” based.
I created “skills” using token:
NOVICE_SKINNER
EXPERT_SKINNER
MASTER_SKINNER

I also have a conversation that can recap the various skill levels the player has achieved, in various skills (right now, skinning and butchering)
I managed to have a sentence and randomized skill check information (using UI.Notify() )

Increasing skills will only be possible through buying the levels (again, the script methods are so few and poor :frowning: )

So if the player succeeds a skinning test, I want to spawn some bristly fur, for example.

Any idea ? Maybe use one of the character methods ?

The corpses aren’t persistent, I think that would be the first thing to change :frowning:

I just did some quick tests, and I can give summoned pets spawned inventory, but I can’t actually add anything or remove anything via in-game-methods and lua scripting as far as I can see. They do have an onAddItem script handler, but no idea how to call it. That’s probably a C++ thing only? I want some introspection in scripting…

How about this:
Spawn a “skinnable corpse” 100% of the time as an item in the world, just a dbr item.
Maybe spawn a ‘destructible’ terrain item, because it has a “lua hook” section
Check the player skill (?? it wasn’t on the API list)

I don’t see how a skill can uniquely affect only one type of game item. I was thinking about 1 million HP item that has super high resist to everything except that one skill - but that would require inventing a new damage type.

Thanks for taking time to look into this. Just to make things clear, what I call “skill” is definitely not like a grim dawn skill, it is a total personal construction, because, as I said in an other thread, I love “skills”, and I think EVERYTHINGS in a RPG should be linked to some kind of skill (like gathering skills, crafting skills, exploration skills, and so on).
Anyways, maybe I could spawn some corpse, depending on the skill check result, and that corpse would hold the proper type of item.
I had a look, I would need to call the coords of the dying animal (without a self. method…), then span the corpse on those coords, depending on the skill check…

Sounds way to circomvoluted to me :frowning: . I wish we could spawn items much more simply.

Actually, It’s frustrating, because conversations seem to allow many more things than scripting…

A little insight of my simple scripts might help you understand…

function gd.quests.boardeath.boarkilled()
	--local playerName = Game.GetLocalPlayer().GetPlayerName()
	local player = Game.GetLocalPlayer()
	
	local randomCast = math.random(1,100)
	local playerSkinnerLevel,skinnerLevelTag = checkSkinnerLevel()
	local sSkillResult = ""
	local bSkillResult = true
	if randomCast>playerSkinnerLevel then bSkillResult = false end
	
	if bSkillResult then
		sSkillResult = "skinning_skill_success"
	else
		sSkillResult = "skinning_skill_failure"
	end

	UI.Notify(sSkillResult)
end

function checkSkinnerLevel()
	local skinnerLevel = 20
	local skinnerLevelTag = "untrained"
	local player = Game.GetLocalPlayer()
	if player:HasToken("SKINNER_MASTER") then skinnerLevel = 90 end
	if player:HasToken("SKINNER_EXPERT") then skinnerLevel = 65 end
	if player:HasToken("SKINNER_NOVICE") then skinnerLevel = 30 end
	
	return skinnerLevel,skinnerLevelTag
end

The problem is interacting right? You need those scripts called at a particular time and our API access is pretty limited. If you could set onDeath for all beasts, run that script and then (onSuccess) do game.Spawn() on the appropriate loot.

Try putting your script name in the onDeath parameter.


As you can see, I do have a feedback (“skinning skill failure”)
The spawned items are from the native DBR loot system (modded to spawn 100% chance on death).

My script goes indeed on the onDeath parameter.

What I need now is a self.spawn(“dbr_string”), to dynamically spawn items at the coords of the dead creature.

This of course must exist somewhere, because the loot system do exists.

As a notice, the UINotify lasts about 2-3 secs, and has a cooldown of about 3-4 seconds. Meaning that if I kill boars really fast, I will have quite a big delay between the death and the notification :undecided:

I lied, there is a state: “Dying” (as opposed to useSKill, Move or Attack) but it only lasts about 2-3 seconds. Maybe that’s configurable. Isn’t there also a long death animation you could play that would allow you more time to use your skinner skill? (Unless it is passive obviously)

I use it passively, because I don’t want to bother the player with some tedious handywork ^^.

Just a skill to increase world interaction. A legendary “gatherer” would get components almost all the time, and sometimes, complete components, while a novice would sometimes get a component.
Anyways…

Whew, now that is very neat.
Am very relieved at least some scripts are feasible.
Thanks for the information cromcrom.

looking forward to your full mod and future projects.

Wow, that’s ambitious :slight_smile:
I love the idea a lot and I love too see some .lua coding.
Finally something I understand a little, haha!

Good luck with the project, and hopefully we get more information integrated to the modding guide… right now it’s pretty basic.

YEAH, this does the trick. At least in single player … :frowning:


function gd.quests.boardeath.boarkilled()
	local player = Game.GetLocalPlayer()
	
	local randomCast = math.random(1,100)
	local playerSkinnerLevel,skinnerLevelTag = checkSkinnerLevel()
	local sSkillResult = ""
	local bSkillResult = true
	local randomMoney = math.random(50,100)+playerSkinnerLevel
	if randomCast>playerSkinnerLevel then bSkillResult = false end
	
	if bSkillResult then
		sSkillResult = "skinning_skill_success"
		player:GiveItem("items/compa_batteredshell.dbr",1,false)
		player:AdjustMoney(randomMoney)		
	else
		sSkillResult = "skinning_skill_failure"
	end

	UI.Notify(sSkillResult)

	
end

function checkSkinnerLevel()
	local skinnerLevel = 80 --for testing purpose. would be 10 for an untrained skinner.
	local skinnerLevelTag = "untrained"
	local player = Game.GetLocalPlayer()
	if player:HasToken("SKINNER_MASTER") then skinnerLevel = 90 end
	if player:HasToken("SKINNER_EXPERT") then skinnerLevel = 65 end
	if player:HasToken("SKINNER_NOVICE") then skinnerLevel = 30 end
	
	return skinnerLevel,skinnerLevelTag
end

Calling the character methods with the player works like a charm.

So with this script, when you kill a boar, and succeed a skinning check (depending on you skinning level), it gives a random amount of money to the player (with a bonus depending on your skinning level), and spawns some battered shell (for testing purpose, I will make the spawned items more relevant…) directly in its inventory.

Nice work, I didn’t think about the quest API. Could make it so 100 skinning successes = level up the skill by quest completed.