Jump to content
Heisen99

Scripters Question & Answer Thread

Recommended Posts

Hello,

I guess we could create a single thread for common questions of which other scripters could answer if they know how to solve someone's issue. So if you have questions of Enforce Script like I've had some, post below and see if someone can help solve it.

 

  • Beans 1

Share this post


Link to post
Share on other sites

For example, I'm wondering if you can do public classes e.g.

public class Global_Accessible_Data
{
   public int CountOfMyApples {get;set;}
   public string NameOfPetDog {get;set;}
}

Can you do the following above, like you can in C# then utilise in other files without using params.

Edited by Heisen99

Share this post


Link to post
Share on other sites
42 minutes ago, Heisen99 said:

For example, I'm wondering if you can do public classes e.g.


public class Global_Accessible_Data
{
   public int CountOfMyApples {get;set;}
   public string NameOfPetDog {get;set;}
}

Can you do the following above, like you can in C# then utilise in other files without using params.

I'm not sure if it's possible to appoint access modifiers to a class in Enforce. Have you tried it and tried to run it? If it gives you an error it isn't possible.

What do you mean with "without using params" though? I have a feeling you're talking about static fields or methods.

Example of regular class:

public class Messenger {
  private String message;
  
  public Messenger(String message) {
    this.message = message;
  }
  
  public void sendMessage() {
    System.out.println(this.message);
  }
}

Messenger messenger = new Messenger("Hello");
messenger.sendMessage();

Example of a class with a static method:

public class Messenger {
	public static void sendMessage(String message) {
		System.out.println(message);
	}
}

Messenger.sendMessage("Hello");

Static means that you don't need an instance of that class to access the field or method. Is that what you mean?

Edited by IMT

Share this post


Link to post
Share on other sites
5 hours ago, IMT said:

I'm not sure if it's possible to appoint access modifiers to a class in Enforce. Have you tried it and tried to run it? If it gives you an error it isn't possible.

What do you mean with "without using params" though? I have a feeling you're talking about static fields or methods.

Example of regular class:


public class Messenger {
  private String message;
  
  public Messenger(String message) {
    this.message = message;
  }
  
  public void sendMessage() {
    System.out.println(this.message);
  }
}

Messenger messenger = new Messenger("Hello");
messenger.sendMessage();

Example of a class with a static method:


public class Messenger {
	public static void sendMessage(String message) {
		System.out.println(message);
	}
}

Messenger.sendMessage("Hello");

Static means that you don't need an instance of that class to access the field or method. Is that what you mean?

Yes my bad, I forgot to include static within my example.

Share this post


Link to post
Share on other sites
5 minutes ago, Heisen99 said:

Yes my bad, I forgot to include static within my example.

I'm also not sure if static is included with Enforce. I guess you can always try. You can also try searching in the already existing scripts. :)

  • Like 1

Share this post


Link to post
Share on other sites

Is it possible to initialize objects inline? Where is the code that implements the class for each item?

What I mean by "initialize objects inline" is something like how C# does it. 
But for this to be viable, I'd need to know the properties of each item beforehand.

Share this post


Link to post
Share on other sites
4 hours ago, SleepyMode said:

Is it possible to pass a function as an argument to another?

Yes it is. For example, the first thing I did was modify the init file so that the default loadout given is in a separate file, then I fiddled with it a bit:

EntityAI item = player.GetInventory().CreateInInventory("HuntingKnife");
SetRandomHealth(item);

Which I changed to, and is literally the same as:

SetRandomHealth( player.GetInventory().CreateInInventory("HuntingKnife") );
Edited by Dancing.Russian.Man

Share this post


Link to post
Share on other sites
2 hours ago, Dancing.Russian.Man said:

Yes it is. For example, the first thing I did was modify the init file so that the default loadout given is in a separate file, then I fiddled with it a bit:


EntityAI item = player.GetInventory().CreateInInventory("HuntingKnife");
SetRandomHealth(item);

Which I changed to, and is literally the same as:


SetRandomHealth( player.GetInventory().CreateInInventory("HuntingKnife") );

Not sure if that's what he meant. In Javascript, you can literally pass functions as parameters to other functions. What you're doing is just passing an object as parameter since CreateInInventory returns a EntityAI. If CreateInInventory would have returntype void it would not be possible to pass it as a parameter.

To answer his question, I don't think it is possible since it violates OOP. However, as you can see it does work as long as the method returns a type and it is the same type as the parameter type.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
11 hours ago, IMT said:

Not sure if that's what he meant. In Javascript, you can literally pass functions as parameters to other functions. What you're doing is just passing an object as parameter since CreateInInventory returns a EntityAI. If CreateInInventory would have returntype void it would not be possible to pass it as a parameter.

To answer his question, I don't think it is possible since it violates OOP. However, as you can see it does work as long as the method returns a type and it is the same type as the parameter type.

Oh I see, they were talking about function pointers. In C# (and C++), these would be called delegates, but I'm not sure if Enscript supports them.

My first guess is no, but I'll get back to you on that.

Edit: Two things:

  1. There is a keyword "func" in Enscript. That alone doesn't give much information. BUT..
  2. In "proto.h", the keyword is used to define parameters for callback functions.
