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 → Destroy a thing in multiplayer that's attached to player
Destroy a thing in multiplayer that's attached to player
2001-07-07, 12:51 PM #1
I'm making a mod where you can open and close a parachute with a hotkey.
It works, but when I test it in multiplayer, sometimes it closes the other person's parachute instead.

The client cog:
Code:
flags=0x404

symbols

thing     player             local
template    parachute=+parachute   local
int      theguy                    local
int      thesector                 local
int      theposition               local
int      thechute                  local
message         trigger

end

#----------

code

trigger:

if (GetSourceRef() == 23)
      {
   theguy = GetParam(0);
   thesector = GetThingSector(theguy);
   theposition = GetThingPos(theguy);
   thechute = CreateThingAtPosNR(parachute, thesector, theposition, '0 0 0');
         AttachThingToThingEx(thechute, theguy, 0x8);
      }
else if(GetSourceRef() == 45)
      {
   DestroyThing(thechute);
      }
   return;
end


and in the parachute cog:

activated:
ID = 23;
SendTrigger(-1, ID, player, 0, 0, 0);

stop_power:
ID2 = 45;
SendTrigger(-1, ID2, player, 0, 0, 0);

I think the problem is from the DestroyThing. Anyone know how to fix it?

[This message has been edited by IDJunkguy (edited July 07, 2001).]
2001-07-07, 2:07 PM #2
Code:
flags=0x404
symbols
thing     player            local
template    parachute=+parachute local
int      theguy                    local
int      thesector                 local
int      theposition               local
int      thechute                  local
message         trigger
end
#----------
code
trigger:
if (GetSourceRef() == 23)
      {
      theguy = GetParam(0);
      thesector = GetThingSector(theguy);   
      theposition = GetThingPos(theguy);   
thechute = CreateThingAtPosNR(parachute, thesector, theposition, '0 0 0');
      AttachThingToThingEx(thechute, theguy, 0x8);
      SendTrigger(-1, 66, player, thechute, 0, 0);
      }
      else
      if(GetSourceRef() == 45)
      {
      DestroyThing(GetParam(1));
      }
      return;
end


In the cog sending the SendTrigger line,
leave your first SendTrigger the same but add a trigger section to that as well so it can recieve the CHUTE's ID number.

Code:
trigger:
if(GetSourceRef() == 66)
{
 if(GetParam(0) == player)
 {
 mychute = GetParam(1);   
 }
}


Then make your second trigger this (so it sends the chute's ID

SendTrigger(-1, 45, player, mychute, 0, 0);


If I've been too confusing basically you need to tell the sender cog your chute id. [http://forums.massassi.net/html/wink.gif]


[This message has been edited by Phat_Daddy (edited July 07, 2001).]
2001-07-08, 9:31 AM #3
Ok thanks, it works so far, but I haven't tested in multiplayer yet. But what should the player in client cog be? Should it be
player = GetLocalPlayerThing();
or
player = GetSourceRef();
or what?
2001-07-08, 10:09 AM #4
Not 100% but...

It looks like all the force_powers, some guns and kyle.cog use

player = GetLocalPlayerThing();

and most guns / items use

player = GetSourceRef();

so it might depend on what flags you give that hotkey in items.dat.

I would bet either works fine.
2001-07-09, 11:57 AM #5
We tested it and it still closed the chute
2001-07-09, 7:45 PM #6
Problem would be using this line:

SendTrigger(-1, 45, player, mychute, 0, 0);

This sends the trigger to EVERYONE.

*quote from JK Specs*
"Sends a trigger, that is generates a trigger: message sent to all the cogs on the destination.
The destination can be either a player (local or remote on the network) reference or -1. If it is -1 the message is broadcast to ALL the connected players.
This verb can be used to reduce bandwidth in multiplayer games, as well as to transmit information that is not normally synched over the network.
The receiving cogs are responsible to declare and code a handler for the trigger: message. And they can check that they want to handle a specific triggerID by using GetSenderID as well as retrieve the parameters passed with GetParam.

Use: SendTrigger(destination, triggerID, flex param0, flex param1, flex param2, flex param3);"


Try:

SendTrigger(player, 45, player, mychute, 0, 0);
2001-07-10, 5:56 AM #7
Actaully its not a problem cause I told him to code the client trigger like this...

Code:
trigger:
if(GetSourceRef() == 66)
{
 if(GetParam(0) == player)
 {
 mychute = GetParam(1);
 }
}
Return;


whichs checks to see if the sender was the player. (player sent is Param(0) is checked againt player defined locally)

You method might save a small amount of bandwidth though. I usually use -1 and old habits die hard.
2001-07-10, 4:14 PM #8
Eh, not sure if you're right on that.. from how I understand it, getlocalplayerthing() would have the same value on ALL computers, and thus it wouldn't quite work..
2001-07-10, 6:10 PM #9
Ok you've lost me now...

if you put

player = GetlocalplayerThing();

in the server cog, I agree that might get confusing. But, in client cogs... I have never seen this mis-identify player.

GetlocalplayerThing() just returns the player's thing number. Im not sure how you can say it would be the same on all machines. Look at all the Force cogs.. they all use GetLocalPlayerThing();.


2001-07-11, 5:26 AM #10
Right now I have player = GetLocalPlayerThing for both client and server cogs. Should I change any of them to GetSourceRef?
2001-07-11, 11:18 AM #11
I would avoid it in the server cog, just pass the player id in one of the trigger params exactly like you have above:

theguy = GetParam(0);

I dont even thing you need to mention a

player = GetSourceRef();

or

player = GetLocalPlayerThing();

in the server cog. I'm betting either one will work in the hotkey cog that sends the trigger to open or close chute.

Although I'm having doubts now due Evil_Greven's posts. Hopefully someone else will step in that knows for sure.
2001-07-11, 1:15 PM #12
The SendTrigger is sending to all players... -1 needs to change to Player. Make sure your client cog is local as well.
Bassoon, n. A brazen instrument into which a fool blows out his brains.
2001-07-11, 1:21 PM #13
You might try using sendmessage. For sendtrigger to work, you'd have to have a bin in the items.dat for it. So use something like this:

player=getlocalplayerthing();
Sendmessage(getinvcog(player, x), user0);

Where x is the bin # with the recipient cog. That should send the message to only your cog, without doing anything to the other players.

------------------
*Rrrring* Microsoft has advanced to the Imperial Age.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.

↑ Up to the top!