Author Topic: will this work?  (Read 700 times)

Legacy_Ryuhi2000

  • Full Member
  • ***
  • Posts: 159
  • Karma: +0/-0
will this work?
« on: April 04, 2011, 07:27:51 pm »


               will this script work  the way i would like  it to?

it compiles fine but  i have several targets and i want to give the gold to each of them. the "Rate" and "Bonus" variables are set to a different value on each of the targets so i was wondering if i ask here.

or should i try doing a  while loop? i very rarely ever use loops since im not to familiar with them tho i was just starting to learn looping from what i saved from a post i saved in the old lesser toolset known features thread on the old forums.

here is the script i have right now:

void main()
{

object oTarget;

int Rate = GetLocalInt(oTarget, "Rate");
int Bonus = GetLocalInt(oTarget, "Bonus");
int Salary = Rate + Bonus;
int Pay = Salary * 8;

oTarget = GetObjectByTag("NPCTAG");

GiveGoldToCreature(oTarget, Pay);

oTarget = GetObjectByTag("NPCTAG2");

GiveGoldToCreature(oTarget, Pay);

oTarget = GetObjectByTag("NPCTAG3");

GiveGoldToCreature(oTarget, Pay);

oTarget = GetObjectByTag("NPCTAG4");

GiveGoldToCreature(oTarget, Pay);

oTarget = GetObjectByTag("NPCTAG5");

GiveGoldToCreature(oTarget, Pay);

oTarget = GetObjectByTag("NPCTAG6");

GiveGoldToCreature(oTarget, Pay);

}
               
               

               
            

Legacy_ehye_khandee

  • Hero Member
  • *****
  • Posts: 1415
  • Karma: +0/-0
will this work?
« Reply #1 on: April 04, 2011, 07:45:29 pm »


               No, this will not work as written.
Specifically, you are trying to load Rate and Bonus from a variable on oTarget, while oTarget is not specified (OBJECT_INVALID) - so in this case, Rate and Bonus would be 0.

I presume you meant that each of the NPCs you use will have the variables stored on the NPC itself - and in this case you should likely use a loop - I can give you this example of sample code with a loop - though, I'm not certain I understand what you want, I'll give it my best shot.



void main()
{

object oTarget;

int Rate, Bonus, Salary, Pay, i; // declare all int variables

for (i=1; i < 7, i++) //set to run for NPCTAG1 thru NPCTAG6
{
  oTarget = GetObjectByTag("NPCTAG"+InToString(i));
  Rate = GetLocalInt(oTarget, "Rate");
  Bonus = GetLocalInt(oTarget, "Bonus");
  Salary = Rate + Bonus;
  Pay = Salary * 8;
  GiveGoldToCreature(oTarget, Pay);
}

}

Hope this helps. NOTE it is NOT tested - written off the top of my head, but it should do the trick.

Be well. Game on.
GM_ODA
               
               

               
            

Legacy_Ryuhi2000

  • Full Member
  • ***
  • Posts: 159
  • Karma: +0/-0
will this work?
« Reply #2 on: April 04, 2011, 08:20:45 pm »


               yes i have the Rate and Bonus variables set on the npcs themselves.

note the loop in the post above i did not realy understand what the for loop was running for or where to plug in the tags of the additional npc tags.

what im trying to do is give the gold to each of those 6 npcs using this math formula:
Pay = (Value of Integer Rate On Target NPC + Value of Integar Bonus On Target NPC) * 8

here is what i had originaly is below this but script editor said no because of how i defined pay if i remember right so i came up with script in the first post i did on this thread.

void main()
{

object oTarget;

int Pay;

oTarget = GetObjectByTag("NPCTAG");

Pay = (GetLocalInt(oTarget, "Rate") + GetLocalInt(oTarget, "Bonus")) * 8;

GiveGoldToCreature(oTarget, Pay);

oTarget = GetObjectByTag("NPCTAG2");

Pay = (GetLocalInt(oTarget, "Rate") + GetLocalInt(oTarget, "Bonus")) * 8;

GiveGoldToCreature(oTarget, Pay);

oTarget = GetObjectByTag("NPCTAG3");

Pay = (GetLocalInt(oTarget, "Rate") + GetLocalInt(oTarget, "Bonus")) * 8;

GiveGoldToCreature(oTarget, Pay);

oTarget = GetObjectByTag("NPCTAG4");

Pay = (GetLocalInt(oTarget, "Rate") + GetLocalInt(oTarget, "Bonus")) * 8;

GiveGoldToCreature(oTarget, Pay);

oTarget = GetObjectByTag("NPCTAG5");

Pay = (GetLocalInt(oTarget, "Rate") + GetLocalInt(oTarget, "Bonus")) * 8;

GiveGoldToCreature(oTarget, Pay);

oTarget = GetObjectByTag("NPCTAG6");

Pay = (GetLocalInt(oTarget, "Rate") + GetLocalInt(oTarget, "Bonus")) * 8;

GiveGoldToCreature(oTarget, Pay);

}
               
               

               
            