proto float TraceLineEx(vector start, vector end, vector mins, vector maxs, out _entity cent, out float plane[4], out int content, out int surfparm, int flags, func filtercallback);
proto float TraceLineExEx(vector start, vector end, vector mins, vector maxs, out _entity cent, out float plane[4], out int content, out int surfparm, int flags, func filtercallback, int layerMask);

So.. Without being able to test it further right now, it seems like you're able have function pointers ("delegates") as arguments. The way you would use the parameter is type in the name of the function without its parentheses.

Edited by Dancing.Russian.Man
  • Like 1

Share this post


Link to post
Share on other sites

Can I add steam mods to my home DayZ SA server? I'm new to coding its sheerly necessitated by my need for DayZ. So I got loadouts and vehicle's going the way I want. But If I go to steam workshop and look how can I get it from subscribe in steam to active in my server? 

Share this post


Link to post
Share on other sites

I have a question about how i get these to be active on my server: https://github.com/Da0ne/DZMods

I've installed as directed and changed the config to load that file but i dont seem to see any of them in game despite pointing it to it and the server running fine. Any help is greatly appreciated

Share this post


Link to post
Share on other sites

Anyone have any luck creating an object and setting a specific direct e.g. spawning a car facing 180 degrees south?

 

on mobile so I can’t post my current attempt.

 

 

Share this post


Link to post
Share on other sites
On 11/21/2018 at 9:44 PM, arniegames4u said:

Anyone have any luck creating an object and setting a specific direct e.g. spawning a car facing 180 degrees south?

 

on mobile so I can’t post my current attempt.

 

 

I got it to work with something like this:

void CreateVehicle(vector position) 
{
  position[0] = position[0] + 5;
  vehicle = GetGame().CreateObject("OffroadHatchback", position);

  vector direction = vehicle.GetDirection();
  direction[0] = 180;

  vehicle.SetDirection(direction);
}

I'm pretty sure the facing direction is either index 0 or 2.  Here's what changing index 1 does :P

https://imgur.com/a/YvTx5tS

  • Like 2
  • Haha 1

Share this post


Link to post
Share on other sites
On 11/17/2018 at 1:56 PM, Dancing.Russian.Man said:

Yes it is. For example, the first thing I did was modify the init file so that the default loadout given is in a separate file, then I fiddled with it a bit:


EntityAI item = player.GetInventory().CreateInInventory("HuntingKnife");
SetRandomHealth(item);

Which I changed to, and is literally the same as:


SetRandomHealth( player.GetInventory().CreateInInventory("HuntingKnife") );

 

As I think it's good to understand the execution of scripts, I'll explain what's happening here.

 

When you form your code like the second, you are actually invoking the inner chain of methods, so what happens is that the code will get as far as SetRandomHealth, sees that there's a parameter passed which is a function call and it'll pause to begin executing the method chain of the following snippet

player.GetInventory().CreateInInventory("HuntingKnife")

The CreateInInventory method returns a value of some data type, the execution context then executes SetRandomHealth with that value.

 

What you point to in your second comment about func is more correct, as the question itself is about whether you can pass delegates to method, where delegates are basically something that knows how to call a method on its behalf - or a pointer to a method (don't confuse my terminology with C++ pointers)

Share this post


Link to post
Share on other sites
storeHouseStateDisabled = false;// Disable houses/doors persistence (value true/false), usable in case of problems with persistence

What does this do and why is it usable in case of problems with persistence?

Share this post


Link to post
Share on other sites

Are we able to mod any of the actions involved in the default actions that come with right clicking?

I've been using the script editor and I used the Find Symbol pane on the left. I found some interesting methods (I assume as it has M next to them) one being called HumanInputController.IsWeaponRaised. I think this is the area I am looking for I believe. I saw that guns and optics seem to share a Scope value. Weapons have it set to 0 while optics seem to have it set to 2. 

If we have a mosin with PU, you right click to raise the gun and left shift to go to the iron sight and I think this is because the Scope value is set to 0 at this point, by default. Scrolling up I think changes the Scope value to 2 which switches to your PU scope thats attached. If you, reload or left shift it will result in you being back to the raised gun state. If you left shift again... boom you're back to the scope since the scope value is still at 2. 

BUT if you release right click at any point I think that scope value is lost and the default is used once left shifting. 

Does anybody know if I am right with the above?

If yes, where is raising and lowering the gun action wise where I could potentially capture the scope value in some way so we stop defaulting to the horrible ironsights? 

Share this post


Link to post
Share on other sites

hi all who can help me with script to have cars spawn with full fuild ? !!

thx for all

Share this post


Link to post
Share on other sites
On 3/27/2019 at 12:17 AM, alphagamer1981 said:

just a simple one, how to change the timer countdown for entering and leaving a server. its currently set at 15 seconds

in \DayZServer\mpmissions\dayzOfflinePerso.chernarusplus\db\Globals.xml

It is the QueueTimeSameServer or RespawnAttempt value (or both, just try it)

Share this post


Link to post
Share on other sites

Is there a way to reference or call another .xml file inside an .xml file? For example, say I want to have a separate types.xml for everything mod related and have the original vanilla types.xml remain vanilla. In Arma 3 you could # include.

Share this post


Link to post
Share on other sites
1 hour ago, Coyote_94YJ said:

Is there a way to reference or call another .xml file inside an .xml file? For example, say I want to have a separate types.xml for everything mod related and have the original vanilla types.xml remain vanilla. In Arma 3 you could # include.

http://xml.silmaril.ie/includes.html

 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×