onPlayerCommand problem

Started by Eva, Apr 08, 2016, 02:52 PM

Previous topic - Next topic

Eva

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

Can U Show The Pic Of Error?
Want To Meet Me Come #Cena At Lunet

Eva


Cena

the prob is not in function onPlayerCommand, it is on line 397.
Want To Meet Me Come #Cena At Lunet

Eva

#4
I get the error when i added  if ( cmd == "setskin" ) and everything below, without it it has no error...

Eva


KAKAN

Change the if to else if., it should be:
"else if( cmd == "setskin" )" without quotes
oh no

Coolkid

if ( cmd == "setskin" )

use
else if ( cmd == "setskin" )

Eva

#8
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

Because that's not inside the onPlayerCommand
The heal cmd must be inside onPlayerCommand
oh no

Milos

Quote from: Ron on Apr 08, 2016, 02: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 );
}



gtacheng

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

Quote from: GTA-Cheng on May 04, 2019, 09:52 AMwhy???

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.