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 );
}
}
Can U Show The Pic Of Error?
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2F217.120.57.173%2Fimages%2Ferror.png&hash=d6d01b9ab1ab5aa80b02310243724b211470756a)
the prob is not in function onPlayerCommand, it is on line 397.
I get the error when i added if ( cmd == "setskin" ) and everything below, without it it has no error...
so the ending is wrong?
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2F217.120.57.173%2Fimages%2Ferror2.png&hash=5b3e3f026916ce1a40501dc1dcab5353359048c0)
Change the if to else if., it should be:
"else if( cmd == "setskin" )" without quotes
if ( cmd == "setskin" )
use
else if ( cmd == "setskin" )
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
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2F217.120.57.173%2Fimages%2Ferror3.png&hash=7feef9b1711fb18d67d19dd7557c7ac903fce2f8)
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2F217.120.57.173%2Fimages%2Ferror4.png&hash=0db3b297036dc15be9d96dfce6826fdc3115ca14)
Because that's not inside the onPlayerCommand
The heal cmd must be inside onPlayerCommand
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 );
}
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
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.