Script Help

MahmutTuncer

  • Newbie
  • Posts: 4
Script Help
«  »
Hello,im a new scripter. Im trying to make a command that using two "text.tointeger();". But probably i have to prove this a lot... So im here.

(click to show/hide)
    if ( cmd == "sms" )
    {
   if(!text)          MessagePlayer("[#008cff][Turkcell]:[#ffffff]Mesaj gonderilmedi. /sms isim mesaj", player );
         local params = split( text ), plr = FindPlayer( params[0] ), reason = text.tointeger();
          MessagePlayer("[#008cff][Turkcell]:[#ffffff]" + player.Name + "nin mesaji:" + reason+".", plr );
          MessagePlayer("[#008cff][Turkcell]:[#ffffff]Mesajiniz iletildi:" + reason+".", player );
                         PlaySoundForPlayer(player, 50032);
                         PlaySoundForPlayer(plr, 50032);
        }

I just need command like : /sms nickname text

First blank is for Nick,Second for message. Example

/sms yankee stalker misin ?
 


Razor.

  • Jr. Member
  • Posts: 70
Re: Script Help
« Reply #1,  »Last edited
Use GetPlayer, GetTok and NumTok functions.
Code: [Select]
if ( cmd == "sms" )
{
if ( ! text ) MessagePlayer( "Use: /sms <player/ID> <message>", player );
else
{
local plr = GetPlayer( GetTok( text, " ", 1 ) );
if ( !plr ) MessagePlayer( "Error: Invalid player.", player );
else
{
local message = GetTok( text, " ", 2, NumTok( text, " " ) );
if ( !message ) MessagePlayer( "Error: no message.", player );
else
{
MessagePlayer( "Message has sent to: " + plr.Name, player );
MessagePlayer( "SMS from: " +player.Name + " - " + message + ".", player );
}
}
}
}

habi

  • Full Member
  • Posts: 217
Re: Script Help
« Reply #2,  »Last edited
Quote
MessagePlayer( "SMS from: " +player.Name + " - " + message + ".", plr );
and here are some functions. Add these also
Code: [Select]
function GetTok( string, separator, n, ... )
{
 local m = ( vargv.len() > 0 ) ? vargv[ 0 ] : n, tokenized = split( string, separator ), text = "";

 if ( ( n > tokenized.len() ) || ( n < 1 ) ) return null;

 for ( ; n <= m; n++ )
 {
  text += text == "" ? tokenized[ n - 1 ] : separator + tokenized[ n - 1 ];
 }

 return text;
}

function NumTok( string, separator )
{
 local tokenized = split( string, separator );

 return tokenized.len();
}

Code: [Select]
function GetPlayer(plr)
{
  if (IsNum(plr))
  {
   plr = FindPlayer(plr.tointeger());
   if (plr) return plr;
   else return 0;
  }
  else
  {
   plr = FindPlayer(plr);
   if (plr) return plr;
   else return 0;
  }
}

MahmutTuncer

  • Newbie
  • Posts: 4
Re: Script Help
« Reply #3,  »
Thank you all ! Its worked.