Jump to content
  • 0

SetPos to an object not location, possible or not ?


Richie

Question

Is there a way to use setpos to teleport a player to an object rather than fixed location ?

 

This works :

player setPos [1576.3456, 15340.697, 0.001];

But this won't :

player setPos (getpos My_Object);

It must be an object because the objects location changes, I'm making a mine addon and the entrance changes per restart, so leaving the mine the player needs to go back to the entrance, entering can stay a fixed location.

 

 

Thanks in advance :)

Link to comment
Share on other sites

25 answers to this question

Recommended Posts

  • 0
//method 1
_objPos = _object modelToWorld [0,2,0]; //x,y,z ... 2 meters in front of entrance (adapts to direction if entrance is rotated)
player setPosATL _objPos;

//method 2
player setPosATL [(getPosATL _object select 0), (getPosATL _object select 1) + 2, (getPosATL _object select 2)]; // 2 meters north from entrance

//method 3 mix 1 and 2 together
_objPos = _object modelToWorld [0,0,1]; //1 meter above
player setPosATL [(getPosATL _object select 0) - 5, (getPosATL _object select 1) + 2, (getPosATL _object select 2)]; // 5 meters west, 2 meters north

it didn't work for you because of ()... you need to use [] because it's an array. Axeman is probably right, but I had problems with these before...

 

also getPos setPos is slowest and most innacurate (for example if you build wooden floor and step on it, values will change and floor will be now ~0 for Z.

getPosATL - for terrain level

getPosASL - for sea level (fastest)

 

search epoch github for FNC_GetPos inside compiles.sqf, that is a function that utilizes ASL, but converts to ATL, works both on land and sea and is fastest (probably best) way to go about.

_objPos = [_object] call FNC_GetPos;

edit: oops forgot to add "call" before function name

Link to comment
Share on other sites

  • 0
setPos player (getPos _myObject);

will work (don't think the brackets are even required).

 

Are you sure that wherever you are executing the setPos is aware of your mine object ? Can test by debugging with diag_log or hint:

format ["%1 is at position: %2",_myObject,getPos _myObject];
Link to comment
Share on other sites

  • 0

Hmmm another snag, because you enter the mine using a selfaction Infistar isn't liking it, any ideas how i would add an exception so it isn't detecting it as a teleport ?

Have teleport script server side using PublicVariableEventHandler (you can even attach the damn thing onto AHConfig.sqf, I do that sometimes when lazy)

//TP ppls
'PV_tpMe' addPublicVariableEventHandler
{
   [] spawn {
   waitUntil {!isNull PV_tpMe};
   _obj = _this select 0;
   _coords = _this select 1;
   _obj setPosATL _coords;
   PV_tpMe = nil;
   };
};

Then simply do a PublicVariableServer

PV_tpMe = [_object,_destination];
PublicVariableServer "PV_tpMe";

Not really safest way to go about, but hey... an option, right?

I guess safer way for this would be pushing most of code server side and having addAction only initiate PV with player as a value (PV_var = player;) then let server figure out the rest of the stuff like where the player is, where's the nearest mine and where to teleport him to etc etc... if cheating is detected, punish

Link to comment
Share on other sites

  • 0

I can't get any of them to work :unsure: here is what my MineExit.sqf looks like :

 

playSound "mineshaft";
titleCut ["Up to the surface we go","BLACK FADED", 25];
sleep 20;
_meobj = getpos exit;
player setPos _meobj;
sleep 5;
titlecut ["and we're back !","BLACK IN",5];

 

It goes through the motions, sound plays, text displays but when it says 'and we're back !' the player hasn't moved

 

My object is called   exit

Do i need an underscore or quotes maybe ?

Link to comment
Share on other sites

  • 0

:lol: typical, changing the name has made no difference, the script runs as it displays the exit text "and we're back !" yet fails to move me :unsure: I thought this would be easier than it is, maybe a fixed exit is the way to go.

 

My object code :

_vehicle_9 = objNull;
if (true) then
{
  _this = createVehicle ["Infostand_1_EP1", [1647.052, 7766.3428,0.01], [], 0, "CAN_COLLIDE"];
  _vehicle_9 = _this;
  _this setDir 215.91753;
  _this setVehicleVarName "MineEntrance";
  MineEntrance = _this;
  _this setPos [1647.052, 7766.3428,0.01];
};

 

My exit code

playSound "mineshaft";
titleCut ["Up to the surface we go","BLACK FADED", 25];
sleep 20;
_meobj = getpos MineEntrance;
player setPos _meobj;
sleep 5;
titlecut ["and we're back !","BLACK IN",5];
Link to comment
Share on other sites

  • 0

You only defined MineEntrance serverside. Use setVehicleInit to define it on clientside ;) . This should work: 

_vehicle_9 = objNull;
if (true) then
{
  _this = createVehicle ["Infostand_1_EP1", [1647.052, 7766.3428,0.01], [], 0, "CAN_COLLIDE"];
  _vehicle_9 = _this;
  _this setDir 215.91753;
  _this setVehicleInit "MineEntrance = this";
  _this setPos [1647.052, 7766.3428,0.01];
};
Link to comment
Share on other sites

  • 0

 

You only defined MineEntrance serverside. Use setVehicleInit to define it on clientside ;) . This should work: 

