Forum

> > Stranded II > General > Coding Questions Go Here
Forums overviewStranded II overviewGeneral overviewLog in to reply

English Coding Questions Go Here

21 replies
Page
To the start Previous 1 2 Next To the start

old Coding Questions Go Here

GolemCC
User Off Offline

Quote
Since there's no basic thread modding questions, I figured I'd start one here.

This one's big. I've been toying around with various methods and commands but for the life of me I can't figure it out. I want to make something like a water rock (the one that fills up when it rains, not the spring), which generates resources and has a different model whether empty or full. I can figure out how to stock it, change the model, and all that.
What I can't figure out is how to make it so that when you USE the object, the item is added to your inventory.

For example, if I have a rock which generates slime, for example, I want to be able to press USE on the rock and have the slime added to my inventory, just as if slime had been lying on the ground and I had pressed USE on that. I don't want to open an exchange window or anything like that.
I've gotten close. I've even made it so the slime appears on the ground exactly where the rock is, but I can't figure out any more.

How can I have using an object translate into picking up an item?

old Re: Coding Questions Go Here

bizzl
User Off Offline

Quote
1
2
3
4
5
6
7
on:use {
	s2:skipevent;
        s2:local $id;
        $id=s2:create("item",[i]slime type[/i]);
	s2:store $id, "unit", 1;
        s2:freevar "id";
}
Better always save the id temporary

old Re: Coding Questions Go Here

Ringwall
User Off Offline

Quote
Um I'm having some problems with the mod I'm working on. I made an item called sand, but whenever I use it in the map editor or make it ingame the game crashes and says something about Memory Access denied or something like that. The same happens for the tomato. any ideas to what is gimping up?

old Re: Coding Questions Go Here

bizzl
User Off Offline

Quote
are the definition files correct?
Especially items can be tricky, since the editor is "foolproof" while the inventory isn't.
The crashes you describe mostly happens because the icon is wrong. neither a empty property (no text behind icon= ) nor a missing file (e.g. icon=/gxf/tomato.bmp while there is no file /gfx/tomato.bmp) is allowed!

old Re: Coding Questions Go Here

GolemCC
User Off Offline

Quote
Thanks, Bizzl. That worked at last.
1
2
3
4
5
6
7
8
9
on:use {
		local $id;
		$id=create("item",[itemnumber]);
		store $id,"unit",1;
		freevar "id";
		msg "Picked up something!",4;
		speech "positive";
		skipevent;
	}

old Re: Coding Questions Go Here

Ringwall
User Off Offline

