I meant something along this:
Code: Select all
class MyClass extends Actor
native;
var bool hiyo;
var bool bSent; //Variable to be set once send() is called from the client
native(1780) final function bool tits();
replication
{
reliable if (Role < ROLE_Authority)
send;
}
function send()
{
Log("debugging");
}
simulated function PreBeginPlay()
{
local Pawn P;
//Set owner in the server and let it replicate
if (Role == ROLE_Authority)
{
for (P = Level.PawnList; P != None; P = P.NextPawn)
{
if (PlayerPawn(P) != None /* && <some other conditions here> */)
{
SetOwner(P);
break;
}
}
}
Super.PreBeginPlay();
}
//Setup a tick waiting for the PlayerPawn(Owner) to be set
//The PostNetBeginPlay() event won't do the trick here since it only works with tear-off replication (bNetTemporary=True)
simulated function Tick(float Delta)
{
if (!bSent && PlayerPawn(Owner) != None && Role < ROLE_Authority)
{
send();
bSent = True;
}
Super.Tick(Delta);
}
//Set the RemoteRole to SimulatedProxy and bNetTemporary=False so the client version of the actor keeps connected to the server version
defaultproperties
{
RemoteRole=ROLE_SimulatedProxy
bNetTemporary=False
}
Although you can remove the whole "Set owner in the server and let it replicate" block from the code as long as you spawn the actor in the server only and like this:
Spawn(Class'MyClass ', <Some_PlayerPawn>,, <Some_PlayerPawn>.Location);
Anyway, the flow should be something like this:
1 - Spawn the actor in the server only (where Role == ROLE_Authority)
2 - Either:
a) assign a playerpawn owner from the spawn itself;
b) assign a playerpawn owner by searching in the pawn list and getting the one you actually want (server side only as well, aka Role == ROLE_Authority, so the Owner reference can replicate properly)
3 - In a client event of your choice (I have chosen Tick since it's the most reliable with the least delay, but that's just a personal preference, PostNetBeginPlay is the best of all but it doesn't get called in bNetTemporary=False actors, hence this alternate mode of doing things), and only AFTER the actor gets the playerpawn owner assigned on that end, call the function you want.