Author Topic: help inserting a check.  (Read 409 times)

Legacy_zero-feeling

  • Sr. Member
  • ****
  • Posts: 287
  • Karma: +0/-0
help inserting a check.
« on: June 28, 2014, 03:01:34 am »


               

the script is for a quest.


the player goes to a placeable (rock) and "mines" for a gem.


the script then is supposed to give 1 of 6 different gems (it does this)


**only lets player mine 5 times regardless of if they have all gems needed.**


the rocks are supposed to stay mineable until the player has one of each gem needed. (does not do this)


**maybe some kind of check is needed?**


 


the object of the quest is to get 5 different gems.


a diamond, emerald, ruby, sapphire, and topaz. (a glaspier is given as a dud)


 


i was looking at the script and noticed there's no check to see if the player has 1 of each gem needed before making the stones unusable. unusable as in not being able to mine the stone for more.


 


heres the script


 


///////////////////////////////////////


//// Created by : ShAdOoOw ///


///////////////////////////////////////


 


#include "pqj_inc"

#include "nw_i0_plot"

void GiveGem(object oPC)

{

 switch(Random(6)+1)

 { // create a random gem on successful dig

       case 1: CreateItemOnObject("gem_sapphire",oPC);

               FloatingTextStringOnCreature("** You have found a Gem **", oPC); // send message with every successful dig

               break;

       case 2: CreateItemOnObject("gem_topaz",oPC);

               FloatingTextStringOnCreature("** You have found a Gem **", oPC);

               break;

       case 3: CreateItemOnObject("gem_diamond",oPC);

                FloatingTextStringOnCreature("** You have found a Gem **", oPC);

                break;

       case 4: CreateItemOnObject("gem_emerald",oPC);

               FloatingTextStringOnCreature("** You have found a Gem **", oPC);

               break;

       case 5: CreateItemOnObject("gem_ruby",oPC);

               FloatingTextStringOnCreature("** You have found a Gem **", oPC);

               break;

       case 6: CreateItemOnObject("gem_dud",oPC);

               FloatingTextStringOnCreature("** You have found a Gem **", oPC);

               break;

   }

}

void main()

{

    object oPC = GetLastUsedBy();

    if (!GetIsPC(oPC)) return;

 

   // if (RetrieveQuestState("q_gems", oPC) == 10 && HasItem(oPC,"plot_pickaxe"))

   int nInt = RetrieveQuestState("q_gems",oPC);

   if(nInt >= 10 && nInt < 60)

    {

     AssignCommand(oPC, ActionPlayAnimation(ANIMATION_LOOPING_GET_MID, 1.0, 4.0));

     DelayCommand(4.5, GiveGem(oPC));

     AddPersistentJournalQuestEntry("q_gems",nInt+10,oPC,FALSE);

     FloatingTextStringOnCreature("** Your Journal Has Been Updated **", oPC);

     SetUseableFlag(OBJECT_SELF, FALSE);

     DelayCommand(900.0, SetUseableFlag(OBJECT_SELF, TRUE));

    }

}

 

I know that this kind of check or something similar should be in there when it's checking for the quest state, but when i try and insert it myself i get errors every time.

 


if (nInt == 40 && GetItemPossessedBy(oPC,"package_4") != OBJECT_INVALID

    && GetItemPossessedBy(oPC,"gem_emerald") != OBJECT_INVALID

    && GetItemPossessedBy(oPC,"gem_ruby") != OBJECT_INVALID

    && GetItemPossessedBy(oPC,"gem_diamond") != OBJECT_INVALID)

    && GetItemPossessedBy(oPC,"gem_sapphire") != OBJECT_INVALID)

    && GetItemPossessedBy(oPC,"gem_topaz") != OBJECT_INVALID)


        return TRUE;

 


any help inserting this in to the script would be appreciated.



               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
help inserting a check.
« Reply #1 on: June 28, 2014, 10:17:47 am »


               You've closed the if condition three times. Try this:

if (nInt == 40 && GetItemPossessedBy(oPC,"package_4") != OBJECT_INVALID

    && GetItemPossessedBy(oPC,"gem_emerald") != OBJECT_INVALID

    && GetItemPossessedBy(oPC,"gem_ruby") != OBJECT_INVALID

    && GetItemPossessedBy(oPC,"gem_diamond") != OBJECT_INVALID

    && GetItemPossessedBy(oPC,"gem_sapphire") != OBJECT_INVALID

    && GetItemPossessedBy(oPC,"gem_topaz") != OBJECT_INVALID)


        return; // not return TRUE, because the script isn't conditional.
