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 → Strange effect on different levels. Why?
Strange effect on different levels. Why?
2001-11-30, 10:14 AM #1
I have a cog for a saber throw MOD. This is the returning saber (the item):

Code:
flags=0x240

symbols

thing       powerup                          local
thing       player                           local
sound       pickupsnd=thrmlpu2.wav           local

message     created
message     timer
message     touched
message     taken
message     removed
message     pulse

end

code

created:
   player = GetSourceRef();
   powerup = GetSenderRef();
   SetPulse(0.2);
   if(!IsMulti())
      SetTimerEx(5, GetSenderRef(), GetThingSignature(GetSenderRef()), 0);
   return;

timer:
   // if this object is still the same (could have been taken and reassigned)
   if(GetThingSignature(GetSenderID()) == GetParam(0))
   {
      DestroyThing(GetSenderID());
      call stop_power;
   }
   return;

touched:
   if(GetLocalPlayerThing() == player)
      TakeItem(powerup, player);
   return;

taken:
   // Do effects.
   PlaySoundThing(pickupsnd, powerup, 1.0, -1, -1, 0);
   AddDynamicTint(player, 0.0, 0.0, 0.2);
   // Cleanup in the saber cog because we tried very hard
   // NOT to call its selected: event just above to avoid
   // playing the mount animation, etc.
   SendMessage(GetInvCog(player,117),user0);   // Deactivate saber throw...
   SendMessage(GetInvCog(player,10),user1);    // Fast mount...
   return;

removed:
   call stop_power;
   return;

pulse:
   // Returning the saber now...
   // Much faster if both the player and the saber is in the water
   if((GetSectorFlags(GetThingSector(player)) & 2) && (GetSectorFlags(GetThingSector(powerup)) & 2))
      SetThingVel(powerup, VectorScale(VectorNorm(VectorSub(GetThingPos(player), GetThingPos(powerup))), 6));
   else
   // Faster if only one of the parent or the saber is in the water
   if((GetSectorFlags(GetThingSector(player)) & 2) || (GetSectorFlags(GetThingSector(powerup)) & 2))
      SetThingVel(powerup, VectorScale(VectorNorm(VectorSub(GetThingPos(player), GetThingPos(powerup))), 4));
   // Normal speed of return if both are out of the water
   else
      SetThingVel(powerup, VectorScale(VectorNorm(VectorSub(GetThingPos(player), GetThingPos(powerup))), 2));
   return;

stop_power:
   SetPulse(0);
   return;

end


The problem is that in some single player levels by LEC all works perfectly and "powerup" goes towards "player" that is me. In other levels (n.3,6,9 for example) "powerup" goes toward an empty precise point in the level, just like GetSourceRef() returns not the player but something different (a ghost?). Any idea?


------------------
"May the SourceCode be with you..."
Nemios, MOD developer.
"May the SourceCode be with you..."
Nemios, MOD developer.
2001-11-30, 12:43 PM #2
Indeed, it's proberly heading towards a vector "0,0,0" because one of the things are invalid, I suggest you put Printint(player) and Printint(powerup) just above SetPulse(0.2), to see which one is not defined.
2001-12-01, 1:17 PM #3
The player is not being defined correctly. If the powerup was fired from the player, then you could use GetThingParent(powerup) to get the player's value. If there won't be MP problems, you could also use GetLocalPlayerThing().

The reason it works in some levels and not in others is that: most SP levels have the value of the player as 0. And because the sourceref of the created message is also zero, the player is defined correctly most of the time.

------------------
There we were, three against a thousand. They came at us with knives, clubs, and spears. Bodies fell left and right...

They were the toughest three we ever fought.

[This message has been edited by SaberMaster (edited December 01, 2001).]
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2001-12-03, 12:24 AM #4
Ok, thanks. I'll try with GetThingParent(powerup) but, how does the parental link work? I have a projectile (the saber) fired from a client cog. When the projectile disappears it creates an explosion (visually it is again a saber) which creates the real powerup (again a saber) so isn't the parent actually the explosion? But the explosion exist for only 0.2 seconds...
Another thing: I tryed this MOD with a friend on line and
- only the server saw the returning saber
- all returning sabers came to the hosting player
while I want this result
- the saber come to his owner and only him can take it
- it's not necessary that the powerup position is broadcasted since only his owner can take it. I'd like that locally each machine does the returning way.
Clearly I can't understand flag values. Is it right to have 0x240 for each cog?

