freeze

Started by Eva, Apr 22, 2016, 04:21 PM

Previous topic - Next topic

Eva

Hello i have a error in this freeze script, does anybody know what is wrong here?

else if ( cmd == "freeze" )
      {
                      if ( stats[ player.ID ].Level < 9 ) MessagePlayer( "[#FF3636]Error - [#FFFF00]You don't have access to it.", player);
      else if ( !text ) MessagePlayer( "[#FF3636]Error - Syntax: [#FFFF00]/freeze <player name>", player);
      else
      {   
         if ( !text ) PrivMessage( "Error - Invalid Format. /freeze <player>", player );
         else if ( !plr ) PrivMessage( "Error - Invalid Nick/ID.", player );
         else if ( plr.ID == player.ID ) PrivMessage( "Error - You can't /freeze yourself.", player );
         else
         {
            if ( !plr.IsSpawned ) PrivMessage( "Error - This player hasn't spawned.", player );
            else if ( plr.IsFrozen ) PrivMessage( "Error - This player has already been frozen.", player );
            else
            {
               Message( "* Admin " + player + " has frozen " + plr + "..." );
               plr.IsFrozen = true;
            }
         }      
      }      
   }
      else if ( cmd == "unfreeze" )
      {
      if ( stats[ player.ID ].Level < 9 ) MessagePlayer( "[#FF3636]Error - [#FFFF00]You don't have access to it.", player);
      else if ( !text ) MessagePlayer( "[#FF3636]Error - Syntax: [#FFFF00]/unfreeze <player name>", player);
      else
                                         {   
         if ( !text ) PrivMessage( "Error - Invalid Format. /unfreeze <player>", player );
         else if ( !plr ) PrivMessage( "Error - Invalid Nick/ID.", player );
         else if ( plr.ID == player.ID ) PrivMessage( "Error - You can't /unfreeze yourself.", player );
         else
         {
            if ( !plr.IsSpawned ) PrivMessage( "Error - This player hasn't spawned.", player );
            else if ( !plr.IsFrozen ) PrivMessage( "Error - This player hasn't been frozen.", player );
            else
            {
               Message( "* Admin " + player + " has unfrozen " + plr + "..." );
               plr.IsFrozen = false;
            }
         }         
      }      
   }


here the error screen

KAKAN

Yes I know. The wrong thing is: the index 'plr' doesn't exist :D
oh no

Xmair

You didn't defined 'plr', try adding:
local plr = FindPlayer( text );

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

Luis_Labarca

/////////////in commands
else if ( cmd == "freeze" )
{
if ( stats[ player.ID ].Level < 9 ) MessagePlayer( "[#FF3636]Error - [#FFFF00]You don't have access to it.", player);
else if ( !text ) MessagePlayer( "[#FF3636]Error - Syntax: [#FFFF00]/freeze <playerID/name>", player);
else{
local plr = GetPlayer( GetTok( text, " ", 1 ) );
if ( !plr ) PrivMessage("Error - Invalid Nick/ID.", player );
else if ( plr.ID == player.ID ) PrivMessage( "Error - You can't /freeze yourself.", player );
else if ( !plr.IsSpawned ) PrivMessage( "Error - This player hasn't spawned.", player );
else if ( plr.IsFrozen ) PrivMessage( "Error - This player has already been frozen.", player );
else{
Message( "* Admin " + player + " has frozen " + plr + "..." );
plr.IsFrozen = true;
}
}
}
else if ( cmd == "unfreeze" )
{
if ( stats[ player.ID ].Level < 9 ) MessagePlayer( "[#FF3636]Error - [#FFFF00]You don't have access to it.", player);
else if ( !text ) MessagePlayer( "[#FF3636]Error - Syntax: [#FFFF00]/unfreeze <playerID/name>", player);
else{
local plr = GetPlayer( GetTok( text, " ", 1 ) );
if ( !plr ) PrivMessage("Error - Invalid Nick/ID.", player );
else if ( plr.ID == player.ID ) PrivMessage( "Error - You can't /unfreeze yourself.", player );
else if ( !plr.IsSpawned ) PrivMessage( "Error - This player hasn't spawned.", player );
else if ( !plr.IsFrozen ) PrivMessage( "Error - This player hasn't been frozen.", player );
else{
Message( "* Admin " + player + " has unfrozen " + plr + "..." );
plr.IsFrozen = false;
}
}
}




