SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 22/06/2020, 07:02 AM   #1
Uvais
Big Clucker
 
Uvais's Avatar
 
Join Date: Oct 2015
Location: Pakistan
Posts: 175
Reputation: 19
Default Door shouts

Code:
CMD:s(playerid, params[])
{
    new str[MAX_PLAYER_NAME+10+70+1];

	if (isnull(params))
	    return SendSyntaxMessage(playerid, "/(s)hout [shout text]");

	if(strlen(params) > 84)
	{
		format(str, sizeof(str), "%s shouts: %.84s", ReturnName(playerid, 2), params);
		LocalChat(playerid, 20.0, str, COLOR_FADE1, COLOR_FADE1, COLOR_FADE2, COLOR_FADE3);

		format(str, sizeof(str), "...%s", params[84]);
		LocalChat(playerid, 20.0, str, COLOR_FADE1, COLOR_FADE1, COLOR_FADE2, COLOR_FADE3);
	}
	else
	{
		format(str, sizeof(str), "%s shouts: %s", ReturnName(playerid, 2), params);
		LocalChat(playerid, 20.0, str, COLOR_FADE1, COLOR_FADE1, COLOR_FADE2, COLOR_FADE3);
	}

	for(new i; i < MAX_HOUSES; i++)
    {
        if(HouseData[i][houseID] > 0 && IsPlayerInRangeOfPoint(playerid, 3.0, HouseData[i][housePos][0], HouseData[i][housePos][1], HouseData[i][housePos][2]))
        {
            if(GetPlayerInterior(playerid) != HouseData[i][houseInterior])
				continue;

			if(GetPlayerVirtualWorld(playerid) != HouseData[i][houseExteriorVW])
				continue;

			foreach(new p: Player)
			{
				if(IsPlayerInRangeOfPoint(p, 30.0, HouseData[i][houseInt][0], HouseData[i][houseInt][1], HouseData[i][houseInt][2]))
				{
					if(GetPlayerInterior(p) != HouseData[i][houseInterior])
						continue;

					if(GetPlayerVirtualWorld(p) != i)
						continue;

     				if (strlen(params) > 64)
					{
					    SendNearbyMessage(playerid, 30.0, COLOR_WHITE, "%s shouts (Door): %.64s", ReturnName(playerid, 2), params);
					    SendNearbyMessage(playerid, 30.0, COLOR_WHITE, "...%s", params[64]);
					}
					else
					{
					    SendNearbyMessage(playerid, 30.0, COLOR_WHITE, "%s shouts (Door): %s", ReturnName(playerid, 2), params);
					}
				}
			}
            return 1;
        }
    }

	for(new i; i < MAX_BUSINESSES; i++)
    {
        if(BusinessData[i][bizID] > 0 && IsPlayerInRangeOfPoint(playerid, 3.0, BusinessData[i][bizPos][0], BusinessData[i][bizPos][1], BusinessData[i][bizPos][2]))
        {
            if(GetPlayerInterior(playerid) != BusinessData[i][bizInterior])
				continue;

			if(GetPlayerVirtualWorld(playerid) != BusinessData[i][bizExteriorVW])
				continue;

			foreach(new p: Player)
			{
				if(IsPlayerInRangeOfPoint(p, 30.0, BusinessData[i][bizInt][0], BusinessData[i][bizInt][1], BusinessData[i][bizInt][2]))
				{
					if(GetPlayerInterior(p) != BusinessData[i][bizInterior])
						continue;

					if(GetPlayerVirtualWorld(p) != i)
						continue;

					if (strlen(params) > 64)
					{
					    SendNearbyMessage(playerid, 30.0, COLOR_WHITE, "%s shouts (Door): %.64s", ReturnName(playerid, 2), params);
					    SendNearbyMessage(playerid, 30.0, COLOR_WHITE, "...%s", params[64]);
					}
					else
					{
					    SendNearbyMessage(playerid, 30.0, COLOR_WHITE, "%s shouts (Door): %s", ReturnName(playerid, 2), params);
					}
				}
			}
            return 1;
        }
    }

	format(str, sizeof(str), "logs/action_logs/%s.txt", ReturnName(playerid, 1));
	Log_Write(str, "[%s] (/shout) %s shouts: %s", ReturnDate(), ReturnName(playerid, 2), params);
	return 1;
}
With my code above, I'm trying to get a shout through a house / business door so the player on the other side is able to hear it but I wrote it down yesterday night and tested it today morning.. SMH For some reason it's not working and I can't see the problem (probably because I'm blind). Any help regarding this would be appreciated, thanks.
__________________
Uvais is offline   Reply With Quote
Old 22/06/2020, 12:16 PM   #2
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,783
Reputation: 619
Default Re: Door shouts

