Forum

> > Stranded II > Scripts > Is it possible to gather from area types ?
Forums overviewStranded II overview Scripts overviewLog in to reply

English Is it possible to gather from area types ?

13 replies
To the start Previous 1 Next To the start

old Is it possible to gather from area types ?

Fafhred
User Off Offline

Quote
I would like to be able to gather sand from beaches.

All gathering methods I can see involve interaction with specific objects rather than areas.

Is there a way to do this? I looked through various posts here, including http://www.unrealsoftware.de/forum_posts.php?post=51341#lastpost , but could not find an answer.

If it is not possible I will instead make flint mineable from any rock (or possibly gathered through high skill digging), then breakable into sand (mineral flint is composed primarily of silicon and oxygen).

I need sand as a crafting material for glass items (bottles, portholes), as well as for ballast; I could re-crush pebbles for that, but doing it from flint would be more realistic.

old How To Build A Script

JasJack67
Super User Off Offline

Quote
Well, it's time you learn to script if your going to asking about it. You need to do a few things to accomplish your goal there...getting sand.

The first idea is the best, simply go to the beach and get sand. So.

1) Y position where the water meets the land is 0. Inland goes positive and inwater goes negative. So you need to get the players Y position when he tries to get sand. Another alternative would be getting the TerrainHieght. If it is above 0 it is land and below 0 is water.

$y=gety("unit",1);


2) In original stranded you can "use the ground" point at the ground and hit E button.

1
2
3
on:useground {
    $y=gety("unit",1);
}

3) Now you have to ask the question...is the player at the beach? You don't want them to get sand from just anywhere they click on the ground huh?

1
2
3
if(($y>=1) and ($y<=25)){

}

4)If they ARE "positioned" between 1-25 then you need a sand ITEM to be created, and store it in the inventory of the player.

1
2
$tmp=create("item",ID,0,0);
store $tmp,"unit",1;

5) so now you put it all together:

1
2
3
4
5
6
7
on:useground {
    $y=gety("unit",1);
    if(($y>=1) and ($y<=25)){
        $id=create("item",ID,0,0);
        store $id,"unit",1;
    }
}

If the player is NOT in the right postion you can send them a message:

1
2
3
4
5
6
7
8
9
on:useground {
    $y=gety("unit",1);
    if($y>=1) and ($y<=25){
        $id=create("item",ID,0,0);
        store $id,"unit",1;
    }else{
        msg "There is no sand here!",3;
    }
}

So you should go to the items.inf file and make you a SAND ITEM so you can fill in the ID in the code.

In the future...you need to post your own code/script and others here will help you fix it...we do not normally just make code for people...at least show us you are trying to learn how to script. If you do not want to learn to script then you are wasting your time, and our time. You can not make a decent mod expecting us to hand you all the scripting. The above should give you and example how to BUILD A SCRIPT to make it do what you want it to. Check the stranded II site Commands page for details about script commands.

edit p.s. There are other ways to accomplish what you ask "about areas". In the commands you can use AREA TRIGGERS...another idea is to check what tool the player has in his hand when he "uses the ground"...if he has an empty bag INHAND he gets sand... if he has a shovel INHAND he gets worms or dirt...if he has a bone INHAND he buries it...etc. (e.g. $tmp=getplayerweapon)
edited 3×, last 29.01.17 10:15:49 am

old Re: Is it possible to gather from area types ?

Fafhred
User Off Offline

Quote
- I was not asking how in full coded details, I was asking if that was possible.

- Please do not assume that because someone is learning the syntax and specifics of a given scripting language, they do not know how to code; for the record I have more than 10 years of professional coding behind me, including a full CAD/CAM suit which went to more than 200k lines of source codes in total (deemed to be beyond what the average coder can keep track of, although I do not remember where I read that).

- If there is a full list of Stranded II scripting language and system parameters somewhere (with syntax), I have not found it (I would not find it if it is only in a German post, for instance); if there is one (in English), then I missed it; please just give me a link, this is all I will need.
So far, I learned part of it through analyzing existing scripts, and I have not by a long shot gone yet through all scripts posted in the downloads section.

