View unanswered posts | View active topics
|
Page 1 of 1
|
[ 12 posts ] |
|
| Author |
Message |
|
MontuZ
|
Post subject: Removing a string from a string? Posted: Wed Mar 08, 2006 7:54 am |
|
 |
| Distro Developer |
 |
Joined: Fri Feb 10, 2006 8:08 am Posts: 314 Location: Myrtle Beach, South Carolina
|
Didn't know what to put for subject.
Syntax: .w OR .whisper <PlayerName> <message>
The cmd below works.
But <PlayerName> must be CaSE sensitive in order to find that person and to remove it from the original message. Is there anyway past that? Or another method, with the same syntax?
I've tried lower(text), lower(player.name), but then I start having issues with removing the persons name they're trying to whisper from the string.
Code: Use uo; Use os; Use util;
Program TextCMD_Whisper( Who, Text )
Var xText := Text; Var xHandle; If( !xText ) SendSysMessage( Who, "Syntax: .w OR .whisper <PlayerName> <message> - PlayerName is CaSE sensitive." ); Return 0; Endif Foreach Player in EnumerateOnlineCharacters() If( xText[Player.name] ) xHandle := Player; Break; Endif Endforeach
If( !xHandle ) SendSysMessage( Who, "Couldn't find that person." ); SendSysMessage( Who, "Syntax: .w <PlayerName> <message> - PlayerName is CaSE sensitive." ); Return 0; Else xText := ( xText - xHandle.name ); // Remove the players name from the string. SendSysMessage( Who, "<To: " + xHandle.name + ">" + xText ); SendSysMessage( xHandle, "<From: " + Who.name + ">" + xText ); Endif
Endprogram
|
|
| Top |
|
 |
|
Beaud
|
Post subject: Posted: Wed Mar 08, 2006 10:11 am |
|
Joined: Tue Feb 14, 2006 2:06 pm Posts: 41 Location: Québec, Canada
|
|
You might use Splitwords but if your character has 2 words in his name ex.: Ebon Twighlight, then Twighlight will be part of your message. Thats the problem, you can't really find out if splitwords[2] is part of the name or not. Suddently I have an idea, you might check if Splitwords[1] exist then you check for splitwords[1] + " " + splitwords[2] and maybe splitwords[3]. You message what left of the string.
_________________
|
|
| Top |
|
 |
|
Firedancer
|
Post subject: Re: Removing a string from a string? Posted: Wed Mar 08, 2006 12:40 pm |
|
Joined: Fri Feb 03, 2006 6:32 am Posts: 104 Location: Austria
|
maybe try this:
Code: Use uo; Use os; Use util;
Program TextCMD_Whisper( Who, Text )
If( !Text ) SendSysMessage( Who, "Syntax: .w OR .whisper <PlayerName> <message> - PlayerName is NOT CaSE sensitive." ); Return 0; Endif var victim; Foreach Player in (EnumerateOnlineCharacters()) If( lower(Text)[lower(Player.name)] ) victim := Player; //so now we found him... Break; Endif Endforeach
If( !victim) SendSysMessage( Who, "Couldn't find that person." ); SendSysMessage( Who, "Syntax: .w <PlayerName> <message> - PlayerName is NOT CaSE sensitive." ); Return 0; Else // we found the player... gotta get the name out: // that might work... //lower(Text([lower(victim.name)]:=""; // damn... won't work.... // it would remove the name allright... but at some disadvantage // it's all the message lowercase then ... so maybe try that: // --> I'm asuming that the name always is the first part of 'Text' // no matter how many spaces there's in the name.... var namelength:=len(victim.name); //how long name is the name? Text:=Text[namelength, len(Text)-namelength]; //grab later half // so we now have the length of the name, and accordingly // we've cut away that half from the text. // now there's just one problem left.... there may be blanks // in the beginning of the text... filter them out.... while(Text[1]==" ") Text[1]:=""; //replace space with empty string endwhile // that should have done it... send it SendSysMessage( Who, "<To: " + victim.name + ">" + Text); SendSysMessage( xHandle, "<From: " + Who.name + ">" + Text ); Endif
Endprogram
hope that works  , basically it should but there may be typos as I got no compiler installed on this pc here (and your capital letters in variable names were a little anoying to me hehe)
|
|
| Top |
|
 |
