Jump to content
  • 0

ARRAYS AGAIN -.-


iFoxkun

Question


  • Group:  Members
  • Topic Count:  24
  • Topics Per Day:  0.01
  • Content Count:  189
  • Reputation:   16
  • Joined:  11/20/11
  • Last Seen:  

I ask too much for help.... D: But its those stinking arrays :<

I can't seem to get the Angel Ears part to work, but the 25200 part works as well as the "none". Oh and even without the equip '24992' a player can still change his/her look. Help D:.


gm02,94,98,4 script Lower 793,{

if(isequipped(24992)) {
OnInit:
setarray .@lowerid[0],25200,25201,25202,25203,25204,25205,25206,25207,25208,25209,25210,25211,25212;
setarray .@lowername$[0],"Angel Ears","Emperor Shoulders","Gangster Scarf","Ice Cream","Little Devil Tail","Neko no Shippo","Saiyan Tail","Scarlet Angel Ears","Jirachi Rucksack","Angeling Rucksack","ArchAngeling Rucksack","Deviling Rucksack","Pokeball Rucksack";
for ( set .@i, 0; .@i < getarraysize(.@lowerid); set .@i, .@i +1 ) ;
for ( set .@i, 0; .@i < getarraysize(.@lowername$); set .@i, .@i +1 ) ;

// == Whisper
defpattern 1, "([^:]+):.*sNone(.*)", "iNone";
defpattern 1, "([^:]+):.*s"+.@lowerid[0]+"(.*)", "iAngelEars";
defpattern 1, "([^:]+):.*s"+.@lowername$[0]+"[.*)", "iAngelEars";
activatepset 1;
end;
// == Action
iNone:
setlook 3,0;
npctalk strcharinfo(0) + " has changed his Dyna Lower Look!";
end;
iAngelEars:
setlook 3,1700;
npctalk strcharinfo(0) + " has changed his Dyna Lower Look!";
end;
} else { end;}
}

Edited by iFoxkun
Link to comment
Share on other sites

10 answers to this question

Recommended Posts


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

for ( set .@i, 0; .@i < getarraysize(.@lowerid); set .@i, .@i +1 ) ;

for ( set .@i, 0; .@i < getarraysize(.@lowername$); set .@i, .@i +1 ) ;

LOL ? you do a Looping....but...loop nothing but ended it ? hmm ?

i doubt will that run fine for you upon loaded ? O.O

suppose to be something like this...

for ( set .@i, 0; .@i < getarraysize(.@lowerid); set .@i, .@i +1 ) {
   for ( set .@i, 0; .@i < getarraysize(.@lowername$); set .@i, .@i +1 ) ;{
        <<content go here>>
   }
}

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  24
  • Topics Per Day:  0.01
  • Content Count:  189
  • Reputation:   16
  • Joined:  11/20/11
  • Last Seen:  

for ( set .@i, 0; .@i < getarraysize(.@lowerid); set .@i, .@i +1 ) ;

for ( set .@i, 0; .@i < getarraysize(.@lowername$); set .@i, .@i +1 ) ;

LOL ? you do a Looping....but...loop nothing but ended it ? hmm ?

i doubt will that run fine for you upon loaded ? O.O

suppose to be something like this...

for ( set .@i, 0; .@i < getarraysize(.@lowerid); set .@i, .@i +1 ) {
for ( set .@i, 0; .@i < getarraysize(.@lowername$); set .@i, .@i +1 ) ;{
	 <<content go here>>
}
}

It ran fine actually, except the fact when I type 25200 || none it works, and Angel Ears doesn't I'll try this tomorrow I'm sleepy

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  23
  • Reputation:   3
  • Joined:  12/10/11
  • Last Seen:  

<p><p>Try This !! But I think What you want is If player have equiped 24992 they can change the look by saying id or name (in .@lowerid /.@lowername$) and his look will change to what he said right?

gm.txt

Ps. Why I can't use a codebox for this script

Edited by maker
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  130
  • Reputation:   43
  • Joined:  12/11/11
  • Last Seen:  

It could often help to do a flowchart and then pseudo-code when you do a NPC and then turn it, a step at a time, in to code:

1) What should the NPC do when ...

Clicked on? -> Nothing -> Put a close/end at the beginning

Spoken near? -> Register item ID or name and check if it matches a previously created pattern.

-> We need to make the arrays

-> We need to make the patterns (there's two ways to handle this, I'll get to that later on)

2) Pseudo-code

