SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 18/10/2011, 10:57 AM   #1
Jason_Thunde
Big Clucker
 
Join Date: Dec 2010
Posts: 78
Reputation: 6
Default Simple Private Message System Using zCMD And Sscanf with Logs

READ THIS
In this tutorial we will be creating a Simple Private Message System using zCMD and sscanf.
The Messages will be written in a log so if the owner or any admins wants to see it.

Your proberlly thinking: Ahhh this is so simple. im only making this tutorial because i wonna help noobs out there.

Includes
Add this on top of your script.
pawn Code:
#include <zcmd>
#include <sscanf2>

This will just include the files so we can use anyfhing there is in there.
Include Downloads at bottom!

New's:
Add this under your #include
pawn Code:
new PMEnabled=1;

We will use this later in the command to check if PM Is Enabled for players or not.
Admins Will be able to Enable or Disable

Function for Logs
Add this at top of your script under new's

pawn Code:
forward PMLog(string[]);

this will create our Log Function

public Function
Add this somewhere you want:
pawn Code:
public PMLog(string[])
{
    new pm[128]; // Creates a new string
    format(pm, sizeof(pm), "%s\n", string); // Formats the string;
    new File:hFile; // Creates a new variable with type File
    hFile = fopen("/LOGS/pm.log", io_append); // Opens the Log File
    fwrite(hFile, pm); // Writes the log
    fclose(hFile); // Closes file
}

Commands:
We will be using zCMD and sscanf for Commands:
Add this anywhere you want:
pawn Code:
CMD:pm(playerid, params [ ] ) // Adding the command
{
    if(IsPlayerConnected(playerid)) // Checks if the Player IS connected
    {
        new pID, Message[60],playername[MAX_PLAYER_NAME],targetName[MAX_PLAYER_NAME],string[128],string2[128]; // Adding new's the pID Will hold the Player's ID Message will hold the message and playername will hold the name of the player that sends it and target to the target
        if(sscanf(params, "us[60]", pID, Message)) return SendClientMessage(playerid, 0xAFAFAFAA, "USAGE: /pm [PlayerID/PlayerName] [Message]"); // Checks if the player has filed in both params if not it will return a error message with Color Grey
        if(pID == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xAFAFAFAA, "Invalid Player"); // Checks if the player he attemps to send to is invalid if not it will send and error message
        if(PMEnabled == 0) return SendClientMessage(playerid, 0xAFAFAFAA, "PM Is Disabled");
        GetPlayerName(pID, targetName, sizeof(targetName)); // Gets the Name of The Target 1st param and stores it in targetName
        GetPlayerName(playerid, playername, sizeof(playername));
        format(string, sizeof(string), "Private Message from %s: %s", playername, Message); // Will format the string the first %s is the name of the guy who sent pm second %s in the Message
        format(string2, sizeof(string2), "Private Message sent to %s: %s", targetName, Message); // The same as above but this time it shows the name off the player you sent it to
        SendClientMessage(playerid, 0xFFFF00AA, string2); // Sends a message to the player who sent the PM
        SendClientMessage(pID, 0xFFFF00AA, string); // Sends a Message to Target
        PMLog(string2); // Writes to the lgo with our function
        PMLog(string); // Writes to the log
    }
    return 1; // Returns 1
}


And This After:
pawn Code:
CMD:nopm(playerid, params [ ] )
{
    if(IsPlayerConnected(playerid)) // If is player connected
    {
        if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xAFAFAFAA, "Your not a admin"); // Checks if the player isent an Admin RCON
        if(PMEnabled == 1) // If PM Is enabled it will disable it
        {
            SendClientMessageToAll(0xFFFF00AA, "An Admin has disabled Private Messages!"); // Sends a Client Message to all players
            PMEnabled = 0; // Sets the PM Enabled to 0
        }
        else if(PMEnabled == 0) // If PM Is Disabled it will enable it
        {
            SendClientMessageToAll(0xFFFF00AA, "An Admin has enabled Private Messages!"); // Sends a Client MEssage to all playesr
            PMEnabled = 1; // Sets the PM Enabled to 1
        }
    }
    return 1;
}

NOTE: REMEMBER TO CREATE FOLDER IN SCRIPTFILES/Logs

Includes Link: http://forum.sa-mp.com/showthread.php?t=120356

http://forum.sa-mp.com/showthread.php?t=91354

__________________
Game-Save - Reliable Game Hosting
http://game-save.cu.cc
Jason_Thunde is offline   Reply With Quote
Old 19/10/2011, 05:03 PM   #2
Mr_Scripter
Huge Clucker
 
Mr_Scripter's Avatar
 
Join Date: Mar 2011
Posts: 370
Reputation: 33
Default Re: Simple Private Message System Using zCMD And Sscanf with Logs

Good tut
__________________

Current Project: Stunt-DM-Drift-Race.
Done: 0%
Looking for 2Mappers... Pm Me

Gamemodes
SanAndreas Team DeathMatch Gamemode-4 hours work
Mr_Scripter is offline   Reply With Quote
Old 19/10/2011, 08:52 PM   #3
FUNExtreme
Gangsta
 
Join Date: Mar 2008
Posts: 790
Reputation: 128
Default Re: Simple Private Message System Using zCMD And Sscanf with Logs

Quote:
Originally Posted by Jason_Thunde View Post
[SIZE="3"]READ THIS
The Messages will be written in a log so if the owner or any admins wants to see it.
The messages will be printed in a log so the owner/admins can see it if they want.

Your proberlly thinking: Ahhh this is so simple. im only making this tutorial because i wonna help noobs out there.
You're probably thinking: Ahhh this is so simple. I'm only making this tutorial because I want to help the noobs out there.

This will just include the files so we can use anyfhing there is in there.
This will just include the files so we can use anything there is in there.
Better: This will make the include files available for usage in our script. (Search the forum to find them)
I corrected some of your mistakes, my english isn't perfect either but I did my best!

Nice tutorial, you explain everything. It is not another copy-paste tutorial, well done!
FUNExtreme is offline   Reply With Quote
Old 19/10/2011, 08:59 PM   #4
[03]Garsino
Guest
 
Posts: n/a
Default Re: Simple Private Message System Using zCMD And Sscanf with Logs

You need to add a length check to your /pm command. Otherwise anyone can join the server and crash it.
  Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] Making a simple PM system with ZCMD & sscanf Toni Tutorials 37 07/07/2019 05:21 PM
[FilterScript] [FS]Private Message System SpiderWalk Filterscripts 42 21/01/2015 06:31 AM
[Tutorial] How to make simple admin commands using sscanf and ZCMD. Odyssey Tutorials 15 24/07/2013 09:57 AM
[Tutorial] How to make a simple spec command [ZCMD and sscanf] [Virtual World and Interior Support] Tee Tutorials 23 20/11/2011 06:09 AM


All times are GMT. The time now is 12:37 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.