Ask a simple question, get a simple answer

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

This may need work; but test it out.

Code: Select all

defineObject{
   name = "water_shooter",
   baseObject = "base_item",
   components = {
      {
         class = "Model",
         model = "assets/models/items/revolver.fbx",
         material = "zarchton_wand",
      },
      {
         class = "Item",
         uiName = "Water Shooter",
         description = "A strange mechanics makes this weapon compressing water and shooting it out in some kind of a jet.",
         gfxAtlas = "mod_assets/textures/iconatlas/iconatlas.dds",
         gfxIndex = 33,
         weight = 1.5,
         traits = { "weapon", "firearm"},
         primaryAction = "waterbolt",
         secondaryAction = "waterbolt",


      },
      {
         class = "ItemAction",
         name = "waterbolt",
         uiName = "Water Bolt",
         cooldown = 5,
         onAttack = function(self, champion, slot, chainIndex)
              local spl = spawn("water_bolt",party.level,party.x,party.y,party.facing,party.elevation)
              spl.projectile:setIgnoreEntity(party)

              -- Set cast by champion so that experience is awarded for kills.
              local ord = champion:getOrdinal()
              spl.projectile:setCastByChampion(ord)

              -- Simulate the position of a player-cast spell.
              local left = nil
              for i = 1,4 do
                if party.party:getChampion(i):getOrdinal() == ord then
                  left = i == 1 or i == 3
                  break
                end
              end
              local wpos = party:getWorldPosition()
              local dx = nil
              local dz = nil
              if party.facing == 0 then
                dx = left and -0.1 or 0.1
                dz = -1
              elseif party.facing == 1 then
                dz = left and 0.1 or -0.1
                dx = -1
              elseif party.facing == 2 then
                dx = left and 0.1 or -0.1
                dz = 1
              else -- party.facing == 3
                dz = left and -0.1 or 0.1
                dx = 1
              end

              spl:setWorldPosition(vec(wpos[1]+dx,wpos[2]+1.35,wpos[3]+dz))
            end,
      },

   },
}
User avatar
THOM
Posts: 1274
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

Oh my goodness... It was the primaryAction that was missing! :?

Thanks, Isaac - thanks to all, that helped! Works fine now.


(That took some doing. :roll: )
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
THOM
Posts: 1274
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

Another question:

I am trying to use the crow and crow_flying object. The flying one just makes circles. Not very impressive but works.

The object simply called "crow" has to be "activated" in some kind. One possibility is that the party passes by. Maybe it is also possible to activate the crow by script - haven't had a closer look on that.

But: Once activated the crow flies a more or less random path over the sky. That's good. At night the crow vanishes. Thats good, because AFAIK birds don't fly at night. But when the morning comes back, the crow is still gone. And I see no way to get it back without respawning.

