SA-MP Forums

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

 
 
Thread Tools Display Modes
Old 04/09/2010, 10:15 AM   #1
Pawno_Master
Huge Clucker
 
Join Date: Jun 2009
Posts: 379
Reputation: 0
Default OnPlayerText question

Well I was wondering..


I've never worked with OnPlayerText and I'm now trying to find out some more about it.
I tried to make a function where if a player speaks, only players in a radius of 25 could see the message but it didn't work out.

Code:
public OnPlayerText(playerid, text[])
{
	new string[56];
	new PlayerName[MAX_PLAYER_NAME];
	for(new i; i<MAX_PLAYERS; i++)
	new Float:XXX,Float:YYY,Float:ZZZ;
	GetPlayerPos(playerid, XXX, YYY, ZZZ);
	if(IsPlayerInRangeOfPoint(i, 25.0, XXX, YYY, ZZZ))
	{
    format(string, sizeof(string), "%s says: %s",PlayerName,text);
    SendClientMessage(i, 0xFF0000AA, string);
    }
	return 1;
}
Code:
C:\SAMP 0.3b Server R2\gamemodes\Unknown-RP.pwn(72) : error 003: declaration of a local variable must appear in a compound block
C:\SAMP 0.3b Server R2\gamemodes\Unknown-RP.pwn(72) : warning 221: label name "Float" shadows tag name
C:\SAMP 0.3b Server R2\gamemodes\Unknown-RP.pwn(72) : error 017: undefined symbol "XXX"
C:\SAMP 0.3b Server R2\gamemodes\Unknown-RP.pwn(72) : warning 215: expression has no effect
C:\SAMP 0.3b Server R2\gamemodes\Unknown-RP.pwn(73) : error 017: undefined symbol "XXX"
C:\SAMP 0.3b Server R2\gamemodes\Unknown-RP.pwn(74) : error 017: undefined symbol "i"
C:\SAMP 0.3b Server R2\gamemodes\Unknown-RP.pwn(77) : error 017: undefined symbol "i"
C:\SAMP 0.3b Server R2\gamemodes\Unknown-RP.pwn(72) : warning 203: symbol is never used: "Float"
Pawn compiler 3.2.3664	 	 	Copyright (c) 1997-2006, ITB CompuPhase


5 Errors.
So yea, looks like I did something terribly wrong, even though I use this at regular commands using SSCANF.
Heard of something like ProxDetectors but I don't understand shit about that.

If someone could help me out? Thanks
Pawno_Master is offline  
Old 04/09/2010, 10:20 AM   #2
iggy1
High-roller
 
iggy1's Avatar
 
Join Date: Mar 2009
Location: One past the end.
Posts: 2,421
Reputation: 273
Default Re: OnPlayerText question

pawn Code:
public OnPlayerText(playerid, text[])
{
    new string[56];
    new PlayerName[MAX_PLAYER_NAME];
    for(new i; i<MAX_PLAYERS; i++)
    {
        new Float:XXX,Float:YYY,Float:ZZZ;
        GetPlayerPos(playerid, XXX, YYY, ZZZ);
        if(IsPlayerInRangeOfPoint(i, 25.0, XXX, YYY, ZZZ))
        {
            format(string, sizeof(string), "%s says: %s",PlayerName,text);
            SendClientMessage(i, 0xFF0000AA, string);
        }
    }
    return 1;
}

You had no opening brace after the 'for' loop.

EDIT: Removed bad advice.

Last edited by iggy1; 04/09/2010 at 10:41 AM.
iggy1 is offline  
Old 04/09/2010, 10:28 AM   #3
Pawno_Master
Huge Clucker
 
Join Date: Jun 2009
Posts: 379
Reputation: 0
Default Re: OnPlayerText question

Right, thanks for that missed that lol
Pawno_Master is offline  
Old 04/09/2010, 10:29 AM   #4
iggy1
High-roller
 
iggy1's Avatar
 
Join Date: Mar 2009
Location: One past the end.
Posts: 2,421
Reputation: 273
Default Re: OnPlayerText question

your welcome m8
iggy1 is offline  
Old 04/09/2010, 10:30 AM   #5
General Abe
Big Clucker
 
General Abe's Avatar
 
Join Date: Jan 2008
Posts: 77
Reputation: 12
Default Re: OnPlayerText question

Quote:
Originally Posted by iggy1 View Post
You had no opening brace after the 'for' loop.
Also loops like that should be <= MAX_PLAYERS. Because if your sever is full the loop will miss a player.
Newly declared variables have a value of 0, which is a valid player slot. Using <= in loops is pretty much script suicide, just wait until you use the loop to modify an array and watch as your server kills itself (the loop will try to write to the 11th slot of var[10], for example).

i < MAX_PLAYERS, remember it...
__________________
Co-developer of Vortex Roleplay, three-time director of development & two-year assistant director of development at NGG.
General Abe is offline  
Old 04/09/2010, 10:37 AM   #6
iggy1
High-roller
 
iggy1's Avatar
 
Join Date: Mar 2009
Location: One past the end.
Posts: 2,421
Reputation: 273
Default Re: OnPlayerText question

Shit i guess iv got some re-coding to do thanks for the tip brian. Luckly i use foreach for most player loops, but now i have to check all my code

nice1 pal.

Feel a bit silly now lol
iggy1 is offline  
Old 04/09/2010, 03:33 PM   #7
Pawno_Master
Huge Clucker
 
Join Date: Jun 2009
Posts: 379
Reputation: 0
Default Re: OnPlayerText question

Because I also like to use /low, /s to get other ranges, since that code is global.
Pawno_Master is offline  
Old 04/09/2010, 05:45 PM   #8
General Abe
Big Clucker
 
General Abe's Avatar
 
Join Date: Jan 2008
Posts: 77
Reputation: 12
Default Re: OnPlayerText question

Then you would use this stock, like so:
pawn Code:
stock localMessage(playerid,  colour, string[], Float: Distance)
{
    new Float:PosFloats[3];
    GetPlayerPos(playerid, PosFloats[0], PosFloats[1], PosFloats[2]);
    foreach(Player, i)
    {
        if(IsPlayerInRangeOfPoint(i, Distance, PosFloats[0], PosFloats[1], PosFloats[2])
        {
            SendClientMessage(i, colour, string);
        }
    }
    return 1;
}

pawn Code:
public OnPlayerText(playerid, text[])
{
    new
        string[128], // 56 cells isn't going to get you very far when the text I/O is 128.
        PlayerName[MAX_PLAYER_NAME];

    GetPlayerName(playerid, PlayerName, MAX_PLAYER_NAME);
    format(string, sizeof(string), "%s says: %s",PlayerName,text);
    localMessage(playerid, 0xFF0000AA, string, 15.0); // Distance you want to send it to
   
    return 1;
}
Excuse me if I missed something, it's 3.19 AM here. Yawn.
__________________
Co-developer of Vortex Roleplay, three-time director of development & two-year assistant director of development at NGG.
General Abe is offline  
 

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
OnPlayerText help FireCat Help Archive 1 08/08/2010 11:46 AM
OnPlayerText question Torran Help Archive 3 24/02/2010 04:03 PM
[SOLVED]OnPlayerText Question JoeDaDude Help Archive 5 22/01/2010 02:03 PM
[HELP] OnPlayerText Littleman774 Help Archive 12 19/05/2009 05:35 PM


All times are GMT. The time now is 11:40 PM.


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