Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: Eva on April 8th, 2016, 03:52 PM

Title: onPlayerCommand problem
Post by: Eva on April 8th, 2016, 03:52 PM
Hello i have a problem with onPlayercommand were i try to add a part im doing something wrong and i cant find the cause.
Im not a scripter but im trying to understand it :)
function onPlayerCommand( player, command, arguments )
{
   local cmd, text;
      cmd = command;
      text = arguments;

      
   if( cmd == "register" ){
      if( !text ){
         MessagePlayer( "Syntax Error!", player );
         MessagePlayer( "Correct syntax: /register <password>", player );
      }
      else if( stats[ player.ID ].Logged == true ){
         MessagePlayer( "You are already logged in.", player );
      }
      else{
         stats[ player.ID ].Register( player, text, sqliteDB );
      }   
   }
   else if( cmd == "login" ){
      if( !text ){
         MessagePlayer( "Syntax Error!", player );
         MessagePlayer( "Correct syntax: /login <password>", player );
      }
      else if( stats[ player.ID ].Logged == true ){
         MessagePlayer( "You are already logged in.", player );
      }
      else{
         stats[ player.ID ].Login( player, text, sqliteDB );
      }
   }   
   else if( stats[ player.ID ].Level > 0 ) RegUserCmds( player, cmd, text );
   else MessagePlayer( "You have to be registered.", player );
}

        if ( cmd == "setskin" )
    {
        if ( text && IsNum( text ) )
        {               
         player.Skin = text.tointeger();
            MessagePlayer( "[#00ff00] Set the skin: " + GetSkinName( player.Skin ), player );
        }
        else MessagePlayer( "[#ffffff] Type /setskin SkinID" , player );
    }
   else if ( cmd == "info" )
   {
      MessagePlayer( "[#ffffff]Server Name:[ " + GetServerName() + " ].", player );
      MessagePlayer( "[#ffffff]Administrator: [TTH]BiZkiT", player );
      MessagePlayer( "[#ffffff]Players:( " + GetPlayers() + "/" + GetMaxPlayers() + " ).", player );   
      MessagePlayer( "[#ffffff]Cars:( " + GetVehicleCount() + " ) ", player );   
      MessagePlayer( "[#ffffff]Game speed:( " + GetGamespeed() + " )." , player );
   }
   else if ( cmd == "spawn" )
    {   
            if ( text )
          {
          local veh = FindVehicle( text.tointeger() );
          veh.Pos = Vector( ( player.Pos.x + 2 ), player.Pos.y, ( player.Pos.z ) );
           MessagePlayer( "[#00ff00]---> You have spawned car ID : [ " + veh.ID + " ).", player );
          }
          else MessagePlayer( "[#00ff00] Type /spawn <car id >.", player );
           return 1;
    }
   else if ( cmd == "goto" )
    {
          local plr = FindPlayer( text );
          local Name = player.Name;
          if ( !plr ) MessagePlayer( "[#ffffff] Player [" + text + " ] the player has no.", player );
          else player.Pos = plr.Pos;
        MessagePlayer( "[#ffffff] Teleported to [" + plr + "].", player );
        MessagePlayer( "[#ffffff] Player " + player.Name + " teleported to you.", plr );
    }
   else if ( cmd == "fps" )
   {
   if ( text )
   {
   local p = FindPlayer( text );
   Message( "[#00ff00]FPS: [#FFFF33]" + p + " it: [#ffffff]" + p.FPS );
   }
   else MessagePlayer( "[#ffffff] Type /fps < player name >" , player);
   }
   else if ( cmd == "gotocar" )
   {
       if ( text.tointeger() )
       {
       local veh = FindVehicle( text.tointeger() );
      player.Pos = veh.Pos;
      MessagePlayer( "[#00ff00]Teleported to car: " + veh.ID + "." , player );
      }
   }
   else if ( cmd == "wep" )
   {
      if ( text )
      {
        local wepid = GetWeaponID( text );
        player.SetWeapon( wepid, 1000 );
        MessagePlayer( "[#00ff00]Your have spawned a [" + GetWeaponName( wepid ) + "] 1000 ammo." , player );
      }
      else MessagePlayer( "[#00ff00] Enter <id/name> weapon ", player );
   }
   else if ( cmd == "heal" || cmd == "heal" )
   {
      if ( player.Health != 100 )
      {
         player.Health = 100; MessagePlayer( "[#00ff00] You have been healed!. ", player );
      }
      else MessagePlayer( "[#00ff00] You already have 100hp. ", player );
   }
                   else if ( cmd == "cmd" )
                  {
         PrivMessage( player, "[#00ff00]Major Commands: (/) heal, spawn <vehiclename>, goto <Playername>, gotocar <ID> , wep <weaponname>, gotoloc <bank>, gotoloc <mansion>, fps, setskin" );
        
                   }   
   else if ( cmd == "gotoloc" )
   {
      if ( text == "mansion" )
      {
         player.Pos = Vector( -302.86,-599.557,12.8527 );
         MessagePlayer( "[#00ff00] Teleported to The Mansion!", player );
      }
      if ( text == "bank" )
      {
         player.Pos = Vector( -876.882,-340.673,11.1034 );
         MessagePlayer( "[#00ff00] Teleported to El Banco Corrupto!", player );
      }
   }