NPC header {
(We could if we wanted to, present the user with a list of items so he/she dont have to remember it)
close; (We do not want the user to click the NPC)
OnInit: (What do we need to do before using the NPC?)
1) Arrays for items
2) Regular expressions
end; (OnInit done)
Labels and code for the RegExp (Here we also want to check for the equipped item since the code starts reading from each label)
}

The arrays are correct for you, I don't see why you put in those two for-loops since they only iterate through the arrays without changing anything.

And if you want to have a loop inside another, you shouldn't use the same iteration variable for both (in this case .@i)

Regular Expressions, "defpatterns", works like this:

You give a pattern for a string to find, the parts that are inside round brackets will be set as a variable you can use! (We like this)

So you can make 1 expression for each item OR pass the name or ID said and check if those are inside the arrays. (More convenient with larger arrays)

Example of using names for the patterns: (I'm not showing how to manually make each pattern since everyone likes it dynamic, and also using a bit of lazy coding)

for(i=0; i < size(.@lowerid); i++){ //For each item (Both lists should be the same size)
defpattern 1, "([^:]+):s"+.@lowerid[ i ], getd("L"+.@lowerid[ i ]); //Make a pattern for the id pointing at the label L<id>
defpattern 1, "([^:]+):s"+.@lowername$[ i ], getd("L"+.@lowerid[ i ]); //Make a pattern for the name pointing at the label L<id>
}
activatepset 1; //Activate the patterns we did
end;

//This is where the code starts reading for the user when they say a certain string, you want to check their items equipped etc. after the appropriate label.
L25200:
code for item 25200
end;
L25201:
code for item 25201
end;
... and so on

Example of using general pattern for all:

defpattern 1, "([^:]+).*)", "CheckItem";
activatepset 1;
end;

CheckItem:
set .@name$, $@p2$; (If the player said the item name)
set .@id, atoi($@p2$); (If the player said the item ID)

Now you loop through the arrays looking for any of those two, if you find a result, then you can do what you need to, otherwise just end;

I'm not 100% sure that the patterns I used above are correct since I can't test them but they should give enough information for you to find the correct one from trial and error.

There are also a lot of examples in https://rathena.svn....le/npc_pcre.txt

I hope this all makes sense, otherwise just ask :D

Edited by plankt
  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  24
  • Topics Per Day:  0.01
  • Content Count:  189
  • Reputation:   16
  • Joined:  11/20/11
  • Last Seen:  

I'm so confused with the wall of text, xD. Could you just give me an example if it were going to change to 1 headgear?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  130
  • Reputation:   43
  • Joined:  12/11/11
  • Last Seen:  

Combining your NPC with the pseudo-code:


gm02,94,98,4 script Lower 793,{
close; //Prevent them from talking to the NPC

OnInit:

//Arrays
setarray .@lowerid[0],25200,25201,25202,25203,25204,25205,25206,25207,25208,25209,25210,25211,25212;
setarray .@lowername$[0],"Angel Ears","Emperor Shoulders","Gangster Scarf","Ice Cream","Little Devil Tail","Neko no Shippo","Saiyan Tail","Scarlet Angel Ears","Jirachi Rucksack","Angeling Rucksack","ArchAngeling Rucksack","Deviling Rucksack","Pokeball Rucksack";

//Regular expressions
defpattern 1, "([^:]+):.*sNone(.*)", "LNone";
for(set .@i,0; .@i < size(.@lowerid); set .@i, .@i+1){ //For each item
defpattern 1, "([^:]+):s"+.@lowerid[.@i], getd("L"+.@lowerid[.@i]); //Make a pattern for the id pointing at the label L<id>
defpattern 1, "([^:]+):s"+.@lowername$[.@i], getd("L"+.@lowerid[.@i]); //Make a pattern for the name pointing at the label L<id>
}
activatepset 1;

end; //Finished with OnInit

//Label for none
LNone:
if(!isequipped(24992)) end;
setlook 3,0;
npctalk strcharinfo(0) + " has changed his Dyna Lower Look!";
end;

//Label for item ID 25200, repeat for every item
L25200:
if(!isequipped(24992)) end; //Make sure they have the item equipped
setlook 3,1700;
npctalk strcharinfo(0) + " has changed his Dyna Lower Look!";
end;
}
[/codeBOX]

Not tested on a server so possible silly errors:

- Syntax error

- Wrong regexp

After some online testing, try these expressions out if the previous don't work:

[code]
([^:]+):.*None(.*) //For None
//For the item ID
defpattern 1, "([^:]+):.*"+.@lowerid[.@i], getd("L"+.@lowerid[.@i]);
//For the item name
defpattern 1, "([^:]+):.*"+.@lowername$[.@i], getd("L"+.@lowerid[.@i]);
[/code]

Edited by plankt
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  24
  • Topics Per Day:  0.01
  • Content Count:  189
  • Reputation:   16
  • Joined:  11/20/11
  • Last Seen:  


gm02,94,98,4 script Lower 793,{
close; //Prevent them from talking to the NPC

OnInit:

//Arrays
setarray .@lowerid[0],25200,25201,25202,25203,25204,25205,25206,25207,25208,25209,25210,25211,25212;
setarray .@lowername$[0],"Angel Ears","Emperor Shoulders","Gangster Scarf","Ice Cream","Little Devil Tail","Neko no Shippo","Saiyan Tail","Scarlet Angel Ears","Jirachi Rucksack","Angeling Rucksack","ArchAngeling Rucksack","Deviling Rucksack","Pokeball Rucksack";

//Regular expressions
defpattern 1, "([^:]+):.*sNone(.*)", "L_None";
for(set .@i,0; .@i < getarraysize(.@lowerid); set .@i, .@i+1);{
 defpattern 1, "([^:]+):s"+.@lowerid[.@i], getd("L_"+.@lowerid[.@i]); 
 defpattern 1, "([^:]+):s"+.@lowername$[.@i], getd("L_"+.@lowerid[.@i]); 
}
activatepset 1;

end; //Finished with OnInit

//Label for none
L_None:
 if(!isequipped(24992)) end;
 setlook 3,0;
 npctalk strcharinfo(0) + " has changed his Dyna Lower Look!";
end;

//Label for item ID 25200, repeat for every item
L_25200:
 if(!isequipped(24992)) end; //Make sure they have the item equipped
 setlook 3,1700;
 npctalk strcharinfo(0) + " has changed his Dyna Lower Look!";
end;
}

Gives me the error of:

"Data reference name= 'L_0' type=C_Name"

"Please report this !!!! - str_data.type=C_NOP"

"Function defpattern"

"Source (NPC): Lower at gm02 (94,98)

"script_rid2sd: fatal error! player not attached!"

"Data: number value=1"

"Data: string value="([^:]+):s""

"Data: variable name='L_0'"

"Source (NPC): Lower at gm02 (94,98)

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  23
  • Reputation:   3
  • Joined:  12/10/11
  • Last Seen:  

I have modified it a bit, let it's more easy to add item and also fix an error above.


gm02,94,98,4 script Lower 793,{
close; //Prevent them from talking to the NPC

OnInit:

//Arrays
setarray .lowerid[0],25200,25201,25202,25203,25204,25205,25206,25207,25208,25209,25210,25211,25212;
setarray .lowername$[0],"Angel Ears","Emperor Shoulders","Gangster Scarf","Ice Cream","Little Devil Tail","Neko no Shippo","Saiyan Tail","Scarlet Angel Ears","Jirachi Rucksack","Angeling Rucksack","ArchAngeling Rucksack","Deviling Rucksack","Pokeball Rucksack";

//Regular expressions
defpattern 1, "([^:]+):.*sNone(.*)", "L_None";
for(set .@i,0; .@i < getarraysize(.lowerid); set .@i, .@i+1) {
defpattern 1, "([^:]+):s"+.lowerid[.@i], "L_"+.@i;
defpattern 1, "([^:]+):s"+.lowername$[.@i], "L_"+.@i;
}
activatepset 1;

end; //Finished with OnInit

//Label for none
L_None:
if(!isequipped(24992)) end;
setlook 3,0;
npctalk strcharinfo(0) + " has changed his Dyna Lower Look!";
end;

//Label L_.@i ,repeat a label equal your item list (L_? == set .@view_change,?
L_0:
set .@view_change,0;
goto Change_Look;

L_1:
set .@view_change,1;
goto Change_Look;

L_2:
set .@view_change,2;
goto Change_Look;


Change_Look:
if(!isequipped(24992)) end; //Make sure they have the item equipped
setlook 3,getiteminfo(.lowerid[.@view_change],11); // Automaticly Call viewpoint of item that he said and setlook
npctalk strcharinfo(0) + " has changed his Dyna Lower Look!";
end;

}
[/codeBOX]

Edited by maker
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  24
  • Topics Per Day:  0.01
  • Content Count:  189
  • Reputation:   16
  • Joined:  11/20/11
  • Last Seen:  

I have modified it a bit, let it's more easy to add item and also fix an error above.


gm02,94,98,4 script Lower 793,{
close; //Prevent them from talking to the NPC

OnInit:

//Arrays
setarray .lowerid[0],25200,25201,25202,25203,25204,25205,25206,25207,25208,25209,25210,25211,25212;
setarray .lowername$[0],"Angel Ears","Emperor Shoulders","Gangster Scarf","Ice Cream","Little Devil Tail","Neko no Shippo","Saiyan Tail","Scarlet Angel Ears","Jirachi Rucksack","Angeling Rucksack","ArchAngeling Rucksack","Deviling Rucksack","Pokeball Rucksack";

//Regular expressions
defpattern 1, "([^:]+):.*sNone(.*)", "L_None";
for(set .@i,0; .@i < getarraysize(.lowerid); set .@i, .@i+1) {
defpattern 1, "([^:]+):s"+.lowerid[.@i], "L_"+.@i;
defpattern 1, "([^:]+):s"+.lowername$[.@i], "L_"+.@i;
}
activatepset 1;

end; //Finished with OnInit

//Label for none
L_None:
if(!isequipped(24992)) end;
setlook 3,0;
npctalk strcharinfo(0) + " has changed his Dyna Lower Look!";
end;

//Label L_.@i ,repeat a label equal your item list (L_? == set .@view_change,?
L_0:
set .@view_change,0;
goto Change_Look;

L_1:
set .@view_change,1;
goto Change_Look;

L_2:
set .@view_change,2;
goto Change_Look;


Change_Look:
if(!isequipped(24992)) end; //Make sure they have the item equipped
setlook 3,getiteminfo(.lowerid[.@view_change],11); // Automaticly Call viewpoint of item that he said and setlook
npctalk strcharinfo(0) + " has changed his Dyna Lower Look!";
end;

}
[/codeBOX]

OOOHH <333 It works ~ Less confusing xP. One problem, when I say "none" it doesnt activate D: Also could you make it onwhisperglobal? ;D

Edited by iFoxkun
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  23
  • Reputation:   3
  • Joined:  12/10/11
  • Last Seen:  

 gm02,94,98,4	script	Lower	793,{ 
close; //Prevent them from talking to the NPC

OnInit:

//Arrays
setarray .lowerid[0],25200,25201,25202,25203,25204,25205,25206,25207,25208,25209,25210,25211,25212;
setarray .lowername$[0],"Angel Ears","Emperor Shoulders","Gangster Scarf","Ice Cream","Little Devil Tail","Neko no Shippo","Saiyan Tail","Scarlet Angel Ears","Jirachi Rucksack","Angeling Rucksack","ArchAngeling Rucksack","Deviling Rucksack","Pokeball Rucksack";

//Regular expressions
defpattern 1, "([^:]+):.*sNone(.*)", "L_None";
for(set .@i,0; .@i < getarraysize(.lowerid); set .@i, .@i+1) {
defpattern 1, "([^:]+):s"+.lowerid[.@i], "L_"+.@i;
defpattern 1, "([^:]+):s"+.lowername$[.@i], "L_"+.@i;
}
activatepset 1;

end; //Finished with OnInit

//Label for none
L_None:
if(!isequipped(24992)) end;
setlook 3,0;
npctalk strcharinfo(0) + " has changed his Dyna Lower Look!";
end;

//Label L_.@i ,repeat a label equal your item list (L_? == set .@view_change,?
L_0:
set .@view_change,0;
goto Change_Look;

L_1:
set .@view_change,1;
goto Change_Look;

L_2:
set .@view_change,2;
goto Change_Look;


Change_Look:
if(!isequipped(24992)) end; //Make sure they have the item equipped
setlook 3,getiteminfo(.lowerid[.@view_change],11); // Call viewpoint of item and setlook
npctalk strcharinfo(0) + " has changed his Dyna Lower Look!";
end;

OnWhisperGlobal:
if(!isequipped(24992)) end;
if((@whispervar0$ == "None") setlook 3,0;
for(set .@i,0; set .@i,getarraysize(.lowerid); set .@i,.@i+1) {
set .@lower_id$,.lowerid[.@i]; // Invert Number to String
if(@whispervar0$ == .@lower_id$ || @whispervar0$ == .lowername$[.@i]) {
setlook 3,getiteminfo(.lowerid[.@i],11);
end;
}
}

}[/codeBOX]

I try None and it's work . pls check did you equip 24992 before say None and then I also add Onwhisperglobal label to it But I haven't try it yet so I'm not really sure is the whisperglobal label work properly.

Edited by maker
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...