I don't know your House enum, but I assume there is a virtual world var as well for the interior?

See this:

Code:
if(GetPlayerVirtualWorld(p) != i)
It looks like it should be HouseData[i][houseInteriorVW] or something similar (except you actually use the house/bizz ID as virtual world). Nvm if this is intentional (I would suggest assigning unique VWs though, as currently players in business 0 and house 0 would be able to see each other in theory).

Otherwise it might be a good idea to add some prints inside the code, to see which parts are executed and where it fails to continue when it should. Then you can see where exactly the issue is.
NaS is offline   Reply With Quote
Old 22/06/2020, 12:18 PM   #3
jasperschellekens
High-roller
 
jasperschellekens's Avatar
 
Join Date: Dec 2016
Location: Holland
Posts: 1,077
Reputation: 126
Default Re: Door shouts

Why have you made such a mess of your code?
Do you have any idea what you are doing? I would do it like this instead:

pawn Code:
new CurrentHouseID[MAX_PLAYERS];
new CurrentBizID[MAX_PLAYERS];

// When enter biz or house, set id into vars above.

CMD:s(playerid, params[])
{
    new str[MAX_PLAYER_NAME+10+70+1], bool: NearStructure, HouseID, BizID;

     if (isnull(params))
         return SendSyntaxMessage(playerid, "/(s)hout [shout text]");

     if(strlen(params) > 84)
     {
          format(str, sizeof(str), "%s shouts: %.84s", ReturnName(playerid, 2), params);
          LocalChat(playerid, 20.0, str, COLOR_FADE1, COLOR_FADE1, COLOR_FADE2, COLOR_FADE3);

          format(str, sizeof(str), "...%s", params[84]);
          LocalChat(playerid, 20.0, str, COLOR_FADE1, COLOR_FADE1, COLOR_FADE2, COLOR_FADE3);
     }
     else
     {
          format(str, sizeof(str), "%s shouts: %s", ReturnName(playerid, 2), params);
          LocalChat(playerid, 20.0, str, COLOR_FADE1, COLOR_FADE1, COLOR_FADE2, COLOR_FADE3);
     }

     for(new i; i < MAX_HOUSES; i++)
     {
          if(HouseData[i][houseID] > 0 && IsPlayerInRangeOfPoint(playerid, 3.0, HouseData[i][housePos][0], HouseData[i][housePos][1], HouseData[i][housePos][2]))
          {
               NearStructure = true;
               HouseID = i;
          }
     }

     for(new i; i < MAX_BUSINESSES; i++)
     {
          if(BusinessData[i][bizID] > 0 && IsPlayerInRangeOfPoint(playerid, 3.0, BusinessData[i][bizPos][0], BusinessData[i][bizPos][1], BusinessData[i][bizPos][2]))
          {
               NearStructure = true;
               BizID = i;
          }
     }

     foreach(new p: Player)
     {
          if(CurrentHouseID[p] == HouseID && NearStructure || CurrentBizID[p] == BizID && NearStructure)
          {
               if (strlen(params) > 64)
               {
                   SendClientMessage(p, 30.0, COLOR_WHITE, "%s shouts (Door): %.64s", ReturnName(playerid, 2), params);
                   SendClientMessage(p, 30.0, COLOR_WHITE, "...%s", params[64]);
               }
               else
               {
                   SendClientMessage(p, 30.0, COLOR_WHITE, "%s shouts (Door): %s", ReturnName(playerid, 2), params);
               }
          }
     }

     format(str, sizeof(str), "logs/action_logs/%s.txt", ReturnName(playerid, 1));
     Log_Write(str, "[%s] (/shout) %s shouts: %s", ReturnDate(), ReturnName(playerid, 2), params);
     return 1;
}
__________________
If you want to have your own custom script, or even want to have one of our already released scripts, join our SCRIPTING SERVICES DISCORD, or send me a private message!


Undead Wasteland Roleplay - The year is 1996. San Andreas is a wasteland ruled by the undead. the once so glorius landscape of San Andreas, is now a shattered decayed place that is only a vague memory of the world as we used to know it.
Discord - Website
jasperschellekens is offline   Reply With Quote
Reply

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
How to move a door/open the LSPD door? EtayJ Scripting Help 2 16/11/2016 03:09 AM
door id GeneralAref Scripting Help 1 16/12/2015 04:10 PM
[FilterScript] Door Run Boricko Filterscripts 35 06/10/2014 09:10 PM
See if a player is near to the driver's door or the passenger door Hantex. Scripting Help 9 03/09/2014 11:06 PM
help iam make map and make door in place cop office and door no open when player need go Abdo2013 Scripting Help 6 16/04/2012 08:13 PM


All times are GMT. The time now is 09:09 AM.


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