Modifiying pawns variables from another pawn?

Topics regarding Scripting with Reality Factory
Post Reply
Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Modifiying pawns variables from another pawn?

Post by Jay »

I already have a new idea for two new scripting commands:

A command with wich you can modify the 'variables' of a pawn from another pawn (with variables i mean like self.think and so on), and also one to retrieve them:


Maybe like this:
SetVariable(char* variable, char* EntityName);
char* GetVariable(char* variable, char* EntityName);

or even better like this (reminds of the old self.think, self.target_name):
(entityName).think="whatever";
(entityName).target_name="somePawn";
BLABLA=(entityName).target_name;

and also i'd like to have the target_name variable to be writeable to take more advantage of this new possibilities.

I need this for kind of a strategy system where i can tell pawns which enemies to attack and also the more intelligent enemys could then 'tell' each other whom to attack. So that they all attack the same person to kill better.

If this possibility already exists, please correct me.

Thanks in advance.
Everyone can see the difficult, but only the wise can see the simple.
-----
User avatar
Spyrewolf
Posts: 450
Joined: Tue Jul 05, 2005 4:53 am
Location: Wellington::New Zealand

Post by Spyrewolf »

not entirely sure but you do this with attributes
and the modify attributes command

if pawnX has attributeX attack pawnX

this is away to bypass scripts and get information between two seperate scripts

int GetAttribute(char *AttributeName, char *EntityName);
Returns the amount of the attribute AttributeName of the entity EntityName. EntityName can specify a Pawn, a StaticEntityProxy or the player ("Player").
Last edited by Spyrewolf on Tue Aug 01, 2006 8:38 pm, edited 1 time in total.
Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Post by Jay »

No this is not possible because attributes are always numbers, and i want to copy/exchange variables(strings) between the scripts.

To get the same effect with just attributes, i would have to give EVERY PAWN an attribute - its 'id', and then make a very complex search method to get the EntityName from the pawn with id XXX (i would have to know, for example the number of living pawns in a level, which means that pawns must set a special player-attribute at their spawning and decrease itr at their death, and then i would have to reassign all the ids,...)- at the cost of speed and time. Not to mention i would have to rewrite all my scripts.

You see - it's very difficult up to impossible to do something like that with just attributes.
Everyone can see the difficult, but only the wise can see the simple.
-----
User avatar
Spyrewolf
Posts: 450
Joined: Tue Jul 05, 2005 4:53 am
Location: Wellington::New Zealand

Post by Spyrewolf »

hmm ok how about the set enemy target group..

HostileDifferent(bool State );
If State is true then the Pawn will include all Pawns with a different group name than it in its list of potential targets.

and

TargetGroup(char *Name );
If the Pawn is set to be hostile to Pawns of a different group this will cause the Pawn to include in its list of potential targets only those Pawns that are in the group Name.


im not too sure what your planning but i'm guessing it could be very complex, is this a possiblity?

just racking the brain here.....
Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Post by Jay »

Spyrewolf wrote: im not too sure what your planning but i'm guessing it could be very complex, is this a possiblity?
Ok. I'll try to explain my goal and my situation. Hope you understand it.

I am trying to make a strategy system that allows me to give the player's friends commands, because there are seven characters in the game and it would be very very VERY boring if most of the stuff that your party does is scripted by the KI.
The thing is, i cannot integrate the commanding-system into the pawns of the characters themselves, because their orders consist of LowLevel AND HighLevel Orders. My first goal is, i want that when some specific character is activated and i click on a hostile pawn, it attacks them;
But for this i need LowLevel ALL THE TIME because otherwise the MouseSelect() comand cannot work properly.
So i need to add the strategy code into my GameSystem pawn which controls almost everything from LevelUps over Inventory to selecting the characters and which key i pressed.

From then, there would only be these little lines of code:

Code: Select all

case 73
{
  if(CHAR_SELECT=1) //Kriston was activated
  {
     if(GetAttribute("GROUP",SELECT)=1)           //1=Hostile
     {
          Kriston.target_name=SELECT; //Kriston is the name of the
          Kriston.think="gotoAttack";     //friendly pawn
      }
  }
}
(I have already added and set the GROUP attribute for each pawn and also the player.)

This is it.
Everyone can see the difficult, but only the wise can see the simple.
-----
User avatar
Spyrewolf
Posts: 450
Joined: Tue Jul 05, 2005 4:53 am
Location: Wellington::New Zealand

Post by Spyrewolf »

ok i see...

i still believe it is do-able,

but you'll need a few more commands + the ones already stated.

try the move to point and distance orders,

i'll explain, once you have selected your pawn and moved them to the area where the enemy is [say by clicking on them] do a distance order and check if they are enemy if both are true then attack,

i do see this is still do-able currently
Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Post by Jay »

Spyrewolf wrote:
try the move to point and distance orders,

i'll explain, once you have selected your pawn and moved them to the area where the enemy is [say by clicking on them] do a distance order and check if they are enemy if both are true then attack,
Hm, yes, but i don't have a command to move a pawn to point XYZ, i only can make him go to a certain script point.