I even cannot find a crow in the main-campaign. And everything important seems to bee hardcoded (there is an component "CrowController" but I don't know, what it does). Does anyone has any experiences with this crow critter? Do I really have to respawn/reactivate it after a night?
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Ask a simple question, get a simple answer

Post by zimberzimber »

A few questions about custom conditions -

How do I force one to make a champion unable to act? (paralyzed/petrified)

How do I force conditions to remove themselves when the champion dies?
onTick() if not champion:isAlive() doesn't work, because it seems like ticks happen only when the hero is alive.

Is there a better way to make Healing Crystals remove negative conditions without defining an onClick function for the object?
My asset pack [v1.10]
Features a bit of everything! :D
User avatar
Zo Kath Ra
Posts: 937
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Ask a simple question, get a simple answer

Post by Zo Kath Ra »

zimberzimber wrote:How do I force conditions to remove themselves when the champion dies?
onTick() if not champion:isAlive() doesn't work, because it seems like ticks happen only when the hero is alive.
could you use PartyComponent.onDie(self, champion) ?
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Ask a simple question, get a simple answer

Post by zimberzimber »

Zo Kath Ra wrote:
zimberzimber wrote:How do I force conditions to remove themselves when the champion dies?
onTick() if not champion:isAlive() doesn't work, because it seems like ticks happen only when the hero is alive.
could you use PartyComponent.onDie(self, champion) ?
Huh, ashamed I didn't think of that...
Then is there a way to check for all conditions and see which are harmful? Something like isHarmful() maybe?
My asset pack [v1.10]
Features a bit of everything! :D
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

THOM wrote:Another question:

I am trying to use the crow and crow_flying object. The flying one just makes circles. Not very impressive but works.

The object simply called "crow" has to be "activated" in some kind. One possibility is that the party passes by. Maybe it is also possible to activate the crow by script - haven't had a closer look on that.

But: Once activated the crow flies a more or less random path over the sky. That's good. At night the crow vanishes. Thats good, because AFAIK birds don't fly at night. But when the morning comes back, the crow is still gone. And I see no way to get it back without respawning.

I even cannot find a crow in the main-campaign. And everything important seems to bee hardcoded (there is an component "CrowController" but I don't know, what it does). Does anyone has any experiences with this crow critter? Do I really have to respawn/reactivate it after a night?
The crow is an unfinished asset that doesn't work (it's missing a correct bounding box, missing a rig and animations, and missing working flight behaviour). Unless you are going to reimplement it from scratch, there is no point in trying to use it.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
Zo Kath Ra
Posts: 937
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Ask a simple question, get a simple answer

Post by Zo Kath Ra »

zimberzimber wrote:
Zo Kath Ra wrote:
zimberzimber wrote:How do I force conditions to remove themselves when the champion dies?
onTick() if not champion:isAlive() doesn't work, because it seems like ticks happen only when the hero is alive.
could you use PartyComponent.onDie(self, champion) ?
Huh, ashamed I didn't think of that...
Then is there a way to check for all conditions and see which are harmful? Something like isHarmful() maybe?
I don't think there is. You can create a table from this data:
https://github.com/JKos/log2doc/wiki/Conditions
The table would map condition names to categories.
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

This [checkConditions] function returns a table of the PC's current conditions, and whether they are harmful or not.
(Format: name, isHarmful [boolean], name, isHarmful,...)

Custom conditions can be added to the list.

Code: Select all

conditions = { -- Name	--isHarmful
				"burdened", true,
				"cursed", true,
				"dead", true,
				"diseased", true,
				"overloaded", true,
				"paralyzed", true,
				"petrified", true,
				"poison", true,
				"slow", true,
				"starving", true,
				"bear_form", false,
				"haste", false,
				"invisibility", false,
				"level_up", false,
				"rage", false,
				"water_breathing", false,
				"fire_shield", false,
				"frost_shield", false,
				"poison_shield", false,
				"protective_shield", false,
				"shock_shield", false,
				"chest_wound", true,
				"feet_wound", true,
				"head_wound", true,
				"left_hand_wound", true,
				"leg_wound", true,
				"right_hand_wound", true,
				}

function checkConditions(self, championOrdinal)
	if championOrdinal then
		local test = type(championOrdinal)
		if test == "number" and championOrdinal > 0 and championOrdinal < 5 then	
			local champion = party.party:getChampion(championOrdinal)
			local results = {}
			for c = 1, #conditions, 2 do
				if champion:hasCondition(conditions[c]) then
					results[#results+1] = ""
					results[#results] = conditions[c]
					results[#results+1] = conditions[c+1]
				end
			end
			return results
		end
		print("Error: "..self.go.id.."[checkConditions]" ,"Bad champion ordinal, expected number (1 to 4), got:", iff(test == "string", '"'..championOrdinal..'"', championOrdinal))
		return
	end
	print(self.go.id, "checkConditions" ,"Error, no ordinal given")	
end
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Ask a simple question, get a simple answer

Post by zimberzimber »

Looks useful, except I have absolutely no idea on how to use tables. :oops:
Help please?
My asset pack [v1.10]
Features a bit of everything! :D
Post Reply