Array question.
#1

Hi, I'm a newbie scripter and I have a question.
How can I know what value to put inside the [] in the "new Reason" array?
PHP код:
COMMAND:report(playerid,params[])
{
        new 
Target
        new 
Reason[];//How can I know what value to put inside []?
        
if(!sscanf(params"us[32]",TargetReason))
        {
        if(
Target == playerid) return SendClientMessage(playeridCOLOR_RED"SERVER: Cant perform this command on yourself!"); //comment this line if you want to try this cmd on yourself
        
if(!IsPlayerConnected(Target)) //if the ID is invalid
        
return SendClientMessage(playeridCOLOR_RED"ERROR: Player is not connected!"); //send the player a message, that the ID doesn't exist
        
new tname[MAX_PLAYER_NAME]; //the name of player one (reporting)
        
new pname[MAX_PLAYER_NAME]; //the name of player two (the reported)
        
GetPlayerName(Target,tname,sizeof(tname)); //get (receive) the player's name for the first
        
GetPlayerName(playerid,pname,sizeof(pname)); //get (receive) the player's name for the second
        
new rstring[256]; //the report-string
        
format(rstring,sizeof(rstring),"* Player %s(%d) reported %s(%d)! (Reason: %s)"pname,playerid,tname,Target,Reason); //only admins will receive this message! a specific player with a reason got reported, here we'll use all variables created
        
SendMessageToAdmins(COLOR_WHITE,rstring); //we'll talk about that later
        //NOW HERE, we'll open the reportpath and WRITE into it
        
new File:Log fopen(reportPATHio_append); //here you're opening the path defined
        
new logData[128]; //create the logdata we wanna write in
        
new name[MAX_PLAYER_NAME]; //define the name again
        
GetPlayerName(Target,name,sizeof(name)); //receive the name again
        
new fTime[6]; //create the specific time for the report
        
getdate(fTime[0], fTime[1], fTime[2]); //get the report's date
        
gettime(fTime[3], fTime[4], fTime[5]); //get the report's time
        
format(logDatasizeof logData"[%02d/%02d/%04d || %02d:%02d:%02d]%s got reported by %s! (Reason: %s)\r\n"fTime[2], fTime[1], fTime[0], fTime[3], fTime[4], fTime[5], tnamepnameReason); //this will write everything (name,reason,time,date etc.) into the logdata
        
fwrite(LoglogData); //write it into the path
        
fclose(Log); //close the log, finished!
        
}
        else return 
SendClientMessage(playeridCOLOR_YELLOW"USAGE: /report <playerid> <reason>"); //detects the wrong params from sscanf and send the client this message
        
return 1;

Reply
#2

Maximum chat input is 128. Minus the length of the command and minus the name or id. So you'd be looking at 100-ish.
Reply
#3

There is a link where I can learn arrays?
I still don't know why I have to put
PHP код:
new Reason[128]; 
Reply
#4

https://sampwiki.blast.hk/wiki/Scripting_Basics#Arrays
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)