[Tutorial] How to: Implement Roleplay Chats [zcmd, sscanf, foreach]
#21

Yea, and what you just did takes a lot of time for every command, and creates a extra string for every command. Who's the smart one now?
Reply
#22

Quote:
Originally Posted by zombieking
View Post
Good tutorial but... you can remove the '_' from the name without strreplace:


-False , you do NOT need it , but you can use it , another way of replacing, without creating any stocks/functions is:

pawn Code:
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,MAX_PLAYER_NAME);
name[strfind(name, "_", false)] = ' ';
So it does the exact same thing , but without any stocks...
I'm just saying that creating stocks when they are not needed is not very smart.. but anyways 10/10 amazing tutorial.
Thank you for bringing that into light, I did write this awhile back so I had no clue what strfind did. Although what you're saying about the stock I do not agree on, the getname stock I've included will create the string when it's called and return it, saving a lot more memory/work than creating a new string every time you want an underscoreless name. (memory isn't a problem on modern computers though)

I've updated my main post. Thanks for the feedback as well.
Reply
#23

When I type /shout and my message its send me the message "USAGE: /(s)hout [message]..
Reply
#24

Quote:
Originally Posted by Extasy4
View Post
When I type /shout and my message its send me the message "USAGE: /(s)hout [message]..
pawn Code:
CMD:shout(playerid, params[])
{      
    if(isnull(params)) {
        return SendClientMessage(playerid, -1, "USAGE: /(s)hout [message]");
    }
   
    else {
        new string[128];
        format(string, sizeof(string), "%s shouts: %s!", GetName(playerid), params);
        ProxDetector(50.0, playerid, string, -1);
    }
    return 1;
}
Reply
#25

Quote:
Originally Posted by VincentDunn
View Post
How do you use strfind to replace the underscore?
pawn Code:
new
    name[MAX_PLAYER_NAME]
;
GetPlayerName(playerid, name, sizeof(name));

name[strfind(name, '_')] = ' ';
Since strfind returns the position of the string you are searching for, the integer is placed between [ ], and we set that character equal to a space, and there you have another method of removing the underscore.
Above all, strfind returns -1 if no occurence is found, causing an "out of bounds" exception and crashing the server. Please remove this from your post, OP.
Reply
#26

Good observation, scrapped that strfind segment altogether, thanks.
Reply
#27

if(strfind(name, " ") >= 0) name[strfind(name, " ")] = ' ';
Reply
#28

Good tutorial, +REP.
Reply
#29

Im using this Thanks
Reply
#30

EDIT: I figured it out, you just need to do this!
Code:
CMD:do(playerid, params[])
{
    new
        string[128],
        action[100];
    if(sscanf(params, "s[100]", action))
    {
        SendClientMessage(playerid, -1, "USAGE: /do [action]");
        return 1;
    }
    else
    {
   		format(string, sizeof(string), "* %s (( %s ))", params, GetName(playerid));
        ProxDetector(30, playerid, string, COLOR_PURPLE);
    }
    return 1;
}
Reply
#31

lol, you have no idea how much this has helped me to understand a few things.

Thank you very much.
Reply
#32

where do u place these codes?
Reply
#33

Hi , Nice tutorial

I got a problem . Whenever i add your /me cmd it says that undefined symbol GetName . How do i fix this ?
Reply
#34

Hey, I'm getting this ERROR:

Code:
C:\Users\Feleren\Desktop\SAMP\pawno\include\Dini.inc(239) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\Feleren\Desktop\Other Servers for SAMP\ProjectUltimate\gamemodes\PUv1.3.pwn(74) : warning 217: loose indentation
C:\Users\Feleren\Desktop\Other Servers for SAMP\ProjectUltimate\gamemodes\PUv1.3.pwn(85) : warning 217: loose indentation
C:\Users\Feleren\Desktop\Other Servers for SAMP\ProjectUltimate\gamemodes\PUv1.3.pwn(105) : warning 217: loose indentation
C:\Users\Feleren\Desktop\Other Servers for SAMP\ProjectUltimate\gamemodes\PUv1.3.pwn(136) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\Feleren\Desktop\Other Servers for SAMP\ProjectUltimate\gamemodes\PUv1.3.pwn(149) : error 021: symbol already defined: "GetPlayerName"
C:\Users\Feleren\Desktop\Other Servers for SAMP\ProjectUltimate\gamemodes\PUv1.3.pwn(150) : error 021: symbol already defined: "strreplace"
C:\Users\Feleren\Desktop\Other Servers for SAMP\ProjectUltimate\gamemodes\PUv1.3.pwn(156) : warning 219: local variable "name" shadows a variable at a preceding level
C:\Users\Feleren\Desktop\Other Servers for SAMP\ProjectUltimate\gamemodes\PUv1.3.pwn(175) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\Feleren\Desktop\Other Servers for SAMP\ProjectUltimate\gamemodes\PUv1.3.pwn(179) : error 017: undefined symbol "foreach"
C:\Users\Feleren\Desktop\Other Servers for SAMP\ProjectUltimate\gamemodes\PUv1.3.pwn(181) : error 017: undefined symbol "i"
C:\Users\Feleren\Desktop\Other Servers for SAMP\ProjectUltimate\gamemodes\PUv1.3.pwn(183) : error 017: undefined symbol "i"
C:\Users\Feleren\Desktop\Other Servers for SAMP\ProjectUltimate\gamemodes\PUv1.3.pwn(195) : error 021: symbol already defined: "format"
C:\Users\Feleren\Desktop\Other Servers for SAMP\ProjectUltimate\gamemodes\PUv1.3.pwn(197) : error 010: invalid function or declaration
C:\Users\Feleren\Desktop\Other Servers for SAMP\ProjectUltimate\gamemodes\PUv1.3.pwn(197) : error 021: symbol already defined: "ProxDetector"
C:\Users\Feleren\Desktop\Other Servers for SAMP\ProjectUltimate\gamemodes\PUv1.3.pwn(197) : warning 215: expression has no effect
C:\Users\Feleren\Desktop\Other Servers for SAMP\ProjectUltimate\gamemodes\PUv1.3.pwn(197) : error 001: expected token: ";", but found ")"
C:\Users\Feleren\Desktop\Other Servers for SAMP\ProjectUltimate\gamemodes\PUv1.3.pwn(197) : fatal error 107: too many error messages on one line

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


10 Errors.
Reply
#35

pawn Code:
stock strreplace(string[], find, replace)
{
    for(new i=0; string[i]; i++)
    {
        if(string[i] == find)
        {
            string[i] = replace;
        }
    }
}

stock GetName(playerid)
{
    new
        name[24];
    GetPlayerName(playerid, name, sizeof(name));
    strreplace(name, '_', ' ');
    return name;
}
i put this
when i enter into game, and type anything... nothing happend.
i mean nothing... its not even shows what i typed. Help please
Reply
#36

Quote:
Originally Posted by bathushan
View Post
i put this
when i enter into game, and type anything... nothing happend.
i mean nothing... its not even shows what i typed. Help please
If you what you are saying is true, then the problem might be in the OnPlayerText callback.
Reply
#37

Where do I need to type the prox dedector code and the above?
Reply
#38

Nice sir +1
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)