Question regarding %
#1

You know when you do admin commands like kick etc...

And you get something like this:

"Admin Action: %s has been banned by %s. reason: %s"

I am talking about the highlighted ones, as they are used for GetName playerid or something like that so it sends the message to everyone like

Admin Action: Player1 has been banned by Admin 1. reason:

and I am wondering how do you do it because when I tried to add that similar stuff to my vehicle respawn I get errors:

pawn Код:
(756) : error 017: undefined symbol "str"
(756) : error 017: undefined symbol "str"
(756) : error 029: invalid expression, assumed zero
(756) : fatal error 107: too many error messages on one line
and the code is:

pawn Код:
CMD:respawnveh(playerid, params[])
{
    #pragma unused params
    if(PlayerInfo[playerid][Admin] < 3)
    return SendClientMessage( playerid, COLOR_RED, "[ERROR]:You are not a Public Safety Member! Or your PSM level is too low!" );
    new bool:VehicleUsed[MAX_VEHICLES] = false;
    foreach(Character, i)//for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInAnyVehicle(i)) VehicleUsed[GetPlayerVehicleID(i)] = true;
    }
    for(new i = 0; i < MAX_VEHICLES; i++)
    {
        if(VehicleUsed[i] == false) SetVehicleToRespawn(i);
        format(str, sizeof(str), "All unccupied vehicles have been respawned by %s ", aName); //newly added
    }
}
Could anyone explain to me how it is done?

Thank you if you are looking into the topic!
Reply
#2

pawn Код:
CMD:respawnveh(playerid, params[])
{
    #pragma unused params
    if(PlayerInfo[playerid][Admin] < 3) return SendClientMessage( playerid, COLOR_RED, "[ERROR]:You are not a Public Safety Member! Or your PSM level is too low!" );
    new bool:VehicleUsed[MAX_VEHICLES] = false, str[128] = "\0", pName[MAX_PLAYER_NAME];
    foreach(Character, i)//for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInAnyVehicle(i)) VehicleUsed[GetPlayerVehicleID(i)] = true;
    }
    for(new i = 1; i < MAX_VEHICLES; i++)
    {
        if(VehicleUsed[i] == false) SetVehicleToRespawn(i);
    }
    GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
    format(str, sizeof(str), "All unccupied vehicles have been respawned by %s(%d)", pName, playerid); //newly added
    SendClientMessageToAll(-1, str);
    return;
}
Reply
#3

Quote:
Originally Posted by Donya
Посмотреть сообщение
pawn Код:
CMD:respawnveh(playerid, params[])
{
    #pragma unused params
    if(PlayerInfo[playerid][Admin] < 3) return SendClientMessage( playerid, COLOR_RED, "[ERROR]:You are not a Public Safety Member! Or your PSM level is too low!" );
    new bool:VehicleUsed[MAX_VEHICLES] = false, str[128] = "\0", pName[MAX_PLAYER_NAME];
    foreach(Character, i)//for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInAnyVehicle(i)) VehicleUsed[GetPlayerVehicleID(i)] = true;
    }
    for(new i = 1; i < MAX_VEHICLES; i++)
    {
        if(VehicleUsed[i] == false) SetVehicleToRespawn(i);
    }
    GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
    format(str, sizeof(str), "All unccupied vehicles have been respawned by %s(%d)", pName, playerid); //newly added
    SendClientMessageToAll(-1, str);
    return;
}
Could you please explain to me how it is done? :\
Reply
#4

He only define your "aName"
For you get player name, you must do this:
pawn Код:
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
Then you must know that "%s" is used for letters,words
This "%d" only for numbers
Reply
#5

Quote:
Originally Posted by Colossus_
Посмотреть сообщение
%s = strings(letters and numbers)
%i / %d = integeras(numbers)
%f = floats(health/positions)

Learn sscanf2 and it will all make sence.

Ill finish that line..

pawn Код:
new str[128], aName[64]; //new variables to format the string and get the name from the playerid..
GetPlayerName(playerid,aName,sizeof(aName));//get the name from playerid..
format(str, sizeof(str), "All unccupied vehicles have been respawned by %s ", aName); //newly added (your line) //format the string..
SendClientMessage(playerid,0x0,str);//and send the playerid the formatted message with black(0x0)colour text.
You can show there id like so

pawn Код:
format(str, sizeof(str), "All unccupied vehicles have been respawned by %s [%d]", aName, playerid); //newly added (your line)
there name is a string..
and there id is a number(integera)..

Good to see you using zcmd even though your asking these questions.
Thanks to you three lol

and as well Colossus_ I have started scripting 1 week ago and I did not want to play around with old crappy cmds so people recommended me zcmd and it is easier than the older ones and faster tho Im sorry for my lack of knowledge about it lol it happens
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)