Programming & Scripting

View unanswered posts | View active topics


Post a new topicPost a reply
Previous topic | Next topic 

User avatar   Beginner BeginnerMember since: 21.08.2011, 11:31Posts: 73Location: Sweden Likes: 1
 

 Post Topic: Make weapons/ammo NOT pickable?
PostPosted 08.03.2012, 18:30 
I'm modding on a multiplayer server (doing live modifications in-game) so the scope of this question is only what's doable through LUA scripting. I'm not interested in changing how the game itself works since that wouldn't translate well to the other players.

What I'm wonder is, can you spawn a weapon or ammo box (CustomAmmoPickup class) or any such thing WITHOUT letting the players pick it up by pressing F on it?

I noticed there seem to be some generic parameters for entities such as bPickable="" or bUsable="" but setting both of these to "0" doesn't seem to make any difference whatsoever in the game. Maybe they are locked to their default values in multiplayer games? I DID seem to be able to affect the items solidity by setting bPhysics=0, which made the object passable whereas without that parameter, you could simply walk through it.

What I would like this for is purely design purposes, for example if I want to create something like an armory in the game with a bunch of guns on the walls. Of course you can do this with bRespawn="1" but they might be guns I won't want players to use in the game, so, yeah... best would be to make them unable to be picked up.

Anybody know if it's possible? :))

  Beginner BeginnerMember since: 19.10.2010, 16:07Posts: 80 Likes: 2
 

 Post Topic: Re: Make weapons/ammo NOT pickable?
PostPosted 09.03.2012, 01:28 
Place them in the level as static objects? You wont need any lua for that.

If your project calls for dynamic spawning, well then spawn them as static object. Dont know how to do that in lua sorry, but that should be possible with the geom entity.

As long as you spawn them as Items or Weapons the game code will add tons of functionality to them. If you just want them for visual appeal then just use the mesh.
User avatar   Beginner BeginnerMember since: 21.08.2011, 11:31Posts: 73Location: Sweden Likes: 1
 

 Post Topic: Re: Make weapons/ammo NOT pickable?
PostPosted 09.03.2012, 01:43 
Quote by Osmodrom:
Place them in the level as static objects? You wont need any lua for that.

If your project calls for dynamic spawning, well then spawn them as static object. Dont know how to do that in lua sorry, but that should be possible with the geom entity.

As long as you spawn them as Items or Weapons the game code will add tons of functionality to them. If you just want them for visual appeal then just use the mesh.


Thankyou for your reply! Yes, it's a great idea to simply use the meshes for the guns/ammo/whatever but, the problem is that I'm trying to do this on a server in a multiplayer game - as you say, dynamic in-game spawning.

In other words, I want to spawn them inside an existing map such as Armada, Quarry etc while the server is up and running (or, right after the level is loaded before any players join, or whatever).

Of course I could just modify the map in Sandbox, but then the players would need to download a new version of the map from somewhere, and with Crysis not having any auto-download feature for maps, it usually only results in an empty server to run a custom map like that :unsure:

I have tried spawning entities of classes BasicEntity, RigidBodyEx etc but even though they seem to spawn correctly without an error and returning a valid entity table ID, they still do not materialize in the map. I'm guessing these entity types are somehow blocked from being spawned in multiplayer games?

Would you have any suggestions for how to go about spawning only the mesh for let's say a SCAR or FY71 without the added functionality of the gun? I don't need finished code, only very general ideas of how to make it work, if possible?

Geom Entity sounds interesting, I actually haven't tried that as far as I can remember. Would I just set up the parameters with class="GeomEntity" and an objModel="" or object_Model="" value for the .cgf mesh I want and then feed it to the SpawnEntity() function?
  Beginner BeginnerMember since: 19.10.2010, 16:07Posts: 80 Likes: 2
 

 Post Topic: Re: Make weapons/ammo NOT pickable?
PostPosted 09.03.2012, 08:51 
I do know how to do this in c++, but this is sadly out of question here. So ill try to give you some hints how id go about this.

First, the server is the only one thats allowed to spawn anything. And usually he propagates any spawns to the connected clients. So if you would just do something like (this is pseude lua code)
Code:
MyEntity ent = Server.SpawnEntity(myspawnparams);
ent.LoadModel("MyWeapon.cgf")
he should spawn the entity on himself and all connected clients. Id say find something that Crytek has made working and copy it. The PowerStruggle and the Factory.lua do spawn Vehicles at runtime. So look at that and rework it so that it spawns statics.

Now heres the crux, i dont know if the servers automatically syncs his entity list with any late connecting clients when talking about BasicEntity/GeomEntity/Static Objects. So any player that connects to a running game, or drops the conn to the server and reconnects, wont have these item displayed.

So i would probably create a hook in the GameRules.Server.OnClientConnect or GameRules.Server.OnClientEnteredGame and then execute some spawn commands on the client.

