SA-MP Forums Archive
[HELP] Electric Fence - 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] Electric Fence (/showthread.php?tid=673789)



[HELP] Electric Fence - RogerX - 04.04.2020

Hello ... I was wondering if anyone knows an electric fence filterscript, or if they could teach me how to do ...
I want that when the player approaches an object (in this case the fence) it loses a certain amount of life, and enter an animation for about 5 seconds without being able to leave it


Re: [HELP] Electric Fence - Janoz12 - 04.04.2020

Hi.

The following should work.

Code:
new Electric_Fence;
#define FenceModelID 16868 //Change to preference

public OnGameModeInit()
{
SetTimer("Check_Position", 1000, true); //Change to preference

Electric_Fence = CreateObject(FenceModelID, xchange, ychange, zchange, 0.0, 0.0, 0.0);

return 1;
}

forward Check_Position();
public   Check_Position()
{

for (new i; i < GetPlayerPoolSize(); i++)
{
new Float: x,Float: y,Float: z;
GetObjectPos(Electric_Fence,x,y,z);

if (!IsPlayerInRangeOfPoint(i, 1.0, x, y, z)) // Change to preference
{
new Float:health;
GetPlayerHealth(i, health);
SetPlayerHealth(i, health-15); // Change to preference
}


}
return 1;
}
Animation is missing.


Re: [HELP] Electric Fence - v1k1nG - 05.04.2020

Hello. Please read this

https://sampwiki.blast.hk/wiki/IsPlayerInRangeOfPoint
https://sampwiki.blast.hk/wiki/SetPlayerHealth
https://sampwiki.blast.hk/wiki/ApplyAnimation

and good luck!


Re: [HELP] Electric Fence - RogerX - 05.04.2020

Quote:
Originally Posted by Janoz12
View Post
Hi.

The following should work.

Code:
new Electric_Fence;
#define FenceModelID 16868 //Change to preference

public OnGameModeInit()
{
SetTimer("Check_Position", 1000, true); //Change to preference

Electric_Fence = CreateObject(FenceModelID, xchange, ychange, zchange, 0.0, 0.0, 0.0);

return 1;
}

forward Check_Position();
public   Check_Position()
{

for (new i; i < GetPlayerPoolSize(); i++)
{
new Float: x,Float: y,Float: z;
GetObjectPos(Electric_Fence,x,y,z);

if (!IsPlayerInRangeOfPoint(i, 1.0, x, y, z)) // Change to preference
{
new Float:health;
GetPlayerHealth(i, health);
SetPlayerHealth(i, health-15); // Change to preference
}


}
return 1;
}
Animation is missing.
I put your code, there was no mistake ... but when I approach the fence I don't lose any life


Re: [HELP] Electric Fence - Janoz12 - 05.04.2020

It's going to be a little complicated to get this to work properly.

The problem occurs because 'IsPlayerInRangeOfPoint' detects if the player is in the range of the set coordinate.

So you put an object in a coordinate, but that object is bigger, but the function 'IsPlayerInRangeOfPoint' only corresponds to the coordinate of the object, but not to the object as such.

Simply put, you have to get close to the exact coordinate, but not the object.

Suggestion:

Try creating the objects normally, and set the coordinates apart so that when a player gets close it will damage it.

Example:

You put a fence normally, and set 3 coordinates inside that fence (left, center, right), and if the player gets close to one of those areas, it damages it.


Re: [HELP] Electric Fence - David (Sabljak) - 05.04.2020

Quote:
Originally Posted by Janoz12
View Post
It's going to be a little complicated to get this to work properly.

The problem occurs because 'IsPlayerInRangeOfPoint' detects if the player is in the range of the set coordinate.

So you put an object in a coordinate, but that object is bigger, but the function 'IsPlayerInRangeOfPoint' only corresponds to the coordinate of the object, but not to the object as such.

Simply put, you have to get close to the exact coordinate, but not the object.

Suggestion:

Try creating the objects normally, and set the coordinates apart so that when a player gets close it will damage it.

Example:

You put a fence normally, and set 3 coordinates inside that fence (left, center, right), and if the player gets close to one of those areas, it damages it.
This,

also you can use

Code:
stock IsPlayerInTheArea(playerid,Float:minx,Float:miny,Float:maxx,Float:maxy)
{
	new Float:posx, Float:posy, Float:posz;
	GetPlayerPos(playerid, posx,posy,posz);
	if(posx >= minx && posx <= maxx && posy >= miny && posy <= maxy)
	{
	    return true;
	}
	else return false;
}
and detect it with X,Y - X,Y like Zone.

Code:
if(IsPlayerInTheArea(playerid,X,Y,X,Y))
{
//He is in your area. do it here
}



Re: [HELP] Electric Fence - RogerX - 05.04.2020

Quote:
Originally Posted by Janoz12
View Post
It's going to be a little complicated to get this to work properly.

The problem occurs because 'IsPlayerInRangeOfPoint' detects if the player is in the range of the set coordinate.

So you put an object in a coordinate, but that object is bigger, but the function 'IsPlayerInRangeOfPoint' only corresponds to the coordinate of the object, but not to the object as such.

Simply put, you have to get close to the exact coordinate, but not the object.

Suggestion:

Try creating the objects normally, and set the coordinates apart so that when a player gets close it will damage it.

Example:

You put a fence normally, and set 3 coordinates inside that fence (left, center, right), and if the player gets close to one of those areas, it damages it.
I tried it, and it didn't work
i'm trying to do this in a separate FilterScript


Re: [HELP] Electric Fence - RogerX - 05.04.2020

Quote:
Originally Posted by David (Sabljak)
View Post
This,

also you can use

Code:
stock IsPlayerInTheArea(playerid,Float:minx,Float:miny,Float:maxx,Float:maxy)
{
	new Float:posx, Float:posy, Float:posz;
	GetPlayerPos(playerid, posx,posy,posz);
	if(posx >= minx && posx <= maxx && posy >= miny && posy <= maxy)
	{
	    return true;
	}
	else return false;
}
and detect it with X,Y - X,Y like Zone.

Code:
if(IsPlayerInTheArea(playerid,X,Y,X,Y))
{
//He is in your area. do it here
}
I didn't understand how I should put your cod


Re: [HELP] Electric Fence - Janoz12 - 05.04.2020

Can you show me your filterscript to see how you have it?


Re: [HELP] Electric Fence - RogerX - 05.04.2020

Quote:
Originally Posted by Janoz12
View Post
Can you show me your filterscript to see how you have it?

Code:
#define FILTERSCRIPT

#include <a_samp>
#include <sscanf>


new Electric_Fence;
#define FenceModelID 987 //Change to preference

public OnGameModeInit()
{
SetTimer("Check_Position", 1000, true); //Change to preference

Electric_Fence = CreateObject(FenceModelID, 1271.32739, -2047.58093, 58.14730, 0.0, 0.0, 0.0);

return 1;
}

forward Check_Position();
public   Check_Position()
{

for (new i; i < GetPlayerPoolSize(); i++)
{
new Float: x,Float: y,Float: z;
GetObjectPos(Electric_Fence,x,y,z);

if (!IsPlayerInRangeOfPoint(i, 1.0, x, y, z)) // Change to preference
{
new Float:health;
GetPlayerHealth(i, health);
SetPlayerHealth(i, health-15); // Change to preference
}


}
return 1;
}