_vehicle_9 = objNull;
if (true) then
{
  _this = createVehicle ["Infostand_1_EP1", [1647.052, 7766.3428,0.01], [], 0, "CAN_COLLIDE"];
  _vehicle_9 = _this;
  _this setDir 215.91753;
  _this setVehicleInit "MineEntrance = this";
  _this setPos [1647.052, 7766.3428,0.01];
};

 

:o It works :o

GZA if you weren't in Germany i'd come buy you a beer :D you legend

Link to comment
Share on other sites

  • 0

xBowBii or Raymix, can you explin how to get round the TP restrictions again, In nice simple terms please :)

 

It's all working fine for me but players testing are getting trapped, once they leave the mine they're being sent straight back to where they started.

 

 

*EDIT*

xBowBii, I just realised we worked on something similer back in March, I made your underground bunkers :) small world

Link to comment
Share on other sites

  • 0

xBowBii or Raymix, can you explin how to get round the TP restrictions again, In nice simple terms please :)

 

You can do it hacky way client side ofc, but I would strongly suggest doing it properly server side trough publicVariableServer. basically server is responsible for teleporting, not the client. I posted you an example code earlier

Link to comment
Share on other sites

  • 0

You can do it hacky way client side ofc, but I would strongly suggest doing it properly server side trough publicVariableServer. basically server is responsible for teleporting, not the client. I posted you an example code earlier

I didn't understand your example code though, any hints ? :)

I've no idea where the code would go, in my selfaction or in the mine in/out scripts :unsure:

Link to comment
Share on other sites

  • 0

Here's more on the subject: 

 

In short terms it works like this - You give server an event handler that will wait for changes in particular variable (kinda works like a function that is triggered automatically). Client side you simply adjust this variable (must be global not local) and use publicVariableServer to notify server of changes. Server then will execute code block inside of event handler and wait for next request. Code block inside in your case would be teleport. The variable you send from client could contain player and possibly coordinates or even mine object.. doesn't matter it can be anything you want.

Basically if server teleports players, then infistar AH will not complain. In fact that is what antihack does itself, too when you TP players around.

Code used for TP is exact same, just that server side you define new local var that holds player id you sent over to it.

So .. like .. instead of player setPos... you would:

send myVar = [player,_coords];

and server side:

_playa = myVar select 0;

_playa setPos... etc etc

 

get the idea? That pretty much explains the code I gave you

 

Ofc then there's security issues if hackers finds out about event handler. So the best thing to do is to spawn mine as a server, then use coords from there, that way you would only need to pass player value to server and it could figure out the rest of stuff that needs to be done, like for example - before TP, server checks if player is indeed within distance of mine.

Link to comment
Share on other sites

  • 0