If i had this command, i would do this:
Store X,Y,Z of the Enemy into Attributes.
Store 1 into A 'ForceToGo' attribute so that the pawn knows that he has to go there,
move the pawn to XYZ
and last i would call a FindTargetOrder() command.

I truly don't know any further. Would you explain what you meant a bit more detailed?

EDIT: No Problem, i found the SetTargetPoint(float OffsetX, float OffsetY, float OffsetZ ); command. Thanks for the help :)

EDIT2: Something REALLY strange is happening: i set the Grp attribute for the pawns and they get values whatever they want. i had 201, something above 16000 and something above 77000 with exactly the same value!!!!

EDIT3: It's not getting better. I don't know why this is all this strange, but i am getting totally wrong numbers when i use the GetAttribute() command on pawns!
Everyone can see the difficult, but only the wise can see the simple.
-----
User avatar
Ransom
Posts: 30
Joined: Sat Jan 14, 2006 7:16 pm

Post by Ransom »

DIT3: It's not getting better. I don't know why this is all this strange, but i am getting totally wrong numbers when i use the GetAttribute() command on pawns!
Juutis and I discussed this months ago. The Get/Set/AddAttribute commands do not work... sucks... I know. But I would assume that the fact that they're referenced in the docs means that at least the groundwork is there for someone to line out the bugs.
User avatar
QuestOfDreams
Site Admin
Posts: 1520
Joined: Sun Jul 03, 2005 11:12 pm
Location: Austria
Contact:

Post by QuestOfDreams »

There's a bug in the Attribute commands (fixed in next release):
http://realityfactory.info.ms/forum/viewtopic.php?t=751

It is already possible to access variables of other pawns
example szEntityName pawn1, pawn2

script1.s:

Code: Select all

{
    TEST [10]

    Spawn[()
    {
         Console(true);
         LowLevel("setup");
    }]

    setup[()
    {
        SetNoCollision();
        PawnRender(false);
        self.think = "run";
    }]

    run[()
    {
        PositionToPlayer(0, 30, TEST, true, false);
        debug(TEST);
    }]
}
script2.s:

Code: Select all

{
    Spawn[()
    {
        Console(true);
        NewOrder("Rotate");
    }]

    Rotate[()
    {
        Rotate("", 30, 0, 20, 0, "");
        pawn1.TEST = pawn1.TEST + 1;
        RestartOrder();
    }]
}
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Post by Juutis »

Yes, that EntityName.VARIABLE thing works. But sometimes it's a bit strange.
For example:

"pawn1.TEST = "test";" doesn't work BUT "pawn1.TEST = StringCopy("test");" works.


And if the pawn that is modifying pawn1's variables has a variable called NUMBER (an integer or float):

"pawn1.TEST = NUMBER;" doesn't work BUT "pawn1.TEST = NUMBER + 0;" works.

This has something to do with messing up numbers and strings.
I'll try to explain a bit. Let's think NUMBER = 10.

"pawn1.TEST = NUMBER;" - somehow this sets pawn1.TEST to 10 BUT it's a string... so it's in fact "10".
"pawn1.TEST = NUMBER + 0;" - this forces the variable to be an integer (or float) because you can't add 0 to a string. So it's 10 + 0 = 10.
Pain is only psychological.
Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Post by Jay »

What? it works already? oh thanks! didin't know that!

EDIT: I got it working now! It rocks! I now can make the friendly pawn attack the hostile one. It's really cool!

However, i cannot get Fields like that:

MouseSelect(false,false).GROUP="HOSTILE";
or
SELECT1.GROUP="HOSTILE";

is there any workaround around it?
Also i think this could be moved to the Scripting section now because it's not a Feature Request anymore.
Everyone can see the difficult, but only the wise can see the simple.
-----
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Post by Juutis »

Try

MouseSelect(false,false).GROUP = StringCopy("HOSTILE");
and
SELECT1.GROUP = StringCopy("HOSTILE");
Pain is only psychological.
Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Post by Jay »

No it says that these are Non-Objects and that it cannot get a field from a non-object.

I used it this way:
if(MouseSelect(false,false).GROUP="HOSTILE")

StringCopy("HOSTILE") didn't change anything.
Everyone can see the difficult, but only the wise can see the simple.
-----
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Post by Juutis »

Ah yes, you are using it that way.

I tested did some research and I think I've found out why it doesn't work.
It seems that the MouseSelect() command somehow returns a string instead of an EntityName. So if you point at a pawn whose name is "pawn1", that line would look something like this to the script engine (or whatever it is that executes the scripts):

if("pawn1".GROUP="HOSTILE")
when it should be
if(pawn1.GROUP="HOSTILE")

In fact you get the same non-object error if you try this:
debug(StringCopy("pawn1").GROUP);
Pain is only psychological.
Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Post by Jay »

Yes that makes sense to me. So what we need is something that can convert a szEntityName into a Entity-Pointer...
Everyone can see the difficult, but only the wise can see the simple.
-----
Post Reply