Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Checking the position of entities
dragonlordsd Offline
Member

Posts: 112
Threads: 7
Joined: May 2011
Reputation: 0
#1
Checking the position of entities

I was working on a scenario, and I was wondering how you would go about creating a function that relied on items being within a certain area to be carried out.

The logic I'm looking for would work something like this:

When [Item] is used on [Entity]:

If [entity1] is in [scriptarea1]
if [entity2] is in [scriptarea2]
if [entity3] is in [script area3]
create [Itemkey] at [scriptarea4]

The idea is to get the player to perform like a summoning ritual or something.

I know how to create items, but I don't know how to make a function conditional on the position of an entity.

Any help would be appreciated

Here's a screen shot of the puzzle layout:

.jpg   2011-05-05_00002.jpg (Size: 183.12 KB / Downloads: 157)

.jpg   2011-05-05_00004.jpg (Size: 289.11 KB / Downloads: 160)
(This post was last modified: 05-05-2011, 09:48 PM by dragonlordsd.)
05-05-2011, 06:56 PM
Find
Tanshaydar Offline
From Beyond

Posts: 3,085
Threads: 17
Joined: Mar 2009
Reputation: 67
#2
RE: Checking the position of entities

Entity Collide Callbacks are not only for players, but also for all type of entities.

05-05-2011, 08:39 PM
Website Find
Acies Offline
Posting Freak

Posts: 1,643
Threads: 60
Joined: Feb 2011
Reputation: 73
#3
RE: Checking the position of entities

(05-05-2011, 08:39 PM)Tanshaydar Wrote: Entity Collide Callbacks are not only for players, but also for all type of entities.

Have one script for enter - set localvar "item1True" = 1
And one script for leave - set localvar "item1True" = 0
Include a condition in all scripts for enter which checks the variables to see if all are = 1, and if they are executes "create item". It can also be done with a single variable. good luck Smile

[Image: mZiYnxe.png]


05-05-2011, 08:46 PM
Find
dragonlordsd Offline
Member

Posts: 112
Threads: 7
Joined: May 2011
Reputation: 0
#4
RE: Checking the position of entities

In my experiments, I managed to make this work:

AddUseItemCallback("", "test_contain", "flask_5", "JarOnFlask", true);

void JarOnFlask(string &in asItem, string &in asEntity)
{
if(GetEntitiesCollide("flask_5", "ScriptArea_1"))
{
CreateEntityAtArea("test_key", "key_study", "ScriptArea_2", false);
}
}

...but it feels kind of awkward. I like Acies' suggestion, but I don't know how to write that into the code.
(This post was last modified: 05-05-2011, 08:52 PM by dragonlordsd.)
05-05-2011, 08:51 PM
Find
Acies Offline
Posting Freak

Posts: 1,643
Threads: 60
Joined: Feb 2011
Reputation: 73
#5
RE: Checking the position of entities

It's more simple than it sounds. I could write a script for one area, then it's simply to copy paste and change some values. Do you want the user to be able to place the items as he wishes like "guessing the combination" or do you want it to fail whenever he tries to place an item in the wrong place?
Edit: And um, are we talking about items from the inventory or entities which can only be carried by hand?

[Image: mZiYnxe.png]


(This post was last modified: 05-05-2011, 09:00 PM by Acies.)
05-05-2011, 08:58 PM
Find
dragonlordsd Offline
Member

Posts: 112
Threads: 7
Joined: May 2011
Reputation: 0
#6
RE: Checking the position of entities

