Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Want to create local thing
Want to create local thing
2006-04-02, 6:20 AM #1
I'm trying to create a local thing, basically a particle effect on your own backpack after you drop it.

Originally I was assigning an id to the dropped backpack via SetThingUserData() in kyle.cog under the killed: message when the backpack was dropped, at the same time it'd send out a trigger to a local cog to create the particle effect on the backpack.

The trouble is, I was struggling to get it to be able to handle more than one backpack. I was using SetThingPulse() to create a pulse to generate the particle effect with CreateThing(). SetThingPulse can supposedly handle multiple things, but I need each CreateThing to reference a different thing...

Code:
# Jedi Knight Cog Script
#
# BPACK_PULSE.COG
#
#
#
# GHORG
#
#

flags=0x240
symbols

	message		trigger
	message		pulse

	thing		pak				local

	template	bpck_effects=+smallcoreflow		local

end

# ========================================================================================

code

trigger:
	if (GetSourceRef() == 327350)
	{
		if ((GetPlayerNum(player) == 0) && (GetParam(0) == 253))
		{
			pak = GetParam(1);
			CaptureThing(pak);
			SetThingPulse(pak, 0.5);
		}
		if (GetPlayerNum(player) == GetParam(0))
		{
			CaptureThing(GetParam(1));
			SetThingPulse(GetParam(1), 0.5);
		}
	}
	return;

pulse:
//	CreateThingAtPosNR(bpck_effects, GetThingSector(pak), GetThingPos(pak), '0 0 0');
	CreateThing(bpck_effects, pak);

	return;
end


The (GetPlayerNum(player) == GetParam(0)) If statements are basically there to differentiate which pack belongs to who. SetThingUserData() to zero on a thing causes a few hiccups, so for the host who has a GetPlayerNum of zero, I've used the number 253 instead.

Anyway... I wrote that up, then decided that aside from the trouble of getting it to handle multiple things, it might be a cleaner solution to just put the pulse in the backpacks class cog, which would be called by it's template when it was created.

These are the two messages that I've added into the pow_backpack.cog class cog.

Code:
created:

	player = GetLocalPlayerThing();
	powerup = GetSenderRef();

		if ((GetPlayerNum(player) == 0) && (GetThingUserData(powerup) == 253))
		{
			SetThingPulse(powerup, 0.5);
		}
		if (GetPlayerNum(player) == GetThingUserData(powerup))
		{
			SetThingPulse(powerup, 0.5);
		}

	Return;


Code:
pulse:

	CreateThing(bpck_effects, GetSenderRef());

	Return;


The problems with this 2nd solution are:
a) The created: message in the class cog will likely be run before kyle.cog gets a chance to assign an ID to it via SetThingUserData(). The class cog needs this ID to determine if it's one of the local player's backpacks.

b) The CreateThing pulse doesn't create local things.

If anyone's got any ideas, it'd be a great help.

Thanks
2006-04-02, 7:11 AM #2
a. There's probably a better way of doing it, but a simple solution that would work is to set the backpack's user data to -1 by default, then when the created message is called, set up a polling pulse to check every 0.1 secs or so whether the user data != -1. If it's not -1, kyle.cog must have sent its value and you can start up the thing pulse.

b. Strange, I thought class cogs aren't synced by default.
2006-04-02, 8:01 AM #3
Hi Chris

I whacked something together just then with a pulse to check for an ID and tried it out. When CreateThing is called it does sync over the network.

I'm not sure what would happen if I put flags=0x240 on a class cog... but I might give it a go.

Any idea if a new iteration of the class cog is generated for every backpack that's dropped?
2006-04-02, 10:30 AM #4
Yes I think each thing has its own class cog rather than there being one class cog per thing type - this was discussed a few days ago but I don't remember where.

If the 0x240 thing doesn't work, you could create the particles locally by making the backpack class cog send out a trigger with the backback thing number as a parameter. Then make a local (0x240) non-class cog to intercept the triggers on each client and create particles locally.
2006-04-02, 12:26 PM #5
The second solution is the way to go. It's not worth making it overcomplicated with triggers.

Quote:
The problems with this 2nd solution are:
a) The created: message in the class cog will likely be run before kyle.cog gets a chance to assign an ID to it via SetThingUserData(). The class cog needs this ID to determine if it's one of the local player's backpacks.

b) The CreateThing pulse doesn't create local things.

If anyone's got any ideas, it'd be a great help.


A. You could try using a Sleep() in the created message to let kyle.cog finish. Or you could use FireProjectile() to create the backpack and then use GetThingParent() to find the player that fired it.