None of the ways makes any sense to me :lol: I have no idea where to start.

I can live inside the editor and build all day long, when it comes to all this tricky stuff it's way over my head, Shame really when it's so close to being finished.

Link to comment
Share on other sites

  • 0

@BowBii: dat list ... #6 wat  :lol:

Richie.. trial and error, man. Don't rush making whole code at once, do it by small bits and build it up slowly. That's the best way to do it while learning. Also make use of debug console, trust me, you will love it (local server ofc, dont use it on live server).

So... start with simple Event handlers... then try to send a simple variable over and confirm it. Then send another one, but this time add some extra to EH, like... kill a player or teleport yourself 5 meters away. All these little bits that help you understand whats going on. Finally when you get better idea of whats going on, continue with general direction of your script you want to make. 

And from point of complexity, spoiler alert, it won't be hard, not for this script, but it will definitely be fun experience

Link to comment
Share on other sites

  • 0

server is just like a client, in fact it actually loads files after restart just like a normal client, minus the gui, unit and all the good stuff :)

So if you treat it that way, it would make more sense when coding.. which also means if you don't use isServer or isDedicated (both are kinda the same for MP) checks, it will also load your variables.

Link to comment
Share on other sites

  • 0

As Raymix is saying, you can essentially set up a function on the server side and then send the players info to the server which will then teleport the player.

Infistar detects things on a server, but doesn't actually run "for" the server, only the client. If infistar has a teleport location check, it might need disabled, but it won't ban the player for using setPos commands anymore.

 

An easy way to do this would be to add a line in the init with an (isServer) check, which points to a script contained in the server pbo which is a loop that checks for a publicvariable. When the variable exists, the contents should be a player object, which then gets teleported. You could add in checking to make sure they are in the area where they can enter the bunker, make sure its a player, and hardcode the coordinates based on which bunker area they are currently in.

Link to comment
Share on other sites

  • 0

I dont even see the point of making an own script passing infistar in that way...

simply do a variable thats activated when running your script

 

then add an exception to the antihack like

 

while (!meTelep) do {antitp}

 

since hackers can easily pass the Infistar anti tp, in the way that was already mentioned, its not really necessary

 

the only thing thats bad about this that its some performance eating beast I guess

Link to comment
Share on other sites

  • 0

I dont even see the point of making an own script passing infistar in that way...

simply do a variable thats activated when running your script

 

then add an exception to the antihack like

 

while (!meTelep) do {antitp}

 

since hackers can easily pass the Infistar anti tp, in the way that was already mentioned, its not really necessary

 

the only thing thats bad about this that its some performance eating beast I guess

 

And since you have your teleport code contained in the mission files, a hacker can easily pass that variable in their teleport code instead of hiding the code on the serverside and performing serverside checks.

Link to comment
Share on other sites

  • 0

You could try to TP serverside which works for me with infistar  ;)

 

Add this to your server_functions.sqf in dayz_server.pbo:

"PVDZE_TP" addPublicVariableEventHandler {
	private["_unit","_pos"];
	_unit = (_this select 1) select 0;
	_pos = (_this select 1) select 1;

	switch (_pos) do {


	case 1: {
		_pos = getPos MineEntrance;
	};
	// Example Pos
	case 2: {
		_pos = [1047.052, 7766.3428,0.01];
	};
	
	};

	_unit setPosATL  _pos;

}; 

 

Use your object code: 

_vehicle_9 = objNull;
if (true) then
{
  _this = createVehicle ["Infostand_1_EP1", [1647.052, 7766.3428,0.01], [], 0, "CAN_COLLIDE"];
  _vehicle_9 = _this;
  _this setDir 215.91753;
  MineEntrance = _this;
  _this setPos [1647.052, 7766.3428,0.01];
}; 

 

And add BattlEye exception in publicvariable.txt:

!="PVDZE_TP"

On client side use this code to TP to MineEntrance:

PVDZE_TP = [player,1];
publicVariableServer "PVDZE_TP";
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...