PDA

View Full Version : Problem with string range


TwinkiDaBoss
04/01/2016, 10:11 PM
Alright so, instead of having the system to display 1 split message it sends 2 exactly the same messages instead.
No errors when compiling


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;
}

Lucky13
04/01/2016, 10:53 PM
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;
}

TwinkiDaBoss
04/01/2016, 11:13 PM
Thanks for the help mate!

Lucky13
04/01/2016, 11:15 PM
Thanks for the help mate!

A +rep for you too! ^^

TwinkiDaBoss
05/01/2016, 02:45 PM
There is a slight problem

With that code +
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);
}
else if(IsPlayerInRangeOfPoint(i,20,Pos[0],Pos[1],Pos[2])) {
format(message, sizeof(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

Lucky13
05/01/2016, 02:52 PM
There is a slight problem

With that code +
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);
}
else if(IsPlayerInRangeOfPoint(i,20,Pos[0],Pos[1],Pos[2])) {
format(message, sizeof(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?

Lucky13
05/01/2016, 02:54 PM
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 :D, so you just have to end the loop at one of that, by adding return 0; to end it.

TwinkiDaBoss
05/01/2016, 03:09 PM
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

Lucky13
05/01/2016, 03:18 PM
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?

TwinkiDaBoss
05/01/2016, 03:25 PM
It seems that its bugged for like ID: 0

Lucky13
05/01/2016, 03:26 PM
It seems that its bugged for like ID: 0

What version of foreach are you using? Is it 3.0?

TwinkiDaBoss
05/01/2016, 03:28 PM
What version of foreach are you using? Is it 3.0?

Last one from here
https://github.com/Kar2k/SAMP-foreach

Lucky13
05/01/2016, 03:30 PM
Last one from here
https://github.com/Kar2k/SAMP-foreach

Not sure which one is but anyways, try changing foreach( new i : Player ) to foreach (Player, i), If you are using an older version of the foreach, it will work, otherwise, no. Let me know though if it did or not.

TwinkiDaBoss
05/01/2016, 03:31 PM
Nope doesnt work, Im getting warning if I do. The problem is basically ID: 0 range 20 doesnt work, but works for everyone else. Range 10 works just fine

Lucky13
05/01/2016, 03:32 PM
So ID 0 can't send a message on the range of 20.0, but he can on 10.0. Other IDs ( 1,2,3, 1000 and so on ) can send both on 10.0 and 20.0?

TwinkiDaBoss
05/01/2016, 03:36 PM
Okay so

ID: 0 says something on range 10, all good
ID: 0 says something on range 20, no one will see it besides himself.

Lucky13
05/01/2016, 03:49 PM
Try to add some print("Works"); under each function at range 20.0, and see in the console if they are printed when ID 0 talks. I really can't figure out what is wrong o.O

zT KiNgKoNg
05/01/2016, 03:54 PM
Hey TwinkiDaBoss....

Here's something that might help with your issue, I've used it in quite a few of my scripts; So I had to dig it up in one of my old BitBucket Repo's.... But it should help you resolve your issue.

Resolution Bit.

forward SendLocalMessage(Float:radi, playerid, string[],col1,col2,col3,col4,col5);
public SendLocalMessage(Float:radi, playerid, string[],col1,col2,col3,col4,col5)
{
if(IsPlayerConnected(playerid)) {
new Float:posx, Float:posy, Float:posz;
new Float:oldposx, Float:oldposy, Float:oldposz;
new Float:tempposx, Float:tempposy, Float:tempposz;

GetPlayerPos(playerid, oldposx, oldposy, oldposz);
for(new i = 0; i < MAX_PLAYERS; i++) {
if(IsPlayerConnected(i)) {
if(IsLogged(i) && CharSpawned(i))
{
GetPlayerPos(i, posx, posy, posz);
tempposx = (oldposx -posx);
tempposy = (oldposy -posy);
tempposz = (oldposz -posz);
if (((tempposx < radi/16) && (tempposx > -radi/16)) && ((tempposy < radi/16) && (tempposy > -radi/16)) && ((tempposz < radi/16) && (tempposz > -radi/16))) {
if(GetPlayerVirtualWorld(i) == GetPlayerVirtualWorld(playerid)) {
SendClientMessageA(i, col1, string);
}
}
else if (((tempposx < radi/8) && (tempposx > -radi/8)) && ((tempposy < radi/8) && (tempposy > -radi/8)) && ((tempposz < radi/8) && (tempposz > -radi/8))) {
if(GetPlayerVirtualWorld(i) == GetPlayerVirtualWorld(playerid)) {
SendClientMessageA(i, col2, string);
}
}
else if (((tempposx < radi/4) && (tempposx > -radi/4)) && ((tempposy < radi/4) && (tempposy > -radi/4)) && ((tempposz < radi/4) && (tempposz > -radi/4))) {
if(GetPlayerVirtualWorld(i) == GetPlayerVirtualWorld(playerid)) {
SendClientMessageA(i, col3, string);
}
}
else if (((tempposx < radi/2) && (tempposx > -radi/2)) && ((tempposy < radi/2) && (tempposy > -radi/2)) && ((tempposz < radi/2) && (tempposz > -radi/2))) {
if(GetPlayerVirtualWorld(i) == GetPlayerVirtualWorld(playerid)) {
SendClientMessageA(i, col4, string);
}
}
else if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi))) {
if(GetPlayerVirtualWorld(i) == GetPlayerVirtualWorld(playerid)) {
SendClientMessageA(i, col5, string);
}
}
}
}
}
}
return true;
}

forward SendClientMessageA(playerid,color,text[]);
public SendClientMessageA(playerid,color,text[])
{
new safetxt[400];
format(safetxt,sizeof(safetxt),"%s",text);
if(strlen(safetxt) <= 99) { SendClientMessage(playerid,color,text); }
else {

new texts[128];
strmid(texts,safetxt,99,256);
strins(safetxt, " ..", 99, 1);
strdel(safetxt, 100, strlen(safetxt));
SendClientMessage(playerid,color,safetxt);
SendClientMessage(playerid,color,texts);

}
}


Example Use (Please take into account this is from my script, and variables and definitions will be different):

public OnPlayerText(playerid, text[])
{
if(IsLogged(playerid) && CharSpawned(playerid))
{
if(IsIp(text) || ContainsIP(text))
{

if(IsStaff(playerid, STAFF_LEVEL_OPERATORI) && IsOnStaffDuty(playerid) || IsModerator(playerid, MODERATOR_LEVEL_JUNIOR) && IsOnModeratorDuty(playerid))
{

} else {
CreateMessage(playerid, "Anti-Cheat", "I'm sorry to say but we do not allow server advertising here.");
CreateStaffAlert("%s (%s) just attempted to advertise an IP Address (Message: %s)", AccountInformation[playerid][AccountName], CharacterInformation[playerid][CHAR(playerid)][CharacterName], text);
}

} else {

if(IsPlayerInAnyVehicle(playerid))
{

} else {

if(IsAlphaNumeric(text))
{
new message[256];
if(IsOnModeratorDuty(playerid))
format(message, sizeof(message), "(( [M] %s says: %s ))", AccountInformation[playerid][AccountName], text);
else if(IsOnStaffDuty(playerid))
format(message, sizeof(message), "(( [S] %s says: %s ))", AccountInformation[playerid][AccountName], text);
else {
if(strlen(CharacterInformation[playerid][CHAR(playerid)][CharacterAccent]) > 0)
format(message, sizeof(message), "[%s] %s says: %s", CharacterInformation[playerid][CHAR(playerid)][CharacterAccent], CharacterInformation[playerid][CHAR(playerid)][CharacterName], text);
else
format(message, sizeof(message), "%s says: %s", CharacterInformation[playerid][CHAR(playerid)][CharacterName], text);
}
SendLocalMessage(15, playerid, message, COLOR_FADE1,COLOR_FADE2,COLOR_FADE3,COLOR_FADE4,CO LOR_FADE5);
} else
return CreateErrorMessage(playerid, "You cannot use special characters in-chat, you may only use Alpha-Numeric (EG: ABC123)");
}
}
}
return true;
}