Legacy_KiKurA

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
will this work?
« Reply #3 on: April 04, 2011, 08:37:56 pm »


               

...
{
oTarget = GetObjectByTag("NPCTAG"+InToString(i)); // Here you change oTarget to the next npc '<img'>
Rate = GetLocalInt(oTarget, "Rate");
...


^^ There is the change in oTarget to the next NPC

i think the InToString should be IntToString though '<img'>
               
               

               


                     Modifié par KiKurA, 04 avril 2011 - 07:40 .
                     
                  


            

Legacy_Ryuhi2000

  • Full Member
  • ***
  • Posts: 159
  • Karma: +0/-0
will this work?
« Reply #4 on: April 04, 2011, 08:50:27 pm »


               ok i missed that line but whats the IntToString for tho in that line?
               
               

               
            

Legacy_KiKurA

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
will this work?
« Reply #5 on: April 04, 2011, 08:52:53 pm »


               it makes the integer type (i) a string type so it can be added to the "NPCTAG"
               
               

               
            

Legacy_KiKurA

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
will this work?
« Reply #6 on: April 04, 2011, 09:48:35 pm »


               

here is what i had originaly is below this but script editor said no because of how i defined pay if i remember right so i came up with script in the first post i did on this thread.

void main()
{

object oTarget;

int Pay;

oTarget = GetObjectByTag("NPCTAG");

Pay = (GetLocalInt(oTarget, "Rate") + GetLocalInt(oTarget, "Bonus")) * 8;
}


mmhmhmhm...

lol, try this '<img'> 

Pay = (((int GetLocalInt(oTarget, "Rate")) + (int GetLocalInt(oTarget, "Bonus"))) * 8;


               
               

               
            

Legacy_ehye_khandee

  • Hero Member
  • *****
  • Posts: 1415
  • Karma: +0/-0
will this work?
« Reply #7 on: April 04, 2011, 10:01:10 pm »


               My script will cycle thru your NPCs tagged NPCTAG1 through NPCTAG6 - let me know if that works for you or not.

G
               
               

               
            

Legacy_Ryuhi2000

  • Full Member
  • ***
  • Posts: 159
  • Karma: +0/-0
will this work?
« Reply #8 on: April 04, 2011, 10:24:21 pm »


               @ehye_khandee it wouldnt fire tho so it might something with GetObjectByTag()
might be the tags of my npcs i plan on having this run on ill check quick and post back

@KiKurA will check that out as well to see what that does since that would be useful to know how to fix that error when i get it on not specifly that script i posted but on others tho
               
               

               
            

Legacy_Ryuhi2000

  • Full Member
  • ***
  • Posts: 159
  • Karma: +0/-0
will this work?
« Reply #9 on: April 04, 2011, 10:49:33 pm »


               @ehye_khandee yea there was a lower case letter in the tag that why it wouldnt fire so i fixed the tag and it worked

@KiKurA yea that made it work for all but to lines in that dont know how but i just copied and pasted your fixed line  over again and then it worked might just be my toolset

it has been acting screwy lately while im trying to export 1 specific area in my module
it should not hang up for like 50 minutes in a 3 by 3 area with just 8 placeables( out of which only 2 are useable), 1 npc, and 4 encounters everything using default bioware scripts except by 2 useable placables.

the machine its being stupid on has a 2.8 quad core and 4 gigs of ram and a radeon hd 4550 with 512mb ram running windows 7 64bit.  if toolset keeps acting screwy ill just reimage the machine
               
               

               
            

Legacy_ehye_khandee

  • Hero Member
  • *****
  • Posts: 1415
  • Karma: +0/-0
will this work?
« Reply #10 on: April 05, 2011, 01:02:33 am »


               is your nwn configured to use only one core?

btw, my script had a typo in it "InToString" should be "IntToString"
               
               

               
            

Legacy_Ryuhi2000

  • Full Member
  • ***
  • Posts: 159
  • Karma: +0/-0
will this work?
« Reply #11 on: April 05, 2011, 01:16:33 am »


               yea its set for just one core could just be the operating system being 64 bit being stupid....why Dell had to make it 64 bit is beyond me since none of the hardware in the box requires 64bit... i prefer 32 bit but i dont have a 32 bit win 7 disk >.< or id switch it........but anyway
Edit: For clarifaction it is just toolset that being stupid not the game itself

yes i fixed that line of the script but then toolset regeted your freshly recopied script...... i ended up making a home brew not tested yet but compiles fine its for a Inn in the module im working on. cuz i wanted to have a cool inn with live staff on shift and the staff getting paid when theyre shift is over. let me know what you think and any changes you would suggest?


void main()
{
 
object oDoor = GetObjectByTag("staffroom");
object oTarget;
 
int Pay;
 
if(GetTimeMinute() == 1 && GetTimeSecond() == 1 && GetTimeMillisecond() == 1)
{
 
AssignCommand(oDoor, ActionSpeakString("Sea Serpent Inn Staff Change If It Has Been 8 Hours Since The Current Staff Have Been On Shift", TALKVOLUME_SHOUT));
 
//pay the hourly employees
 
//waitress
oTarget = (GetObjectByTag("Prish"));
 
Pay = (GetLocalInt(oTarget, "Rate") + GetLocalInt(oTarget, "Bonus"));
 
GiveGoldToCreature(oTarget, Pay);
 
//security guard
oTarget = (GetObjectByTag("Keli"));
 
Pay = (GetLocalInt(oTarget, "Rate") + GetLocalInt(oTarget, "Bonus"));
 
GiveGoldToCreature(oTarget, Pay);
 
switch (GetTimeHour())
{
 
//3rd to 1st shift
case 8:
 
AssignCommand(oDoor, ActionOpenDoor(oDoor));
 
AssignCommand(oDoor, ActionSpeakString("Sea Serpent Inn Staff Change It Is Now Time For 3rd Shift To Leave And 1st Shift To Take Over", TALKVOLUME_SHOUT));
 
//Start Staff change
   oTarget = GetObjectByTag("CelawynFears");//Shift ending Room Renter
 
   AssignCommand(oTarget, ActionForceMoveToObject(GetObjectByTag("NW_STOREBAR01")));
 
   AssignCommand(oTarget, ActionForceMoveToObject(GetObjectByTag("CelawynFearsWP")));
 
   oTarget = GetObjectByTag("DalloDian");//Next shift room renter
 
   AssignCommand(oTarget, ActionForceMoveToObject(GetObjectByTag("room_renter")));
 
   oTarget = GetObjectByTag("SiliaBlake");//Shift ending Bar Tender
 
   AssignCommand(oTarget, ActionForceMoveToObject(GetObjectByTag("SiliaBlakeWP")));
 
   oTarget = GetObjectByTag("ElvawenAmolyan");//Next shift Bar Tender
 
   AssignCommand(oTarget, ActionForceMoveToObject(GetObjectByTag("bar_tender")));
//End Staff Change
 
DelayCommand(10.0, AssignCommand(oDoor, ActionCloseDoor(oDoor)));
 
//NPC PAY
oTarget = GetObjectByTag("CelawynFears");//room renter
 
Pay = (GetLocalInt(oTarget, "Rate") + GetLocalInt(oTarget, "Bonus")) * 8;
 
GiveGoldToCreature(oTarget, Pay);
 
oTarget = GetObjectByTag("SiliaBlake");//bar tender
 
Pay = (GetLocalInt(oTarget, "Rate") + GetLocalInt(oTarget, "Bonus")) * 8;
 
GiveGoldToCreature(oTarget, Pay);
     break;
 
//1st to 2nd shift
case 16:
 
AssignCommand(oDoor, ActionOpenDoor(oDoor));
 
AssignCommand(oDoor, ActionSpeakString("Sea Serpent Inn Staff Change It Is Now Time For 1st Shift To Leave And 2nd Shift To Take Over", TALKVOLUME_SHOUT));
 
//Start Staff change
   oTarget = GetObjectByTag("DalloDian");//Shift ending Room Renter
 
   AssignCommand(oTarget, ActionForceMoveToObject(GetObjectByTag("NW_STOREBAR01")));
 
   AssignCommand(oTarget, ActionForceMoveToObject(GetObjectByTag("DallosBed")));
 
   oTarget = GetObjectByTag("TeroLane");//Next shift room renter
 
   AssignCommand(oTarget, ActionForceMoveToObject(GetObjectByTag("room_renter")));
 
   oTarget = GetObjectByTag("ElvawenAmolyan");//Shift ending Bar Tender
 
   AssignCommand(oTarget, ActionForceMoveToObject(GetObjectByTag("ElvawensBed")));
 
   oTarget = GetObjectByTag("CarenaMendt");//Next shift Bar Tender
 
   AssignCommand(oTarget, ActionForceMoveToObject(GetObjectByTag("bar_tender")));
//End Staff Change
 
DelayCommand(10.0, AssignCommand(oDoor, ActionCloseDoor(oDoor)));
 
//NPC PAY
oTarget = GetObjectByTag("DalloDian");//room renter
 
Pay = (GetLocalInt(oTarget, "Rate") + GetLocalInt(oTarget, "Bonus")) * 8;
 
GiveGoldToCreature(oTarget, Pay);
 
oTarget = GetObjectByTag("ElvawenAmolyan");//bar tender
 
Pay = (GetLocalInt(oTarget, "Rate") + GetLocalInt(oTarget, "Bonus")) * 8;
 
GiveGoldToCreature(oTarget, Pay);
     break;
 
//2nd to 3rd shift
case 0:
 
AssignCommand(oDoor, ActionOpenDoor(oDoor));
 
AssignCommand(oDoor, ActionSpeakString("Sea Serpent Inn Staff Change It Is Now Time For 2nd Shift To Leave And 3rd Shift To Take Over", TALKVOLUME_SHOUT));
 
//Start Staff change
   oTarget = GetObjectByTag("TeroLane");//Shift ending Room Renter
 
   AssignCommand(oTarget, ActionForceMoveToObject(GetObjectByTag("NW_STOREBAR01")));
 
   AssignCommand(oTarget, ActionForceMoveToObject(GetObjectByTag("TeroLaneWP")));
 
   oTarget = GetObjectByTag("CelawynFears");//Next shift room renter
 
   AssignCommand(oTarget, ActionForceMoveToObject(GetObjectByTag("room_renter")));
 
   oTarget = GetObjectByTag("CarenaMendt");//Shift ending Bar Tender
 
   AssignCommand(oTarget, ActionForceMoveToObject(GetObjectByTag("CarenaMendtWP")));
 
   oTarget = GetObjectByTag("SiliaBlake");//Next shift Bar Tender
 
   AssignCommand(oTarget, ActionForceMoveToObject(GetObjectByTag("bar_tender")));
//End Staff Change
 
DelayCommand(10.0, AssignCommand(oDoor, ActionCloseDoor(oDoor)));
 
//NPC PAY
oTarget = GetObjectByTag("TeroLane");//room renter
 
Pay = (GetLocalInt(oTarget, "Rate") + GetLocalInt(oTarget, "Bonus")) * 8;
 
GiveGoldToCreature(oTarget, Pay);
 
oTarget = GetObjectByTag("CarenaMendt");//bar tender
 
Pay = (GetLocalInt(oTarget, "Rate") + GetLocalInt(oTarget, "Bonus")) * 8;
 
GiveGoldToCreature(oTarget, Pay);
     break;
 
     default:
     // do nothing
     break;
 
}//end switch
 
}//end if
 
}//end main
               
               

               


                     Modifié par Ryuhi2000, 05 avril 2011 - 03:28 .
                     
                  


            

Legacy_ehye_khandee

  • Hero Member
  • *****
  • Posts: 1415
  • Karma: +0/-0
will this work?
« Reply #12 on: April 05, 2011, 03:49:32 am »


               A bit of a longish script but it _looks_ like it would do the trick - I note you are not using the same tags as you had specified in the original request - so a loop is doable but not so straight forward. Still, this script could be reduced to a loop and maybe 10 or 15 lines of code. No offense, I'm just really strict about lean mean code (I can't help it - my first computer was a commodore 64!).

Be well. Game on.
GM_ODA
               
               

               
            

Legacy_Ryuhi2000

  • Full Member
  • ***
  • Posts: 159
  • Karma: +0/-0
will this work?
« Reply #13 on: April 05, 2011, 04:24:47 am »


               i meant the tag of the npc not that the tag was "NPCTAG" fail.

and i honestly dont understand how can i further reduce the code lines can you like send me a example of how i can loop that to be less? i made it into switch/case which reduced my code by like 60 lines
               
               

               
            

Legacy_ehye_khandee

  • Hero Member
  • *****
  • Posts: 1415
  • Karma: +0/-0
will this work?
« Reply #14 on: April 05, 2011, 04:42:09 am »


               Too late for my fuzzy brain tonight, I'll post an example tomorrow with my coffee.