Page 1 of 2

some scripts help pls

Posted: Mon Dec 31, 2012 5:02 pm
by Drakkan
Hi all,
could I ask you guys for some scripts help ?


1. I need lever on the wall, when activated to spawn lets say iron_key in nearby alcove


EDIT: SOLVED. I set lever on any action to decrease counter and counter to run following script:

Code: Select all

function createkey()
keyalcove: addItem (spawn "iron_key")   
end
[/color]

2. I have an altar (named Altar1) and a alcove (named Alcove1). What I need, when put particular item (lets say blue_gem) on Altar1, gem will be destroyed and in alcove will appear new item (for example red_gem)


EDIT: SOLVED via teleporter trick

Code: Select all

function altaralcovecheck()

for i in altar_1:containedItems() do
if i.name == "blue_gem" then
teleporter_1: activate()
timer_1: activate() --this is the line added
alcove_1: addItem (spawn "red_gem")
break
end
end
end
[/color]



3. can I somehow set statue (goromog_statue_blockage) to be destructible ? I saw somewhere on the forum something similar for rock blockage, but cant find it again :/


EDIT: SOLVED
clone object you want to be destroyable and add this to your object.lua

Code: Select all

cloneObject{
   name = "destructible_statue",
   baseObject = "goromorg_statue_blockage", -- you might want to change this to any statue you like (even working for cave blockades)
   brokenModel = "assets/models/env/floor_dirt.fbx", -- you can use any better model but this is ok
   health = 100, -- adjust this to your needs
   evasion = -1000,
   hitEffect = "hit_dust",
   hitSound = "impact_generic",
   onProjectileHit = function()
      return false -- projectiles (arrows and such) shouldn't be able to destroy it
   end,
   onHit = false, -- this is used to negate the "indestructible" property
   onDie = function(self)
      -- when statue is destroyed, spawn 2-5 rocks
      rocks = math.random(1,2)+1
      for i = 1,rocks do
         spawn("rock", self.level, self.x, self.y, i%4)
      end
   end
}
[/color]

4. some easy script / instruction how to define my own key (I want some door to be opened just with this key and I do not want this to be some "regular key (like Iron, brass, etc...)


EDIT: SOLVED
put in Object.lua your unique cloned key

Code: Select all

cloneObject{
name = "unique_iron_key",
baseObject = "iron_key",
}
[/color]

Re: some scripts help pls

Posted: Tue Jan 01, 2013 12:08 am
by Drakkan
one issue solved :)

Re: some scripts help pls

Posted: Tue Jan 01, 2013 12:32 am
by Sutekh
I guess the easiest way to define your own key is to just simply clone an existing one and give it a unique name:

cloneObject{
name = "unique_iron_key",
baseObject = "iron_key",
}

You can also add another line to show a different name when the key is picked up, if you want to:

uiName = "Name of Key"

Re: some scripts help pls

Posted: Tue Jan 01, 2013 12:40 am
by Drakkan
Sutekh wrote:I guess the easiest way to define your own key is to just simply clone an existing one and give it a unique name:

cloneObject{
name = "unique_iron_key",
baseObject = "iron_key",
}

You can also add another line to show a different name when the key is picked up, if you want to:

uiName = "Name of Key"
working fine, easy solution. Thanks
last script left :)

Re: some scripts help pls

Posted: Tue Jan 01, 2013 3:53 am
by msyblade
Okay, this is not tested yet, if u still have trouble, ill debug it. The teleporter is what I end up using instead of destroying item in the alcove. just set up a teleporter on the altar square for items, deactivated. Have it target an empty square nearby the player will never see.When the gem is placed, teleporter will come on, make gem disappear, and a red_gem will appear in alcove_1. Just change to what you need (teleporter name, red gem spawn) and let me know if it works! :P

Code: Select all

function altaralcovecheck()
	
	for i in altar_1:containedItems() do
		if i.name == "blue_gem" then
			teleporter_1: activate()
			 alcove_1: addItem (spawn "red_gem"))
		break
		end
	end
end

Re: some scripts help pls

