Aller au contenu

Photo

Can someone make this script easier to use?


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

#1
Leyf

Leyf
  • Members
  • 28 messages
So i have this script.....



//Put this script OnEnter#include "nw_i0_generic"void main(){
object oPC = GetEnteringObject();
if (!GetIsPC(oPC)) return;
object oTarget;object oSpawn;location lTarget;oTarget = GetWaypointByTag("waypoint tag");
lTarget = GetLocation(oTarget);
oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "creature tag", lTarget);
oTarget = oSpawn;
SetIsTemporaryEnemy(oPC, oTarget);
AssignCommand(oTarget, ActionAttack(oPC));
AssignCommand(oTarget, DetermineCombatRound(oPC));
}
And I would like to be able to use this script, but edit what it does using variables.
So what im really asking is, can someone take this script and add a string for whatever NPC tag i want to use
Whatever waypoint i want to use
and how many creatures i would like to spawn

It doesnt sound like too difficult of a job.. :D

#2
Shallina

Shallina
  • Members
  • 1 011 messages
It's really easy and easy to find :) You should use one of those script tutorial and do it yourself.



It's very good exercice to learn the basic of scripting. And there are no good module without good scripting :)



Wich mean, to do what you really want you 'll have to learn to script.

#3
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
Something kinda like so:

//Put this script OnEnter
#include "nw_i0_generic"
void main()
{
    object oPC = GetEnteringObject();
    if (!GetIsPC(oPC)) return;

    string sWP = GetLocalString(OBJECT_SELF, "WAYPOINT");
    string sCreature = GetLocalString(OBJECT_SELF, "CREATURE");
    object oTarget = GetWaypointByTag(sWP);
    location lTarget = GetLocation(oTarget);
    int iSpawn = GetLocalInt(OBJECT_SELF, "NUMBER_TO_SPAWN");
    object oSpawn;
    
    while (iSpawn > 0)
    {
        oSpawn = CreateObject(OBJECT_TYPE_CREATURE, sCreature, lTarget);
        //SetIsTemporaryEnemy(oPC, oSpawn);
        //AssignCommand(oSpawn, ActionAttack(oPC));
        //You probably only need this line:
        AssignCommand(oSpawn, DetermineCombatRound(oPC));
        iSpawn--;
    }
}

You will need to add variables to the trigger of course. One string named "WAYPOINT" for the waypoint tag. One string named "CREATURE" for the creature tag. And one int named "NUMBER_TO_SPAWN" for the amount of creatures you want to spawn.

Hope it helps. Good luck.

Modifié par GhostOfGod, 04 février 2011 - 04:36 .


#4
MasterChanger

MasterChanger
  • Members
  • 686 messages
In this particular case you are actually making more work for yourself by duplicating something that's present in the game, not that it's a bad exercise. When you use "encounter" triggers, you can easily set the tags of the creatures you want to spawn, how many (or a range), at which waypoints, whether you want it to reset and how often, etc. There might be reasons to recreate encounter trigger scripts if you're looking for more complex functionality, but at this point I don't think you need to do that.

In the interest of learning, though, the concept that GoG is using is called Local variables. KnightMare explains it starting on page 9 of his tutorial (version 9/12/10). A local variable is basically a variable stored on an object (module, area, creature, item, placeable, etc.) either by a script or in the object's properties tab in the Toolset. Once stored, other scripts can retrieve this variable.

This allows, as you've been requested, scripts to be made more "generic" and pull bits of info from the object in question. Say you wanted to give a bunch of domestic cats secret names that they would use in a song-and-dance montage. You could pull up the blueprint of that NPC (Non-Person Catracter :P), go to "Variables" and select string SecName = "....". Then when you retrieve the local string on that particular cat, it would be the name specific to them.

And if the Player-Character is supposed to receive a secret cat name at a certain point, you could save that as a local string through a script, and later retrieve it with other scripts.

Does this concept make sense? See if you can follow some of the examples KM gives in his tutorial.

#5
Leyf

Leyf
  • Members
  • 28 messages
Thank you SO much Ghost of God! And Master Changer, I have been trying to get my Encounter tool to work for days, still no luck :(