SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 04/04/2020, 09:21 PM   #1
RogerX
Little Clucker
 
RogerX's Avatar
 
Join Date: Mar 2017
Location: Marte
Posts: 41
Reputation: 6
Post [HELP] Electric Fence

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
__________________
Meus Projetos


Mapas






FilterScript's




GameModes
RogerX is offline   Reply With Quote
Old 04/04/2020, 09:51 PM   #2
Janoz12
Little Clucker
 
Join Date: Aug 2016
Posts: 27
Reputation: 2
Default Re: [HELP] Electric Fence

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.
Janoz12 is offline   Reply With Quote
Old 05/04/2020, 12:56 AM   #3
v1k1nG
Huge Clucker
 
v1k1nG's Avatar
 
Join Date: Feb 2018
Posts: 497
Reputation: 35
Default Re: [HELP] Electric Fence

Hello. Please read this

https://wiki.sa-mp.com/wiki/IsPlayerInRangeOfPoint
https://wiki.sa-mp.com/wiki/SetPlayerHealth
https://wiki.sa-mp.com/wiki/ApplyAnimation

and good luck!
__________________
My test server: 51.91.122.18:7778
My Discord contact: [SF]kAn3#9933
YT https://www.youtube.com/channel/UCrM...QtP2pczguqvppw
v1k1nG is offline   Reply With Quote
Old 05/04/2020, 01:07 AM   #4
RogerX
Little Clucker
 
RogerX's Avatar
 
Join Date: Mar 2017
Location: Marte
Posts: 41
Reputation: 6
Default Re: [HELP] Electric Fence

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
__________________
Meus Projetos


Mapas






FilterScript's




GameModes
RogerX is offline   Reply With Quote
Old 05/04/2020, 06:08 AM   #5
Janoz12
Little Clucker
 
Join Date: Aug 2016
Posts: 27
Reputation: 2
Default Re: [HELP] Electric Fence

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.
Janoz12 is offline   Reply With Quote
Old 05/04/2020, 08:38 AM   #6
David (Sabljak)
Huge Clucker
 
Join Date: Nov 2011
Posts: 342
Reputation: 18
Default Re: [HELP] Electric Fence

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
}
David (Sabljak) is offline   Reply With Quote
Old 05/04/2020, 10:47 AM   #7
RogerX
Little Clucker
 
RogerX's Avatar
 
Join Date: Mar 2017
Location: Marte
Posts: 41
Reputation: 6
Default Re: [HELP] Electric Fence

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
__________________
Meus Projetos


Mapas






FilterScript's




GameModes
RogerX is offline   Reply With Quote
Old 05/04/2020, 10:52 AM   #8
RogerX
Little Clucker
 
RogerX's Avatar
 
Join Date: Mar 2017
Location: Marte
Posts: 41
Reputation: 6
Default Re: [HELP] Electric Fence

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
__________________
Meus Projetos


Mapas






FilterScript's




GameModes
RogerX is offline   Reply With Quote
Old 05/04/2020, 02:15 PM   #9
Janoz12
Little Clucker
 
Join Date: Aug 2016
Posts: 27
Reputation: 2
Default Re: [HELP] Electric Fence

Can you show me your filterscript to see how you have it?
Janoz12 is offline   Reply With Quote
Old 05/04/2020, 03:44 PM   #10
RogerX
Little Clucker
 
RogerX's Avatar
 
Join Date: Mar 2017
Location: Marte
Posts: 41
Reputation: 6
Default Re: [HELP] Electric Fence

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;
}
__________________
Meus Projetos


Mapas






FilterScript's




GameModes
RogerX 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
SA-MP Electric Cars? Brentbad04 General 14 09/03/2014 11:06 AM
Electric Objects Kasra230 Everything and Nothing 1 12/06/2013 11:30 AM
Electric gates help please. sammypiv Help Archive 2 27/03/2010 09:33 AM
Electric fence Sal_Kings Help Archive 14 12/11/2009 08:24 AM
Electric Vence Zaka Help Archive 12 08/11/2009 05:17 PM


All times are GMT. The time now is 07:16 AM.


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