Page 1 of 1

xQd's thread of scripting questions

Posted: 22 Jul 2017, 14:48
by xQd
I am currently modding CoC alot with the goal of making the gameplay as hard as possible. Instead of creating a new thread with every new question I have, I figured I should post them all in a single thread.

1. So right now I am trying to make it so you get less ammo from unloading a weapon. When you unload a weapon, you get the exact amount of remaining bullets from the mag. Therefore, if you play stealthly, like how I usually do, you get to kill NPCs without giving them a chance to fire once and you end up with a full mag from the weapon they carried. I also noticed that they barely use their secondary so you get a full mag from their backup weapon as well.

I have tried to implement this code provided by Alundaio from here.

It doesn't do anything, I used the printf function on data.ammo_current and it shows 90 bullets in the mag of most of the weapons, which is impossible. Maybe it has to do with the fact that some functions from death_manager.script regarding loot drops from NPCs execute twice at the same time when they die? I posted that bug here.

Re: xQd's thread of scripting questions

Posted: 23 Jul 2017, 16:51
by Alundaio
In death_manager.script after set_weapon_drop_condition is called you can do something like this:

Code: Select all

item:set_ammo_elapsed( math.random(0,item:get_ammo_in_magazine()) )

Re: xQd's thread of scripting questions

Posted: 23 Jul 2017, 17:52
by xQd
Alundaio wrote:In death_manager.script after set_weapon_drop_condition is called you can do something like this:

Code: Select all

item:set_ammo_elapsed( math.random(0,item:get_ammo_in_magazine()) )


This solution works. Thank you very much.

Re: xQd's thread of scripting questions

Posted: 26 Jul 2017, 09:50
by xQd
I have a custom descr_functor for my custom task which modifies the PDA description text of my task depending on the name and community of the task giver. I can successfully extract the name of the task giver but I cannot figure out how to get their community, it always crashes when I try to call either community() or character_community() on the task giver.

Here is the code snippet in task_functor.script:

Code: Select all

   local id = tsk.task_giver_id
   local se_obj = id and alife_object(id)
   if not (se_obj) then
      printf("task giver not valid!")
      return ""
   else
      printf("task giver valid: id=%s   task_id=%s",id,tsk.id)
      local name = se_obj:character_name()
      local faction = se_obj:character_community() --> this is where it crashes(attempting to call character_community() method, nil value); also tried character_community(se_obj)
      if (field == "descr") then
         return strformat(game.translate_string(p) or "",name,faction)
      end
   end


I don't get it, why character_community() works in any other script but it doesn't work in task_functor.script?

Re: xQd's thread of scripting questions

Posted: 26 Jul 2017, 22:02
by Alundaio
But character_name() works?

Re: xQd's thread of scripting questions

Posted: 27 Jul 2017, 04:05
by xQd
Alundaio wrote:But character_name() works?


character_name() works, it prints out the correct name.

I have tried to return the level the task_giver is in, using:

Code: Select all

game.translate_string(alife():level_name(game_graph():vertex(se_obj.m_game_vertex_id):level_id()))

That works too.

I have tried se_obj.community, it doesn't crash the game, but it prints nil. Maybe it has to do with the fact that the NPC's player_id is set to 'trader' ? The community is set inside the character_desc_*.xml.

I needed this because the traders are dynamic, they can spawn in any level and faction. Therefore, I needed a good way to inform the player via PDA task description from whom they got the task. The trader's character name didn't seem enough, so I also wanted to add the trader NPC's faction to the description.

The level name seems good enough for me though, no need to show the faction name anymore.