Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #31  
Old 12-15-2012, 05:16 PM
Stowen Stowen is offline
Graalian since '01
Join Date: Sep 2005
Location: Massachusets, USA
Posts: 156
Stowen will become famous soon enough
Send a message via AIM to Stowen Send a message via MSN to Stowen
How would I go about getting a list of all the players weapons?
Reply With Quote
  #32  
Old 12-15-2012, 11:01 PM
MysticalDragon MysticalDragon is offline
Global Administration
MysticalDragon's Avatar
Join Date: Oct 2002
Location: Lynn Ma
Posts: 883
MysticalDragon is just really niceMysticalDragon is just really nice
Send a message via AIM to MysticalDragon Send a message via MSN to MysticalDragon
Quote:
Originally Posted by Stowen View Post
How would I go about getting a list of all the players weapons?
PHP Code:
    for ( iplayer.weapons ) {
        if ( !
i.name.starts"-" ) ) {
          
temp.itemList.addi.name );
        }
      } 
Remove the "-" part if you want system NPCs to be included
__________________
~Delteria Support
~Playerworld Support
~PWA Chief
http://support.toonslab.com
[email protected]



Reply With Quote
  #33  
Old 12-15-2012, 11:24 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by MysticalDragon View Post
PHP Code:
    for ( iplayer.weapons ) {
        if ( !
i.name.starts"-" ) ) {
          
temp.itemList.addi.name );
        }
      } 
Remove the "-" part if you want system NPCs to be included
Ideally use temp.i instead of just i. I think variables used in for statements are always temporary, but it improves readability imo.
__________________
Reply With Quote
  #34  
Old 12-16-2012, 12:50 AM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is a jewel in the roughTricxta is a jewel in the rough
Quote:
Originally Posted by cbk1994 View Post
Ideally use temp.i instead of just i. I think variables used in for statements are always temporary, but it improves readability imo.
For stowen's benefit, might be worth mentioning that since the temp array is instantiated inside the for loop it'll be disposed of after the for loop ends so referencing it'll just refer to a null object, correct, no?
__________________
Quote:
Originally Posted by Crono View Post
No look at it, Stefan is totally trolling Thor. Calling Classic a "playerworld" (something it's not supposed to be) is the ultimate subtle insult to a true fan.

It's genius.
Reply With Quote
  #35  
Old 12-16-2012, 02:30 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Tricxta View Post
For stowen's benefit, might be worth mentioning that since the temp array is instantiated inside the for loop it'll be disposed of after the for loop ends so referencing it'll just refer to a null object, correct, no?
It's not disposed of after the loop ends. It will be disposed of at the end of the function, though.
__________________
Reply With Quote
  #36  
Old 12-16-2012, 05:27 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Quote:
Originally Posted by cbk1994 View Post
It's not disposed of after the loop ends. It will be disposed of at the end of the function, though.
Yeah, when I read that I was confused because I was under the impression it only terminated after the function. Other functions cannot read the variable tho right? like mid function you cannot call another function and try to read the variable?

I know temp. variables can be quite tricky to work with.
Reply With Quote
  #37  
Old 12-16-2012, 06:10 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by scriptless View Post
Yeah, when I read that I was confused because I was under the impression it only terminated after the function. Other functions cannot read the variable tho right? like mid function you cannot call another function and try to read the variable?

I know temp. variables can be quite tricky to work with.
Temporary variables aren't tricky to work with. In my experience, well over half of the variables you work with are temporary. They're only in scope in the current function, which is what makes them so useful.
__________________
Reply With Quote
  #38  
Old 12-16-2012, 11:20 PM
Stowen Stowen is offline
Graalian since '01
Join Date: Sep 2005
Location: Massachusets, USA
Posts: 156
Stowen will become famous soon enough
Send a message via AIM to Stowen Send a message via MSN to Stowen
Thanks guys, I had something very similar it just had an error on my part so it wasn't working.
Reply With Quote
  #39  
Old 12-16-2012, 11:25 PM
Stowen Stowen is offline
Graalian since '01
Join Date: Sep 2005
Location: Massachusets, USA
Posts: 156
Stowen will become famous soon enough
Send a message via AIM to Stowen Send a message via MSN to Stowen
In any case, now that I get a list of weapons, how would I go about detecting if a weapon gets added? Should I make a variable after onCreated that holds the info, and a timeout that keeps checking? I can script something that checks the weapons folder, and makes a list of all the weapons there. Then check the new weapons if its in the list, just disregard.
Reply With Quote
  #40  
Old 12-19-2012, 12:00 AM
Stowen Stowen is offline
Graalian since '01
Join Date: Sep 2005
Location: Massachusets, USA
Posts: 156
Stowen will become famous soon enough
Send a message via AIM to Stowen Send a message via MSN to Stowen
Okay, I was testing some stuff out. I changed the temps to this. and made a new function to create a seperate list. I tried this and it kept returning false:

PHP Code:
function CheckInventory() {
  if (
this.itemList == this.itemList2) {
    
player.chat "Check: Yes";
  }else 
player.chat "Check: No";

I also had them sent to me in a PM, both lists were the same. Why would it return they are not?
Reply With Quote
  #41  
Old 12-19-2012, 01:00 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Comparing arrays doesn't always work well. You can coerce them to strings for the comparison like so:

PHP Code:
if ((@ array1) == (@ array2)) { // this looks ugly, there is
                               // probably a better way to format this 
__________________
Reply With Quote
  #42  
Old 12-19-2012, 01:06 AM
Stowen Stowen is offline
Graalian since '01
Join Date: Sep 2005
Location: Massachusets, USA
Posts: 156
Stowen will become famous soon enough
Send a message via AIM to Stowen Send a message via MSN to Stowen
You mean like this?:

PHP Code:
if ((@ itemList) == (@ itemList2)) 
Reply With Quote
  #43  
Old 12-19-2012, 09:12 AM
Tim_Rocks Tim_Rocks is offline
a true gentlemen
Tim_Rocks's Avatar
Join Date: Aug 2008
Location: USA
Posts: 1,863
Tim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to behold
Quote:
Originally Posted by Stowen View Post
You mean like this?:

PHP Code:
if ((@ itemList) == (@ itemList2)) 
That's exactly what he wrote, you just have different variable names...
__________________
Reply With Quote
  #44  
Old 12-19-2012, 10:45 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Stowen View Post
You mean like this?:

PHP Code:
if ((@ itemList) == (@ itemList2)) 
Yes, but depending on what you're doing, remember that your lists will need to be in the same order for that to work. If you want to compare them without paying attention to order, you'll have to do a bit more work.
__________________
Reply With Quote
  #45  
Old 12-19-2012, 02:20 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Quote:
Originally Posted by Stowen View Post
You mean like this?:

PHP Code:
if ((@ itemList) == (@ itemList2)) 
since you have been using a this.variable, you might also want to add this. into your check

PHP Code:
if ((@ this.itemList) == (@ this.itemList2)) 
__________________
MEEP!
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 11:27 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.