SA-MP Forums Archive
2 errors. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: 2 errors. (/showthread.php?tid=515832)



2 errors. - Johnson_Brooks - 28.05.2014

[pawn]
C:\Users\Notis\Desktop\GTA SA-MP Server\gamemodes\CnR.pwn(1931) : error 006: must be assigned to an array
C:\Users\Notis\Desktop\GTA SA-MP Server\gamemodes\CnR.pwn(1932) : error 006: must be assigned to an array[/code]

pawn Код:
On the cmd:ban command:
    PlayerInfo[targetid][pBanned] = 1;
    PlayerInfo[targetid][pBannedBy] = pName; // error 1
    PlayerInfo[targetid][pBannedFor] = reason; //error 2
Why ?


Re: 2 errors. - Konstantinos - 28.05.2014

You can use strcat, memcpy or format for copying a string to another.

pawn Код:
strcpy(PlayerInfo[targetid][pBannedBy], pName, MAX_PLAYER_NAME);
strcpy(PlayerInfo[targetid][pBannedFor], reason, sizeof (reason));
pawn Код:
#define strcpy(%0,%1,%2) strcat((%0[0] = '\0', %0), %1, %2)



Re: 2 errors. - Rittik - 28.05.2014

pBannedBy[128];
pBannedFor[128];


Re: 2 errors. - Johnson_Brooks - 28.05.2014

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
You can use strcat, memcpy or format for copying a string to another.

pawn Код:
strcpy(PlayerInfo[targetid][pBannedBy], pName, MAX_PLAYER_NAME);
strcpy(PlayerInfo[targetid][pBannedFor], reason, sizeof (reason));
pawn Код:
#define strcpy(%0,%1,%2) strcat((%0[0] = '\0', %0), %1, %2)
What i want to do there is to save the Admin that banned the player and the reason . Thats why i used that code . But still your code is giving me more errors .


Re: 2 errors. - Konstantinos - 28.05.2014

That's what it does and it shouldn't give you errors unless you've done something wrong.

Can you post the errors and the code?


Re: 2 errors. - Lacamora - 28.05.2014

Quote:

#define strcpy(%0,%1,%2) strcat((%0[0] = '\0', %0), %1, %2)

why re you define strcpy as strcat
he can simply stock the name and the reason without using those


Re: 2 errors. - Lacamora - 28.05.2014

PHP код:
PlayerInfo[targetid][pBanned] = 1;
    
PlayerInfo[targetid][pBannedBy] = pName// error 1
    
PlayerInfo[targetid][pBannedFor] = reason//error 2 
change to

PHP код:
PlayerInfo[targetid][pBanned] = 1;
new 
text1[50],text[40];
format(text1,sizeof(text1), " %s.",pName);
PlayerInfo[targetid][pBannedBy] = text1;
format(text,sizeof(text), " %s.",reason);
PlayerInfo[targetid][pBannedBy] = text
PS : sorry for double post


Re: 2 errors. - Johnson_Brooks - 28.05.2014

Quote:
Originally Posted by Lacamora
Посмотреть сообщение
PHP код:
PlayerInfo[targetid][pBanned] = 1;
    
PlayerInfo[targetid][pBannedBy] = pName// error 1
    
PlayerInfo[targetid][pBannedFor] = reason//error 2 
change to

PHP код:
PlayerInfo[targetid][pBanned] = 1;
new 
text1[50],text[40];
format(text1,sizeof(text1), " %s.",pName);
PlayerInfo[targetid][pBannedBy] = text1;
format(text,sizeof(text), " %s.",reason);
PlayerInfo[targetid][pBannedBy] = text
PS : sorry for double post
Im getting the same errors with your code .
Anyways here's the full code
pawn Код:
CMD:ban(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] < 1) return NOACCESS
    new targetid, reason[128];
    if(sscanf(params, "us[30]", targetid, reason)) return SendClientMessage(playerid, -1, "USAGE: /ban [id] [reason]");
    if(!IsPlayerConnected(targetid) || targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "The player is not connected.");
    new pName[MAX_PLAYER_NAME], targetname[MAX_PLAYER_NAME], day, month, year, hour, minute, second, string[150];
    GetPlayerName(playerid,pName,MAX_PLAYER_NAME);
    GetPlayerName(playerid,targetname,MAX_PLAYER_NAME);
    getdate(day, month, year);
    gettime(hour, minute, second);
    format(string, sizeof(string), "[{FF0000}BAN{EEEEEE}]Administrator %s has banned %s for %s",pName,targetname,reason);
    SendClientMessageToAll(COLOR_WHITE,string);
    format(string, sizeof(string),"[{FF0000}BAN{EEEEEE}]Administrator %s has banned you for %s",pName,reason);
    SendClientMessage(targetid,COLOR_WHITE,string);
    SendClientMessage(targetid,COLOR_WHITE,"--------------------------------------");
    SendClientMessage(targetid, COLOR_RED, "Ban Information");
    format(string, sizeof(string), "Banned by: %s", pName);
    SendClientMessage(targetid, COLOR_RED, string);
    format(string, sizeof(string), "Banned for: %s", reason);
    SendClientMessage(targetid, COLOR_RED, string);
    format(string, sizeof(string), "Ban date: %d/%d/%d at %d:%d:%d.", day, month, year, hour, minute, second);
    SendClientMessage(targetid, COLOR_RED, string);
    SendClientMessage(targetid, COLOR_WHITE,"Please press the F8 button to take a screenshot to use it on your appeal");
    SendClientMessage(targetid,COLOR_WHITE,"--------------------------------------");
    PlayerInfo[targetid][pBanned] = 1;
//    PlayerInfp[targetid][pBannedBy] = pName; // error lines
//    PlayerInfo[targetid][pBannedFor] = reason; // error lines
    SetTimerEx("BanPlayer", 200, false, "i", targetid);
    return 1;
}



Re: 2 errors. - Konstantinos - 28.05.2014

Quote:
Originally Posted by Lacamora
Посмотреть сообщение
why re you define strcpy as strcat
he can simply stock the name and the reason without using those
When using strcat for copying a string to another, you have to reset it first.

@Johnson_Brooks: All I see is the lines you had. Change them to those I told you and add the macro to the script. If you still you get the errors you mentioned, post the code and the errors.


Re: 2 errors. - Johnson_Brooks - 28.05.2014

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
When using strcat for copying a string to another, you have to reset it first.

@Johnson_Brooks: All I see is the lines you had. Change them to those I told you and add the macro to the script. If you still you get the errors you mentioned, post the code and the errors.
Код:
C:\Users\\Desktop\GTA SA-MP Server\gamemodes\CnR.pwn(12) : warning 201: redefinition of constant/macro (symbol "strcpy(%0,%1,%2)")
C:\Users\\Desktop\GTA SA-MP Server\gamemodes\CnR.pwn(1939) : error 001: expected token: ")", but found "["
C:\Users\\Desktop\GTA SA-MP Server\gamemodes\CnR.pwn(1939) : warning 215: expression has no effect
C:\Users\\Desktop\GTA SA-MP Server\gamemodes\CnR.pwn(1939) : error 001: expected token: ";", but found "]"
C:\Users\\Desktop\GTA SA-MP Server\gamemodes\CnR.pwn(1939) : error 029: invalid expression, assumed zero
C:\Users\Desktop\GTA SA-MP Server\gamemodes\CnR.pwn(1939) : fatal error 107: too many error messages on one line