Having trouble with functions, stocks.
#1

So, here is the problem- I've tried making an "IsPlayerSuperAdmin" stock, but I have no idea how to do it.
I've made the following commands, but when one player is doing /login with the right password, it gives the whole server "IsPlayerSuperAdmin" permissions.
Here is the code:
Код:
new superadmin;
stock IsPlayerSuperAdmin(playerid)
{




 if(superadmin==1){
      return 1;
    }
  return 0;
}
Other commands I've made:
Код:
CMD:login(playerid, params[]){
    new password;
    if(sscanf(params, "i",password))return SendClientMessage(playerid, 0x33AA33AA, "USAGE: /login [PASSWORD]");
    if(password != blablabla) return SendClientMessage(playerid, 0x33AA33AA, "Wrong Password.");
    superadmin=1;
    SendClientMessage(playerid, 0x33AA33AA, "You have logged in.");
    return 1;
    }
Код:
CMD:kill(playerid, params[]){
    new TargetID;
    if(!IsPlayerSuperAdmin(playerid)) return SendClientMessage(playerid,-1,"You're not connected as a super Admin.");
    if(sscanf(params, "u", TargetID))return SendClientMessage(playerid, 0x33AA33AA, "USAGE: /kill [Target ID]");
    if(!IsPlayerConnected(TargetID)) return SendClientMessage(playerid, 0x33AA33AA, "This player isn't connected.");
    SetPlayerHealth(TargetID, 0.0);
    SendClientMessage(playerid, 0x33AA33AA, "You have killed the player.");
    return 1;
    }
Reply
#2

What you have done wrong is this:
new superadmin;

The line above you used, this isn't a player but a global one.
So it should be this:

new superadmin[MAX_PLAYERS];

So this would be a correct check:
PHP код:
stock IsPlayerSuperAdmin(playerid)
{
 if(
superadmin[playerid]==1){
      return 
1;
    }
  return 
0;

About your login:

PHP код:
CMD:login(playeridparams[]){
    new 
password;
    if(
sscanf(params"i",password))return SendClientMessage(playerid0x33AA33AA"USAGE: /login [PASSWORD]");
    if(
password != blablabla) return SendClientMessage(playerid0x33AA33AA"Wrong Password.");
    
superadmin=1;
    
SendClientMessage(playerid0x33AA33AA"You have logged in.");
    return 
1;
    } 
superadmin=1; sets only one var while in this case we want to use superadmin[playerid]=1;

Also don't forget to empty the it on connect or disconnect otherwise when ID5 admin leaves, the next ID5 is still admin.
superadmin[playerid]=0;
Reply
#3

Alright mate, I've tried it out now and I've figured my problem, thank you so much for your quick response, it's much appreciated!
Have an awesome day.
Reply
#4

Quote:
Originally Posted by XpoZzA
Посмотреть сообщение
Alright mate, I've tried it out now and I've figured my problem, thank you so much for your quick response, it's much appreciated!
Have an awesome day.
Thanks, You too mate. Glad i could help. Its good to see some new faces
Reply
#5

Please, don't use "stock" until you are making an include -> https://sampforum.blast.hk/showthread.php?tid=570635
Also this code can be shorted:
PHP код:
stock IsPlayerSuperAdmin(playerid

 if(
superadmin[playerid]==1){ 
      return 
1
    } 
  return 
0

PHP код:
IsPlayerSuperAdmin(playerid
      return (
superadmin[playerid]); 
Reply
#6

Oh, alright. Thank you!
Reply
#7

Why don't you just simply use boolean variable?

PHP код:
new bool:superadmin[MAX_PLAYERS]; 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)