Aller au contenu

Photo

Is there a way to unequip all weapons from all creatures in an area?


  • Veuillez vous connecter pour répondre
9 réponses à ce sujet

#1
andysks

andysks
  • Members
  • 1 645 messages

Hi all. As the title says. I seem to not find it, or does nothing like that exist?

 

If this requires some short of loop, some help on that would be also needed since I don't get looping scripts :). At all.



#2
andysks

andysks
  • Members
  • 1 645 messages

Alright, right after I saw this I found the SetWeaponVisibility function. I guess that should do. But how can I Get all creatures in area?



#3
kevL

kevL
  • Members
  • 4 056 messages
hi Andy,

loops.

look at some code like this:
object oCreature = GetNearestObject(OBJECT_TYPE_CREATURE, OBJECT_SELF, 1);
SetWeaponVisibility(oCreature, 0, 0);

oCreature = GetNearestObject(OBJECT_TYPE_CREATURE, OBJECT_SELF, 2);
SetWeaponVisibility(oCreature, 0, 0);

oCreature = GetNearestObject(OBJECT_TYPE_CREATURE, OBJECT_SELF, 3);
SetWeaponVisibility(oCreature, 0, 0);
the only thing that changes is the iterator. Using a loop:
 
int i = 1;
object oCreature = GetNearestObject(OBJECT_TYPE_CREATURE, OBJECT_SELF, i);
while (GetIsObjectValid(oCreature))
{
    SetWeaponVisibility(oCreature, 0, 0);

    i++;
    oCreature = GetNearestObject(OBJECT_TYPE_CREATURE, OBJECT_SELF, i);
}


#4
kevL

kevL
  • Members
  • 4 056 messages
ps. something like this for the situation as described:

object oCreature = GetFirstObjectInArea();
while (GetIsObjectValid(oCreature))
{
    if (GetObjectType(oCreature) == OBJECT_TYPE_CREATURE)
    {
        SetWeaponVisibility(oCreature, 0, 0);
    }

    oCreature = GetNextObjectInArea();
}


#5
andysks

andysks
  • Members
  • 1 645 messages

I see. This makes things a bit more clear, thanks KevL. One question about loops, why do we need this while line at the beginning? I mean, what would happen if it wasn't there but the rest of the script were as it is now?



#6
Dann-J

Dann-J
  • Members
  • 3 161 messages

The 'while' function *is* the loop. Without that, things would only happen once (which is the antithesis of a loop).

 

Oh for the good old days of Basic programming, with its gotos and gosubs...


  • GCoyote aime ceci

#7
kevL

kevL
  • Members
  • 4 056 messages

with its gotos and gosubs...


gaah!


edit: see "batchfile"

#8
kevL

kevL
  • Members
  • 4 056 messages

I see. This makes things a bit more clear, thanks KevL. One question about loops, why do we need this while line at the beginning? I mean, what would happen if it wasn't there but the rest of the script were as it is now?


read it like,

while (condition is TRUE)
// do this
// and dont forget to increment advance the condition before the next loop!!!
// or break; to put a sudden stop to the loop, and continue outside its scope.
// speaking of continue; use this to skip the current iteration and move onto the next iter.

#9
andysks

andysks
  • Members
  • 1 645 messages

It makes sense now. It's a good thing to know, these loops :). And I guess any function which uses a GetNext*** can be used like that?



#10
kevL

kevL
  • Members
  • 4 056 messages
yep. when GetFirst* is called, the engine keeps its own little table of what "next" should/ will be ...