PlayPlayerSound problem
#1

Hello,

I've created a /setadmin command and i have added a sound.

Код:
printf("Admin %s made %s a level %d admin.", player, giveplayer, level);
					   
                       PlayerPlaySound(playerid,1097,0.0,0.0,0.0);
I would like to send the sound to the player but i can't use "player" because it's the Nick of the player.

So i'm finding a cmd to get players id from name

Thanks


Regards
Reply
#2

A little googling would help you. Here's what I found.

pawn Код:
stock GetPlayerIdFromName(playername[])
{
  for(new i = 0; i <= MAX_PLAYERS; i++)
  {
    if(IsPlayerConnected(i))
    {
      new playername2[MAX_PLAYER_NAME];
      GetPlayerName(i, playername2, sizeof(playername2));
      if(strcmp(playername2, playername, true, strlen(playername)) == 0)
      {
        return i;
      }
    }
  }
  return INVALID_PLAYER_ID;
}
Source: https://sampforum.blast.hk/showthread.php?tid=97246
Reply
#3

Thanks, yea i already found that but i don't know how to use it.
I'm a newbie

Regards
Reply
#4

I've tried it but it doesnt work.

Код:
newid1;

printf("Admin %s made %s a level %d admin.", player, giveplayer, level);
					  //id = GetPlayerID(player);
                       
					id1 = GetPlayerIdFromName(giveplayer);
					
                  SetTimer("MyTimer",10000,0); // Stop Sound
                  PlayerPlaySound(id1,1057,0.0,0.0,0.0);
                  PlayerPlaySound(id1,1097,0.0,0.0,0.0);
I get the sound and not the player
Reply
#5

Can you give us the whole command please
Reply
#6

Код:
 PlayerPlaySound(giveplayer,1057,0.0,0.0,0.0);
                  PlayerPlaySound(giveplayer,1097,0.0,0.0,0.0);
I'm on my phone.
Reply
#7

Quote:
Originally Posted by Dice_
Посмотреть сообщение
Код:
 PlayerPlaySound(giveplayer,1057,0.0,0.0,0.0);
                  PlayerPlaySound(giveplayer,1097,0.0,0.0,0.0);
I'm on my phone.
"giveplayer" is a string.

Surely you must have the id of the player somewhere though

What command processor are you using,
Are you using SSCANF,
We need all the information to help you.
Reply
#8

Here is all the code :

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	new cmd[256], idx;
cmd = strtok(cmdtext, idx);
if(strcmp(cmd, "/setadmin", true) == 0)
{
       new string[128];
      
       new tmp[256];
       
       new giveplayerid;
       if (IsPlayerAdmin(playerid))
       {
               tmp = strtok(cmdtext, idx);
               if(!strlen(tmp))
               {
                       SendClientMessage(playerid, 0xE70000FF, "USAGE: /setadmin [playerid] [level]");
                       SendClientMessage(playerid, 0xE70000FF, "FUNCTION: Player will be an admin.");
                       return 1;
               }
               giveplayerid = ReturnUser(tmp);
               tmp = strtok(cmdtext, idx);
               new level = strval(tmp);
               new level1 = 0;
               new player[MAX_PLAYER_NAME], giveplayer[MAX_PLAYER_NAME]; //for sound

    
               
               
               
               if(giveplayerid != INVALID_PLAYER_ID)
               {
                       GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                       GetPlayerName(playerid, player, sizeof(player));
                       PlayerInfo[giveplayerid][AdminLevel] = level;
                       
                       new pname[128]; // The name length
	new file[128]; // The file length
	GetPlayerName(playerid, pname, sizeof(pname)); //  This get's the player name with the name length
    format(file, sizeof(file), savefolder,pname); // Formatting file
    if(!dini_Exists(file)) { // If the file exist
    }
    else { // if not
        
        dini_IntSet(file, "Level", PlayerInfo[playerid][AdminLevel]);
    }


					   printf("Admin %s made %s a level %d admin.", player, giveplayer, level);
					  //id = GetPlayerID(player);
                       
					id1 = GetPlayerIdFromName(giveplayer);
					
                  SetTimer("MyTimer",10000,0); // Stop Sound
                  PlayerPlaySound(id1,1057,0.0,0.0,0.0);
                  PlayerPlaySound(id1,1097,0.0,0.0,0.0);
                       
                       
                       if (PlayerInfo[playerid][AdminLevel] == 9) {

  SendClientMessage(playerid, 0x00DB00FF, "YOU ARE NOW A STAFF MANAGER OF THE SERVER(Level 9)");


	}else {
    

    
                       
                       
                       SendClientMessage(giveplayerid, 0x00DB00FF,"------------------------------------------------------------------------------");
                       format(string, sizeof(string), "CONGRATS ! YOU ARE NOW AN ADMINISTRATOR LEVEL %d THANKS TO %s.", level,  player);
                       SendClientMessage(giveplayerid, 0x00DB00FF, string);
                       SendClientMessage(giveplayerid, 0x00DB00FF, "------------------------------------------------------------------------------");
                       
                       format(string, sizeof(string), "You have given %s level %d admin.",  giveplayer,PlayerInfo[giveplayerid][AdminLevel]);
                               SendClientMessage(playerid, 0x00C2ECFF, string);

							   }
               }
               else if(giveplayerid == INVALID_PLAYER_ID)
               {
                       format(string, sizeof(string), "%i is not an active player.", giveplayerid);
                       SendClientMessage(playerid, 0xE60000FF, string);
               }
       }
       else
       {
           SendClientMessage(playerid, 0xE70000FF, "Only the owner can promote!");
       }
       return 1;
}
Reply
#9