the basic idea is this:
the player places four skulls (entities, but not items) in the circles on the alchemic formula decal. Then by applying a formula (an inventory item) to one of the skulls (since they're so close together, it can be any one of them) it causes a key to appear.

Just to make it easier, I want a function that, when activated by using the item on the skull, checks if there are four skulls within a set area. They don't really have to be positioned exactly, that would probably make it too annoying to solve.
(This post was last modified: 05-05-2011, 09:13 PM by dragonlordsd.)
05-05-2011, 09:12 PM
Find
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#7
RE: Checking the position of entities

(05-05-2011, 09:12 PM)dragonlordsd Wrote: the basic idea is this:
the player places four skulls (entities, but not items) in the circles on the alchemic formula decal. Then by applying a formula (an inventory item) to one of the skulls (since they're so close together, it can be any one of them) it causes a key to appear.

Just to make it easier, I want a function that, when activated by using the item on the skull, checks if there are four skulls within a set area. They don't really have to be positioned exactly, that would probably make it too annoying to solve.

You could make them auto-position exactly using a sticky-area, and then activate variables based on a callback defined in the sticky area properties.
05-05-2011, 09:18 PM
Find
Acies Offline
Posting Freak

Posts: 1,643
Threads: 60
Joined: Feb 2011
Reputation: 73
#8
RE: Checking the position of entities

(05-05-2011, 09:18 PM)Apjjm Wrote: You could make them auto-position exactly using a sticky-area, and then activate variables based on a callback defined in the sticky area properties.

This idea is even better, as I believe it saves space in your scripting file. However, I need to brush up on stickyAreas, was a while ago since I used them. I'll look into it.

[Image: mZiYnxe.png]


05-05-2011, 09:28 PM
Find
dragonlordsd Offline
Member

Posts: 112
Threads: 7
Joined: May 2011
Reputation: 0
#9
RE: Checking the position of entities

...interesting. Yeah, I've seen sticky areas before, but I have no idea how to code them, and I haven't found any tutorials that use them.

But you're right, if it would work, it would be a really nice touch.
05-05-2011, 09:39 PM
Find
Acies Offline
Posting Freak

Posts: 1,643
Threads: 60
Joined: Feb 2011
Reputation: 73
#10
RE: Checking the position of entities

Information:
name the stickyArea 1: Skull01
name your grabbable skull 1: Skull01_dyn
name your static skull 1: Skull01_stat
name the stickyArea 2: Skull02
name your grabbable skull 2: Skull02_dyn
name your static skull 2: Skull02_stat

And so on. In the entity tab for the skull on the ground you have to set "static_physics" = true. Place each sticky area at the position of these static skulls. The static skulls should also be set to "Active" = false in the general tab.

SkullMessage = The Skull fits perfectly in place. (Or something else of your liking)

Script:
Spoiler below!

void AttachSkull(string &in asArea, string &in asBody)
{
AddTimer(asArea, 0.5f, "SkullTimer");
AddLocalVarInt("SkullsNumber", 1);

}

void SkullTimer(string &in asTimer)
{
SetEntityActive(asTimer+"_dyn", false);
SetEntityActive(asTimer+"_stat", true);
PlaySoundAtEntity("", "Soundfile.ogg", asTimer+"_stat", 0.1f, false);
SetMessage("Area", "SkullMessage", 0);
}


Editing the sticky area:

.jpg   GuideToSkull.JPG (Size: 15.89 KB / Downloads: 147)

You change the the attachable to "Skull02_dyn" for stickyArea 2 named Skull02 - and so on. Haha, this is a mess.

Best of luck, if any troubles come up i'll help you. *Whipes of sweaty forehead*
Noticed I had forgotten the finale..

CreateSuccessMessage = Set it to whatever you like
You should have created the item and set it to "Active" = false in the editor already (named it "ItemCreated" - change it to your liking.)

Script:
Spoiler below!

void OnStart()
{
AddUseItemCallback(string& asName, string& asItem, string& asEntity, string& asFunction, bool abAutoDestroy);
}

void MyFunc(string &in asItem, string &in asEntity)
{
if(GetLocalVarInt("SkullNumber")==4)
{
SetMessage("Area", "CreateSuccessMessage", 0);
SetEntityActive("ItemCreated", true);
//--- here you can add particle systems and sounds as well, during the creation of your item ---
return;
}
}


[Image: mZiYnxe.png]


(This post was last modified: 05-06-2011, 12:49 AM by Acies.)
05-05-2011, 09:59 PM
Find




Users browsing this thread: 1 Guest(s)