How do i make gate open and close? Please help me with this small thing
#1

Hello,
I need help with a small thing: i have a gate, and i want it to open automatically only for players that have [BD] tag in front of their name. (I want it to open when they go near the gate and i want it to close when they go away from it.)

Here is the gate coordinates when the gate is in the ground:
Код:
CreateDynamicObject(988, -488.89850, -562.67981, 25.35821,   0.00000, 0.00000, 0.00000);
I want it to open like that the gate moves up in air, and closes that it moves back down. (Only for players that have [BD] tag in front of their name).

Please help me guys,
Thanks in advance.
Reply
#2

this Filterscript can make Open and close gates anywhere
https://sampforum.blast.hk/showthread.php?tid=345906
Reply
#3

Quote:
Originally Posted by AliBro
Посмотреть сообщение
this Filterscript can make Open and close gates anywhere
https://sampforum.blast.hk/showthread.php?tid=345906
Dude, i don't want that, i want what i typed in my post.
Reply
#4

Use strcmp to check the player-name.
Setting the last parameter to 4 means that only the first 4 characters will be compared.

Код:
new name[MAX_PLAYER_NAME]; 
GetPlayerName(playerid, name, sizeof(name));
if (strcmp(name, "[BD]", true, 4))
{
    // Do code here
}
Define your object and then use MoveDynamicObject (for Streamer) to move it:
Код:
MoveDynamicObject(objectid, Float:x, Float:y, Float:z, Float:speed, Float:rx, Float:ry, Float:rz);
Reply
#5

Quote:
Originally Posted by Darkwood17
Посмотреть сообщение
Use strcmp to check the player-name.
Setting the last parameter to 4 means that only the first 4 characters will be compared.

Код:
new name[MAX_PLAYER_NAME]; 
GetPlayerName(playerid, name, sizeof(name));
if (strcmp(name, "[BD]", true, 4))
{
    // Do code here
}
Define your object and then use MoveDynamicObject (for Streamer) to move it:
Код:
MoveDynamicObject(objectid, Float:x, Float:y, Float:z, Float:speed, Float:rx, Float:ry, Float:rz);
Can you please give the full code, i didn't understand?
Reply
#6

This?
Код:
new GateObj;

public OnGameModeInit()
{
	GateObj = CreateDynamicObject(988, -488.89850, -562.67981, 25.35821,   0.00000, 0.00000, 0.00000);
	SetTimer("Gate", 500, true);
	
	return 1;
}

forward Gate();
public Gate()
{
	for(new i = 0; i < MAX_PLAYERS; i ++)
	{
		if(!IsPlayerConnected(i)) continue;
		
		if(IsPlayerInRangeOfPoint(i, 7.0, 488.89850, -562.67981, 25.35821))
		{
			new Name[24];
			GetPlayerName(i, Name, 24);
			
			if(strfind(Name, "[BD]", true) != -1) MoveObject(GateObj, -488.89850, -562.67981, 35.35821, 5.0, 0.0, 0.0, 0.0);
		}
		else MoveObject(GateObj, -488.89850, -562.67981, 25.35821, 5.0, 0.0, 0.0, 0.0);
	}
	return 1;
}
Reply
#7

Quote:
Originally Posted by F1N4L
Посмотреть сообщение
This?
Код:
new GateObj;

public OnGameModeInit()
{
	GateObj = CreateDynamicObject(988, -488.89850, -562.67981, 25.35821,   0.00000, 0.00000, 0.00000);
	SetTimer("Gate", 500, true);
	
	return 1;
}