Firstly, install SSCANF if its not already in use it makes life a lot easier for sorting strings out.
https://sampforum.blast.hk/showthread.php?tid=570927

Secondly use the code i have supplied (It should work if it doesnt feel free to PM me)

Lastly I suggest moving to a command processor like ZCMD or something of the sort.

Код:
#include <sscanf>

public OnPlayerCommandText(playerid, cmdtext[])
{
	new params[256], cmd[24];
	sscanf(cmdtext, "ss", cmd, params);
	
	if(strcmp(cmd, "/setadmin", true) == 0)
	{
		new targetid, level;
	   
		if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xE70000FF, "Only the owner can promote!");
		if(sscanf(params, "ri", targetid, level)) return SendClientMessage(playerid, 0xE70000FF, "/setadmin [Player/ID] [Level]" );
		if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, 0xE70000FF, "The player you have selected is not connected" );
		if(targetid == playerid) return SendClientMessage(playerid, 0xE70000FF, "You cannot set your own level :/");
		
		//Set the information
		//PlayerInfo[targetid][AdminLevel] = level;

		//Save the information
		new file[128];
		format(file, sizeof(file), savefolder, GetPName(targetid));
		if(dini_Exists(file)) dini_IntSet(file, "Level", level);

		//Play a sound
		PlayerPlaySound(targetid,1057,0.0,0.0,0.0);
		PlayerPlaySound(targetid,1097,0.0,0.0,0.0);
		SetTimer("MyTimer",10000,0); // Stop Sound
		
		//Print to log
		printf("Admin %s made %s a level %d admin.", GetPName(playerid), GetPName(targetid), level);

		//Send message to self confirming what you have done
		new str[64];
		format(str, sizeof(str), "You have given %s level %d admin.",  GetPName(targetid), level);
		SendClientMessage(playerid, 0x00C2ECFF, str);
	   
		//Send message to the user you made admin
		if(level == 9)  SendClientMessage(targetid, 0x00DB00FF, "YOU ARE NOW A STAFF MANAGER OF THE SERVER(Level 9)");
		else 
		{
			SendClientMessage(targetid, 0x00DB00FF,"------------------------------------------------------------------------------");
			
			format(str, sizeof(str), "CONGRATS ! YOU ARE NOW AN ADMINISTRATOR LEVEL %d THANKS TO %s.", level,  GetPName(playerid));
			SendClientMessage(targetid, 0x00DB00FF, str);
			
			SendClientMessage(targetid, 0x00DB00FF, "------------------------------------------------------------------------------");
		}
		
	}
	return 1;
}

stock GetPName(playerid)
{
	new pname[24];
	GetPlayerName(playerid, pname, 24);
	return pname;
}
Reply
#10

Thanks alot, im gonna try it
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)