Graal Forums  

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

Closed Thread
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-20-2005, 09:10 PM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
for

I basically know how to use the new for function but I have a question.


It's supposed to replace the with command but I am not sure exactly how one is supposed to actually do a function with it, though setting variables i an do.

I think it is something like this:
NPC Code:

for (pl: players) {
pl.setlevel2(level,x,y);

}


But I am not sure if that's right. I ahve been trying it like that but my results are inconclusive, can someone tell me if this is right, and if not, the proper way to do it?
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
  #2  
Old 02-20-2005, 09:17 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
I'll give you some examples, hopefully this helps:

NPC Code:

with (findnpc("NPC Name"))
with (allplayers[i])



NPC Code:

for (item: clientr.item)
for (i=0; i<allplayerscount; i++)



NPC Code:

setlevel2(level,x,y);
player.setlevel2(level,x,y);




I believe these are all the player-level manipulations you can do:

player.level - object, read only
player.x - floating point value
player.y - floating point value
player.z - floating point value

Last edited by Gambet; 02-20-2005 at 09:41 PM..
  #3  
Old 02-20-2005, 09:30 PM
Evil_Trunks Evil_Trunks is offline
Evil
Evil_Trunks's Avatar
Join Date: Dec 2004
Posts: 391
Evil_Trunks is on a distinguished road
Quote:
Originally Posted by falco10291029
I basically know how to use the new for function but I have a question.


It's supposed to replace the with command but I am not sure exactly how one is supposed to actually do a function with it, though setting variables i an do.

I think it is something like this:
NPC Code:

for (pl: players) {
pl.setlevel2(level,x,y);

}


But I am not sure if that's right. I ahve been trying it like that but my results are inconclusive, can someone tell me if this is right, and if not, the proper way to do it?
don't even bother reading Gambet's post, it's not helpful at all

you have it correct, you prefix the command/variable with the player's object

by default it uses player so these two commands are equal
NPC Code:
setlevel2(level,x,y);
player.setlevel2(level,x,y);



if you want to get a variable of another player, i think you should be able to figure it out, you have it correct in your example, but here's an example of getting a player's object then using it

NPC Code:
pobj = findplayer("Evil_Trunks");
pobj.hp = pobj.maxhp;
pobj.setlevel2(player.level,player.x,player.y);



it would heal Evil_Trunks to max hp, then bring him to wherever the active player is

in your example, you are getting each item of the "players" array, which contains an object for each player in the level
__________________

  #4  
Old 02-20-2005, 09:35 PM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
Thank you Evil_trunks for your help, Good to know I'm doing something right . And Also thanks for the examples of having it do something based on two players, I can now finmd my scripts that use multiple with or fors and the variable thiso.work and thiso.level=h.nw ect ect .
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
  #5  
Old 02-20-2005, 09:35 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Actually, my post is helpful. I didnt give him the script myself, instead I showed some examples on how to use each of those commands correctly. He should be able to do the rest from there. Its the best way of learning, by viewing examples, instead of just scripting things for the person.
  #6  
Old 02-20-2005, 09:44 PM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
Not really, your post said I was wrong and that I should use with and the old for command. Also Evil_trunks did give me examples by showing the prefix commands and the example of setting another player's values through a different ones. Also i now know from that that IU dont need to use for in an instance like:

NPC Code:


for(pl: this.player) {
pl.client.string-=5000000;
}

__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
  #7  
Old 02-20-2005, 09:48 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
I didnt say your post was wrong. I was giving examples on how to use the with, for, and setlevel commands with the new engine. You shouldve picked up from there. If I needed to further elaborate, then I'm sorry. But Evil pretty much summed it all up.
  #8  
Old 02-20-2005, 09:50 PM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
Well I didnt need wioth examples i'm fine with that command You may have misread my only question was if I used that for command correctly and from your post it seemed like you were saying that it was only usable with the values you supplied.
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
  #9  
Old 02-20-2005, 09:52 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Ah, my mistake then.
  #10  
Old 02-21-2005, 01:25 AM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by falco10291029
It's supposed to replace the with command
It does not replace the with command, and it is called a for-each loop.

