command question
#1

Guys, I have a little question it's about commands if I made a command like this
Код:
CMD:kick(playerid,params)
{
       new id;
       if(sscanf(params, "u", id) return scm(playerid, COLOR_USAGE, "USAGE:/kick [id]");
       if(id == INVALID_PLAYER_ID) return scm(playerid, COLOR_ERROR, "invalid id");
       Kick(id);
       return 1;
}
It's a kick command, So the question is
* If the var id acts as a global var will it mess? Or Should I put id[MAX_PLAYERS]

I mean if someone type /kick 0 and another one suddenly type /kick 1 , first one is a slow typer and the both command will execute at once
Then what would be declared as id there?

Or all commands works separately for each 1?
Reply
#2

https://sampwiki.blast.hk/wiki/Scripting_Basics#Variables

I recommend you read that.

And to answer your question, no. It's a local variable.
Reply
#3

Quote:
Originally Posted by Arthur Kane
Посмотреть сообщение
https://sampwiki.blast.hk/wiki/Scripting_Basics#Variables

I recommend you read that.

And to answer your question, no. It's a local variable.
Thanks for fast reply and I mean global In game
Reply
#4

I don't understand what you're asking.
Reply
#5

I think it's better if you're going with method MAX_PLAYERS and don't forget about the timer kick otherwise it will just say to kicked player ("Server Closed the Connection")
Reply
#6

Quote:
Originally Posted by DarknesS1988
Посмотреть сообщение
I think it's better if you're going with method MAX_PLAYERS
No, it is not. It does not make sense to store per-player array just for 1 second until they get kicked? What is the purpose?

Local variable "id" is just fine, it does what it has to do and that's all you need. There is one (main) thread so they cannot be executed at the same time. After the code execution is finished, it is deleted and when another player types the command, it creates a new variable again. No conflicts.
Reply
#7

Код:
CMD:kick(playerid, params[]) // params is a string.
{
       new id;

       // you missed an extra bracket after 'id'
       if(sscanf(params, "u", id))  return scm(playerid, COLOR_USAGE, "USAGE:/kick [id]");
       if(id == INVALID_PLAYER_ID) return scm(playerid, COLOR_ERROR, "invalid id");

       Kick(id);
       return 1;
}
The code you have just given us is perfectly fine. I've improved it where I've noticed a couple of issues.
Reply
#8

Quote:
Originally Posted by Calisthenics
Посмотреть сообщение
No, it is not. It does not make sense to store per-player array just for 1 second until they get kicked? What is the purpose?

Local variable "id" is just fine, it does what it has to do and that's all you need. There is one (main) thread so they cannot be executed at the same time. After the code execution is finished, it is deleted and when another player types the command, it creates a new variable again. No conflicts.
Thank you very much bro I was looking for an answer like this

Quote:
Originally Posted by Infin1ty
Посмотреть сообщение
Код:
CMD:kick(playerid, params[]) // params is a string.
{
       new id;

       // you missed an extra bracket after 'id'
       if(sscanf(params, "u", id))  return scm(playerid, COLOR_USAGE, "USAGE:/kick [id]");
       if(id == INVALID_PLAYER_ID) return scm(playerid, COLOR_ERROR, "invalid id");

       Kick(id);
       return 1;
}
The code you have just given us is perfectly fine. I've improved it where I've noticed a couple of issues.
lol yeah, thanks it's just an example
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)