------------------
"May the SourceCode be with you..."
Nemios, MOD developer.
"May the SourceCode be with you..."
Nemios, MOD developer.
2001-12-03, 9:12 AM #5
The parent of a thing is the thing that it was fired from. EG, the parent of a bryar bolt is the player
who fired it.

I don't think getting the parent is going to work in this case. When you fire the saber projectile from
the player, the player will be the projectile's parent. Now instead of creating an explosion and then
a powerup, create the powerup in the removed message of the saber-proj's cog. Then set the
userdata of the powerup to the parent of the saber-proj.

The created message of the powerup will run immediately after the powerup is created. It will run
before the next line of code is run in the cog that created it. So use sleep or set a timer to wait until
the userdata has been assigned before you try to retrieve it.

As for making the saber return to the player:

If only the host saw the returning saber, what did the other players see?

All returning sabers went to the host because his value is usually 0. And because player was not
defined correctly, it had a value of 0.

If you don't want the powerup's position broadcasted, that would make the coding a lot easier. New
templates aren't normally created on other computers anyway. So if only create the powerup on the
right player's computer, there is no reason to worry about MP problems because it doesn't have to be
synced and it won't run on the other players' comps.

[This message has been edited by SaberMaster (edited December 03, 2001).]
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2001-12-03, 12:27 PM #6
I partially resolved it in this manner:
I didn't really need an "explosion", so in static.jk on "fleshhit" and "explode" I put the powerup, so GetThingParent() worked correctly. The problem is again in multiplayer. I totally removed flag definition but the result was:
-My saber returned to me but clients saw it floating around me until it disappears (because of the timer I think).
-Clients' saber returned only visually to them in their POV (for me that was floating around them) but actually they didn't catch them.
So I can't understand flags. In single player all seem to work now. What I want is:
I see my saber returning and disappear as I catch it. Same to the others, but I want that each of us run locally his cog (for the other sabers too) since we don't need to know the real position of other sabers (we can catch only ours). Is this clear? Can you help me? (This MOD lets me learn a lot!)

------------------
"May the SourceCode be with you..."
Nemios, MOD developer.

[This message has been edited by Nemios (edited December 04, 2001).]
"May the SourceCode be with you..."
Nemios, MOD developer.
2001-12-04, 6:40 AM #7
Code:
symbols

thing		powerup					local
thing		touchthing				local
thing		player					local
sound	pickupsnd=thrmlpu2.wav	local

message	created
message	timer
message	touched
message	taken
message	pulse

end
#-----------------------------------------------------------------------
code
#-----------------------------------------------------------------------
created:
	powerup = GetSenderRef();
	player = GetThingParent(powerup);
	SetThingPulse(powerup, 0.2);
	if(!IsMulti()) SetTimerEx(5, GetSenderRef(), GetThingSignature(GetSenderRef()), 0);

Return;
#-----------------------------------------------------------------------
timer:
	if(GetThingSignature(GetSenderID()) == GetParam(0)) DestroyThing(GetSenderID());

Return;
#-----------------------------------------------------------------------
touched:
	powerup=GetSenderRef();
	touchthing=GetSourceRef();
	player=GetThingParent(powerup);
	if(touchthing == player) TakeItem(powerup, player);

Return;
#-----------------------------------------------------------------------
taken:
	player=GetSourceRef();
	powerup=GetSenderRef();
	PlaySoundThing(pickupsnd, powerup, 1.0, -1, -1, 0);
	AddDynamicTint(player, 0.0, 0.0, 0.2);
	SendMessage(GetInvCog(player,117),user0);	// Deactivate saber throw...
	SendMessage(GetInvCog(player,10),user1);		// Fast mount...
//	SetLifeLeft(powerup, 0.1);

