Savant Posted October 31, 2008 Author Share Posted October 31, 2008 I am just beginning to script, and have been looking through the forums, but I can't seem to figure out how to perform AOE through Sadscript. I know there is an AOE option through the Spell Editor, but I'd like to script some more involved effects. I have some programming experience (mostly Java), so I'm just trying to get more comfortable with the syntax and the various functions and subs available. Is there a way I can somehow iterate through all of the players and NPCs on a map? Something like a "for loop" in Java, but getting the number of players and NPCs on the map and then go through each one to see if they are within range for the effect (I think I can handle the "within range" part). I'm not sure if looping is possible in Sadscript. Also, I noticed that there is a "GetPlayersOnMap" function. Is that a way to get the number of players on the map, so I could iterate through each one in a loop? Is there a similar function for NPCs. Sorry for all the questions. Thanks! Link to comment Share on other sites More sharing options...
Godlord Posted October 31, 2008 Share Posted October 31, 2008 @Savant:> I am just beginning to script, and have been looking through the forums, but I can't seem to figure out how to perform AOE through Sadscript. I know there is an AOE option through the Spell Editor, but I'd like to script some more involved effects. > > I have some programming experience (mostly Java), so I'm just trying to get more comfortable with the syntax and the various functions and subs available. Is there a way I can somehow iterate through all of the players and NPCs on a map? Something like a "for loop" in Java, but getting the number of players and NPCs on the map and then go through each one to see if they are within range for the effect (I think I can handle the "within range" part). > > I'm not sure if looping is possible in Sadscript. Also, I noticed that there is a "GetPlayersOnMap" function. Is that a way to get the number of players on the map, so I could iterate through each one in a loop? Is there a similar function for NPCs. > > Sorry for all the questions. Thanks!Check the Sadscript Tutorial section and the EE 2.7.304 command reference, at the Sadscript section.Regards, Goddianicus. Link to comment Share on other sites More sharing options...
Savant Posted October 31, 2008 Author Share Posted October 31, 2008 I need a little more guidance, please. I think I can use a Do While loop to iterate (and just decrement/increment within the loop until I've checked through every possible target), but I'm still not sure about getting the number of players and number of NPCs in a map. The Sadscript command reference lists all of the functions and subs, but without good explanations for all of those in the list, it's a bit difficult to decipher. Link to comment Share on other sites More sharing options...
Godlord Posted October 31, 2008 Share Posted October 31, 2008 @Savant:> I need a little more guidance, please. I think I can use a Do While loop to iterate (and just decrement/increment within the loop until I've checked through every possible target), but I'm still not sure about getting the number of players and number of NPCs in a map. The Sadscript command reference lists all of the functions and subs, but without good explanations for all of those in the list, it's a bit difficult to decipher.The function names speak for themselves.Regards, Goddianicus. Link to comment Share on other sites More sharing options...
Savant Posted October 31, 2008 Author Share Posted October 31, 2008 Anyone else have something a little more helpful? Thanks. Link to comment Share on other sites More sharing options...
DarkMazer Posted October 31, 2008 Share Posted October 31, 2008 There is a For loop in SadScript; the syntax is:```For variable = num1 To num2 'bodyNext```Some things to note, though, are that it only increments by 1 (that shouldn't be a problem in this case, though), and that the words I capitalized there are keywords. GetMaxPlayers() returns how many players can log in to the game, GetPlayersOnMap(Map#) returns how many players are on a map, and the maximum number of NPCs on a map is 15 (at least in EE 2.7). You may also want to know that GetPlayerX(index) and GetPlayerY(index) return the X and Y coordinates of a player, respectively, and that GetNpcX(map#, npcindex) and GetNpcY(map#, npcindex) return an NPC's X and Y coordinates. Those will help if you want to limit range. Also, knowing how to find certain commands on the command list really helps. Link to comment Share on other sites More sharing options...
Savant Posted October 31, 2008 Author Share Posted October 31, 2008 Thanks so much for the tips! So I guess the only way to do it is to iterate through all the possible players and NPCs, correct? I was hoping there was some way to narrow it down a bit, since I worry it would be a bit cumbersome and slow the server down, but maybe it will be fine. Not like there will be tons of players online. Another question: If I use GetPlayersOnMap() to get the number of players on the map and iterate through that, are those indexes going to correspond to the indexes of the actual players? I'm wondering if the "Index"/"index" that is used to reference players in scripts is a "server-wide" index, and the GetPlayersOnMap() command doesn't correspond. For example, there maybe 5 players on a certain map, but their "Indexes" are like 8-12 or something. Also, for NPCs, should I just go up to 15? Are those indexes not going to correspond either? EDIT: Okay, so for players, it looks like I can iterate from 0 to Get_Max_Players() and use IsPlaying() first before I try checking for a player's map and coordinates. Still trying to work through cycling through NPCs…Thanks again. I just need to talk this through with people. Link to comment Share on other sites More sharing options...
Godlord Posted October 31, 2008 Share Posted October 31, 2008 @Savant:> Anyone else have something a little more helpful? Thanks.It would be helpful if you learnt how to read and search yourself IMO.Regards, Goddianicus. Link to comment Share on other sites More sharing options...
Savant Posted October 31, 2008 Author Share Posted October 31, 2008 Goddianicus, your responses on this thread have done little beyond irking me and padding your post count. The purpose of this forum is to ask questions and appeal to the community for help in working through scripting problems. I am not asking for someone to script something for me; I am asking for help in overcoming a roadblock that I have encountered after doing my own research and experimentation. I'd appreciate if your subsequent responses on this thread are actually productive, rather than condescending.Thanks! Link to comment Share on other sites More sharing options...
Marsh Posted November 1, 2008 Share Posted November 1, 2008 Godlord, though im sure you are trying to help people go through the sections that are already available. I have received many reports about your posting and not just in this thread. Your responses aren't exactly helpful. You have the right idea but are going about it the wrong way. Your above comments dont answer the question. The function names may be clear enough to you, but other people may not realize how, especially when they are new. Try making posts that have more to do with the subject instead of just saying read this or read that, your first post here was a good response. I know you have a great many helpful posts on this forum. Just because you understand it so well doesn't mean they will. remember you don't always have to respond. Link to comment Share on other sites More sharing options...
Godlord Posted November 1, 2008 Share Posted November 1, 2008 @Marsh:> Godlord, though im sure you are trying to help people go through the sections that are already available. I have received many reports about your posting and not just in this thread. Your responses aren't exactly helpful. You have the right idea but are going about it the wrong way. Your above comments dont answer the question. The function names may be clear enough to you, but other people may not realize how, especially when they are new. Try making posts that have more to do with the subject instead of just saying read this or read that, your first post here was a good response. I know you have a great many helpful posts on this forum. Just because you understand it so well doesn't mean they will. remember you don't always have to respond.You know what, I can better stop even writing tutorials and everything, people don't bother reading them, they aren't even thankful.> Try making posts that have more to do with the subject instead of just saying read this or read that.If you've to do that for every topic, you would be wasting database space, time and even then you're just copying something you or somebody else wrote already in a topic. If you want to develop a game, then don't be lazy and learn to read, that's a very important thing to do.Regards, Goddianicus. Link to comment Share on other sites More sharing options...
codemeister1990 Posted November 1, 2008 Share Posted November 1, 2008 I read your tutorials, they should've been more descriptive, you lost meyou didn't explain what longs are, yet you used them in the tutorialetc etc Link to comment Share on other sites More sharing options...
Marsh Posted November 1, 2008 Share Posted November 1, 2008 I know most people don't read and they should. But its impossible to change that. But he said that he already looked at the tutorial and didn't understand it.Also his tutorials are based off of previous programming knowledge. I would just assume everyone knew what a long was. Link to comment Share on other sites More sharing options...
codemeister1990 Posted November 1, 2008 Share Posted November 1, 2008 then it shouldn't be labelled as beginner tutorialsyou should assume I'm completely knew to the subject, that I know absolutely NOTHING about programming, because I pretty much don'tsure I learned about variables from algebra, and I've picked up some basic understanding from ruby (rmxp/vx), but that's it, and some people don't even know that Link to comment Share on other sites More sharing options...
Godlord Posted November 1, 2008 Share Posted November 1, 2008 @codemeister1990:> I read your tutorials, they should've been more descriptive, you lost me> you didn't explain what longs are, yet you used them in the tutorial> etc etcI'm trying to rewrite the tutorials when I've the time as they were written in the reply box which means I could've forgotten to mention some things. They were very useful a long time ago as there weren't much tutorials on Eclipse back then.But they also, as Marsh stated, rely the knowledge you should have. I would mainly explain currency if I ever used it, but not long, as again you use long a lot more than you use currency (or long long [C/C++], 64-bit integer) and it's a 32-bit integer or just an integer (on 32-bit processors).> I know most people don't read and they should. But its impossible to change that. But he said that he already looked at the tutorial and didn't understand it.Weird, he said he had experience with Java…@codemeister1990:> then it shouldn't be labelled as beginner tutorials> you should assume I'm completely knew to the subject, that I know absolutely NOTHING about programming, because I pretty much don't> sure I learned about variables from algebra, and I've picked up some basic understanding from ruby (rmxp/vx), but that's it, and some people don't even know thatThey aren't, except for Sadscript: the Beginning, which is a code sample overview meant to be studied actually and which is very outdated.Regards, Goddianicus. Link to comment Share on other sites More sharing options...
DarkMazer Posted November 1, 2008 Share Posted November 1, 2008 Whoa, back on topic. @Savant:> Thanks so much for the tips! So I guess the only way to do it is to iterate through all the possible players and NPCs, correct?…> > Also, for NPCs, should I just go up to 15? Are those indexes not going to correspond either? > > EDIT: Okay, so for players, it looks like I can iterate from 0 to Get_Max_Players() and use IsPlaying() first before I try checking for a player's map and coordinates. Still trying to work through cycling through NPCs...> > Thanks again. I just need to talk this through with people.Yes, iterating through all players is the only way to do it. The main use of GetPlayersOnMap in this case is that, if all of the players on the map are found before you're done iterating through the loop, you can abort early and save yourself some processing time. However, it's not necessary, especially if the server's being run on a fast computer. If there's a large cap on the number of maximum players, and the server computer isn't overly fast, it may be worth considering, though. How you would do that is add another variable and have that variable count how many players you have located on the map so far, and check to see if that number equals the number of players on the map. It might be easier to use a Do While loop in that case, so you can check that at the same time you check if your index is less than the maximum number of players. For the NPCs, I believe all you have to do is run through NPC numbers 1 through 15 and check if they exist (you can use GetMapNpcNum(map#, NPCindex) for that), then do what's necessary with them. I think it would be prudent to use GetMapNpcHP(map#, NPCindex) to make sure the NPC's not dead first, as well. As for the correspondence issue, NPC indexes are unique to each map, so NPC#1 on map 13 is different from NPC#1 on map 56. In other words, don't worry. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now