- Now, If I understand correctly, gety("unit",1) returns the distance from the nearest waterline ?
This is a good start, but there are plenty of places where herbs starts straight at the waterline, therefore it is not sufficient to assert the presence of a beach, and therefore sand.
The rest of your example I already knew and used for a different purpose about 3 years ago, the first time I worked on my project.

- To answer your last paragraph, I was asking a feasibility question for something I had not found how-to, NOT looking to fix a bug, that I have plenty of experience with.

old Re: Is it possible to gather from area types ?

JasJack67
Super User Off Offline

Quote
no gety is the height the player is at...the idea that waterline is 0 can be utilized as the terrain texture for sand is utilizing this same y height...so anywhere the y height is near 0 would be sand texture.

No need to feel offended, that was not my intent. I have seen a few of your posts now and trying to help...but I do not see any appreciation for answering a question (or TRYING to) that we try to answer, when we could really just ignore your post all together.

A simple thank you usually gets you more help...but being critical of the answers you get will likely lead to unanswered posts. Remember...no one here really needs to help you...we do this out of our own free will...my answer is based on your post...maybe you can post a better question or format it in a way that gets the responses your looking for.

anyways, here is the link and use Google translate like I do...if ya want.

> http://www.strandedonline.de/s2_commands.php

old Re: Is it possible to gather from area types ?

Fafhred
User Off Offline

Quote
Thank you; now this is what I needed, but I never found it because it was in the German website.

I was feeling offended because you were patronizing me instead of answering the questions as stated.

old Re: Is it possible to gather from area types ?

JasJack67
Super User Off Offline

Quote
sorry about that...if ya only knew how many times people post expecting someone to do all the work, you might understand the patronizing...sorry but I did not intend to patronize you.

It's all good bro...let us know if you need any more help and I will try to help without pre-judgements. lol

edit p.s. Please keep in mind that when I post, I post with the thought that other people will be using the SEARCH option to find answers to their questions in this forum...this is why I post answers the way I do...some info i throw in there for that one person who is looking for similar/related info...it is not intended to belittle or patronize YOU, just to inform/help future members when they land on my posts through searches.
edited 1×, last 29.01.17 11:30:33 am

old Re: Is it possible to gather from area types ?

Fafhred
User Off Offline

Quote
Np, no hard feelings now that it is sorted.
Just don't be so quick with your assumptions in the future


Update:
I am now proceeding with coding this part, through a new procedure in game.inf
However this procedure is not executed, for some reason, although it is after the end of the 'on start' procedure.
Does it need to be also executed once at the start of a new game to be executed on later runs, even though it is outside the 'on start' section ?

Here is the relevant area with just the analysis and the beginning of the code, plus the tests which allow me to know that this section is not executed:
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
33
34
//
	//Drinking (Sea)
	on:usesea {
		if (inarea_freshwater("unit",1)) {
			process "drinking",1000;
			drink 0,0,25,0;
		}else{
			process "drinking",1000;
			drink 0,0,-15,0;
			msg "Ugh! Saltwater!";
			speech "negative";		// this test modification is executed right away.
			msg "disgusting!",3;
		}
	}

	//Digging
	on:dig { msg "testing, dig detected!",3; }

	on:dig {
		speech "positive";  			// but this procedure is not executed...
		msg "Digging!",4;
		if (terrain()==0) {
			speech "positive";
			msg "I am on is a beach!",4;
//			if (have an empty bag) {
//				replce bag with sandbag
//				add digging sound ?
//				say 'I filled a bag with sand'
		}else{
			speech "negative";
			msg "This is not a beach!",3;
//				say 'there is a lot of sand here' the first time?
		}
	}
The simplified unconditional line, added as last test right after //Digging, is not executed either.

I also tried a fresh start and a brand new spade, and zith the second 'on:dig' area entirely commented out, without any difference.
on:dig is straight out of http://www.strandedonline.de/s2_commands.php?list=all:
on:Event { Commands }
dig - when the player uses a spade (behaviour=spade), this event occurs to all objects nearby

