Register

If you already have an account with us, please use the login panel below to access your account.

Results 1 to 17 of 17
  1. #1
    6 Year Veteran Harry Slice's Avatar
    Join Date
    Jun 2013
    Location
    Netherlands.
    Age
    34
    Posts
    195
    In-Game Name(s)
    Harry_Slice
    Post Thanks / Like

    Scripting Tutorial || Basic Commands || Taking suggestions!

    Hi,

    First off I would highly recommend you to read James' tutorial: Click here, his tutorial is great to start to understand the basics of Pawn.

    I'll be talking on my tutorial about commands which are made with both ZCMD and SSCANF.

    Link to ZCMD: Click here!
    Link to SSCANF: Click here!

    Contents:

    1.0 - What are ZCMD and SSCANF?
    1.1 - What is ZCMD?
    1.2 - What is SSCANF?

    2.0 - First commands!
    2.1 - Ban command!
    2.2 - Suggestion!
    2.3 - Advanced /report command

    1.1: What is ZCMD? ZCMD is a command processor in a include which has been created by Zeex, it is one of the fastest command processors out there.
    1.2: What is SSCANF? SSCANF is a plugin that takes a string and extracts different types of data from it., I'do highly recommend to read this: Click here!, it will make you understand it easier.

    2.1: To make a /ban command you need one include and one plugin: ZCMD & SSCANF.

    Okay let's go to the code, this is going to be the base where we work from:

    Needed functions for this command:

    Code:
    stock PlayerRPName(playerid)
    {
        new name[MAX_PLAYER_NAME];
        strmid(name, str_replace('_', ' ', ReturnPlayerName(playerid)), 0, MAX_PLAYER_NAME); // Removes the underscore between the player's forename and surname
        return name; // Returns the new name without the '_'
    }
    
    stock ReturnPlayerName(playerid)
    {
    	new name[MAX_PLAYER_NAME+1]; // Making a new string
    	GetPlayerName(playerid, name, sizeof(name));  // Get's the player's name.
    	return name; // Returns it
    }
    Due to a security update from 0.3x they have decided that when there is being called that a player is kicked/banned, he will get kicked/banned before any other functions, therefore you have to delay the kick/ban with a delay of 1 second so he can recieves the clientmessage about him being kicked/banned.

    Therefore you need this(This is what the timer does when it's being called):
    Code:
    forward BanTimer(playerid);
    public BanTimer(playerid)
    {
    	return Ban(playerid);
    }
    It'll become something like this:

    Code:
    CMD:ban(playerid, params[])
    {
        if(IsPlayerAdmin(playerid)) // Checks if the player who wrote the command is admin if so, continue!
        {
            new userid, reason[128], string[128]; // userid = the target's playerid, reason = his ban reason, string = we will format our clientmessages into that!
    	    if (sscanf(params, "us[128]", userid, reason)) // This will check wether the /ban command contains a player & string.
    	        return SendClientMessage(playerid, 0xFFFFFFFF, "/ban [playerid] [reason]"); // If not, it will send the synthaxmessage!
    	        
    	    format(string, sizeof(string), "AdmCmd: %s was banned by %s, reason: %s", PlayerRPName(userid), PlayerRPName(playerid), reason); // Formats the string!
    		SendClientMessageToAll(0xFF6347AA, string); // Send a global message to every player that the player has been banned.
    		
    		SetTimerEx("BanTimer", 1000, false, "i", userid); // Sets a timer on the userid, banning him when 1 sec passed to he is able to see his ban reason.
        
        }
    	return 1; // Just to know that the command has been recieved.
    }
    Image:



    2.2: Suggest on this thread where you would like to see a tutorial about, I'll take everything, I can better spend my time by making the things the people want instead of taking random commands that most people can make from theirselves.

    2.3: Okay, thanks for the suggestion in the first place, we will use the functions we used last time again, to get the player's name ect, we will be using the foreach include by Y_Less, it's a better loop than the regular one.

    We will be using an enumerator to save the player's report text! Here is the code to make a new enumerator!

    Code:
    enum _AccountData
    {
    	pReportText[128]
    };
    new AccountData[MAX_PLAYERS][_AccountData];
    We will have to reset the string at, under OnPlayerConnect add:
    Code:
    format(AccountData[playerid][pReportText], 5, "None"); // Clears it!
    The command will look like this:

    IMAGE:



    Text:

    Code:
    CMD:report(playerid, params[])
    {
    	new string[128], reason[128]; // string = string to format for the clientmessage, reason = /report [text]!
    	if (sscanf(params, "s[128]", reason)) // This will check wether the /report command contains a string.
    		return SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /report [text]"); // If not, it will send the synthaxmessage!
    		
    	if(AccountData[playerid][pReportText]) return SendClientMessage(playerid, 0xFFFFFFF, "You already got a pending report!"); // Checking if the player got a report
    
    	SendClientMessage(playerid, "Your report message has been sent to online administrators."); // Sends the client the the player who wrote the comamnd!
        format(string, sizeof(string), "Report from [%d]%s: %s", playerid, PlayerRPName(playerid), reason); // Make the message correctly to send it to the admins
    
    	format(AccountData[playerid][pReportText], 128, "%s", reason); // Adds the reason to his reporttext variable!
    		    
    	foreach(Player, i)
    	{
    	    if (IsPlayerAdmin(i)) // Check if the player is rcon admin, if so continue!
    	    	SendClientMessage(i, 0xF5DEB3FF, string); // Sends the message to them!
    	}
    	return 1; // Just to know that the command has been recieved.
    }
    Okay, now the /acceptreport & /denyreport commands.

    We will start off with the /acceptreport command:

    Image:



    Code:

    Code:
    CMD:acceptreport(playerid, params[])
    {
        if (IsPlayerAdmin(playerid)) // Checks if the player is RCON admin
        {
            new target, string[128]; // new variable, and a new string for our messages!
            
            if  (sscanf(params, "u", target)) // This will check wether the /report command contains a playerid.
    			return SendClientMessage(playerid, 0xFFFFFFF, "USAGE: /acceptreport [playerid]"); // If not, it will send the synthaxmessage!
        
    		if(!strcmp(AccountData[target][pReportText], "None", true, 5)) // Compares the reportext to the basic, if it's the same the player didn't /report!
    			return SendClientMessage(playerid, 0xFFFFFFF, "This player doens't got a pending report!"); // Checks if the player got a report, if not send the message!
    
            format(string, sizeof(string), "Admin %s accepted your report", PlayerRPName(playerid)); // Message that goes to the player with an active report!
    		SendClientMessage(target, 0xFFFFFFF, string); // Send the message to the person who did /report!
    		
    		format(string, sizeof(string), "You have accepted %s's report", PlayerRPName(target)); // Message that goes to the admin who accepted the /report!
    		SendClientMessage(playerid, 0xFFFFFFF, string); // Send the message to the person who did /report!
    		
    		format(AccountData[playerid][pReportText], 5, "None"); // Clears it!
    	}
    	return 1;
    }
    /denyreport!

    IMAGE:



    CODE:

    Code:
    CMD:denyreport(playerid, params[])
    {
        if (IsPlayerAdmin(playerid)) // Checks if the player is RCON admin
        {
            new target, reason[128], string[128]; // new variable, and a new string for our messages, reason for denial!
    
            if  (sscanf(params, "us[128]", target, reason)) // This will check wether the /report command contains a playerid & a string.
    			return SendClientMessage(playerid, 0xFFFFFFF, "USAGE: /denyreport [playerid] [reason]"); // If not, it will send the synthaxmessage!
    
    		if(!strcmp(AccountData[target][pReportText], "None", true, 5)) // Compares the reportext to the basic, if it's the same the player didn't /report!
    			return SendClientMessage(playerid, 0xFFFFFFF, "This player doens't got a pending report!"); // Checks if the player got a report, if not send the message!
    
            format(string, sizeof(string), "Admin %s declined your report reason: %s", PlayerRPName(playerid), reason); // Message that goes to the player with an active report!
    		SendClientMessage(target, 0xFFFFFFF, string); // Send the message to the person who did /report!
    
    		format(string, sizeof(string), "You have declined %s's report, reason: %s", PlayerRPName(target), reason); // Message that goes to the admin who accepted the /report!
    		SendClientMessage(playerid, 0xFFFFFFF, string); // Send the message to the person who did /report!
    		
    		format(AccountData[playerid][pReportText], 5, "None"); // Clears it!
    	}
    	return 1;
    }
    Last edited by Harry Slice; 3rd June 2014 at 04:19 AM.

  2. Laughed at Moke_Clark laughed at this post
    Likes Arn, Cartorious., Hyder, Moke_Clark liked this post
  3. #2
    Banned 500 Posts
    Join Date
    Jun 2013
    Posts
    660
    In-Game Name(s)
    SSS
    Post Thanks / Like
    Good job Harry, I was about to write the same thing.

  4. Laughed at JoeSlice, Mike. laughed at this post
  5. #3
    4 Year Veteran 500 Posts500 Posts500 Posts500 Posts Flux's Avatar
    Join Date
    Aug 2013
    Location
    United Kingdom
    Posts
    2,255
    In-Game Name(s)
    Calvin_Adam
    Post Thanks / Like
    I'm going to keep it off the Featured Guides list for now, however when you've added some more content (just a bit more, not loads) requested by users then I'll add it.

    Good job so far!


  6. #4
    6 Year Veteran Harry Slice's Avatar
    Join Date
    Jun 2013
    Location
    Netherlands.
    Age
    34
    Posts
    195
    In-Game Name(s)
    Harry_Slice
    Post Thanks / Like
    Quote Originally Posted by Calv View Post
    I'm going to keep it off the Featured Guides list for now, however when you've added some more content (just a bit more, not loads) requested by users then I'll add it.

    Good job so far!
    I am waiting for suggestions :)

  7. #5
    Head Administrator 500 Posts500 Posts500 Posts500 Posts500 Posts
    Join Date
    Nov 2011
    Location
    Estonia
    Posts
    5,401
    In-Game Name(s)
    Sweety Bellik Corleon
    Post Thanks / Like
    Quote Originally Posted by StevenRuhl View Post
    Good job Harry, I was about to write the same thing.
    'Hi im R-T-even Suhl, i'm from 2009 ' (take it as a joke next time steven ruhl)

    Yeah time to learn !
    Last edited by Sweety; 2nd June 2014 at 02:58 PM.
    Sweety Bellik Corleon


    Cece / Gabriele / Hayakun / Divya / Candie

  8. Likes Mike. liked this post
  9. #6
    8 Year Veteran 500 Posts Agent Gideon's Avatar
    Join Date
    Jul 2013
    Location
    Georgia
    Posts
    945
    In-Game Name(s)
    Jason Gideon
    Post Thanks / Like
    I'm a programmer IRL + have PAWNO experience aswell. So, this guide was not bad at all. However, for the guy who do not know anything about programming, it's pretty hard.

    First, you should have explained what includes were. What functions could do. You should have spoken about variables too.

    Anyway, good job.
    Last edited by Agent Gideon; 2nd June 2014 at 02:17 PM.

    Jason Gideon, Level 21

    Programming languages which I know: C# (OOP, ASP.Net, ASP.Net MVC and etc), C++, Java(Swing, JavaFX, Android), HTML & Css (Even though they are not programming language), Javascript (Including its libraries like: jQuery, Ajax, Underscore.js, Angular.js and etc.), Pawn.

    Mapper


    Finding new ways to hurt each other is what we're good at. - Jason Gideon

    The only ones who should kill are those who are prepared to be killed. - Lelouch vi Britannia

    Senior Helper [Former]

    Member of the GFX Team, Requests Moderator [Former]

    Sergeant in Los Santos Police Department, TnR Division, Recruitment Sub-Division ((R3)) - R6 System - [Former]

    Secretary of Defense and Management of Public Services in Goverment ((R3)) - R6 System - [Former]

    Senior Officer in Los Santos Police Department, TnR Division, Training Sub-Division ((R2)) - R6 System - [Former]

    Senior Officer in Los Santos Police Department, Special Weapons and Tactics division ((R2)) - R6 System - [Former]

    Reporter in San Andreas News Agency ((R2)) - R6 System - [Former]

  10. Likes Paul Walker liked this post
  11. #7
    6 Year Veteran Donbot™'s Avatar
    Join Date
    Apr 2012
    Location
    5th Ave. ANTIFA
    Posts
    2,733
    In-Game Name(s)
    blacklivesmatter
    Post Thanks / Like
    Quote Originally Posted by Agent Gideon View Post
    I'm a programmer IRL + have PAWNO experience aswell. So, this guide was not bad at all. However, for the guy who do not know anything about programming, it's pretty hard.

    First, you should have explained what includes were. What functions could do. You should have spoken about variables too.

    Anyway, good job.
    thats why he said read james' guide first

    http://www.gta-sarp.com/forums/showt...cripting-guide





  12. #8
    10 Year Veteran 500 Posts500 Posts ###'s Avatar
    Join Date
    May 2013
    Posts
    1,320
    In-Game Name(s)
    Jack Redke
    Post Thanks / Like
    Just to help you out - /report command.





  13. #9
    8 Year Veteran 500 Posts Agent Gideon's Avatar
    Join Date
    Jul 2013
    Location
    Georgia
    Posts
    945
    In-Game Name(s)
    Jason Gideon
    Post Thanks / Like
    Quote Originally Posted by ### View Post
    Just to help you out - /report command.
    Defines:

    PHP Code:
    #define COLOR_LIGHTGOLD 0xFAFAD2FF 
    CMD:Report:

    PHP Code:
    CMD:Report(playeridparams[]) {
            new 
    wMsg[523], msg[500];
            if(
    sscanf(params"s[500]"msg))
            {
            
    SendClientMessage(playerid,-1,"USAGE: /report [report message]");
            }
            else
            {
            
    SendClientMessage(playerid,-1,"Your report message has been sent to online administrators.");
            new 
    pName[MAX_PLAYER_NAME];
            
    GetPlayerName(playeridpNamesizeof(pName));
            
    removeUnderscore(pName);
            
    format(wMsgsizeof(wMsg), "Report from %s[%d]: %s"pNameplayeridmsg);
            new 
    pCount;
            
    pCount=GetPlayersCount();
            for(new 
    i=0;i<pCount;i++)
            {
                if(
    IsPlayerConnected(i) && IsPlayerAdmin(i)) SendClientMessage(iCOLOR_LIGHTGOLDwMsg);
            }
    }

    In OnPlayerCommandText

    PHP Code:
    new cmd[STR_SIZE],params[500];
     
    sscanf(cmdtext,"s[32]s[500]",cmd,params);
     if(!
    strcmp("/report",cmd)) 
     {
              
    Report(playeridparams);
              return 
    1;
     } 
    GetPlayersCount:

    PHP Code:
    stock GetPlayersCount() {
        new 
    count=0;
        new 
    i=0;
        for(
    i=0;i<MAX_PLAYERSi++) {
        if(
    IsPlayerConnected(i)) count++;
        }
        return 
    count;

    OT: Sadly, I don't know how admin system is scripted on the SARP. Basically, report message just goes to RCON administrators.

    P.S: Was too lazy to make it tutorial-ish.
    Last edited by Agent Gideon; 2nd June 2014 at 07:16 PM.

    Jason Gideon, Level 21

    Programming languages which I know: C# (OOP, ASP.Net, ASP.Net MVC and etc), C++, Java(Swing, JavaFX, Android), HTML & Css (Even though they are not programming language), Javascript (Including its libraries like: jQuery, Ajax, Underscore.js, Angular.js and etc.), Pawn.

    Mapper


    Finding new ways to hurt each other is what we're good at. - Jason Gideon

    The only ones who should kill are those who are prepared to be killed. - Lelouch vi Britannia

    Senior Helper [Former]

    Member of the GFX Team, Requests Moderator [Former]

    Sergeant in Los Santos Police Department, TnR Division, Recruitment Sub-Division ((R3)) - R6 System - [Former]

    Secretary of Defense and Management of Public Services in Goverment ((R3)) - R6 System - [Former]

    Senior Officer in Los Santos Police Department, TnR Division, Training Sub-Division ((R2)) - R6 System - [Former]

    Senior Officer in Los Santos Police Department, Special Weapons and Tactics division ((R2)) - R6 System - [Former]

    Reporter in San Andreas News Agency ((R2)) - R6 System - [Former]

  14. Likes Paul Walker liked this post
  15. #10
    3 Year Veteran 500 Posts
    Join Date
    Oct 2012
    Location
    Canada!
    Posts
    902
    In-Game Name(s)
    Dylan Riversparks
    Post Thanks / Like
    I was waiting too see this from you! Good work as always my friend :)

    Currently in school for Electrical Power Tech
    Learning Computer Programming part time [JS/Java/CSS/HTML]


    If you need Help with anything at all, Feel free to PM or VM me your questions I'd be Hlappy to Help[/I]

  16. #11
    2 Year Veteran BicMercer's Avatar
    Join Date
    Oct 2011
    Location
    daufq u wanna know fo huh
    Posts
    22
    In-Game Name(s)
    Lewis Mercer
    Post Thanks / Like
    You should explain more in depth of the code, being said that means by explaining what a string is, how to format a string and each parameter's meaning in each function.

    E.G:
    Prob. like a 9th of the people in this thread knows what this means.

    Code:
    strmid(name, str_replace('_', ' ', ReturnPlayerName(playerid)), 0, MAX_PLAYER_NAME);

    To sum up my point, try to explain the code a little more further.

    You should add in the SA-MP wiki website for people to look at, it might help.

    Nice tutorial anyways, it's good. (Scripting Experience)


    Joined ~ SARP 2011

  17. #12
    developer
    retired administrator
    500 Posts Calvin Catt's Avatar
    Join Date
    Sep 2011
    Posts
    880
    In-Game Name(s)
    Calvin Catt
    Post Thanks / Like
    I suggest a /report system, with /acceptreport, and /denyreport

    Senior Developer
    Currently studying software engineering.
    Never been permanently banned successfully.
    | 1 | 2 | 3 |


  18. #13
    6 Year Veteran Harry Slice's Avatar
    Join Date
    Jun 2013
    Location
    Netherlands.
    Age
    34
    Posts
    195
    In-Game Name(s)
    Harry_Slice
    Post Thanks / Like
    Quote Originally Posted by Calvin Catt View Post
    I suggest a /report system, with /acceptreport, and /denyreport
    Added, see 2.3

  19. #14
    4 Year Veteran 500 Posts500 Posts500 Posts500 Posts Flux's Avatar
    Join Date
    Aug 2013
    Location
    United Kingdom
    Posts
    2,255
    In-Game Name(s)
    Calvin_Adam
    Post Thanks / Like
    I've added this to the list of Featured Guides so it can be easily accessible. It would be brilliant if you could try to update it regularly with new commands.

    Good job.


  20. #15
    6 Year Veteran Harry Slice's Avatar
    Join Date
    Jun 2013
    Location
    Netherlands.
    Age
    34
    Posts
    195
    In-Game Name(s)
    Harry_Slice
    Post Thanks / Like
    Quote Originally Posted by Calv View Post
    I've added this to the list of Featured Guides so it can be easily accessible. It would be brilliant if you could try to update it regularly with new commands.

    Good job.
    Since I am hired in the dev team, I know I should focus on fixing sa-rp, I'll update it but not yet!
    Last edited by Harry Slice; 6th June 2014 at 04:30 PM.

  21. Likes Flux liked this post
  22. #16
    6 Year Veteran Donbot™'s Avatar
    Join Date
    Apr 2012
    Location
    5th Ave. ANTIFA
    Posts
    2,733
    In-Game Name(s)
    blacklivesmatter
    Post Thanks / Like
    Quote Originally Posted by Agent Gideon View Post
    Defines:

    PHP Code:
    #define COLOR_LIGHTGOLD 0xFAFAD2FF 
    CMD:Report:

    PHP Code:
    CMD:Report(playeridparams[]) {
            new 
    wMsg[523], msg[500];
            if(
    sscanf(params"s[500]"msg))
            {
            
    SendClientMessage(playerid,-1,"USAGE: /report [report message]");
            }
            else
            {
            
    SendClientMessage(playerid,-1,"Your report message has been sent to online administrators.");
            new 
    pName[MAX_PLAYER_NAME];
            
    GetPlayerName(playeridpNamesizeof(pName));
            
    removeUnderscore(pName);
            
    format(wMsgsizeof(wMsg), "Report from %s[%d]: %s"pNameplayeridmsg);
            new 
    pCount;
            
    pCount=GetPlayersCount();
            for(new 
    i=0;i<pCount;i++)
            {
                if(
    IsPlayerConnected(i) && IsPlayerAdmin(i)) SendClientMessage(iCOLOR_LIGHTGOLDwMsg);
            }
    }

    In OnPlayerCommandText

    PHP Code:
    new cmd[STR_SIZE],params[500];
     
    sscanf(cmdtext,"s[32]s[500]",cmd,params);
     if(!
    strcmp("/report",cmd)) 
     {
              
    Report(playeridparams);
              return 
    1;
     } 
    GetPlayersCount:

    PHP Code:
    stock GetPlayersCount() {
        new 
    count=0;
        new 
    i=0;
        for(
    i=0;i<MAX_PLAYERSi++) {
        if(
    IsPlayerConnected(i)) count++;
        }
        return 
    count;

    OT: Sadly, I don't know how admin system is scripted on the SARP. Basically, report message just goes to RCON administrators.

    P.S: Was too lazy to make it tutorial-ish.
    note to beginners: there is absolutly no point of making msg 500 cells big as user max input is only 128 cells

    http://wiki.sa-mp.com/wiki/Limits





  23. Thanks Agent Gideon thanked for this post
    Likes Jizzy Black liked this post
  24. #17
    5 Year Veteran
    Join Date
    Mar 2015
    Location
    Belgium
    Posts
    1,676
    In-Game Name(s)
    Sam
    Post Thanks / Like
    Nice tutorial

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Click to connect to Discord (San Andreas Roleplay)Click to go to the official San Andreas Multiplayer websiteDownload Teamspeak