Quote
I've got a question about making my blast furnace... how do you script it so that the blast furnace starts out with eternal fire? My foolish attempt at it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
### Blast Furnace
id=110
name=blast furnace
icon=gfx\blastfurnace.bmp
model=gfx\blastfurnace.3ds
scale=1.6
state=0,5,0
health=3000
color=230,230,230
mat=stone
behaviour=fireplace
script=start
	on:build_finish {
		event "blastfurnacebuild",0,0;
	on:impact {
		if (random(5)==1){
			$tmp=impact_class();
			$tmp2=impact_id();
			addstate $tmp,$tmp2,"eternalfire";
			freevar $tmp;
			freevar $tmp2;
		}
	}
	on:use {
		if (gotstate("unit",1,6)){
			if ((gotstate("self",4)+gotstate("self",5))>0){
				process "warming me up",3000;
				freestate "unit",1,6;
			}
		}
	}
script=end

As you can see I tried copying the torch script, as I'm a total noob at scripting myself.

old Re: Coding Questions Go Here

GolemCC
User Off Offline

Quote
And while we're at it, what's the deal with lines like:
1
event "blastfurnacebuild",0,0;
anyway?
Story mode standbys? We don't need to add those to custom buildings, do we?

old Re: Coding Questions Go Here

Ringwall
User Off Offline

Quote
Well, from what I've seen they're used for custom maps and such. Such as when you make your first hammer in the adventure game, it creates a diary event. So if someone were to make a map, and wanted something to occur when they made the blast furnace, then they would have in the script something like:
1
if (event_blastfurnacebuild)<0{

Don't trust me on that being actual code, that's just a guess as what it might look like.

old Re: Coding Questions Go Here

bizzl
User Off Offline

Quote
1
2
3
on:build_finish {
		event "blastfurnacebuild",0,0;
        [b]} //you forgot this[/b]
Tht was actually the only problem I found so far.

The Event fired are, like Ringwall supsected, for mapping, but the code he gave is wrong.
If you want to catch a certain, script fired event you always have to use s2 cmd on , like when you want to catch the usage or stuff.
You can then use it to add a diary entry or give the player stuff.
Example:
1
2
3
4
5
6
7
8
9
10
11
s2:on:blastfurnacebuild {
s2:local $id;
$id=s2:create("item",1);
s2:store $id,"unit",1;
s2:freevar "id";
s2:clear;
s2:add "Woah, I got a bag";
s2:add "after I build a [i]xyz[/i]";
s2:add "that's stupid";
s2:diary "Oh. My. God.";
}

old Re: Coding Questions Go Here

Ringwall
User Off Offline

Quote
yeah, I highly doubted it was right. I was giving an example to how it might be used.

PS my blast furnace now is lighted with a gallows, but, is it possible to make a combination required to be combined with a fire/eternalfire object?

old Re: Coding Questions Go Here

bizzl
User Off Offline

Quote
You mean with some object in the near range that has fire?
Look at the code of some of the potion combinations, you just have to exchange
1
s2:count_behaviourinrange "object","watersource"
through some check for fire states.

old Re: Coding Questions Go Here

GolemCC
User Off Offline

Quote
For checking if you're near any fire source:
1
2
3
if ((count_inrange("state",5,50)+count_inrange("state",4,50))>0){
actions go here;
}

For checking if you're near an eternal fire:
1
2
3
if (count_inrange("state",5,50))>0){
actions go here;
}

old Re: Coding Questions Go Here

Ringwall
User Off Offline

Quote
Argh, no luck with that. I hope this will work:
1
if (gotstate("object",$id,"fire")+gotstate("object",$id,"eternalfire")>0){

EDIT
@ GolemCC
Hmm I hope this one works...

Crap. Not working... but does this work in a combination or does it have to be something where you use the item like in cooking meat?
edited 1×, last 28.04.07 10:03:37 pm

old Re: Coding Questions Go Here

GolemCC
User Off Offline

Quote
Here, use this as an example. It's my code for cooking chocolate chip cookies. It's a combination that requires a fire source:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
### Cookies (Paste + Fire + Cacao powder)
combi=start
req=82
req=68,3
gen=66,12
script=start
	if ((count_inrange("state",5,50)+count_inrange("state",4,50))>0){
		fry;
		process "baking",2000;
	}else{
		msg "I need a fire source!",3;
		speech "negative";
		skipevent;
	}
script=end
combi=end

old Re: Coding Questions Go Here

Ringwall
User Off Offline

Quote
Well, I put in a modified form of your script GolemCC, and it still didn't work. But guess what, it's my falut. I'm not sure if it would have worked with my earlier codes, but a big problem was that the fire was too deep inside the blast furnace for Mr. Stranded to reach. doh! So I just moved the model back a bit and now it works fine. Thanks for all your help guys.

old Re: Coding Questions Go Here

GolemCC
User Off Offline

Quote
Or for futures, you could just make it so the recipe works in a bigger radius.
The part where it says:
1
("state",5,50)
or anything like that, the second number, 50, represents range.
You could increase that so you don't have to be right up against it for it to work.

old Re: Coding Questions Go Here

Ringwall
User Off Offline

Quote
Oh, I suppose that would work well for not moving suddenly backward from the buildsite once you finish construction.

*Fixing*
To the start Previous 1 2 Next To the start
Log in to replyGeneral overviewStranded II overviewForums overview