Incidentally, those statements need to refer to the gem's tag. Evidently, gem_emerald etc is the resref (template name) but the tag may well be different.

You'll also have to do something about the quest state nInt. As it stands, it's being updated every time a gem is found, whereas what you want is an update when a unique gem is found for the first time - or just forget nint until all the gems are found, then set it to 60.

I'm sure you appreciate that there's an exploit; the PC can keep mining gems forever, as long as they put them on the ground.
               
               

               
            

Legacy_zero-feeling

  • Sr. Member
  • ****
  • Posts: 287
  • Karma: +0/-0
help inserting a check.
« Reply #2 on: June 28, 2014, 03:05:21 pm »


               
so please pardon my ignorance of the scripting language, i'm in the learning prosses, but i need to make this:

 

// if (RetrieveQuestState("q_gems", oPC) == 10 && HasItem(oPC,"plot_pickaxe"))

   int nInt = RetrieveQuestState("q_gems",oPC);

   if(nInt >= 10 && nInt < 60)

 

into this:

 

// if (RetrieveQuestState("q_gems", oPC) == 10 && HasItem(oPC,"plot_pickaxe"))

   int nInt = RetrieveQuestState("q_gems",oPC);

   if (nInt >= 10 && nInt < 60) 

   && GetItemPossessedBy(oPC,"gem_emerald") != OBJECT_INVALID

   && GetItemPossessedBy(oPC,"gem_ruby") != OBJECT_INVALID

   && GetItemPossessedBy(oPC,"gem_diamond") != OBJECT_INVALID

   && GetItemPossessedBy(oPC,"gem_sapphire") != OBJECT_INVALID

   && GetItemPossessedBy(oPC,"gem_topaz") != OBJECT_INVALID)

   return;

 

correct?

 

---------------------------

 

secondly, originally the player would need to have a pickaxe to do any mining, it's obviously not the case now with the // in front of the line, would i just need to add:

 

&& HasItem(oPC,"plot_pickaxe")

 

to the front of the check as well? or is that a whole new type of check?

 

----------------------------

 

as for the exploit, yes i'm quite aware of the exploit and have made it very much NOT worth the time and effort to do so. 

 

the gems are almost worthless to sell to anyone but the quest giver and he will only buy one of each for a good price, where as merchants will only pay 3-7 gold per gem.

900 seconds wait time for the gem stone quarry to reactivate

area clean after 10 seconds of the player leaving.

and a butt load of monsters between each gem quarry.

 

kinda makes it not worth the effort. 

but i would like to know if there is another/better way to stop this.

               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
help inserting a check.
« Reply #3 on: June 29, 2014, 09:43:02 am »


               I'd structure it like this:
  • If the player has all the required gems (quest status 60), send a message and return
  • If the player has no pickaxe, send a message and return
  • Create a random gem
  • If the player now has all the required gems, set quest status 60
  • Otherwise, I wouldn't refer to nInt at all.

    If the pickaxe is a weapon which the player can equip, you can check that it's actually equipped using


    if (GetTag(GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPC)) == "plot_pickaxe")
    Again, I'm assuming that "plot_pickaxe" is the item tag, and not the resref.

               
               

               
            

Legacy_zero-feeling

  • Sr. Member
  • ****
  • Posts: 287
  • Karma: +0/-0
help inserting a check.
« Reply #4 on: June 29, 2014, 10:31:14 am »


               

Proleric,


 


please keep in mind i do not want to come across as being rude.


 


as much as i appreciate you trying to help me, and i honestly do appreciate the effort, your in fact not.


i'm what you would call a "noob" to scripting and i have a bit of a learning handicap.


by you offering how you would do things does make sense and is actually what i wanted in the first place, it doesn't help me learn because there aren't any examples to learn from.


this is the case with many scripters here, they assume everyone knows what their doing when in fact people like me only know some of what their doing, that's why we ask the questions we do.


in my previous post i asked "do i need to change this (script) to this (new script)?


i was honestly hoping for a yes or no answer.


if a no answer came up, then why, with an example or finished product with an explanation behind //


this would have helped me learn.


i didn't make this script originally, it was made by ShAdOoOw, who is reluctant to help me fix his script, telling me to post it here.


again, i don't mean to be rude, just trying to point out i learn by seeing examples better than seeing suggestions on how to do things.


 


to address your question above, all my resrefs and tags are the same unless they need to be different due to some scripting conflict.


 


i hope these comments don't turn you away from helping me, because i do need the help, and i don't mean to offend.


i just want to be able to learn and hopefully not have to ask for help all the time.



               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
help inserting a check.
« Reply #5 on: June 29, 2014, 02:32:25 pm »


               


