Skip to content

Learning to script: How to get pc's area

Hey guys I've been slowly learning how to use the nw script. So far the pattern has been

1.) Learn something new
2.) write some scripts
3.) Run up against a wall
4.) Rage quit
5.) Come back later bright eyed and optimistic
6.) Repeat

Hoping you guys can help me skip the rage quit this time. Right now I created an item with a use unique power property. In the on activated item script I roll a 1d100 and they receive an item depending on the roll. I plan on having the results of the d100 be different depending on the area that they're in (the game will be crafting heavy and they're searching the natural environment for things).

Below you'll find my attempt at that. I think the error lies in the if statement
if ((GetTag(oItem) == "it_Search") && (GetTag(oArea001) == GetTag(oUserArea)))

but I could be totally wrong about that. The attempted code on the right of the && symbol is trying to get the area of a placeable and the area of a player then check to see if they are the same using the == Please lemmee know what horrible mistake(s) I'm making. Thanks in advance and sorry for the inconvenience.





//Search Tool

//The Item that was activated
object oItem = GetItemActivated();
//The person that used the item
object oUser = GetItemActivator();
//Rocks in area001 and use that object to get the area the rocks are in (Area001)
object oRocks001 = GetObjectByTag("pl_Area001",1);
object oArea001 = GetArea(oRocks001);

//
object oUserArea = GetArea(oUser);

//If the object being used is the Search Tool then execute the following script
if ((GetTag(oItem) == "it_Search") && (GetTag(oArea001) == GetTag(oUserArea)))
{

//The loot tree for Area001
int nSearchSkill = GetSkillRank(SKILL_SEARCH, oUser, FALSE);
int nItemFound = 1;
int nRandomItem = d100(1);

if(GetIsSkillSuccessful(oUser, SKILL_SEARCH, 12))
{
if(nRandomItem <= 30)
{
CreateItemOnObject("it_TreeBranch", oUser, nItemFound);
}
else if((nRandomItem > 30) && (nRandomItem <= 50))
{
CreateItemOnObject("it_Log", oUser, nItemFound);
}
else if((nRandomItem > 50) && (nRandomItem <= 55))
{
CreateItemOnObject("it_BirdEgg", oUser, nItemFound);
}
else if((nRandomItem > 55) && (nRandomItem <= 60))
{
CreateItemOnObject("it_Mushroom", oUser, nItemFound);
}
else if((nRandomItem > 60) && (nRandomItem <= 70))
{
CreateItemOnObject("it_Acorn", oUser, nItemFound);
}
else if((nRandomItem > 70) && (nRandomItem <= 80))
{
CreateItemOnObject("it_Insect", oUser, nItemFound);
}
else if((nRandomItem > 80) && (nRandomItem <= 90))
{
CreateItemOnObject("it_Flint", oUser, nItemFound);
}
else if((nRandomItem > 90) && (nRandomItem <= 95))
{
CreateItemOnObject("it_GraniteRock", oUser, nItemFound);
}
else if((nRandomItem > 95) && (nRandomItem <= 100))
{
CreateItemOnObject("it_SmallBone", oUser, nItemFound);
}
}
}

Comments

  • CalgacusCalgacus Member Posts: 273
    edited March 2019
    Try
    object oRocks001 = GetObjectByTag("tagOfRocks");
    I think your call is trying to get the second area with tag "pl_Area001" of which I suspect there is none.
    lexicon reference

    PS: I appreciate your admitting of "rage quit"ing, I thought I was the only one. sniff, sniff, makes me feel less alone :'( .
  • BeaverMageBeaverMage Member Posts: 20
    Unfortunately not. The placeable's tag was edited to pl_Area001 pl is for placeable and Area001 because its only reason for existence is to capture Area001
  • CalgacusCalgacus Member Posts: 273
    Are there at least 2 placeables with that tag "pl_Area001" in Area001?
  • BeaverMageBeaverMage Member Posts: 20
    No, its the only one
  • BeaverMageBeaverMage Member Posts: 20
    Also the loot table should be fine. Originally I had it working for an on enter generic trigger and items were spawning fine but I wanted to give people more control as to when they search.
  • BeaverMageBeaverMage Member Posts: 20
    I just got an idea... I could Set a local variable and put a script on the area so that a local variable increases by one when you enter and decreases by one when you leave. Then I could see if the local variable is equivalent to 1 with ==. You think that'd work? If so i'd still like to know what I did wrong on the previous script.
  • CalgacusCalgacus Member Posts: 273
    The fact that you have only one placeable by that tag is what is wrong.
    Try this call:
    object oRocks001 = GetObjectByTag("pl_Area001", 0 ); //notice the 1 is gone
    That method counts found objects from 0.
  • BeaverMageBeaverMage Member Posts: 20
    Haha, when you're right you're right it works perfectly now. I thought I needed to put 1 in there because there was 1 placeable.
  • BeaverMageBeaverMage Member Posts: 20
    Thanks a bunch man
Sign In or Register to comment.