if ( cmd == "kick" )
{
if ( !text ) MessagePlayer( "Correct syntax : /kick <id> <reason>", player );
else if ( split(text, " ").len() < 2) return MessagePlayer("Correct syntax : /kick <id> <reason>", player )
else
{
local a = split(text, " "), plr = FindPlayer( text.tointeger() ), player = FindPlayer( text.tointeger() );
if ( !IsNum( a[0] ) || text( a[1] )) MessagePlayer( "Format: /kick <id> <reason>", player );
else {
KickPlayer( a[0].tointeger() );
Message( "Format: /kick <"+a[0]+"> <"+a[1]">" );
}
}
}
Error : Attempt to call String
Alright hold on, ABRA KADABRA!
.
.
.
Well looks like there is no magic we can use to get the line number automatically that causes the error.
>.< It is kickplayer not working
How faking hard is it to understand a message like that :-\
local dafuq = "you're trying to do";
print( dafuq() );
// 'dafuq' is a string.
// why 'dafuq' are you trying to use it as a function?
cant understand yor code if u want use this
if ( cmd == "kick" )
{
if ( !text ) MessagePlayer( "Correct syntax : /kick <id> <reason>", player );
else
{
local plr = FindPlayer( text );
if ( !plr ) MessagePlayer( "Invalid ID", player );
else {
KickPlayer( plr );
Message( "Admin " + player.Name + " kick " + plr.Name + "." );
}
}
}
KickPlayer( FindPlayer( a[0].tointeger() ) );
Don't look at the crap what shawn posted, its the same command except the thing that command has gotten the player instance, which you didn't, the KickPlayer function needs an instance not a string.
Quote from: [VSS]Shawn on Jul 17, 2015, 01:50 PMcant understand yor code if u want use this
if ( cmd == "kick" )
{
if ( !text ) MessagePlayer( "Correct syntax : /kick <id> <reason>", player );
else
{
local plr = FindPlayer( text );
if ( !plr ) MessagePlayer( "Invalid ID", player );
else {
KickPlayer( plr );
Message( "Admin " + player.Name + " kick " + plr.Name + "." );
}
}
}
Woa, if someone will type the ID there, the cmd is not gonna work
Its a copy paste from somewhere
EDIT:
You have just pasted this (http://wiki.vc-mp.org/wiki/Scripting/Squirrel/Functions/KickPlayer), with some edits,, right??
EDIT #2:
Better use my code
else if ( cmd == "kick" )
{
if ( !text ) MessagePlayer( "Error - Syntax: /kick <player> <reason>", player);
else
{
local plr = GetPlayer( GetTok( text, " ", 1 ) );
if ( !plr ) MessagePlayer( "Error - Unknown player.", player);
else
{
local reason = GetTok( text, " ", 2 );
if ( !reason ) reason = "None";
Message( "" + plr.Name + " have been kicked. Reason: " + reason + "" );
EchoMessage( "" + plr.Name + " have been kicked. Reason: " + reason + "" );
plr.Kick();
}
}
}
Please help me how to fix i changed that line to
if ( !IsNum( a[0] ) || !text( a[1] )) MessagePlayer( "Format: /kick <id> <reason>", player );
Quote from: CopyPaste on Jul 17, 2015, 04:00 PMPlease help me how to fix
Oh go F* your self. I'm pretty much getting tired of retards like you coming here with some shitty code and a simple error message. Never saying where the error occurs or giving some proper information that would help people to locate the issue.
So we're pretty much forced to guess and shit around the code you posted because we can't possibly test code just like that out of context. And when we finally give you the code you're like "
I don't understaaaaand!". Well, f* me. Why did you even ask in the first place?
IF YOU CAN'T PROPERLY ASK A FAKIN QUESTION THEN STOP ASKING AND GET THE F* OUT OF HERE BECAUSE WE'RE PRETTY MUCH TIRED OF SHITBAGS LIKE YOU
hey bro You need this?
if ( cmd == "kick" ){
if ( !text ) MessagePlayer( "Correct syntax : /kick <id> <reason>", player );
else if ( split(text, " ").len() < 2) return MessagePlayer("Correct syntax : /kick <id> <reason>", player )
else {
local a = split(text, " ");
if ( !IsNum( a[0] ) || IsNum( a[1] ) ) MessagePlayer( "Format: /kick <id> <reason>", player );
else {
KickPlayer( FindPlayer( a[0].tointeger() ) );
Message( "You have Kicked <"+FindPlayer( a[0].tointeger())+"> <"+text.slice(a[0].len() + 1)+">" );
}
}
}
If you need any other help pm me :)
Exactly , that was what I want thanks :)
and sorry slc im noob at scripting please don't read my topics :(
Quote from: CopyPaste on Jul 17, 2015, 05:04 PMExactly , that was what I want thanks :)
Just tell me what the hell did I post up there, compare your whole command, and check whats the main difference in Ksna's command and your command and then check my reply...
You people really don't deserve help, you just want ready-to-use scripts.
Lol Fucking Kakan Check out your code GetPlayer does not exist fucker
add function and i am not copy paster like u
GetPlayer Function:
function GetPlayer( plr )
{
if ( plr )
{
if ( IsNum( plr ) )
{
plr = FindPlayer( plr.tointeger() );
if ( plr ) return plr;
else return false;
}
else
{
plr = FindPlayer( plr );
if ( plr ) return plr;
else return false;
}
}
else return false;
}
Perma-Banned CopyPaste. He and Ksna are the same person. So for some reason he does come up with the right script.
If you can do it yourself, or copy it from somewhere else. Great! Just don't come here with another account and answer your own question like that.
S.L.C. gave you the reason why it wasn't working, and you did nothing with that answer.
Quote from: MatheuS on Jul 17, 2015, 06:54 PMGetPlayer Function:
..
That code makes no sense.
if ( plr ) { .. }
else { plr = FindPlayer( plr ); }
When is that ever going to work? Sure if you actually specify plr the function works, but that else makes no sense at all.
This was in Warchiefs simply replayed.
Quote from: Thijn on Jul 17, 2015, 07:26 PMPerma-Banned CopyPaste. He and Ksna are the same person. So for some reason he does come up with the right script.
If you can do it yourself, or copy it from somewhere else. Great! Just don't come here with another account and answer your own question like that.
S.L.C. gave you the reason why it wasn't working, and you did nothing with that answer.
Quote from: MatheuS on Jul 17, 2015, 06:54 PMGetPlayer Function:
..
That code makes no sense.
if ( plr ) { .. }
else { plr = FindPlayer( plr ); }
When is that ever going to work? Sure if you actually specify plr the function works, but that else makes no sense at all.
Quote from: Thijn on Jul 17, 2015, 07:26 PMThat code makes no sense.
if ( plr ) { .. }
else { plr = FindPlayer( plr ); }
When is that ever going to work?
That function will work for sure . The parameter is defined as identifier
"plr" which we generally refer to instance . Although being custom ,
"plr" is symbolized as the
"instance holder" due to intensive use by most of the VC:MP scripters while specifying to
"target instance" . This myth ends here .
Because , our purpose through
"GetPlayer" function is to get the target
"instance" . So , it is quite clear that passed argument will not be an instance & indeed would be either player's name or his id . Now , the check
if( plr ) at the beginning of the function is useless since we're attempting to check whether an argument to
"plr" is passed ? While the fact is that if no argument is passed then it will itself throw error
"Wrong Number Of Parameters" & function execution will be seized .
Thereafter we're checking whether the passed argument is a
"numeric string" . If then we're converting this string to integer & passing this as an argument to function FindPlayer which will attempts to check whether there is an valid player instance corresponding to this . This checking will be based on id . Thereafter we're assigning the result to
"plr" which would now contain either an instance or null .
Actually this could be considered as identical to compound assignment ( aka short-hand ) :-
function IsEven( num )
{
num %= 2;
num == 0 ? print("Even") : print("Not even");
}
Thereafter if
"plr" got an instance then we're attempting to return it otherwise returning false . The other check would be on the basis of name & not id .
function GetPlayer( plr )
{
// checking if the argument to plr is passed [Useless]
if ( plr )
{
// checking if the passed argument is a numeric string
if ( IsNum( plr ) )
{
// 1. converting numeric string "plr" to actual integer
// 2. passing this as an argument to FindPlayer
// 3. "plr" now contain either an instance or null instead of id
plr = FindPlayer( plr.tointeger() );
// 1.checking whether an instance has been received ?
// 2. returning the resultant instance
if ( plr ) return plr;
// otherwise returning false
else return false;
}
// if the passed argument isn't numeric string
else
{
// 1. passing the string (player's name) to FindPlayer
// 2. "plr" now contain either an instance or null instead of name
plr = FindPlayer( plr );
// 1.checking whether an instance has been received ?
// 2. returning the resultant instance
if ( plr ) return plr;
// otherwise returning false
else return false;
}
}
else return false; // [Useless]
}
Failure case scenario : This function will work in most cases but still struggle at something . For example , if you're passing it a number then check will be made on the basis of id & not player's name . What if someone joined the server with nick
123456 . If we'll write
/kick 1234 , then it will return invalid player . Because , as I said earlier , it will recognize 1234 as an id & then attempts to check it . Truth is that there is no such id actually exist . This could easily be fixed by making an additional check once checking through id has been failed or checking via name before id . However I consider it a bit overkill since numeric names look absurd . So , I prefer
using this :-
local plr = IsNum(text) ? FindPlayer(text.tointeger() ) : FindPlayer(text);
And for the number lovers this one :-
if( IsNum(player.Name) ) KickPlayer( player );