B. You're saying that the particles are created on all computers for each class cog's CreateThing()? Is this with the 0x200 flag? Or is it not creating anything at all?
Historians are the most powerful and dangerous members of any society. They must be watched carefully... They can spoil everything. - Nikita Khrushchev.
Kill one man, and you are a murderer. Kill millions of men, and you are a conqueror. Kill them all, and you are a god. - Jean Rostand.
2006-04-03, 4:06 AM #6
If each thing has it's own iteration of the class cog, I might have to re-check my code.

Quote:
If the 0x240 thing doesn't work, you could create the particles locally by making the backpack class cog send out a trigger with the backback thing number as a parameter. Then make a local (0x240) non-class cog to intercept the triggers on each client and create particles locally.

This was basically what I had with the first solution, except that I was struggling to get it to be able to handle multiple backpacks in the SetThingPulse(). I might be able to use either JK's heap functions or I think there was some kind of heap/stack addon made by Sige or someone that might make it possible.

The particles are created on each computer. Is 0x200 thing flags? Are there any cog flags you can set other than 0x240? I can't seem to find a list of them in datamaster, jkspecs or the old template txt files.
2006-04-03, 4:16 AM #7
Datamaster says:

0x40 = Cog will run locally on each computer. Default flag for all item and class cogs.
0x200 = Cog does not send syncing information to other computers.

