Page 1 of 1

Modifiying pawns variables from another pawn?

Posted: Tue Aug 01, 2006 7:58 pm
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.

Posted: Tue Aug 01, 2006 8:26 pm
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").

Posted: Tue Aug 01, 2006 8:37 pm
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.

Posted: Tue Aug 01, 2006 8:46 pm
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.....

Posted: Tue Aug 01, 2006 9:13 pm
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.

Posted: Tue Aug 01, 2006 9:28 pm
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

Posted: Tue Aug 01, 2006 9:50 pm
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!

Posted: Tue Aug 01, 2006 11:19 pm
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.

Posted: Tue Aug 01, 2006 11:35 pm
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();
    }]
}

Posted: Wed Aug 02, 2006 8:58 am
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.

Posted: Wed Aug 02, 2006 9:57 am
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.

Posted: Wed Aug 02, 2006 10:27 am
by Juutis
Try

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

Posted: Wed Aug 02, 2006 10:40 am
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.

Posted: Wed Aug 02, 2006 11:36 am
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);

Posted: Fri Aug 04, 2006 1:05 pm
by Jay
Yes that makes sense to me. So what we need is something that can convert a szEntityName into a Entity-Pointer...