Title: Re: onPlayerCommand problem
Post by: Cena on April 8th, 2016, 03:56 PM
Can U Show The Pic Of Error?
Title: Re: onPlayerCommand problem
Post by: Eva on April 8th, 2016, 04:05 PM
(http://217.120.57.173/images/error.png)
Title: Re: onPlayerCommand problem
Post by: Cena on April 8th, 2016, 04:10 PM
the prob is not in function onPlayerCommand, it is on line 397.
Title: Re: onPlayerCommand problem
Post by: Eva on April 8th, 2016, 04:16 PM
I get the error when i added  if ( cmd == "setskin" ) and everything below, without it it has no error...
Title: Re: onPlayerCommand problem
Post by: Eva on April 8th, 2016, 04:26 PM
so the ending is wrong?
(http://217.120.57.173/images/error2.png)
Title: Re: onPlayerCommand problem
Post by: KAKAN on April 8th, 2016, 04:47 PM
Change the if to else if., it should be:
"else if( cmd == "setskin" )" without quotes
Title: Re: onPlayerCommand problem
Post by: Coolkid on April 8th, 2016, 04:47 PM
if ( cmd == "setskin" )

use
else if ( cmd == "setskin" )
Title: Re: onPlayerCommand problem
Post by: Eva on April 8th, 2016, 05:23 PM
did else if (cmd =="setskin"}
now got a different error, i tried to change the else if to if there, but thats not it :P
(http://217.120.57.173/images/error3.png)
(http://217.120.57.173/images/error4.png)
Title: Re: onPlayerCommand problem
Post by: KAKAN on April 8th, 2016, 05:56 PM
Because that's not inside the onPlayerCommand
The heal cmd must be inside onPlayerCommand
Title: Re: onPlayerCommand problem
Post by: Milos on April 9th, 2016, 05:21 AM
Quote from Ron on April 8th, 2016, 03:52 PM

   else if( cmd == "login" ){
      if( !text ){
         MessagePlayer( "Syntax Error!", player );
         MessagePlayer( "Correct syntax: /login <password>", player );
      }
      else if( stats[ player.ID ].Logged == true ){
         MessagePlayer( "You are already logged in.", player );
      }
      else{
         stats[ player.ID ].Login( player, text, sqliteDB );
      }
   }   
   else if( stats[ player.ID ].Level > 0 ) RegUserCmds( player, cmd, text );
   else MessagePlayer( "You have to be registered.", player );
}

Title: Re: onPlayerCommand problem
Post by: GTA-Cheng on May 4th, 2019, 10:52 AM
why???

AN ERROR HAS OCCURED [the index 'text' does not exist]

CALLSTACK
*FUNCTION [onPlayerCommand()] scripts/Command.nut line [70]

LOCALS
[cmd] "goto"
[arguments] NULL
[command] "goto"
[player] INSTANCE
[this] TABLE

Title: Re: onPlayerCommand problem
Post by: dracc on May 4th, 2019, 01:24 PM
Quote from GTA-Cheng on May 4th, 10:52 AM
why???

AN ERROR HAS OCCURED [the index 'text' does not exist]

CALLSTACK
*FUNCTION [onPlayerCommand()] scripts/Command.nut line [70]

LOCALS
[cmd] "goto"
[arguments] NULL
[command] "goto"
[player] INSTANCE
[this] TABLE
Because the variable named "text" is not available in your current scope. I can't tell you more than that as you didn't tell us what tour code looks like. Your problem is probably worthy of a new thread as you clearly are not using the same exact code as OP of this thread.