SA-MP Forums Archive
Problem with string range - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Problem with string range (/showthread.php?tid=597780)



Problem with string range - TwinkiDaBoss - 04.01.2016

Alright so, instead of having the system to display 1 split message it sends 2 exactly the same messages instead.
No errors when compiling

PHP код:
SendRPMessage(playerid,Float:tmpRange,tmpMsg[]) {
    new 
Float:Pos[3],
        
string[128],
        
Length strlen(tmpMsg);
    
GetPlayerPos(playerid,Pos[0],Pos[1],Pos[2]);
    foreach(new 
Player) {
        if(
IsPlayerConnected(i)) {
            if(
IsPlayerInRangeOfPoint(i,tmpRange,Pos[0],Pos[1],Pos[2])) {
                if(
Length 80) {
                    
strmid(stringtmpMsg0Length 2);
                    
Msg(i,-1,tmpMsg);
                    
                    
strmid(stringtmpMsgLength 2Length);
                    
Msg(i,-1,tmpMsg);
                }
                else {
                    
Msg(i,-1,tmpMsg);
                }
            }
        }
    }
    return 
true;




Re: Problem with string range - Lucky13 - 04.01.2016

There you go:

Код:
SendRPMessage(playerid,Float:tmpRange,tmpMsg[]) {
    new Float:Pos[3],
        string[128],
        Length = strlen(tmpMsg);

    GetPlayerPos(playerid,Pos[0],Pos[1],Pos[2]);
    foreach(new i : Player) { 
        if(IsPlayerConnected(i)) {
            if(IsPlayerInRangeOfPoint(i,tmpRange,Pos[0],Pos[1],Pos[2])) {
                if(Length > 80) {
                    strmid(string, tmpMsg, 0, Length/2);
                    Msg(i,-1,string);
                    
               		strmid(string, tmpMsg, Length/2, Length);
                        Msg(i,-1,string);
                }
                else {
                    Msg(i,-1,tmpMsg);
                }
            }
        }
    }
    return true;
}
Tested on a 128 characters string and working properly.

EDIT: This is what I edited if you want to know:


Your code:
Код:
SendRPMessage(playerid,Float:tmpRange,tmpMsg[]) { 
    new Float:Pos[3], 
        string[128], 
        Length = strlen(tmpMsg); 

    GetPlayerPos(playerid,Pos[0],Pos[1],Pos[2]); 
    foreach(new i : Player) { 
        if(IsPlayerConnected(i)) { 
            if(IsPlayerInRangeOfPoint(i,tmpRange,Pos[0],Pos[1],Pos[2])) { 
                if(Length > 80) { 
                    strmid(string, tmpMsg, 0, Length / 2); 
                    Msg(i,-1,tmpMsg); 
                     
                    strmid(string, tmpMsg, Length / 2, Length); 
                    Msg(i,-1,tmpMsg); 
                } 
                else { 
                    Msg(i,-1,tmpMsg); 
                } 
            } 
        } 
    } 
    return true; 
}
My Code:
Код:
SendRPMessage(playerid,Float:tmpRange,tmpMsg[]) {
    new Float:Pos[3],
        string[128],
        Length = strlen(tmpMsg);

    GetPlayerPos(playerid,Pos[0],Pos[1],Pos[2]);
    foreach(new i : Player) { 
        if(IsPlayerConnected(i)) {
            if(IsPlayerInRangeOfPoint(i,tmpRange,Pos[0],Pos[1],Pos[2])) {
                if(Length > 80) {
                    strmid(string, tmpMsg, 0, Length/2);
                    Msg(i,-1,string);
                    
               		strmid(string, tmpMsg, Length/2, Length);
                        Msg(i,-1,string);
                }
                else {
                    Msg(i,-1,tmpMsg);
                }
            }
        }
    }
    return true;
}



Re: Problem with string range - TwinkiDaBoss - 04.01.2016

Thanks for the help mate!


Re: Problem with string range - Lucky13 - 04.01.2016

Quote:
Originally Posted by TwinkiDaBoss
Посмотреть сообщение
Thanks for the help mate!
A +rep for you too! ^^


Re: Problem with string range - TwinkiDaBoss - 05.01.2016

There is a slight problem

With that code +
PHP код:
public OnPlayerText(playeridtext[])
{
    new 
message[128];
    new 
Float:Pos[3];
    if(
AccInfo[playerid][Muted] == 0) {
        
GetPlayerPos(playerid,Pos[0],Pos[1],Pos[2]);
        
format(messagesizeof(message), "%s says: %s"GetRoleplayName(playerid), text);
        
IC_ChatLog(message);
        
SetPlayerChatBubble(playeridtext0xFFFFFF10.03000);
        foreach(new 
Player) {
            if(
IsPlayerInRangeOfPoint(i,10,Pos[0],Pos[1],Pos[2])) {
                
format(messagesizeof(message), "{FFFFFF} %s"text);
                
SendRPMessage(playerid,10,message);
            }
             else if(
IsPlayerInRangeOfPoint(i,20,Pos[0],Pos[1],Pos[2])) {
                
format(messagesizeof(message), "{BABABA} %s"text);
                
SendRPMessage(playerid,20,message);
            }
        }
    }
    else {
        
Msg(playerid,COLOR_RED,"You are muted. You cannot speak");
        return 
0;
    }
    return 
0;

It shows amount of messages based on players around you. Ie 2 players, it will show 2 messages


Re: Problem with string range - Lucky13 - 05.01.2016

Quote:
Originally Posted by TwinkiDaBoss
Посмотреть сообщение
There is a slight problem

With that code +
PHP код:
public OnPlayerText(playeridtext[])
{
    new 
message[128];
    new 
Float:Pos[3];
    if(
AccInfo[playerid][Muted] == 0) {
        
GetPlayerPos(playerid,Pos[0],Pos[1],Pos[2]);
        
format(messagesizeof(message), "%s says: %s"GetRoleplayName(playerid), text);
        
IC_ChatLog(message);
        
SetPlayerChatBubble(playeridtext0xFFFFFF10.03000);
        foreach(new 
Player) {
            if(
IsPlayerInRangeOfPoint(i,10,Pos[0],Pos[1],Pos[2])) {
                
format(messagesizeof(message), "{FFFFFF} %s"text);
                
SendRPMessage(playerid,10,message);
            }
             else if(
IsPlayerInRangeOfPoint(i,20,Pos[0],Pos[1],Pos[2])) {
                
format(messagesizeof(message), "{BABABA} %s"text);
                
SendRPMessage(playerid,20,message);
            }
        }
    }
    else {
        
Msg(playerid,COLOR_RED,"You are muted. You cannot speak");
        return 
0;
    }
    return 
0;

It shows amount of messages based on players around you. Ie 2 players, it will show 2 messages
If 2 players are talking, they will receive the same message 2 times?


Re: Problem with string range - Lucky13 - 05.01.2016

Not tested, but this should fix it:

Код:
public OnPlayerText(playerid, text[])
{
    new message[128];
    new Float:Pos[3];
    if(AccInfo[playerid][Muted] == 0)
	{
        GetPlayerPos(playerid,Pos[0],Pos[1],Pos[2]);
        format(message, sizeof(message), "%s says: %s", GetRoleplayName(playerid), text);
        IC_ChatLog(message);
        SetPlayerChatBubble(playerid, text, 0xFFFFFF, 10.0, 3000);
        foreach(new i : Player)
		{
            if(IsPlayerInRangeOfPoint(i,10,Pos[0],Pos[1],Pos[2]))
			{
                format(message, sizeof(message), "{FFFFFF} %s", text);
                SendRPMessage(playerid,10,message);
                return 0;
            }
       		else if(IsPlayerInRangeOfPoint(i,20,Pos[0],Pos[1],Pos[2]))
			{
                format(message, sizeof(message), "{BABABA} %s", text);
                SendRPMessage(playerid,20,message);
                return 0;
            }
        }
    }
    else
	{
        Msg(playerid,COLOR_RED,"You are muted. You cannot speak");
        return 0;
    }
    return 0;
}
Tell me if it didn't though.

EDIT: Your problem is this:

Код:
            if(IsPlayerInRangeOfPoint(i,10,Pos[0],Pos[1],Pos[2]))
            {
                format(message, sizeof(message), "{FFFFFF} %s", text);
                SendRPMessage(playerid,10,message);
               
            }
       	    else if(IsPlayerInRangeOfPoint(i,20,Pos[0],Pos[1],Pos[2]))
	    {
                format(message, sizeof(message), "{BABABA} %s", text);
                SendRPMessage(playerid,20,message);
                
            }
Basically, the player will be in range of 10.0 and 20.0, because 10 is included in 20 , so you just have to end the loop at one of that, by adding return 0; to end it.


Re: Problem with string range - TwinkiDaBoss - 05.01.2016

Yeah there is a slight problem, range 20 wont be seen for soem reason

EDIT: I seen what my buddy wrote in range 20 but he doesnt when I talk


Re: Problem with string range - Lucky13 - 05.01.2016

Quote:
Originally Posted by TwinkiDaBoss
Посмотреть сообщение
Yeah there is a slight problem, range 20 wont be seen for soem reason

EDIT: I seen what my buddy wrote in range 20 but he doesnt when I talk
Try changing the "else if" with "if":

From this:

Код:
else if(IsPlayerInRangeOfPoint(i,20,Pos[0],Pos[1],Pos[2]))
			{
                format(message, sizeof(message), "{BABABA} %s", text);
                SendRPMessage(playerid,20,message);
                return 0;
            }
To this:

Код:
if(IsPlayerInRangeOfPoint(i,20,Pos[0],Pos[1],Pos[2]))
			{
                format(message, sizeof(message), "{BABABA} %s", text);
                SendRPMessage(playerid,20,message);
                return 0;
            }
Do you see your message in the range 20.0?


Re: Problem with string range - TwinkiDaBoss - 05.01.2016

It seems that its bugged for like ID: 0