Finally something abit unrelated, but if you change any assets only on server side the cheat protection will kick any player not having the same files. This cheat protection also works when the punkbuster is turned off, and it does a lazy swoop over the assets and therefore kick them somwhat randomly.
To prevent that you would need to add your modified lua to the Protect.xml file inside Game/Scripts/Network.
Keep in mind when adding something like gamerules.lua that this opens up cheating on your server to some extent.

Hope this helps you some.
User avatar   Beginner BeginnerMember since: 21.08.2011, 11:31Posts: 73Location: Sweden Likes: 1
 

 Post Topic: Re: Make weapons/ammo NOT pickable?
PostPosted 09.03.2012, 14:43 
Quote by Osmodrom:
First, the server is the only one thats allowed to spawn anything. And usually he propagates any spawns to the connected clients. So if you would just do something like (this is pseude lua code)
Code:
MyEntity ent = Server.SpawnEntity(myspawnparams);
ent.LoadModel("MyWeapon.cgf")
he should spawn the entity on himself and all connected clients. Id say find something that Crytek has made working and copy it. The PowerStruggle and the Factory.lua do spawn Vehicles at runtime. So look at that and rework it so that it spawns statics.


Well, this is the problem in a nutshell - it's very easy to spawn vehicles, weapons, ammo boxes and everything that's normally used in multiplayer games. You can even spawn HQ, AlienEnergyPoints and Factories.

However if you try to spawn any other entity than a strictly interactive multiplayer object, such as BasicEntity, RigidBodyEx, and now GeomEntity too which I've tried - nothing materializes in the map even after a correctly performed spawn command with valid parameters. So it seems the reworking it to statics bit is actually impossible - my guess is that it's been cut out of the MP part of the game for bandwidth reasons or some such.

I think it may even be just how you say, that the server probably recieves and executes the spawn command OK but then simply doesn't feed anything out to the clients (including me as I'm testing this as a client user on my own server) since that's not supposed to be necessary in an MP game. I've tried all kinds of ForceUpdate* commands and things like that too, DrawSlot etc, but I can't find any way to force the invisible object to update.

However, I just thought of something. Apparently you can, if you want, set a bounding box for objects to trigger a certain event, according to this page in the Wiki:
wiki/index.php/Lua_API/Entity/SetTriggerBBox

I wonder if there would be any way to change the weapon/ammo pickup bounding box to something so small that it ends up inside the mesh and thus can't be picked up with 'F' by players when they approach it?

Does anybody know if there's any value or flag to set for entity objects that handles this, or is it maybe hardcoded into each client game and uneffectable by the server?

I could see a lot of uses for something like that if it were possible - for example, make cars, helicopters and tanks simply for decoration too (or as obstacles to hide behind) but that can't be actually driven - if you could disable the entry points of course, but maybe you can't do that either ?(
  Beginner BeginnerMember since: 19.10.2010, 16:07Posts: 80 Likes: 2
 

 Post Topic: Re: Make weapons/ammo NOT pickable?
PostPosted 09.03.2012, 16:23 
Hmm, should doable atleast i never had any problems spawning basic entity in c++ with multiplayer.

You tried stuff like?
Code:
CryAction.CreateGameObjectForEntity(self.id);
CryAction.BindGameObjectToNetwork(self.id);


Or for the items.
Code:
entity:Event_DisableUsable();


my ce2 is currently broken so waiting for a fresh install, but i think ill try some stuff out later.
User avatar   Beginner BeginnerMember since: 21.08.2011, 11:31Posts: 73Location: Sweden Likes: 1
 

 Post Topic: Re: Make weapons/ammo NOT pickable?
PostPosted 09.03.2012, 18:03 
Quote by Osmodrom:
You tried stuff like?
Code:
CryAction.CreateGameObjectForEntity(self.id);
CryAction.BindGameObjectToNetwork(self.id);



Uhm, yes. I have tried all of the following methods in pure desperation, none of which will help spawn a BasicEntity or any other "non-action-type" entity:

Code:
CryAction.CreateGameObjectForEntity(myEnt);
CryAction.BindGameObjectToNetwork(myEnt);
CryAction.ForceGameObjectUpdate(myEnt, true);
myEnt:LoadGeometry(0, self.Properties.objModel);
myEnt:Physicalize(0, PE_RIGID, { mass=0 });
myEnt:RedirectAnimationToLayer0(0, true);
myEnt:Activate(1);


Quote by Osmodrom:
Or for the items.
Code:
entity:Event_DisableUsable();



Oh, now this was somewhat interesting news I must say. First of all - the command you wrote doesn't work, it doesn't seem to exist at all according to the error returned when I tried it on an ammo box. It is also not listed under entity commands on the crydev wiki:
wiki/index.php/Lua_API/Entity

However, I found this in the code for BasicEntity.lua (I cut away all the irrelevant parameters):

Code:
BasicEntity.FlowEvents =
{
   Inputs =
   {
      EnableUsable = { BasicEntity.Event_EnableUsable, "bool" },
      DisableUsable = { BasicEntity.Event_DisableUsable, "bool" },
   },
   Outputs =
   {
      EnableUsable = "bool",
      DisableUsable = "bool",
   },
}


...so obviously this is a feature entities seem to have. Any clue how to set it without using that one command you wrote, since that isn't available? Are they supposed to be set through some generic flag-setting command or such maybe?

Btw I also did try spawning them with bPickable=0, bUsable=0 and all that, but that makes no difference if they're just in the params that get fed to the spawn function.
  Beginner BeginnerMember since: 19.10.2010, 16:07Posts: 80 Likes: 2
 

 Post Topic: Re: Make weapons/ammo NOT pickable?
PostPosted 09.03.2012, 20:07 
This is related to the flowgraph functionality of the BasicEntity.

If you drill it down you will end up with self:ProcessBroadcastEvent("DisableUsable");

This should end up in the c++ implementation. Altough i wasnt able to find it in the game code. Eventually your lucky with it anyway :).
User avatar   Beginner BeginnerMember since: 21.08.2011, 11:31Posts: 73Location: Sweden Likes: 1
 

 Post Topic: Re: Make weapons/ammo NOT pickable?