PHP Code:
for(ab) {
  
// Code

What it really does it cycle through an array, and set the value of b with the next index to a.

It is essentially the same as:
PHP Code:
for(i=0;i<b.size();i++) {
  
b[i];

  
// Code

__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
  #11  
Old 02-21-2005, 02:41 AM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
Actually the for-each command can replace with, and the for loop cant without using with, so yes i believe it can, plus stefan said himself that it's meant to.
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
  #12  
Old 02-21-2005, 02:43 AM
Lance Lance is offline
dark overlord
Lance's Avatar
Join Date: Sep 2003
Location: Space Jam Mountain
Posts: 5,072
Lance is on a distinguished road
Quote:
Originally Posted by falco10291029
Actually the for-each command can replace with, and the for loop cant without using with, so yes i believe it can, plus stefan said himself that it's meant to.
Hint: It's not the foreach part that replaces the with. It's that line where you are accessing functions/variables of the player object.
  #13  
Old 02-21-2005, 02:59 AM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
yes I suppose it actually replaces for with combo if you need to use for-each.

What i mean by this is:

NPC Code:

for (pl: allplayers) {
if (pl.client.hp>1000) {
pl.chat="I am Hacking!";
sendtorc(pl.account @ "is Hacking");//I think i did that part right, not entirely sure though
}
}


replaces:
NPC Code:

for (i=0;i<allplayerscount;i++) {
with(allplayers[i]) {
if (strtofloat(#s(client.hp))>1000) {
setplayerprop#c, I am hacking!;
sendtorc #a is hacking!;
}
}
}

__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!

Last edited by falco10291029; 02-21-2005 at 03:10 AM..
  #14  
Old 02-21-2005, 05:22 AM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by falco10291029
Actually the for-each command can replace with, and the for loop cant without using with, so yes i believe it can, plus stefan said himself that it's meant to.
It doesn't replace with, if it did, this would work:

PHP Code:
for(plallplayers) {
  
client.test "blah";

but it doesn't.

you still have to do:

PHP Code:
for(plallplayers) {
  
with(findPlayer(pl.account)) {
    
client.test "blah";
  }


You can also just aswell do:

PHP Code:
allplayers[index].account 
no need for a foreach loop at all.
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
  #15  
Old 02-21-2005, 06:05 AM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
NPC Code:

for(pl: allplayers) {

pl.client.test = "blah";
}


like that, no with.
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
  #16  
Old 02-21-2005, 02:30 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by falco10291029
NPC Code:

for(pl: allplayers) {

pl.client.test = "blah";
}


like that, no with.
exactly, you have to access the object directly, if it was a substitute for 'with', you would just have to do client.test = "blah";
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
  #17  
Old 02-22-2005, 01:19 AM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
Well then the prefix of pl or whatever then acts as a replacement for with.
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
  #18  
Old 02-22-2005, 02:14 AM
Lance Lance is offline
dark overlord
Lance's Avatar
Join Date: Sep 2003
Location: Space Jam Mountain
Posts: 5,072
Lance is on a distinguished road
Quote:
Originally Posted by falco10291029
Well then the prefix of pl or whatever then acts as a replacement for with.
Yes.
  #19  
Old 02-22-2005, 03:04 AM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by falco10291029
Well then the prefix of pl or whatever then acts as a replacement for with.
That is so redundant.

with() is what you use so you don't have to use the prefix.
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
  #20  
Old 02-22-2005, 03:09 AM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
Quote:
Originally Posted by ApothiX
That is so redundant.

with() is what you use so you don't have to use the prefix.
I personally find it easier to use the prefix.
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
  #21  
Old 02-22-2005, 05:17 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
The "with" command is kinda changing the environment - by default variables and functions without prefix are either mapped onto the current npc or the current player. With "with" you can change the current npc or current player, so that functions without prefix are mapped onto other objects, in old scripting engine this was the only way to warp another player because "setlevel2" is always warping the "current" player.
Only a few variables were accessible with prefix (players[index].x etc.) in the old engine. In the new engine everything is accessible directly, so you can access numeric attributes like "x" or "y", string attributes like "account" or "nick", built-in functions like "setlevel2" or "setani" or even script functions of other objects, e.g. StatsDatabase.addStatsForPlayer(player), if you declare a function as "public function".
So the with-command is not really needed anymore, but often very useful if you want to do a lot of operations on an object, also it can sometimes be faster, although some script optimizations are disabled inside with-blocks (because the lookup of this. numeric variables is changed, this is different to old scripting engine).
  #22  
Old 02-22-2005, 02:58 PM
Python523 Python523 is offline
Banned
Join Date: Aug 2001
Location: Illinois
Posts: 3,498
Python523 is on a distinguished road
Quote:
Originally Posted by falco10291029
Well then the prefix of pl or whatever then acts as a replacement for with.
My. God. Learn to think like a computer scientist. It does not "replace" with.

allplayers is an object of some sort that acts as an array of all of the players online. By using the foreach syntax of with, you are merely just cycling through every element of that object array and setting each instance at a specific point in time to a specific player. There is no REPLACING. It is just another method to do it.
  #23  
Old 02-22-2005, 10:28 PM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
Quote:
Originally Posted by Python523
My. God. Learn to think like a computer scientist. It does not "replace" with.

allplayers is an object of some sort that acts as an array of all of the players online. By using the foreach syntax of with, you are merely just cycling through every element of that object array and setting each instance at a specific point in time to a specific player. There is no REPLACING. It is just another method to do it.
My. God. Learn to read. I said it acts as a replacement, not that it actually is one. I am aware that it is only an alternative, and that the with command still works.

By acting as a replacement (For those of you who don't know english, acting as means purposely having similar traits of such, but not actually being it) it means that you can use it as one, though it isn't necessary. Thank you for taking my post and messing it up with your *****ic "thinking". No, really.
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
  #24  
Old 02-22-2005, 11:11 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by falco10291029
My. God. Learn to read. I said it acts as a replacement, not that it actually is one. I am aware that it is only an alternative, and that the with command still works.

By acting as a replacement (For those of you who don't know english, acting as means purposely having similar traits of such, but not actually being it) it means that you can use it as one, though it isn't necessary. Thank you for taking my post and messing it up with your *****ic "thinking". No, really.
My. God. Learn GScript. It is NOT replacing with at all. The default way to do it is with prefixes, therefor, with is what is doing the replacing. It is like internet-shorthand, you don't replace 'u' with 'you', you replace 'you' with 'u'.
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
  #25  
Old 02-22-2005, 11:13 PM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
Quote:
Originally Posted by Apothix
My. God. Learn GScript. It is NOT replacing with at all. The default way to do it is with prefixes, therefor, with is what is doing the replacing. It is like internet-shorthand, you don't replace 'u' with 'you', you replace 'you' with 'u'.
Holy crap did you even read my post? Obviously not and I'll leave you to figure out why you couldn't possibly have by looking at your post and mine just before it. (Hint: look at the bold part)
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
  #26  
Old 02-22-2005, 11:14 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by falco10291029
Holy crap did you even read my post? Obviously not and I'll leave you to figure out why you couldn't possibly have by looking at your post and mine just before it. (Hint: look at the bold part)
Obviously I read your post if I was explaining how you were wrong about stating that prefixes are the replacement.

Think before you post.
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
  #27  
Old 02-22-2005, 11:18 PM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
Quote:
Originally Posted by Apothix
Obviously I read your post if I was explaining how you were wrong about stating that prefixes are the replacement.

Think before you post.
I find this funny. You'll note that my post says that i know it isn't.

Think.
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
  #28  
Old 02-22-2005, 11:57 PM
Lance Lance is offline
dark overlord
Lance's Avatar
Join Date: Sep 2003
Location: Space Jam Mountain
Posts: 5,072
Lance is on a distinguished road
Quote:
Originally Posted by Python523
My. God. Learn to think like a computer scientist. It does not "replace" with.

allplayers is an object of some sort that acts as an array of all of the players online. By using the foreach syntax of with, you are merely just cycling through every element of that object array and setting each instance at a specific point in time to a specific player. There is no REPLACING. It is just another method to do it.
I can tell that your 'It' is referring to the foreach loop. We've kinda already established that part.

Quote:
Originally Posted by ApothiX
My. God. Learn GScript. It is NOT replacing with at all.
It looks like your 'It' is referring to the new method of accessing object properties. If so, your statement is incorrect.

Quote:
The default way to do it is with prefixes, therefor, with is what is doing the replacing.
'Default'? Another vague 'it'?

Quote:
It is like internet-shorthand, you don't replace 'u' with 'you', you replace 'you' with 'u'.
What? Do you not understand the definition of the word 'replace'? Your vague and inconsistent explanations and examples would seem to suggest so.

Last edited by Lance; 02-23-2005 at 12:08 AM..
  #29  
Old 02-23-2005, 12:56 AM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by falco10291029
I find this funny. You'll note that my post says that i know it isn't.

Think.
Show me where it says this?
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
  #30  
Old 02-23-2005, 02:22 AM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
Here:
Quote:
I am aware that it is only an alternative, and that the with command still works.
and also here:
Quote:
By acting as a replacement ... it means that you can use it as one, though it isn't necessary.
Again, read.
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
  #31  
Old 02-23-2005, 04:10 AM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by falco10291029
Here:

and also here:

Again, read.
You are still calling it a replacement, which it is not
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
  #32  
Old 02-23-2005, 04:43 AM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
Quote:
Originally Posted by ApothiX
You are still calling it a replacement, which it is not
How am i calling it a replacement? I specificallyt am saying that it isn't and that it is merely an alternative.
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
  #33  
Old 02-23-2005, 02:35 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by falco10291029
How am i calling it a replacement? I specificallyt am saying that it isn't and that it is merely an alternative.
Oh, I don't know.. Perhaps it was the whitty-as-hell definition you gave
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
  #34  
Old 02-23-2005, 02:51 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
WHO cares if it is a replacement or an alternative. You can do things with prefixes that before where only possible with the with command.
Closed Thread


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 01:46 PM.


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