|
Zacharias
|
Post subject: Posted: Wed Mar 08, 2006 1:26 pm |
|
Joined: Wed Mar 08, 2006 7:30 am Posts: 16
|
Another way (what "beaud" ment):
Code: text := SplitWords(text); var player; var i := 0; var maxcount; var realplayer; Foreach Player in (EnumerateOnlineCharacters()) i := 0; var player := SplitWords(Player.name); while (lower(player[i]) == lower(text[i])) if (i > maxcount) // Check if there is a name which does still fit better if (!player[(maxcount+1)]) // Check if real name is longer than searched name maxcount = i; realplayer = Player.serial; endif endif i = i+1; endwhile Endforeach
if (maxcount) i = (maxcount + 1); var strippedtext; while (text[i]) strippedtext := strippedtext." ".text[i]; endwhile SendSysMessage(realplayer, strippedtext); else SendSysMessage(who, "Player is not online"); endif
Advantage: The correct player will be choosen, if names have equal parts.e.g. there are: Max Mustermann and Max Mustermann the Second if you type ".w Max Mustermann Hello, how are you?" the other programs maybe send the Message to "Max Mustermann the Second", depending on their rank in the EnumerateOnlineChars-list, because they see just the fitting of "Max Mustermann" in his name. Or is the list sorted? btw: didn't compile my code. It could have mistakes, but I think you get my idear?[/code]
|
|
| Top |
|
 |
|
MontuZ
|
Post subject: Posted: Wed Mar 08, 2006 2:19 pm |
|
 |
| Distro Developer |
 |
Joined: Fri Feb 10, 2006 8:08 am Posts: 314 Location: Myrtle Beach, South Carolina
|
Firedancers worked. but always grabbed 1 letter in from their name and put it in front of the message.
Action:
.w Jonothan Jack hey sup?
Result:
<From: Unreal>n hey sup?
I put *** where it happend. I don't know why it did happen, lol. But I figured out how to fix it.
Code: Use uo; Use os; Use util;
Program TextCMD_Whisper( Who, Text )
If( !Text ) SendSysMessage( Who, "Syntax: .w OR .whisper <PlayerName> <message>" ); Return 0; Endif
var victim; Foreach Player in (EnumerateOnlineCharacters()) If( lower(Text)[lower(Player.name)] ) victim := Player; //so now we found him... Break; Endif Endforeach
If( !victim ) SendSysMessage( Who, "Couldn't find that person." ); SendSysMessage( Who, "Syntax: .w <PlayerName> <message>" ); Return 0; Else
While(Text[1]==" ") // In the event that they put more than 1 space before the persons name. Text[1]:=""; //replace space with empty string Endwhile
Var namelength:= len(victim.name) + 1; // *** Don't know why but the + 1 is needed for the next step. It was not counting something, I checked if it wasn't counting " " spaces but it did, wierd? Text:=Text[namelength, len(Text) - ( namelength - 1 )]; // *** Have to subtract from namelenght at the end so it doesn't cut off the last letter in the message. If( !Text ) // They put a name, but didn't put a message SendSysMessage( Who, "Syntax: .w OR .whisper <PlayerName> <message>" ); Return 0; Endif
While(Text[1]==" ") // In the event that they put more than 1 space before the message. Text[1]:=""; //replace space with empty string Endwhile
SendSysMessage( Who, "<To: " + victim.name + ">" + Text); SendSysMessage( victim, "<From: " + Who.name + ">" + Text ); Endif
Endprogram
Action:
.w [Insertspaceshere] UnrEAl [Insertspaceshere] hey DUDE WtH IS up!?
Result:
<From: Unreal>hey DUDE WtH IS up!?
<To: Unreal>hey DUDE WtH IS up!?
I've also tested it agenst players with almost the same names, example:
Jack BoB; Jack BoB Jack.
Sent the message to the correct player in the right format. Which is perfect IMO, lol.
As for Zacharias code, it did have a lot of errors  But never the less. after I fixed the errors it still didn't send the message. I didn't try to fix any of it seening as Firedancers worked almost flawlessly with some minor fixes.
Anyway anyone have any idea about the *** area?
|
|
| Top |
|
 |
|
Zacharias
|
Post subject: Posted: Wed Mar 08, 2006 3:18 pm |
|
Joined: Wed Mar 08, 2006 7:30 am Posts: 16
|
My codes never work at the first time ^^
but now:
compiled and checked: it works!
But didn't test the Jack BoB-thingy. (think this will work, too)
Code: Use uo; Use os; Use util;
Program TextCMD_Whisper( Who, command )
command := SplitWords(command); var i; var maxcount := 0; var possibleplayer; var realplayer; Foreach Player in (EnumerateOnlineCharacters()) i := 1; var possibleplayer := SplitWords(Player.name); while (lower(possibleplayer[i]) == lower(command[i])) if (i > maxcount) // Check if there is a name which does still fit better if (possibleplayer[(i+1)]) // Check if real name is longer than searched name else maxcount := i; realplayer := Player; endif endif i := i+1; endwhile Endforeach
if (maxcount) i := (maxcount + 1); var strippedtext; while (command[i]) if (strippedtext) strippedtext := strippedtext + " " + command[i]; else strippedtext := command[i]; endif i := (i + 1); endwhile SendSysMessage(realplayer, "<" + who.name + "> " + strippedtext); else SendSysMessage(who, "Player is not online: "); endif
endprogram
|
|
| Top |
|
 |