Return;
#-----------------------------------------------------------------------
pulse:
	powerup=GetSenderRef();
	player=GetThingParent(powerup);
	if((GetSectorFlags(GetThingSector(player)) & 2) && (GetSectorFlags(GetThingSector(powerup)) & 2))
	{
		SetThingVel(powerup, VectorScale(VectorNorm(VectorSub(GetThingPos(player), GetThingPos(powerup))), 6));
	}
	else if((GetSectorFlags(GetThingSector(player)) & 2) || (GetSectorFlags(GetThingSector(powerup)) & 2))
	{
		SetThingVel(powerup, VectorScale(VectorNorm(VectorSub(GetThingPos(player), GetThingPos(powerup))), 4));
	}
	else SetThingVel(powerup, VectorScale(VectorNorm(VectorSub(GetThingPos(player), GetThingPos(powerup))), 2));

Return;
#-----------------------------------------------------------------------
end


Remember that template cogs run all on computers. In your cog, the player and powerup would have been reset when someone else's powerup was created.

This cog is designed to handle all of the saber powerups in the game. If the powerup is not destroyed when it's taken, use the SetLifeLeft() that's marked off. I took out the removed message and stoppower because a thingpulse should stop when the thing dies.

Not sure, but I think that when an object has a parent is passes the value down to any object fired from it. So if the saber-proj fires the powerup, the parent of the powerup should be the player who fired the saber-proj.

Let me know how this works. [http://forums.massassi.net/html/wink.gif]

------------------
There we were, three against a thousand. They came at us with knives, clubs, and spears. Bodies fell left and right...

They were the toughest three we ever fought.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2001-12-05, 8:55 PM #8
Ok, I hadn't time to test that on multiplayer but these are the results on single player:

Quote:
<font face="Verdana, Arial" size="2">Originally posted by SaberMaster:
Remember that template cogs run all on computers. In your cog, the player and powerup would have been reset when someone else's powerup was created.
</font>


I understand this (but the only misfuncion seemed to be the impossibility to catch the saber for clients) but placing again the assignment of powerup and player inside "pulse" seems to lose the correct powerup thing. It probably returns 0 or the player itself since the saber remains where the saber proj stopped and I "return myself" (while I try to move a force slows me forcing to remain almost in the same position).

Quote:
<font face="Verdana, Arial" size="2">This cog is designed to handle all of the saber powerups in the game. If the powerup is not destroyed when it's taken, use the SetLifeLeft() that's marked off. I took out the removed message and stoppower because a thingpulse should stop when the thing dies.[/B]</font>


SetLifeLeft() seems not necessary. Probably releted with the above problem (player thing never dies during the power) but if I take out the "removed" and "stop_power" messages the thing (the player) keeps pulsing.

Quote:
<font face="Verdana, Arial" size="2">Not sure, but I think that when an object has a parent is passes the value down to any object fired from it. So if the saber-proj fires the powerup, the parent of the powerup should be the player who fired the saber-proj.[/B]</font>


I thought the same thing and probably this is true at least in the "created" message, then it loses the correct thing value. I could use GetThingSignature() to save the correct value and push each powerup towards his owner but how can I retrieve again a thing from an ID to use it in the SetThingVel() verb?

Quote:
<font face="Verdana, Arial" size="2">Let me know how this works.[/B]</font>


Just did it! [http://forums.massassi.net/html/wink.gif] Thank you for your interest.


------------------
"May the SourceCode be with you..."
Nemios, MOD developer.
"May the SourceCode be with you..."
Nemios, MOD developer.
2001-12-06, 6:00 AM #9
I wrote a small test-mod just now and used the cog I posted above. In my mod, the explode and fleshhit of the bryarbolt created the saber powerup. The powerup was the shield powerup with my cog instead of the original.

The cog worked fine. Not only for me, but for the AI as well. Wherever I shot, a powerup was created and it zoomed right back at me. And the same happened for the AI.

And because it worked for the AI (who don't have a value of 0), there can't be any problem with GetThingParent().

So I'm really not sure what your problem is. I can send you the mod if you want...

------------------
It's not for nothing Santa's red...
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2001-12-06, 6:19 AM #10
I have to say that the FireProjectile() verb is into a client_saber COG to correctly work on multiplayer games (as Hideki says on his tutorial). Could this be a reason?
Please email me your test. I'll give it a look. (sprivitera@ngi.it)
Many thanks, I'll keep you informed.

------------------
"May the SourceCode be with you..."
Nemios, MOD developer.
"May the SourceCode be with you..."
Nemios, MOD developer.

↑ Up to the top!