Please help with format
#1

Hello, I am making my first format line, an I have a problem... here is my code:

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    new string[256];
    new kName[MAX_PLAYER_NAME];
    new pName[MAX_PLAYER_NAME];

    kName = GetPlayerName(killerid, kName, sizeof(kName));
    pName = GetPlayerName(playerid, pName, sizeof(pName));

    format(string, sizeof(string), "Dear, %s, if player %s will kill you again please report him to administrators.", pName, kName);
    GameTextForPlayer(playerid, string, 5000, 5);

  SendDeathMessage(killerid, playerid, reason);
    GivePlayerMoney(killerid, -10000);
    GameTextForPlayer(killerid, "~r~Fighting ~w~is ~r~NOT ~g~allowed~n~~w~in this ~g~server~n~~w~go to ~y~//dm!", 5000, 5);
    return 1;
}

And my 2 errors:

[code=errors]
C:\Documents and Settings\Alive\Desktop\alive's server\gamemodes\alive.pwn(92) : error 033: array must be indexed (variable "kName")
C:\Documents and Settings\Alive\Desktop\alive's server\gamemodes\alive.pwn(93) : error 033: array must be indexed (variable "pName")
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


2 Errors.
[/code]

Line 92 = kName = GetPlayerName(killerid, kName, sizeof(kName));
Line 93 = pName = GetPlayerName(playerid, pName, sizeof(pName));

I am really stuck at this.. So can someone help me, please?
Would be very nice...
Reply
#2

add on ur top of ur script

Код:
new pName;
new kName;
Reply
#3

Quote:
Originally Posted by [TDR
Strike ]
add on ur top of ur script

Код:
new pName;
new kName;
Rofl, nice solution, making the local strings into global integers.

Don't do that, you don't understand what you're doing. The idea of creating these strings is to store names, as shown in the first post.

To fix it, do this:
pawn Код:
GetPlayerName(killerid, kName, sizeof(kName));
GetPlayerName(playerid, pName, sizeof(pName));
What you were doing was getting the value returned by GetPlayerName(), not the name itself, which is most likely 0 or 1, and storing it to each array respectively, but you didn't tell the compiler which cell of the array to store the value to, so it issued an error.

And by the way, your format() line is valid, so don't worry about that. Though it's not going to use all 256 characters you allow it to.

Hope this helps,

~Cueball~
Reply
#4

Thanks, Cueball.. (Cuecumber)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)