Posted: Tue Jan 01, 2013 5:36 am
by Drakkan
msyblade wrote:Okay, this is not tested yet, if u still have trouble, ill debug it. The teleporter is what I end up using instead of destroying item in the alcove. just set up a teleporter on the altar square for items, deactivated. Have it target an empty square nearby the player will never see.When the gem is placed, teleporter will come on, make gem disappear, and a red_gem will appear in alcove_1. Just change to what you need (teleporter name, red gem spawn) and let me know if it works! :P

Code: Select all

function altaralcovecheck()
	
	for i in altar_1:containedItems() do
		if i.name == "blue_gem" then
			teleporter_1: activate()
			 alcove_1: addItem (spawn "red_gem"))
		break
		end
	end
end
EDIT - bug discovered. when I put on altar blue_gem and then any other item - it is teleported as well (no red gem for it of course). Can you debug pls ?

Really nice trick with that teleporter :D working fine for now,, thanks a lot ! I was wondering how to make it little more complicated. It is not necessary however if you want try solution I will be glad. My idea is that first blue_gem will spawn lets say red_gem, second blue_gem will spawn for example long_sword, third blue_gem will spawn some armor etc... you have the idea.

I think best way here is to use more counters and set them to 1,2,3 etc... each sacrifised gem shoud decrease counter and run script to spawn item in alcove. What you think ? Any way how to script altar to decrease all conected counters when blue_gem inserted ?

Re: some scripts help pls

Posted: Tue Jan 01, 2013 11:46 am
by msyblade
place a timer set to 0.1 to connect to the tele set to deactivate and the timer to ITSELF for deactivate and add this to the script:

function altaralcovecheck()

for i in altar_1:containedItems() do
if i.name == "blue_gem" then
teleporter_1: activate()
timer_1: activate() --this is the line added
alcove_1: addItem (spawn "red_gem"))
break
end
end
end

and replace the timer name with your timer also :)

Re: some scripts help pls

Posted: Tue Jan 01, 2013 2:40 pm
by xbdj
I dont see why you use the teleport instead of just destroy

This code works, and then simply set up a connector from the altar to the function (I have called "paywithbluegem") that runs the function everytime an item is placed (or removed as you see fit) to the altar

Code: Select all

function paywithbluegem()
	for i in altar_2:containedItems() do
		if i.name == "blue_gem" then
			i:destroy()
			dungeon_alcove_5:addItem(spawn "red_gem")
			break
		end
	end
end
ps my altar and alcove have slightly differenty names than your, so adjust accordingly
I tried putting a blue gem on the altar to initially via the editor...that confused the function, so if you need that, the code needs to be fixed

Edit: generally the function gets confused if other items are on the altar...
Edit2: I get it...the altar only Activates when the first item is placed upon it, so...it needs to be empty and one blue gem needs to be placed upon it - then it works

Re: some scripts help pls

Posted: Tue Jan 01, 2013 2:41 pm
by Drakkan
msyblade wrote:place a timer set to 0.1 to connect to the tele set to deactivate and the timer to ITSELF for deactivate and add this to the script:

function altaralcovecheck()

for i in altar_1:containedItems() do
if i.name == "blue_gem" then
teleporter_1: activate()
timer_1: activate() --this is the line added
alcove_1: addItem (spawn "red_gem"))
break
end
end
end

and replace the timer name with your timer also :)
wroking fine now, thans a lot !

Re: some scripts help pls

Posted: Tue Jan 01, 2013 3:01 pm
by xbdj
If you make a button on the wall, that activates the script, you can make it work better I think
And then a counter to give different things depending on how many blue gems have been placed on the altar
This way you can also pay with more than one blue gem at a time, and get more loot in one go

Code: Select all

function paywithbluegem()
	for i in altar_2:containedItems() do
	    print(i.name)
		if i.name == "blue_gem" then
			i:destroy()
			if counter_2:getValue() == 0 then 
				dungeon_alcove_5:addItem(spawn "red_gem")
				counter_2:increment()
			
			else if counter_2:getValue() == 1 then 
				dungeon_alcove_5:addItem(spawn "green_gem")
				counter_2:increment()
			
			else if counter_2:getValue() == 2 then 
				dungeon_alcove_5:addItem(spawn "rock")
				counter_2:increment()
			end
		end
	end
end
end
end
ps. I dont quite get the block structure of Lua...I had to ad 2 more "end"s before it worked...and I dont get why it needs them