This topic was marked solved by its starter, on April 10th, 2016, 06:06 PM

Eva

  • Full Member
  • Posts: 116
onPlayerCommand problem
« 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 );
      }
   }

Cena

  • Jr. Member
  • Never give up in scripting xD
  • Posts: 55
Want To Meet Me Come #Cena At Lunet

Eva

  • Full Member
  • Posts: 116

Cena

  • Jr. Member
  • Never give up in scripting xD
  • Posts: 55
Re: onPlayerCommand problem
« Reply #3, on April 8th, 2016, 04:10 PM »
the prob is not in function onPlayerCommand, it is on line 397.
Want To Meet Me Come #Cena At Lunet

Eva

  • Full Member
  • Posts: 116
Re: onPlayerCommand problem
« Reply #4, on April 8th, 2016, 04:16 PM »Last edited on April 8th, 2016, 04:18 PM
I get the error when i added  if ( cmd == "setskin" ) and everything below, without it it has no error...

KAKAN

  • Wiki Contributor
  • Posts: 3,345
Re: onPlayerCommand problem
« Reply #6, on April 8th, 2016, 04:47 PM »
Change the if to else if., it should be:
"else if( cmd == "setskin" )" without quotes
You can contact me using Discord, at Developers.CPP( check off-board to find the invite link )
Github: https://github.com/theKAKAN

Coolkid

  • Full Member
  • Posts: 173

Eva

  • Full Member
  • Posts: 116
Re: onPlayerCommand problem
« Reply #8, on April 8th, 2016, 05:23 PM »Last edited on April 8th, 2016, 05:25 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


KAKAN

  • Wiki Contributor
  • Posts: 3,345
Re: onPlayerCommand problem
« Reply #9, on April 8th, 2016, 05:56 PM »
Because that's not inside the onPlayerCommand
The heal cmd must be inside onPlayerCommand
You can contact me using Discord, at Developers.CPP( check off-board to find the invite link )
Github: https://github.com/theKAKAN

Milos

  • Jr. Member
  • Posts: 79
Re: onPlayerCommand problem
« Reply #10, 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 );
}


GTA-Cheng

  • Newbie
  • Posts: 13
Re: onPlayerCommand problem
« Reply #11,  »
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


dracc

  • Jr. Member
  • Posts: 81
Re: onPlayerCommand problem
« Reply #12,  »
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.