|
Firedancer
|
Post subject: Posted: Thu Mar 09, 2006 2:57 am |
|
Joined: Fri Feb 03, 2006 6:32 am Posts: 104 Location: Austria
|
Unreal wrote: Firedancers worked. but always grabbed 1 letter in from their name and put it in front of the message.
argh, silly yep. Code: Text:=Text[namelength, len(Text)-namelength];
so of course namelength it would keep the last letter of the name *slaps head*. Guess it should have been: Code: Text:=Text[namelength+1, len(Text)-(namelength+1)];
Quote: I've also tested it agenst players with almost the same names, example: Jack BoB; Jack BoB Jack.
Sent the message to the correct player in the right format. Which is perfect IMO, lol.
hmm must have been luck... it takes the first player it finds. Might happen that messages are sent wrong as Zacharias said. Anyway thinking about it, both our methods have a problem.... what if the player is speaking about another player?? e.g. ".message Jack Hi Jack, did you know Simon the Killer has gotten sick?"... Now 'Simon the Killer' might get the message just as well - especially with Zacharias Method of best fit, which otherwise was a good idea. So either you do an additional check if the name really starts right from the beginning (still a problem - e.g. ".message Jack Bob Jack, Simon got sick!"... does jack bob or jack bob jack get that??) or you think about using a seperator different than blank.... e.g. So if you want to avoid messages ending wrong, you have to define a seperator character, which is something that can never come up in a name. Like a * for example.... Like typing "Jack Bob*Jack how are you?" This would make the function a bit different... you then have to loop through the string to find out the position of the *, then you can cut away the first part and you got the name, cut away the 2nd part and you got the message. (Note: the message can include further * then, as you only use the very first one as a seperator) e.g. Code: var vari; var seperatorposition; for (vari:=1; vari<=len(Text); vari:=vari+1) if(Text[vari]=="*") seperatorposition:=vari; break; endif endfor var name:=Text[1,seperatorposition-1]; var messageText:=Text[seperatorposition+1, len(Text)-seperatorposition]
or somesuch 
|
|
| Top |
|
 |
|
Zacharias
|
Post subject: Posted: Thu Mar 09, 2006 4:50 am |
|
Joined: Wed Mar 08, 2006 7:30 am Posts: 16
|
Okay, now I am using a separator. This should fix the last problem.
Code: Use uo; Use os; Use util;
Program TextCMD_Whisper( Who, command )
var separator := "*"; // setting separator
command := SplitWords(command); var check := 0; var i; var maxcount := 0; var possibleplayer; var realplayer;
Foreach part in command if (part == separator) check := 1; endif endforeach
if (!check) SendSysMessage( who, "Syntax: .w <PlayerName> " + separator + " <message> OR" ); SendSysMessage(who, ".whisper <PlayerName> " + separator + " <message>"); return; endif
Foreach Player in (EnumerateOnlineCharacters()) i := 1; var possibleplayer := SplitWords(Player.name); possibleplayer.append(separator); while (lower(possibleplayer[i]) == lower(command[i])) if (i > maxcount) // Check if there is a name which does still fit better if (possibleplayer[(i+1)]) // Check if real name is longer than searched name else maxcount := i; realplayer := Player; endif endif i := i+1; endwhile Endforeach
if (maxcount) i := (maxcount + 1); var strippedtext; while (command[i]) if (strippedtext) strippedtext := strippedtext + " " + command[i]; else strippedtext := command[i]; endif i := (i + 1); endwhile SendSysMessage(realplayer, "<" + who.name + "> " + strippedtext); else var name; i := 0; while (command[i] != separator) if (name) name := name + " " + command[i]; else name := command[i]; endif i := (i + 1); endwhile SendSysMessage(who, "Player is not online: " + name); endif
endprogram
@Firedancer:
Couldn't you fix the problem in your script, if you first grab and store all names in an array and then do an array.sort() before checking for specific name? Mhmm, but you still can't speak about other persons...
|
|
| Top |
|
 |
|
MontuZ
|
Post subject: Posted: Thu Mar 09, 2006 6:27 am |
|
 |
| Distro Developer |
 |