The problem is that CreateThing and FireProjectile are synced, even when a cog has the 0x240 flag (otherwise weapon cogs and stuff wouldn't fire projectiles on all clients).
2006-04-03, 7:15 AM #8
Oooh, never noticed the cogscript flags in Datamaster before, although the listing on jkhub seems more updated.

Ok, got it licked with the first solution, ie sending triggers. The trigger code is above, this is the local cog that receives it:
Code:
# Jedi Knight Cog Script
#
# BPACK_PULSE.COG
#
#
#
# GHORG
#
#

flags=0x240
symbols

	message		trigger
	message		pulse

	thing		pak				local
	thing		player				local

	template	bpck_effects=+smallcoreflow		local

end

# ========================================================================================

code

trigger:

	if (GetSourceRef() == 327350)
	{
		player = GetLocalPlayerThing();
		if ((GetPlayerNum(player) == 0) && (GetParam(0) == 253))
		{
			pak = GetParam(1);
			CaptureThing(pak);
			SetThingPulse(pak, 0.5);
		}
		if (GetPlayerNum(player) == GetParam(0))
		{
			pak = GetParam(1);
			CaptureThing(pak);
			SetThingPulse(pak, 0.5);
		}
	}
	return;

pulse:
	CreateThing(bpck_effects, GetSenderRef());

	return;
end


The particle effect is only local and will generate for as many backpacks as needed.

I didn't know that GetSenderRef() in a pulse cog will reference the first parameter of the SetThingPulse, in this case each and every backpack.

Only trouble is the pulse stops when the timer on the item has expired and it's ready to be removed from the game. But I don't think i'll worry about that.

Cheers for your help
2006-04-03, 9:05 AM #9
Originally posted by GHORG:
If each thing has it's own iteration of the class cog, I might have to re-check my code.


The class cog is for the template and all things of that class use the one class cog.

Quote:
The problem is that CreateThing and FireProjectile are synced, even when a cog has the 0x240 flag (otherwise weapon cogs and stuff wouldn't fire projectiles on all clients).


Even with 0x200? I'm pretty sure 0x200 stops thing creation from being synced.

Quote:
Oooh, never noticed the cogscript flags in Datamaster before, although the listing on jkhub seems more updated.


Nope, it's the same thing last I checked.

Quote:
I didn't know that GetSenderRef() in a pulse cog will reference the first parameter of the SetThingPulse, in this case each and every backpack.


A thing pulse is different than a normal pulse in that the pulse event is sent by the thing to its cogs. In any event message sent by a thing, the thing that sent it is the sender and can be referenced with GetSenderRef().


It really would be better to avoid using triggers and user data as that's a very inelegant solution.
Historians are the most powerful and dangerous members of any society. They must be watched carefully... They can spoil everything. - Nikita Khrushchev.
Kill one man, and you are a murderer. Kill millions of men, and you are a conqueror. Kill them all, and you are a god. - Jean Rostand.
2006-04-04, 11:27 AM #10
Originally posted by Centrist:
Even with 0x200? I'm pretty sure 0x200 stops thing creation from being synced.



This was a big thing back a while. I did extensive testing myself, what caused me to do it, I dunno. (I can't remember where the topic is, I'll find it for ya) FireProjectile (even if the template is in static.jkl) causes lag/info over the network. FireProjectileLocal() in MotS is making alot more sense now isn't it? ;)

I tried 0x240, didn't try 0x200 by itself.
-Hell Raiser
2006-04-04, 11:57 AM #11
Found the relevant info:

Quote:
From this topic at the hub:

I didn't want to believe it, but it's true. If a cog is flagged 0x240, and you use FireProjectile, or CreateThingAtPos, the thing will be created over the network anyway. Also, if the template is in static.jkl, some info still gets sent over the network. I tried this using a 0.0001 pulse, and ping times reflected what I was seeing. If it was a level template, ping spiked to 230, static.jkl template, 100 or more, and with nothing going on, ping was 31, sometimes 62.

The level template I chose to test with was the bryar bolt. When I tested CreateThingAtPosNR, the projectile wasn't fired out for my client. However, I could hear the explosion sound of it at my position no matter what. Ping from the Host (doing the firing) to the client was normal. Ping from client (having the explosion sound only played at client pos) to host spiked 200.

I'm fairly certian it might be the fleshhit/explode parameters in the template causing the explosion to be heard client side. The explosion is created globally, but client side didn't get the original projectile, so JK assumes the client player as the projectile instead. It also explains the ping spiking for the client as well.

I'm really dependant on FireProjectile() in pulses of 0.0001, so I want to scrap any use of it and replace with CTAPNR() ASAP. I'm going to do some more testing and see exactly what I can get away with. This 'cogging error' is probably why good mods lag so bad, what with using FireProjectile() on a static.jkl template however many times there are players, PLUS a trigger message to boot. :oops:

No wonder MotS has FireProjectileLocal(). -_-

[Update]
CreateThing and CreateThingNR acts like CreateThingAtPosNR under cog flags 0x240. Projectile isn't fired, but if it has fleshhit/or explode, that thing will be created, and info sent out.

If the thing has no fleshhit/explode in it's template, ping remains normal.

So after all this testing, CreateThing(), CreateThingNR(), and CreateThingAtPosNR() will not trasmit any info over the network if they're in a 0x240 cog.

All of my findings are quite troublesome though. FireProjectile is known for setting a parent, and alot of people code with that in mind. Not sure how to work around that pitfall. however, SM Sith Lord mentioned attachment setting parents, so I'm going to test that right now.

edit again

There is no way to set a things parent in JK. Chalk more up to MotS


With the new JK.exe patches with cog verbs, we have GetPlayerLVec()/GetPlayerPtich() which can be used in place of using the old FireProjectile() method for getting the player's torso LVec/Pitch. Using CreateThingAtPosNR() and the GetPlayerLVec() verb, adding that to the Player position, you can effectively replace FP() alltogether.

The NR might be some abbriviation concerning network transmission. I always thought it meant "No Return", but that's silly, as it returns the thing created.

Eventually SetThingParent() will be available, and all this stuff will be a thing of the past. ;)
-Hell Raiser
2006-04-04, 12:08 PM #12
[QUOTE=Hell Raiser]This was a big thing back a while. I did extensive testing myself, what caused me to do it, I dunno. (I can't remember where the topic is, I'll find it for ya) FireProjectile (even if the template is in static.jkl) causes lag/info over the network. FireProjectileLocal() in MotS is making alot more sense now isn't it? ;)

I tried 0x240, didn't try 0x200 by itself.[/QUOTE]

It's been awhile since I tested the flags, so I'm not sure. When I have time after work I'll test again. I mentioned 0x200 by itself because class cogs have the 0x40 flag by default (no way to really be sure in JK, but you can see this in MotS).
Historians are the most powerful and dangerous members of any society. They must be watched carefully... They can spoil everything. - Nikita Khrushchev.
Kill one man, and you are a murderer. Kill millions of men, and you are a conqueror. Kill them all, and you are a god. - Jean Rostand.
2006-04-04, 1:14 PM #13
This was using a modified Bryar cog (just for flags and templates)
-Hell Raiser
2006-04-10, 6:51 AM #14
Is it possible to get/set the weapon/ammo bins in a backpack after it's been dropped?

GetInv only seems to be player and I can't seem to find anything else it might be... Trying to search the forums only covers threads since the forum-change unfortunately.
2006-04-10, 9:44 AM #15
There's some backpack verbs to do just that.

They're under the Multiplayer cog verbs in the DM:

NthBackpackBin
NthBackpackValue
NumBackpackItems
-Hell Raiser
2006-04-11, 7:11 AM #16
Cheers :)
2006-04-11, 8:31 AM #17
I've been meaning to test the thing creation sync stuff, but one of the hard drives in my RAID0 array is dying on me. :eek:

When I get around to it, I'll post a new thread.
Historians are the most powerful and dangerous members of any society. They must be watched carefully... They can spoil everything. - Nikita Khrushchev.
Kill one man, and you are a murderer. Kill millions of men, and you are a conqueror. Kill them all, and you are a god. - Jean Rostand.

↑ Up to the top!