SA-MP Forums Archive
An Additon to /siren command - 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: An Additon to /siren command (/showthread.php?tid=375462)



An Additon to /siren command - Harmon - 07.09.2012

I have a /siren command for officers in my script.
I've been trying to add another option /siren cop for Cruisers to add two more light objects to both sides of the rear windshield. I'm having trouble trying to get the right coordinates on a vehicle to place the objects in their correct place I want them to be in.

Here is the code and here is the SS of what I want.

Код:
else if(strcmp(siren, "cop", true, strlen(siren)) == 0)
				{
				    if(Siren[VID] == 0)
				    {
						Siren[VID] = 1;
						GetPlayerName(playerid, sendername, sizeof(sendername));
						SirenObject[VID] = CreateObject(18646, 10.0, 10.0, 10.0, 0, 0, 0);
						AttachObjectToVehicle(SirenObject[VID], VID, 0.0, 0.75, 0.275, 0.0, 0.1, 0.0);
						SirenObject[VID] = CreateObject(18646, 10.0, 10.0, 10.0, 0, 0, 0);
						AttachObjectToVehicle(SirenObject[VID], VID, 1.0, 1.50, 0.275, 0.0, 0.1, 0.0);
						SirenObject[VID] = CreateObject(18646, 10.0, 10.0, 10.0, 0, 0, 0);
						AttachObjectToVehicle(SirenObject[VID], VID, 1.0, -1.50, 0.275, 0.0, 0.1, 0.0);
						format(string, sizeof(string), "* %s puts the siren on the roof.", sendername);
						ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
					} else { return SendClientMessage(playerid, COLOR_GREY, "This vehicle already has a siren!"); }
                }
Heres the screenshot of where i want the Last two AttachObjectToVehicle cords to be.

http://i1172.photobucket.com/albums/.../sa-mp-588.png

Rep will be given to whoever helps. Thank you for viewing this topic


Re: An Additon to /siren command - Harmon - 07.09.2012

Sorry if this is double posting or against the rules, I would like to add that if its possible to edit the /siren off command to make both of the last 2 objects to disappear because they are not going away.. here is the /siren off command

Код:
 else if(strcmp(siren, "off", true, strlen(siren)) == 0)
                {
                    if(Siren[VID] == 1)
                    {
                    	Siren[VID] = 0;
                    	GetPlayerName(playerid, sendername, sizeof(sendername));
                    	DestroyObject(SirenObject[VID]);
                    	DestroyObject(SirenObject[VID]);
                    	DestroyObject(SirenObject[VID]);
                    	format(string, sizeof(string), "* %s takes down the siren.", sendername);
                    	ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                    } else { return SendClientMessage(playerid, COLOR_GREY, "This vehicle doesn't have siren!"); }
                }
            } else { SendClientMessage(playerid, COLOR_GREY, "   You are not part of a Team!"); }
        }
        return 1;
    }



Re: An Additon to /siren command - XGh0stz - 07.09.2012

Код:
// Declaring SirenObject1,2,3,etc. (Top of Script somewhere)

static SirenObject1[2000]; // change 2000 to the number of vehicles in your server though
static SirenObject2[2000];
static SirenObject3[2000];

// Siren On Code:

SirenObject1[VID] = CreateObject();// Of course you'll need to fill in the object info :P
SirenObject2[VID] = CreateObject();
SirenObject3[VID] = CreateObject();

// Siren Off Code:

DestroyObject(SirenObject1[VID]);
DestroyObject(SirenObject2[VID]);
DestroyObject(SirenObject3[VID]);
You're using SirenObject[VID] for 3 object ids which can only hold 1, thus each time you do SirenObject[VID]=, it's just over writting what was previously stored. So then when you use DestroyObject(SirenObjectpVID]); 3 times, it only delete the last object id that was stored to it, 3 times (Deleting the same object 3 times). So, I've provided a example above that stores all 3 object ids to 3 diffirent Varibles (Adding a number after each one: 1, 2 and 3). So when it comes time to destroy the objects, simply destroy all 3 of those varibles as shown...

There are far greater ways to do this, but kept it real simple so you can grasp the basic concept
(But it will be vital later on to practice good optimized code and learning everything about mem/cpu usage etc.)

As for moving attached objects inside the vehicle, I've never attempted this, so I don't know if possible or not. But just play around with the cordinates and see what can be done. If you cant seem to move the object inside at all, then it's not likely possible... (Try placing the object way in the vehicle just to see if its even possible)

EDIT: Just noticed the REP comment, but I responded to help, not to gain REP (That part is completely optional)


Re: An Additon to /siren command - Harmon - 07.09.2012

Well Thank you, This helped the siren object problem. Is there any way to find out which Cord moves side to side... up and down.. on a vehicle so I'm aware of which cords to edit in the correct way.


Re: An Additon to /siren command - XGh0stz - 07.09.2012

Although I'm not positive of this, I believe X is Left/Right and Y is Up/Down and then Z would be the Height. You can just try adjusting the Y only (Add or Subtract to it) and then check which way it has moved, then comment a note about object directions etc.

The fastest way of figuring all this out is just by running a few tests taking note of which direction a object moves when X/Y/Z is adjusted. It's possible those directions are listed in the Wiki with the CreateObject Function Page, but either way, it's alot faster than waiting around for someone to respond (If they respond even).