Joined: Fri Feb 10, 2006 8:08 am Posts: 314 Location: Myrtle Beach, South Carolina
|
You're right it was luck, I tried it again and the message was sent to the wrong person.
But now with a separator we're changing the syntax. Which is a problem, don't want that
I tested this again, agenst multiple players; their names where; Dude, Dude One and Dude Two. From my player Unreal.
I tried
.w dude one dude two
Result:
<To: Dude One>dude two
<From: Unreal>dude two
.w dude two dude one
Result:
<To: Dude Two>dude one
<From: Unreal>dude one
.w dude dude one dude two
Result:
<To: Dude>dude one dude two
<From: Unreal>dude one dude two
And any other possible way you could arrange their names, lol. All worked. But as it seems everytime I do do something it works for me. So test it out and tell fill me in. lol.
Code: Use uo; Use os; Use util;
Program TextCMD_Whisper( Who, Text )
If( !Text ) SendSysMessage( Who, "Syntax: .w OR .whisper <PlayerName> <Message>" ); Return 0; Endif While( Text[1]==" " ) Text[1] := ""; Endwhile
Var Victim; Foreach Player in EnumerateOnlineCharacters() Var MaxNameLen := Len( Player.name ); If( Lower( Text[1, MaxNameLen] )[Lower( Player.name )] ) /* This should be EXACTLY what we want, to search the first part of the param, for the lenght of the player name. *\ Victim := Player; Break; Endif Endforeach
If( !Victim ) SendSysMessage( Who, "Couldn't find that person." ); Return 0; Else
Var NameLength := Len( Victim.name ) + 1; Text := Text[ NameLength, Len( Text ) - ( NameLength - 1 )]; While( Text[1] == " " ) Text[1] := ""; Endwhile
If( !Text ) SendSysMessage( Who, "Syntax: .w OR .whisper <PlayerName> <Message>" ); Return 0; Endif
SendSysMessage( Who, "<To: " + Victim.name + ">" + Text); SendSysMessage( Victim, "<From: " + Who.name + ">" + Text ); Endif
Endprogram
|
|
| Top |
|
 |
|
Zacharias
|
Post subject: Posted: Thu Mar 09, 2006 7:31 am |
|
Joined: Wed Mar 08, 2006 7:30 am Posts: 16
|
|
the problem is following:
From: Mr. Killer
To: dude
Message: one o'clock morning meet me at the tree to kill dude one
He types:
.w dude one o'clock morning meet me at the tree to kill dude one
If "dude one" is online (and dude also) "dude one" may recieve the message.
if "dude one" is online and "dude" not, he will recieve the message..
In this example "dude one" would recieve:
<From: Mr. Killer>o'clock mornging meet me at the tree to kill dude one
which would be a desaster in Mr. Killers eyes. So it's recommended to use a separator.
|
|
| Top |
|
 |
|
nevalon
|
Post subject: Posted: Thu Mar 09, 2006 7:44 am |
|
Joined: Tue Mar 07, 2006 7:28 am Posts: 39 Location: Poland
|
|
Hmm maybe tray to change typing:
.w dude: one o'clock morning meet me at the tree to kill dude one
And allow players to use only one ":"... It'll get whole script easier.
_________________ Sorry for my English... I don't know it well.
|
|
| Top |
|
 |
|
MontuZ
|
Post subject: Posted: Thu Mar 09, 2006 9:16 am |
|
 |
| Distro Developer |
 |
Joined: Fri Feb 10, 2006 8:08 am Posts: 314 Location: Myrtle Beach, South Carolina
|
All because of spaces in the name. I know why in some games spaces aren't allowed in your name and I'm pretty sure this is 1 of them.
I'm using 096 so for SplitWords( Text, "-" ); < Seperator
Code: Use uo; Use os; Use util;
Program TextCMD_Whisper( Who, Text )
If( !Text ) SendSysMessage( Who, "Syntax: .w OR .whisper <PlayerName> - <Message>" ); Return 0; Endif
Var Param := SplitWords( Text, " - " );
While( Param[1]==" " ) Param[1] := ""; Endwhile If( !Param[1] ) SendSysMessage( Who, "Syntax: .w OR .whisper <PlayerName> - <Message>" ); Return 0; Endif
Var Victim; Foreach Player in EnumerateOnlineCharacters() If( Lower( Param[1] )[Lower( Player.name )] ) Victim := Player; Endif Endforeach
If( !Victim ) SendSysMessage( Who, "Couldn't find that person." ); Return 0; Else
While( Param[2]==" " ) Param[2] := ""; Endwhile
If( !Param[2] ) SendSysMessage( Who, "Syntax: .w OR .whisper <PlayerName> - <Message>" ); Return 0; Endif
SendSysMessage( Who, "<To: " + Victim.name + ">" + Param[2] ); SendSysMessage( Victim, "<From: " + Who.name + ">" + Param[2] ); Endif
Endprogram
|
|
| Top |
|
 |
|
Page 1 of 1
|
[ 12 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 0 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|