So what am I missing ?
Or is this command simply bugged ? (I have seen in the past bugs in programming languages and even once tracked down the source of a bug all the way to a bug in the computer series' ROM, so I am not excluding any option).
edited 8×, last 29.01.17 11:21:08 pm

old Re: Is it possible to gather from area types ?

JasJack67
Super User Off Offline

Quote
i see a couple things that "might" be the problem.

line 10
msg "Ugh! Saltwater!";
i think should have a text number but it might work without it.
msg "Ugh! Saltwater!",3;

line 22
if (terrain()==0) {
This is not correct to my knowledge. You need the terrainy which is the terrain y height. 0 would be EXACTLY where the water meets the land...so you'd be digging directly at the water line ONLY for it to work. But the actual syntax is wrong to my understanding. Also you would want it to be FROM 0 to ANOTHER POSITIVE NUMBER like 25,(positive would be toward inland)
$x=getx("unit",1);
$z=getz("unit",1);
$tmp=terrainy($x,$z);

if (($tmp >= 0) && ($tmp <= 25)){

Even if you wanted the terrain height to be only 0 it would be like this:
$x=getx("unit",1);
$z=getz("unit",1);

$tmp=terrainy($x,$z);
if ($tmp==0){

Lastly:
I do not believe you can have TWO on:dig in the same script=start to script=end. The first one runs but the second one does not (I believe, but it might work)...you should put them both into ONE on:dig

So Im not saying there is 3 things that need fixed for sure, but I think 1 of the 3 is the cause. But if my assessment is correct all 3 are culprits. One wrong comma, , , or quote " " " and the script is broken. The terrain() command you used I have never seen or used it like that...I dont see how that it returns the height where the player is standing or digging, you have to tell terrainy to get the coordinates and assign them to a variable like $tmp, or some other variable you make...then reference that variable.

If terrain() is suppose to work then ya might try terrainy() instead.
edited 5×, last 30.01.17 04:03:18 am

old Re: Is it possible to gather from area types ?

Fafhred
User Off Offline

Quote
Actually, line 10 is part of the original code, unchanged
The number is only there to assign a color to the text line, instead of the default color for it (one of the first things I figured 3 years ago).

I had also tested with the second on:dig procedure (lines 19 to 34) commented out, the first one was to test if on:dig was executed at all.

I used google translate due to the fact that most of the commands are still only explained in German.

As terrainy syntax shows in this commands list, it does not return how close the location is to the water, which is why I was trying to use terrain:
(Returns the height of the terrain at a certain position.
Water surface is Y=0, under water is Y<0 and over water is Y>0.).
Areas just above water would still be above water, not specifying how close the way I understood this translation (I have used languages returning -1, 0, or +1 as only parameters, and that was how I understood that translation).
For my purpose I need to test that I am just above the waterline, very close to it; testing the value needed for the parameter would be my next step once on:dig is executed.

As for the syntax, it is not explained at all in the commands list; I parroted it from an original line of code a bit above it (3rd line of on:start), using loadmaptakeover with this exact syntax:
if (loadmaptakeover()==0){
But yes, it does not tell me anywhere the nature of the returned parameters, it could be a logical variable for loadmaptakeover (true/false) and numerical for terrain and terrainy; any decent language manual provides syntax explanation and nature of returned parameter for every command; every single other language I used over the years does...

So yes, I definitely need a list of commands showing their respective syntaxes.
At the moment I can only code by guesses at syntax, and trial and error; not a very effective way to code, and I think that was why I gave up 3 years ago.

If your code example is correct, then the paragraph for terrainy is definitely mistranslated.
I am going to try using it that way, but that still does not explain why the on:dig procedure is not executed when there is just
1
2
//Digging
	on:dig { msg "testing, dig detected!",3; }	// but this procedure is not executed...
at the start of
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//Digging
	on:dig { msg "testing, dig detected!",3; }	// but this procedure is not executed...

//	on:dig {
//		speech "positive";  			// and neither is...
//		msg "Digging!",4;
//		if (terrain()==0) {
//			speech "positive";
//			msg "I am on is a beach!",4;
//			if (have an empty bag) {
//				replce bag with sandbag
//				add digging sound ?
//				say 'I filled a bag with sand'
//		}else{
//			speech "negative";
//			msg "This is not a beach!",3;
//				say 'there is a lot of sand here' the first time?
//		}
//	}
If it finds error because of commented out lines of code, something is very off...


As for the terrain command, is it 2 up from terrainy in http://www.strandedonline.de/s2_commands.php?list=all , and the fact that it had a much more detailed explanation is why I was using it...
edited 9×, last 30.01.17 07:54:57 am

old Re: Is it possible to gather from area types ?

JasJack67
Super User Off Offline

Quote
Once your in the game turn on DEBUG MODE:

Hit the ~ key
type in dm
hit Enter
click the Turn On Debug Mode button
close the window and test...if your script has an error you will be promted what line and what error.

when you dig it should throw an error and tell you what line of code has the error...if there is an error.

also, did you make a -win -debug. bat file for your mod? To run the mod in a window with debug already ON?

Doing so will throw any errors you might have when the mod is LOADING too. It's an great tool and I highly recommend you do so when testing your code...you no longer have to search for, or figure out where an error is.
-------------------------------------------------------
p.s.
That terrain() syntax is terrainy(x,z) meaning that the command terrainy is getting the terrain y height at the coordinates you specify as X,Z. Leaving it blank ( )does not mean it checks 0,0 it means THERE IS NO COORDINATES FOR IT TO GET THE Y POSITION you have to put in coordinates. The coordinates you need to check when digging would be where the player is currently standing...that's why you need to get ("unit",1) x,z position and assign them to variables, then use those variables as the X,Z

$tmp=terrainy($x,$z)

In the future, you need to type the command EXACTLY as it is listed in the commands page...you can not alter it or make up your own unless you change the source code. So terrain() is not a valid command but terrain andterrainy(x,z) is.

You can use terrain by itself as a valid command... to alter the height of the terrain or get the x or y coordinate of the terrain.(but that is not the height y is height)
Here i lower the terrain -0.5 using mode 2 using those same ("unit",1) x,z variables.
terrain $x, $z, 2, -0.5;


You will notice in the commands that loadmaptakeover does not have ( ) after it...what this command does is return a 0 or 1... 0 if yes or 1 if no.
1
2
3
4
5
6
if(loadmaptakeover()==0){
 yes we are loading a map..so do this
}
if(loadmaptakeover()==1){
 no we are not loading a map...so do this
}
edited 6×, last 30.01.17 11:14:42 am

old Re: Is it possible to gather from area types ?

Fafhred
User Off Offline

Quote
Why do you think I am asking for a file or document (in English) with the commands syntax?
Most commands, including 'terrain', DO NOT provide syntax or examples in http://www.strandedonline.de/s2_commands.php?list=all

I do not know where you are picking your syntax examples fro,; but definitely not from there.

At the moment, all I can do is educated guesswork at the syntaxes by analogy to syntax I can see used for similar commands... NOT a good way to program...


And there is no error message, it just is not executed, but moves on as if that code was not there...

old Re: Is it possible to gather from area types ?

JasJack67
Super User Off Offline

Quote
yes...from there...and i use google translate when it is german i cant read:

list page:
Quote
terrain
Categories: misc, return
Sorry, not available in english!
Returns or modifies the height of the terrain at a specific location.
The position is set with X and Z. About mode is decided on what should be done:
0 - the height of the terrain is returned as a value between 0-100 (the height parameter can not be specified here!)
1 - the terrain is set to the specified altitude (value between 0-100)
2 - the terrain is changed by the specified height (negative values ​​for lowering)
3 - returns the corresponding X position in the terrain matrix. Not every 3D coordinate has an associated coordinate in the terrain (since the terrain has only a limited number of vertices).
4 - returns the corresponding Z position in the terrain matrix (see FIG. 3).

The height is given with this command with a value between 0 and 100. Here, 0 stands for very low, 100 for very high. At about 50, the sea level is. Only in mode 1 and 2 can the height parameter be specified


If you search the command in the search box a second view is shown that has additional syntax information. See below I searched the command terrain and it now shows more syntax. Terrain X, Z, mode [, height]

searched:
Quote
Terrain X, Z, mode [, height]
Categories: misc, return
Sorry, not available in english!
Returns or modifies the height of the terrain at a specific location.
The position is set with X and Z. About mode is decided on what should be done:
0 - the height of the terrain is returned as a value between 0-100 (the height parameter can not be specified here!)
1 - the terrain is set to the specified altitude (value between 0-100)
2 - the terrain is changed by the specified height (negative values ​​for lowering)
3 - returns the corresponding X position in the terrain matrix. Not every 3D coordinate has an associated coordinate in the terrain (since the terrain has only a limited number of vertices).
4 - returns the corresponding Z position in the terrain matrix (see FIG. 3).

The height is given with this command with a value between 0 and 100. Here, 0 stands for very low, 100 for very high. At about 50, the sea level is. Only in mode 1 and 2 can the height parameter be specified


Since the terrany does not show any detail of it's syntax on the LIST page, I put terrainy in the search box and it shows another view that has more syntax. See below I searched and you see it says terrainy x,y instead of just terrainy. There is two pages for every command it seems and I just figured that out on my own one day.

list page:
Quote
terrainy
Categories: return
Returns the height of the terrain at a certain position.
Water surface is Y=0, under water is Y<0 and over water is Y>0.


searched:
Quote
terrainy X, Z
Categories: return
Returns the height of the terrain at a certain position.
Water surface is Y=0, under water is Y<0 and over water is Y>0.


you just need to figure out when and where to put ( ) and " " sometimes.

No it's not convenient, but it is what I do...I don't know what else to say to help you...only that there is a learning curve and once you build enough of your own scripts you begin to understand the syntax better. I have worked on my mod for 3 years now, and have added over 1,000,000 million lines of script, (no joke) so it is very easy for me to figure out scripts and syntax. My first 3 months I struggled, just like you are now. It is what it is...once you find a command your interested in search it in the search box for more detail syntax...if you click the sub-categories at the top they also will show this "detailed" syntax...i dont know why it does not show in the LIST pages.

-------------------------------
Quote
And there is no error message, it just is not executed, but moves on as if that code was not there...

Hmm...did you make only 1 on:dig now? I do not think you can have 2, like i said before.

get rid of the 1st testing on:dig and try this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
on:dig {
          speech "positive";
          msg "Digging!",4;
          $x=getx("unit",1);
          $z=getz("unit",1);
          $tmp=terrainy($x,$z);
          if (($tmp >= 0) && ($tmp <= 50)){
               speech "positive";
               msg "I am on is a beach!",4;
          }else{
               speech "negative";
               msg "This is not a beach!",3;
          }
     }
edited 4×, last 30.01.17 02:45:20 pm

old Re: Is it possible to gather from area types ?

Fafhred
User Off Offline

Quote
Terrible programming technique, sorry.

When something in code does not work, you start by trying to find the fault step-by-step as I did with having just
1
2
//Digging
     on:dig { msg "testing, dig detected!",3; }     // but this procedure is not executed...
You never try making a full replacement code before you found what did not work in the simplest code.

I need to find and understand WHY that single line is not executed before I can move on and expand on using that command.

old Re: Is it possible to gather from area types ?

JasJack67
Super User Off Offline

Quote
Quote
Terrible programming technique, sorry.


I guess I have my own way of getting the results I am looking for. If i had to rely on making a post every time I could not get a command to work I would have over 10,000 posts! lol

Anyways...listen...Stranded 2 had a "grave area with headstones" that players dig in...it utilizes the command "inarea_dig". So in the source code, that area was defined when the S2 map was created by DC. When you start up a random map in a mod it has no defined "inarea_dig".

Just like the behavior of a fishing rod can be set to fishingrod and your fishing rod will cast at any area defined in the source code as water...in your mod the sea is STILL defined as water...so the pole works right.

With that explanation, you might not know that there is additional syntax for the fishing behavior AND the digging behavior. It goes something like this:

if i cast by rod and there is no water near, the event fish_failure is executed. If there is water then event fish_success is executed. On that same note your shovel with behavior "spade" is set up the same way...if your in a area_dig then dig_success is executed, if your not in a area_dig then dig_failure is executed.

So unless you make your own map and you define an "dig area" then your mod has no dig area. This means every time you use the shovel your throwing the event dig_failure.

So you need to use this:
1
2
3
on:dig_failure {

}
Sorry I did not mention this earlier, I actually forgot when we were talking about on:dig above.

Also...I am still pretty sure you can not have 2 dig events between the script=start and script=end...I never got an answer from you if you made both yours into one, so I will not mention that again.
edited 1×, last 01.02.17 02:04:52 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewStranded II overviewForums overview