////add function


function GetPlayer( plr )
{
if ( plr )
{
if ( IsNum( plr ) )
{
plr = FindPlayer( plr.tointeger() );
if ( plr ) return plr;
else return null;
}
else
{
plr = FindPlayer( plr );
if ( plr ) return plr;
else return null;
}
}
else return null;
}


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;
}

Luis_Labarca

You can use this also is the only thing that changes that, in this, you must add the reason why the same thing these giving freeze

//in commands
else if ( cmd == "freeze" )
{
if ( stats[ player.ID ].Level < 9 ) MessagePlayer( "[#FF3636]Error - [#FFFF00]You don't have access to it.", player);
else if ( !text ) MessagePlayer( "[#FF0000]Error - Syntax: [#FFFF00]/freeze <playerID/name> <reason>", player);
else{
local plr = GetPlayer( GetTok( text, " ", 1 ) );
if ( !plr ) PrivMessage("Error - Invalid Nick/ID.", player );
else if ( plr.ID == player.ID ) PrivMessage( "Error - You can't /freeze yourself.", player );
else if ( !plr.IsSpawned ) PrivMessage( "Error - This player hasn't spawned.", player );
else if ( plr.IsFrozen ) PrivMessage( "Error - This player has already been frozen.", player );
else{
local reason = GetTok( text, " ", 2 NumTok( text, " " ) );
if ( !reason ) MessagePlayer("[#FF0000]Error - Syntax: [#FFFF00]/freeze <playerID/name> <reason>", player );
else {
Message( "* Admin " + player + " has frozen " + plr + " reason "+reason+"" );
plr.IsFrozen = true;
}
}
}
}


////add function


function GetPlayer( plr )
{
if ( plr )
{
if ( IsNum( plr ) )
{
plr = FindPlayer( plr.tointeger() );
if ( plr ) return plr;
else return null;
}
else
{
plr = FindPlayer( plr );
if ( plr ) return plr;
else return null;
}
}
else return null;
}


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();
}

Eva

Thank you very much i will try this, and thanks for the clear explanations :) im learning!

Luis_Labarca

Quote from: Ron on Apr 22, 2016, 07:51 PMThank you very much i will try this, and thanks for the clear explanations :) im learning!

friend nothing we are to help ;)

Eva

it works but theres 1 problem in it as it doesnt return the Error msg
else if ( plr.ID == player.ID ) PrivMessage( "Error - You can't /freeze yourself.", player );

and also unfreeze

Mötley

I am not in front of pc and can't see the text well. just delete that line for now see what happens

Coolkid

Quote from: Ron on Apr 23, 2016, 07:42 PMit works but theres 1 problem in it as it doesnt return the Error msg
else if ( plr.ID == player.ID ) PrivMessage( "Error - You can't /freeze yourself.", player );

and also unfreeze
Instead of privmessage use MessagePlayer hopefully it Will help

MaTaDeToR

#10
Quote from: Ron on Apr 23, 2016, 07:42 PMit works but theres 1 problem in it as it doesnt return the Error msg
else if ( plr.ID == player.ID ) PrivMessage( "Error - You can't /freeze yourself.", player );

and also unfreeze
You are using an old format @Ron; therefore, try this PrivMessage( player, "Error - You can't /freeze yourself");
Well just that the format has been changed.

Anik

there is a code button.... Please use that to paste any code.

Eva

Thanks very much indeed thats working :)

KAKAN

Quote from: Ron on Apr 24, 2016, 09:01 AMThanks very much indeed thats working :)
http://wiki.vc-mp.org/wiki/Scripting/Squirrel/Functions
You can check the functions and their syntax there.
oh no

Mötley

#14
Personally I would use this line instead of the line you have

else if ( stats[ plr.ID ].Level > 9 ) MessagePlayer( "Error - You can't /freeze admins.", player );but you need to modify it to your level system.