x


Sending an RPC

How would I go about sending an RPC back to the send of the last one? Lets say.. I sent an RPC to a health script the took away the other players health and once the health equaled 0 how would I send an RPC back to the killer telling him to add the kill? is it something like -

info.sender.RPC("addkill",RPCMode.All);

but that doesn't seem right and doesn't work.

more ▼

asked Jan 23 '12 at 05:24 PM

twoface262 gravatar image

twoface262
129 40 52 55

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Networked code doesn't usually try to do things that way. Say you have 4 players and one bullet. The bullet was spawned by player 3, so it controls it and the other players mirror the position (the bullet code looks like: if not owner {do nothing}.)

When the bullet, in player 3's copy, hits player 1, it sends out bulletHit(player1, 8 damage, RPC.ALL). All four players run the math, see player 1 was dead, give points... .

If you have more a server/client version, the server program runs everything. It does the damage, scores ... and sends all client messages like updateScore(p3, newScore), or beginDeath(player1).

more ▼

answered Jan 23 '12 at 05:39 PM

Owen Reynolds gravatar image

Owen Reynolds
11.3k 1 7 45

Well how would it tell who player1 is? That is what my question is.

Jan 23 '12 at 07:36 PM twoface262

The same way without a network. The bullet eventually triggers an OnCollision(Collision col). It looks up PLY=col.transform to see who it hit and do damage. That's a transform.

At some point we want the number of who was hit so we can keep stats. Maybe the npcs are numbered (check PLY.GetComponent(npcScript).num) or maybe we kept a list when we made them, so we check that list for which slot.

Jan 24 '12 at 12:57 AM Owen Reynolds

What about raycasts? I want to get who the shot the raycast. Not who the bullet object hit.

Jan 24 '12 at 01:48 AM twoface262

Same basic principle. Nothing really changes other than the origin of the signals. When you send your RPC, include a reference to the NetworkPlayer who fired the shot- that way, when it arrives the target will know what to do with it. Remember that NetworkPlayer instances are one of the few types that can be sent over RPC calls.

Jan 24 '12 at 02:08 AM syclamoth

Alright thanks! :D

Jan 24 '12 at 03:51 AM twoface262
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3735
x3458
x701
x237

asked: Jan 23 '12 at 05:24 PM

Seen: 1033 times

Last Updated: Jan 24 '12 at 03:51 AM