PDA

View Full Version : Issue with kicking players from an event


FunnyBear
10/12/2016, 05:30 PM
Solved.

iLearner
10/12/2016, 06:33 PM
if(!strcmp(params, "kick", true))
{
if( sscanf(params, "su", params, id))
return SendUsageError( playerid, "/toggle [Kick] [ID]" );


if(!strcmp(params, "kick", true))
{
if( sscanf(params, "su", id))
return SendUsageError( playerid, "/toggle [ID]" );

Since you're already checking if param is kick, you have to check the id under the command, i think so, at least.

And where did /toggle come from? isnt it supposed to be /event kick id

Hansrutger
10/12/2016, 07:28 PM
Make a sscanf before the strcmp to check for even more parameters, but make it optional so it doesn't have to be included.

EVERY format specifier (that is, everything except '', {} and p) now has an optional equivalent - this is just their letter capitalised, so for example the old "z" optional string specifier is now "S" (there is still "z" and, for completeness, "Z", but both give warnings). In addition to optional specifiers, there are also now default values:
(http://forum.sa-mp.com/showthread.php?t=570927)

So simply:

new subcmd[10], subcmdval[128];
if (sscanf(params, "s[10]S()[128]", subcmd, subcmdval))
{
//Return something if user doesn't put it anything for "s[10]"!
}

if (strcmp(subcmd, "kick", true))
{
new targetid;
if (sscanf(subcmdval, "u", targetid))
{
//Return something if user did "/cmd kick" but didn't put any value afterwards!
}
// Continue what happens if id was given
}

FunnyBear
10/12/2016, 08:32 PM
Make a sscanf before the strcmp to check for even more parameters, but make it optional so it doesn't have to be included.


(http://forum.sa-mp.com/showthread.php?t=570927)

So simply:

new subcmd[10], subcmdval[128];
if (sscanf(params, "s[10]S()[128]", subcmd, subcmdval))
{
//Return something if user doesn't put it anything for "s[10]"!
}

if (strcmp(subcmd, "kick", true))
{
new targetid;
if (sscanf(subcmdval, "u", targetid))
{
//Return something if user did "/cmd kick" but didn't put any value afterwards!
}
// Continue what happens if id was given
}


Hey there, thanks for the reply. I have tried what you have suggested but it still does not seem to work.

Have you got another solution?

Thanks!

Hansrutger
10/12/2016, 09:01 PM
Ehm'... What do errors do you get? If no errors, please show how you ended up coding it.

NeXoR
10/12/2016, 09:08 PM
I had a similar problem which I posted on the forums aswell, listen up what you gotta do.
You need an option string where you store the option, and then store the rest of the given text back to the params variable, IE:
new option[10];
sscanf(params, "s[10]s[128]", option, params);
if(!strcmp(option, "kick", true))
{
sscanf(params, "u", id);
}

The string size on the first sscanf is 128 because it is the maximum length of an input text, so params without the options could never ever be higher than the params with the option, logically.

FunnyBear
10/12/2016, 09:12 PM
Solved.

FunnyBear
10/12/2016, 09:16 PM
I had a similar problem which I posted on the forums aswell, listen up what you gotta do.
You need an option string where you store the option, and then store the rest of the given text back to the params variable, IE:
new option[10];
sscanf(params, "s[10]s[128]", option, params);
if(!strcmp(option, "kick", true))
{
sscanf(params, "u", id);
}

The string size on the first sscanf is 128 because it is the maximum length of an input text, so params without the options could never ever be higher than the params with the option, logically.


That doesn't work either, sorry.

Yaa
10/12/2016, 09:27 PM
CMD:event(playerid, params[])
{
if( pInfo[playerid][pAdmin] < 5 )
return 0;

new id;

if (isnull(params))
return SendUsageError( playerid, "/event [create/rename/teles/kick/freeze/disarm/weapons/end]" );

if(!strcmp(params, "kick", true))
{
new kid;
if (sscanf(params, "su", "kick", kid))
return SendUsageError( playerid, "/event [kick] [ID]" );

if(inEvent[kid] == 1)
{
format(str, sizeof(str), "[EVENT] {FFFFFF}%s has been kicked from the event", Name[kid], kid);
SendClientMessageToAll(COLOR_EVENT, str);
SetPlayerHealth(kid, 0);
inEvent[kid] = 0;
eInfo[eventFrozen] = 0;
TogglePlayerControllable(kid, 1);

}
else
{
Error(playerid, "This player is not participating in your event");
}

}
return 1;
}

FunnyBear
10/12/2016, 09:31 PM
CMD:event(playerid, params[])
{
if( pInfo[playerid][pAdmin] < 5 )
return 0;

new id;

if (isnull(params))
return SendUsageError( playerid, "/event [create/rename/teles/kick/freeze/disarm/weapons/end]" );

if(!strcmp(params, "kick", true))
{
new kid;
if (sscanf(params, "su", "kick", kid))
return SendUsageError( playerid, "/event [kick] [ID]" );

if(inEvent[kid] == 1)
{
format(str, sizeof(str), "[EVENT] {FFFFFF}%s has been kicked from the event", Name[kid], kid);
SendClientMessageToAll(COLOR_EVENT, str);
SetPlayerHealth(kid, 0);
inEvent[kid] = 0;
eInfo[eventFrozen] = 0;
TogglePlayerControllable(kid, 1);

}
else
{
Error(playerid, "This player is not participating in your event");
}

}
return 1;
}

I actually tried that before, it works and sends the usage errors but it does not execute the code if you fill in all parameters.

Anything else?

Yaa
10/12/2016, 09:45 PM
I actually tried that before, it works and sends the usage errors but it does not execute the code if you fill in all parameters.

Anything else?

this one

CMD:event(playerid, params[])
{
if( pInfo[playerid][pAdmin] < 5 )
return 0;

new subcmd[10], subcmdval[128], id;

if (sscanf(params, "s[10]S()[128]", subcmd, subcmdval))
return SendUsageError( playerid, "/event [create/rename/teles/kick/freeze/disarm/weapons/end]" );

if(!strcmp(subcmd, "kick", true))
{
if (sscanf(subcmdval, "u", id))
return SendUsageError( playerid, "/event [kick] [ID]" );

if(inEvent[id] == 1)
{
format(str, sizeof(str), "[EVENT] {FFFFFF}%s has been kicked from the event", Name[id], id);
SendClientMessage(id, COLOR_EVENT, str);

}
else
return Error(playerid, "This player is not participating in your event");

SetPlayerHealth(id, 0);
inEvent[id] = 0;
eInfo[eventFrozen] = 0;
TogglePlayerControllable(id, 1);

}
return 1;
}

and this MINE lastest


CMD:event(playerid, params[])
{
if( pInfo[playerid][pAdmin] < 5 )
return 0;

new id;

if (isnull(params))
return SendUsageError( playerid, "/event [create/rename/teles/kick/freeze/disarm/weapons/end]" );

if(!strcmp(params, "kick", true))
{
new kid;
if (sscanf(params, "su", "kick", kid))
return SendUsageError( playerid, "/event [kick] [ID]" );

if(inEvent[kid] == 1)
{
format(str, sizeof(str), "[EVENT] {FFFFFF}%s has been kicked from the event", Name[kid], kid);
SendClientMessageToAll(COLOR_EVENT, str);
SetPlayerHealth(kid, 0);
inEvent[kid] = 0;
eInfo[eventFrozen] = 0;
TogglePlayerControllable(kid, 1);

}
else
{
Error(playerid, "This player is not participating in your event");
}

}
return 1;
}

aren't same do u can test it before speak ?

FunnyBear
10/12/2016, 10:07 PM
this one

CMD:event(playerid, params[])
{
if( pInfo[playerid][pAdmin] < 5 )
return 0;

new subcmd[10], subcmdval[128], id;

if (sscanf(params, "s[10]S()[128]", subcmd, subcmdval))
return SendUsageError( playerid, "/event [create/rename/teles/kick/freeze/disarm/weapons/end]" );

if(!strcmp(subcmd, "kick", true))
{
if (sscanf(subcmdval, "u", id))
return SendUsageError( playerid, "/event [kick] [ID]" );

if(inEvent[id] == 1)
{
format(str, sizeof(str), "[EVENT] {FFFFFF}%s has been kicked from the event", Name[id], id);
SendClientMessage(id, COLOR_EVENT, str);

}
else
return Error(playerid, "This player is not participating in your event");

SetPlayerHealth(id, 0);
inEvent[id] = 0;
eInfo[eventFrozen] = 0;
TogglePlayerControllable(id, 1);

}
return 1;
}

and this MINE lastest


CMD:event(playerid, params[])
{
if( pInfo[playerid][pAdmin] < 5 )
return 0;

new id;

if (isnull(params))
return SendUsageError( playerid, "/event [create/rename/teles/kick/freeze/disarm/weapons/end]" );

if(!strcmp(params, "kick", true))
{
new kid;
if (sscanf(params, "su", "kick", kid))
return SendUsageError( playerid, "/event [kick] [ID]" );

if(inEvent[kid] == 1)
{
format(str, sizeof(str), "[EVENT] {FFFFFF}%s has been kicked from the event", Name[kid], kid);
SendClientMessageToAll(COLOR_EVENT, str);
SetPlayerHealth(kid, 0);
inEvent[kid] = 0;
eInfo[eventFrozen] = 0;
TogglePlayerControllable(kid, 1);

}
else
{
Error(playerid, "This player is not participating in your event");
}

}
return 1;
}

aren't same do u can test it before speak ?

It's still not working.

Has anyone else got any other solutions?

Hansrutger
10/12/2016, 11:00 PM
Is, in /event kick [id], the [id] part a player? If it's not a player then use "i" instead of "u". I just assumed it was a player. :x

Edit:
I'm stupid, it can't be a player because you are using the [id] part in an array, so it should be "i" indeed instead of "u". I hope that does the trick otherwise I don't know, debug it with lots of printf()'s.

Second edit (fml):
No it should be possible because the array is probably a player array anyways... Either way test with "i", who know's...

FunnyBear
10/12/2016, 11:05 PM
Is, in /event kick [id], the [id] part a player? If it's not a player then use "i" instead of "u". I just assumed it was a player. :x

Yeah, ID stands for the ID of a player. The problem with your code is that it will always output the general usage error, not the sub-command usage error:

return SendUsageError( playerid, "/event [create/rename/teles/kick/freeze/disarm/weapons/end]" );


However, if I fill in all of the parameters (e.g. /event kick 1), it will execute the code.

Furthermore, if I do /event create (to start an event) it will also output the general usage error, however, if I add anything to the end of it (/event create xdsjdjsa), it will execute the code although more parameters were not necessary.

Thanks.

P.S. I'm starting to think that the 'optional parameters' are not so 'optional' in this case.

FunnyBear
11/12/2016, 09:32 AM
Can someone help me, please?

Hansrutger
11/12/2016, 05:13 PM
Solved - always keep your includes/plugins updated. :P