PostPosted 09.03.2012, 20:56 
Quote by Osmodrom:
This is related to the flowgraph functionality of the BasicEntity.


So you are saying it's something I can't use in the LUA, or?

Quote by Osmodrom:
If you drill it down you will end up with self:ProcessBroadcastEvent("DisableUsable");


I tried this command ran on myEnt: just for fun, it didn't return any error but also didn't really do anything either. But maybe it wasn't supposed to?

Quote by Osmodrom:
This should end up in the c++ implementation. Altough i wasnt able to find it in the game code. Eventually your lucky with it anyway :).


I don't know... I've been trying some of this stuff for more or less the whole 6 months I've had my server up, I don't know how many times I've even tried exactly the same things over and over hoping for a different result (isn't that the definition of an idiot? :cheesy: ) in getting a Basic Entity to spawn or whatnot, the only consistent results I'm getting is that nothing ever works.

All those entity functions on the CryDev wiki page for example, I can't manage to get any of them to work in a multiplayer environment. Sure, I can GetPos() and IsSlotGeometry(); and stuff like that and get correct readings, but I can't really affect any existing values in them.

I understand that a lot of this stuff can be done fairly easily in single player modding, it seems to be when you're trying it for multiplayer that pretty much all things just fail :sad:
  Beginner BeginnerMember since: 19.10.2010, 16:07Posts: 80 Likes: 2
 

 Post Topic: Re: Make weapons/ammo NOT pickable?
PostPosted 09.03.2012, 22:44 
Nah your not an idiot ^^, never stop trying on such things.

If you wouldnt have such specific requirements, eg that you only want to do it in server side lua and not distribute anything to your users, then your headache may go away :).

You probably have to find a very creative solution to your problem.
User avatar   Beginner BeginnerMember since: 21.08.2011, 11:31Posts: 73Location: Sweden Likes: 1
 

 Post Topic: Re: Make weapons/ammo NOT pickable?
PostPosted 12.03.2012, 00:21 
Quote by Osmodrom:
If you wouldnt have such specific requirements, eg that you only want to do it in server side lua and not distribute anything to your users, then your headache may go away :).

You probably have to find a very creative solution to your problem.

Yes, but the problem with that is I don't just have a small group of specific users. On a public server, many people come and go and if you make it required to download a mod before connecting, my server would be empty and then it wouldn't matter if I succeed or not. I'm looking to enhance the gaming experience, not kill the server :happy:

And yeah, it would have to be pretty creative I think... but, seriously, I just spawned some entities and after I spawned them, I grabbed these variables from them:

Code:
local isClass = myEnt.class;
local isHidden = myEnt:IsHidden();
local isActive = myEnt:IsActive();

These return respectively the correct class name, "false" (for hidden) and "true" (for active). Should this not mean that the entities were spawned correctly and should be visible? But still I can't see them on the server map. Can you think of anything else that I might do to help visualize them even though they get listed as both active and not-hidden?

Btw I am trying this with BasicEntity, GeomEntity and RigidBodyEx with the same results, and I am spawning them with these commands (parameters omitted):

Code:
local myEnt = System.SpawnEntity(params);
CryAction.CreateGameObjectForEntity(myEnt);
CryAction.BindGameObjectToNetwork(myEnt);
CryAction.ForceGameObjectUpdate(myEnt, true);
myEnt:Activate(1);

Anything you can think of that I might have missed? ?(
  Beginner BeginnerMember since: 19.10.2010, 16:07Posts: 80 Likes: 2
 

 Post Topic: Re: Make weapons/ammo NOT pickable?
PostPosted 14.03.2012, 17:26 
Im no expert with the lua side of the CryEngine.

But stuff that jumps to my mind if the item spawns, returns everything correct etc.

use the DumpEntities function in the EntityUtils.lua, it dumps all entites to the log. Give your entity an unique name and search for it.

Other things are, maybe the spawn pos is wrong for whatever reasons and it spawns at the fall back of 0,0,0.

Maybe the mesh isnt loaded for other reasons.

Dont know if that helps, but that would be the points where id start and toil around.