i didn't make this script originally, it was made by ShAdOoOw, who is reluctant to help me fix his script, telling me to post it here.


again, i don't mean to be rude, just trying to point out i learn by seeing examples better than seeing suggestions on how to do things.




zero its not that I wouldnt want to help you, but its not just you who is PMing me he needs to make a script / repair script. And I have my own projects (basically everyone here has), so while I am able to help, you and all who are PMing me will be always better to post here where anyone else can help you too. And if I will have some time I will help as well.



               
               

               
            

Legacy_Ed Venture

  • Full Member
  • ***
  • Posts: 200
  • Karma: +0/-0
help inserting a check.
« Reply #6 on: June 29, 2014, 03:11:11 pm »


               Zero,
As a noob myself, I can understand your frustration. For what you're doing, I use Setting and GettingLocalInt. A simple increase in the int can be used to count and countdown all kinds of events.
Adding Conditionals can check to see what items the PC has or what has been dropped on the ground.
It can be difficult to consume the information that you get here. That's why these guys can do in minutes, what can take me hours. Learn what you can and be patient. Half the fun is in the learning. That's why I like to work on a desktop, it gives me someplace to bang my head.
I hope this helps. If not, you can tell me to shut up.

Ed
               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
help inserting a check.
« Reply #7 on: June 29, 2014, 03:31:14 pm »


               


 


so please pardon my ignorance of the scripting language, i'm in the learning prosses, but i need to make this:

 

// if (RetrieveQuestState("q_gems", oPC) == 10 && HasItem(oPC,"plot_pickaxe"))

   int nInt = RetrieveQuestState("q_gems",oPC);

   if(nInt >= 10 && nInt < 60)

 

into this:

 

// if (RetrieveQuestState("q_gems", oPC) == 10 && HasItem(oPC,"plot_pickaxe"))

   int nInt = RetrieveQuestState("q_gems",oPC);

   if (nInt >= 10 && nInt < 60) 

   && GetItemPossessedBy(oPC,"gem_emerald") != OBJECT_INVALID

   && GetItemPossessedBy(oPC,"gem_ruby") != OBJECT_INVALID

   && GetItemPossessedBy(oPC,"gem_diamond") != OBJECT_INVALID

   && GetItemPossessedBy(oPC,"gem_sapphire") != OBJECT_INVALID

   && GetItemPossessedBy(oPC,"gem_topaz") != OBJECT_INVALID)

   return;

 

correct?

 



Not quite. Count up your open and close parentheses.  You've still got one too many ")".


               
               

               
            

Legacy_Pstemarie

  • Hero Member
  • *****
  • Posts: 4368
  • Karma: +0/-0
help inserting a check.
« Reply #8 on: June 30, 2014, 01:52:10 am »


               
Try this...

 

// if (RetrieveQuestState("q_gems", oPC) == 10 && HasItem(oPC,"plot_pickaxe"))

   int nInt = RetrieveQuestState("q_gems",oPC);

   if ( (nInt >= 10 && nInt < 60) &&

        GetItemPossessedBy(oPC,"gem_emerald") != OBJECT_INVALID &&

        GetItemPossessedBy(oPC,"gem_ruby") != OBJECT_INVALID &&

        GetItemPossessedBy(oPC,"gem_diamond") != OBJECT_INVALID &&

        GetItemPossessedBy(oPC,"gem_sapphire") != OBJECT_INVALID &&

        GetItemPossessedBy(oPC,"gem_topaz") != OBJECT_INVALID)  )

   return;


               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
help inserting a check.
« Reply #9 on: June 30, 2014, 03:23:55 am »


               


 


Try this...

 

// if (RetrieveQuestState("q_gems", oPC) == 10 && HasItem(oPC,"plot_pickaxe"))

   int nInt = RetrieveQuestState("q_gems",oPC);

   if ( (nInt >= 10 && nInt < 60) &&

        GetItemPossessedBy(oPC,"gem_emerald") != OBJECT_INVALID &&

        GetItemPossessedBy(oPC,"gem_ruby") != OBJECT_INVALID &&

        GetItemPossessedBy(oPC,"gem_diamond") != OBJECT_INVALID &&

        GetItemPossessedBy(oPC,"gem_sapphire") != OBJECT_INVALID &&

        GetItemPossessedBy(oPC,"gem_topaz") != OBJECT_INVALID)  )

   return;

 




That's one way, but since all the logic operations here are the same precedence you don't need that extra set. I was thinking just remove the ) after the 60.


As an aside, stylistically I much prefer to have the operator first on multiline boolean clauses like that.  It's easier to read and see what's happening that way (to me anyway...)