SA-MP Forums Archive
Help with system - 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: Help with system (/showthread.php?tid=612609)



Help with system - ,TomY' - 19.07.2016

Hi. I using this filterscript: http://pastebin.com/D8fDVFma

And... I have some problems. When create spawns and I type /crate to watch where is it, system shows random distance. Also when I near a crate system say: You aren't near the crate!

Maybe somebody can help?


Re: Help with system - Freaksken - 19.07.2016

Can you show your /crate command?


Re: Help with system - ,TomY' - 19.07.2016

Code:
CMD:crate(playerid, params[])// Outputs distance from crate in meters
{
    if(CrateObject != 0)
	{
		new rand = random(sizeof(g_CrateSpawns)),
        	Float: CrateDis = GetPlayerDistanceFromPoint(playerid, g_CrateSpawns[rand][0], g_CrateSpawns[rand][1], g_CrateSpawns[rand][2]),
        	string[64];

		format(string, sizeof(string), "* You're %.0f meters away from the Lost Crate.", CrateDis);
		SendClientMessage(playerid, COLOR_YELLOWGREEN, string);// Sending message to the player.
	}
	else
	{
	    SendClientMessage(playerid, COLOR_RED, "The crate hasn't been spawned yet. Check again soon.");// Sending message to the player.
	}
	return 1;
}



Re: Help with system - Freaksken - 19.07.2016

Woops it was on pastebin, didn't see that. I'll take a look.

EDIT:
Ok, so that FS has an array of g_CrateSpawns with X Y Z coordinates. These are all the possible positions the crate can spawn at. The crate is created in CrateMessage at a random position of the array. When you use /crate you shouldn't use new rand = random(sizeof(g_CrateSpawns)); because that will chose a random position of the array. You should store the position of the crate when you create it.

Code:
//Top of script
new CrateObject;
new CrateIndex;

//Create the crate
new rand = random(sizeof(g_CrateSpawns));
CrateObject = CreateDynamicObject(CRATE_MODEL_ID, g_CrateSpawns[rand][0], g_CrateSpawns[rand][1], g_CrateSpawns[rand][2]-0.4, -1, -1, -1);
CrateIndex = rand;

//The /crate command
new Float: CrateDis = GetPlayerDistanceFromPoint(playerid, g_CrateSpawns[CrateIndex][0], g_CrateSpawns[CrateIndex][1], g_CrateSpawns[CrateIndex][2]);