AFK system
#1

Hey, i just made an AFK system. (My first script)

pawn Код:
#include <a_samp>

#define COLOR_ONE 0xFF0000FF
#define COLOR_TWO 0x00FF00FF

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Mac's AFK System");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{
       
    return 1;
}

public OnPlayerConnect(playerid)
{

    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/AFK", cmdtext, true, 10) == 1)
    {
        new message[40], name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));

        format(message,sizeof(message),"%s is now AFK!",name);
        SendClientMessage( playerid, COLOR_ONE, message);
        return 1;
    }
    public OnPlayerCommandText(playerid, cmdtext[])
    {

    if (strcmp("/BACK", cmdtext, true, 10) == 1)
    {
        new message[40], name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));

        format(message,sizeof(message),"%s is now BACK!",name);
        SendClientMessage( playerid, COLOR_TWO, message);
        return 1;
    }
    return 0;
}
But then i get three errors:

Код:
C:\Users\***\Desktop\samp\scripts\Mac's AFK System.pwn(37) : error 029: invalid expression, assumed zero
C:\Users\***\Desktop\samp\scripts\Mac's AFK System.pwn(37) : error 029: invalid expression, assumed zero
C:\Users\***\Desktop\samp\scripts\Mac's AFK System.pwn(52) : error 030: compound statement not closed at the end of file (started at line 28)
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


3 Errors.
Whats the problem here?
Reply
#2

pawn Код:
#include <a_samp>

#define COLOR_ONE 0xFF0000FF
#define COLOR_TWO 0x00FF00FF

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Mac's AFK System");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{

    return 1;
}

public OnPlayerConnect(playerid)
{

    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/AFK", cmdtext, true, 10) == 1)
    {
        new message[40], name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));

        format(message,sizeof(message),"%s is now AFK!",name);
        SendClientMessage( playerid, COLOR_ONE, message);
        return 1;
    }
    if (strcmp("/BACK", cmdtext, true, 10) == 1)
    {
        new message[40], name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));

        format(message,sizeof(message),"%s is now BACK!",name);
        SendClientMessage( playerid, COLOR_TWO, message);
        return 1;
    }
    return 0;
}
you just need one OnPlayerCommandText.
Reply
#3

Thanks, but now when i type /afk. It says "[USER] is now BACK"
When i type /back, it says "Unknown command"
Reply
#4

Код:
#include <a_samp>

#define COLOR_ONE 0xFF0000FF
#define COLOR_TWO 0x00FF00FF

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Mac's AFK System");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{

    return 1;
}

public OnPlayerConnect(playerid)
{

    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if(strcmp(cmd, "/afk", true) == 0)
    {
        SetPVarInt(playerid, "AFK", 1);
        new message[40], name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        TogglePlayerControllable(playerid, 0);

        format(message,sizeof(message),"%s is now AFK!",name);
        SendClientMessageToAll( COLOR_ONE, message); // Removed (playerid, 
        return 1;
    }
    if(strcmp(cmd, "/back", true) == 0)
    {
        if(GetPVarInt(playerid, "AFK") == 1)
        {
        SetPVarInt(playerid, "AFK", 0);
        new message[40], name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        TogglePlayerControllable(playerid, 1);

        format(message,sizeof(message),"%s is now BACK!",name);
        SendClientMessageToAll( COLOR_TWO, message); // Removed (playerid, 
        return 1;
        }
    }
    return 0;
}
Pretty good for a first time thing. I made some minor adjustments to it for you, i highlighted them in red
Reply
#5

Quote:
Originally Posted by Joshb93
Посмотреть сообщение
Код:
#include <a_samp>

#define COLOR_ONE 0xFF0000FF
#define COLOR_TWO 0x00FF00FF

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Mac's AFK System");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{

    return 1;
}

public OnPlayerConnect(playerid)
{

    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/AFK", cmdtext, true, 10) == 1)
    {
        new message[40], name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        TogglePlayerControllable(playerid, 0);

        format(message,sizeof(message),"%s is now AFK!",name);
        SendClientMessageToAll( COLOR_ONE, message); // Removed (playerid, 
        return 1;
    }
    if (strcmp("/BACK", cmdtext, true, 10) == 1)
    {
        new message[40], name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        TogglePlayerControllable(playerid, 1);

        format(message,sizeof(message),"%s is now BACK!",name);
        SendClientMessageToAll( COLOR_TWO, message); // Removed (playerid, 
        return 1;
    }
    return 0;
}
Pretty good for a first time thing. I made some minor adjustments to it for you, i highlighted them in red
Weird, i cant compile it:

Код:
C:\Users\***\Desktop\samp\scripts\AFK-MAC.pwn(4) : warning 235: public function lacks forward declaration (symbol "OnFilterScriptInit")
C:\Users\***\Desktop\samp\scripts\AFK-MAC.pwn(6) : error 017: undefined symbol "print"
C:\Users\***\Desktop\samp\scripts\AFK-MAC.pwn(7) : error 017: undefined symbol "print"
C:\Users\***\Desktop\samp\scripts\AFK-MAC.pwn(8) : error 017: undefined symbol "print"
C:\Users\***\Desktop\samp\scripts\AFK-MAC.pwn(12) : warning 235: public function lacks forward declaration (symbol "OnFilterScriptExit")
C:\Users\***\Desktop\samp\scripts\AFK-MAC.pwn(18) : warning 235: public function lacks forward declaration (symbol "OnPlayerConnect")
C:\Users\***\Desktop\samp\scripts\AFK-MAC.pwn(24) : warning 235: public function lacks forward declaration (symbol "OnPlayerCommandText")
C:\Users\***\Desktop\samp\scripts\AFK-MAC.pwn(26) : error 017: undefined symbol "strcmp"
C:\Users\***\Desktop\samp\scripts\AFK-MAC.pwn(28) : error 017: undefined symbol "MAX_PLAYER_NAME"
C:\Users\***\Desktop\samp\scripts\AFK-MAC.pwn(28) : error 009: invalid array size (negative, zero or out of bounds)
C:\Users\***\Desktop\samp\scripts\AFK-MAC.pwn(28) : error 036: empty statement
C:\Users\***\Desktop\samp\scripts\AFK-MAC.pwn(28) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


8 Errors.
Reply
#6

I redid it, try now

EDIT: Left out SetPVarInt under /back.. might want to remake

Sozzz..
Reply
#7

Quote:
Originally Posted by Joshb93
Посмотреть сообщение
I redid it, try now

EDIT: Left out SetPVarInt under /back.. might want to remake

Sozzz..
I compiled it, without any errors. But when im in my server, and trying to /afk and /back it says "Unknown Command"
Reply
#8

Quote:
Originally Posted by rooney12
Посмотреть сообщение
I compiled it, without any errors. But when im in my server, and trying to /afk and /back it says "Unknown Command"
Are you typing it with capitals?

/AFK

not

/afk
Reply
#9

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (!strcmp("/AFK", cmdtext, true))
    {
        new message[40], name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));

        format(message,sizeof(message),"%s is now AFK!",name);
        return SendClientMessage( playerid, COLOR_ONE, message);
    }
    if (!strcmp("/BACK", cmdtext, true))
    {
        new message[40], name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));

        format(message,sizeof(message),"%s is now BACK!",name);
        return SendClientMessage( playerid, COLOR_TWO, message);
    }
    return 0;
}
when strcmp have success the return is 0.
Reply
#10

Yep, i do. But it still doesnt work. Wanna try it? I can send you IP.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)