forward Gate(playerid);
public Gate(playerid)
{
	if(IsPlayerInRangeOfPoint(playerid, 7.0, 488.89850, -562.67981, 25.35821))
	{
		new Name[24];
		GetPlayerName(playerid, Name, 24);
		
		if(strfind(Name, "[BD]", true) != -1) MoveObject(GateObj, -488.89850, -562.67981, 35.35821, 5.0, 0.0, 0.0, 0.0);
	}
	else MoveDynamicObject(GateObj, -488.89850, -562.67981, 25.35821, 5.0, 0.0, 0.0, 0.0);
	
	return 1;
}
PHP код:
SetTimer("Gate"500true);
forward Gate(playerid);
public 
Gate(playerid
where did playerid come from :/ ?
Reply
#8

Quote:
Originally Posted by xTURBOx
Посмотреть сообщение
PHP код:
SetTimer("Gate"500true);
forward Gate(playerid);
public 
Gate(playerid
where did playerid come from :/ ?
I edited, thx.

But your code is also wrong!

Код:
if(IsPlayerInRangeOfPoint(i,3.0,-488.89850, -562.67981, 25.35821) && strcmp(GetName(i), "[BD]", true, 4)) 
        { 
         if(GateOpen = 0)  
          { 
            MoveDynamicObject(BDgate, -488.89850, -562.67981, 26, 3.0, Float:rx = -1000.0, Float:ry = -1000.0, Float:rz = -1000.0); 
            GateOpen = 1; 
          } 
        } 
        else if(GateOpen = 1) 
        { 
           MoveDynamicObject(BDgate, -488.89850, -562.67981, 25.35821, 3.0, Float:rx = -1000.0, Float:ry = -1000.0, Float:rz = -1000.0); 
           GateOpen = 0: 
        }
Whenever the gate is opening/closing, the variable will change and will give some ingame conflict.
Reply
#9

Quote:
Originally Posted by F1N4L
Посмотреть сообщение
This?
Код:
new GateObj;

public OnGameModeInit()
{
	GateObj = CreateDynamicObject(988, -488.89850, -562.67981, 25.35821,   0.00000, 0.00000, 0.00000);
	SetTimer("Gate", 500, true);
	
	return 1;
}

forward Gate();
public Gate()
{
	for(new i = 0; i < MAX_PLAYERS; i ++)
	{
		if(!IsPlayerConnected(i)) continue;
		
		if(IsPlayerInRangeOfPoint(i, 7.0, 488.89850, -562.67981, 25.35821))
		{
			new Name[24];
			GetPlayerName(i, Name, 24);
			
			if(strfind(Name, "[BD]", true) != -1) MoveObject(GateObj, -488.89850, -562.67981, 35.35821, 5.0, 0.0, 0.0, 0.0);
		}
		else MoveObject(GateObj, -488.89850, -562.67981, 25.35821, 5.0, 0.0, 0.0, 0.0);
	}
	return 1;
}
It's not working, the gate isn't opening at all..

Quote:
Originally Posted by xTURBOx
Посмотреть сообщение
PHP код:
new BDgate;
new 
GateOpen;
public 
OnGameModeInit()
{
    
BDgate CreateDynamicObject(988, -488.89850, -562.6798125.35821,   0.000000.000000.00000);
    
GateOpen 0;
    
SetTimer("BDGateCheck",3000,true);
    return 
1;
}
forward BDGateCheck();
public 
BDGateCheck()
{
    for(new 
i=0i<GetPlayerPoolSize(); i++)
    {
        if(
IsPlayerInRangeOfPoint(i,3.0,-488.89850, -562.6798125.35821) && strcmp(GetName(i), "[BD]"true4))
        {
         if(
GateOpen 0
          {
            
MoveDynamicObject(BDgate, -488.89850, -562.67981263.0Float:rx = -1000.0Float:ry = -1000.0Float:rz = -1000.0);
            
GateOpen 1;
          }
        }
        else if(
GateOpen 1)
        {
           
MoveDynamicObject(BDgate, -488.89850, -562.6798125.358213.0Float:rx = -1000.0Float:ry = -1000.0Float:rz = -1000.0);
           
GateOpen 0:
        }
    }
}
GetName(playerid)
{
  new 
Name[MAX_PLAYER_NAME];
  
GetPlayerName(playerid,Namesizeof(name));
  return 
Name;

It gives these errors:
Код:
(17) : error 017: undefined symbol "GetPlayerPoolSize"
(21) : warning 211: possibly unintended assignment
(23) : error 017: undefined symbol "rx"
(23) : warning 215: expression has no effect
(23) : error 017: undefined symbol "rz"
(23) : warning 215: expression has no effect
(23) : error 001: expected token: ";", but found ")"
(23) : fatal error 107: too many error messages on one line
Reply
#10

Quote:
Originally Posted by Hillo
Посмотреть сообщение
It's not working, the gate isn't opening at all..


It gives these errors:
Код:
(17) : error 017: undefined symbol "GetPlayerPoolSize"
(21) : warning 211: possibly unintended assignment
(23) : error 017: undefined symbol "rx"
(23) : warning 215: expression has no effect
(23) : error 017: undefined symbol "rz"
(23) : warning 215: expression has no effect
(23) : error 001: expected token: ";", but found ")"
(23) : fatal error 107: too many error messages on one line
First of all, if you get the GetPlayerPoolSize error update your SA-MP server.

Both codes above by F1N4L and xTURBOx are incorrectly written and wrong.

You don't need to set the last 3 parameters (rx, ry, rx) because they have default value:
Код:
MoveDynamicObject(BDgate, -488.89850, -562.67981, 26, 3.0); 
MoveDynamicObject(BDgate, -488.89850, -562.67981, 25.35821, 3.0);
And this should be:
Код:
if (GateOpen == 0)
But you actually don't need to check if the gate is open, because this is automatic gate, not a command.
And you actually don't need to loop through all players. Just create the timer under OnPlayerSpawn or OnPlayerConnect.

This is how your code should look like:
Код:
// at the top of your script
new BDgate;

public OnGameModeInit()
{
	BDgate = CreateDynamicObject(988, -488.89850, -562.67981, 25.35821,   0.00000, 0.00000, 0.00000);
	return 1;
}

public OnPlayerSpawn(playerid)
{
	SetTimer("BDGateCheck", 500, true);
	return 1;
}

forward BDGateCheck(playerid);
public BDGateCheck(playerid)
{
	new name[MAX_PLAYER_NAME];
	GetPlayerName(playerid, name, sizeof(name));
	if(IsPlayerInRangeOfPoint(i, 5.0, -488.89850, -562.67981, 25.35821) && strcmp(name, "[BD]", true, 4))
	MoveDynamicObject(BDgate, -488.89850, -562.67981, 20, 3.0); // Open the gate
	else MoveDynamicObject(BDgate, -488.89850, -562.67981, 25.35821, 3.0); // Close the gate
	return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)