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 → Controllable vehicles cog, need help...
Controllable vehicles cog, need help...
2002-02-03, 3:52 AM #1
Okay, so i made a controllable vehicle cog(s)... in SP it works just fine, but when another player joins, it's messed up... it's Client/Server...

Server side cog:
Code:
symbols

thing		player		local
int		act=0		local
int		padID

message	startup
message	activated
message	pulse
message killed

end

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

code
startup:
	player = GetLocalPlayerThing();
	SendTrigger(-1, 120 + padID, player, 0, 0, 0);
Return;
activated:

if(act == 0)
	{
	SendTrigger(-1, 130 + padID, player, 0, 0, 0);
	SetPulse(0.05);
	act = 1;
	}
else
if(act == 1)
	{
	SetPulse(0.0);
	SendTrigger(-1, 140 + padID, player, 0, 0, 0);
	act = 0;
	}
Return;

killed:
if(player == GetSenderRef())
	{
	SendTrigger(-1, 140 + padID, player, 0, 0, 0);
	}
Return;

pulse:
	SendTrigger(-1, 150 + padID, player, 0, 0, 0);
Return;

end


Client side:
Code:
flags=0x240
symbols
thing		pattach
thing		pad
thing		player		local
template	lookt=+ghost
template	smoke=+twinkle
vector		look		local
int		lookie		local
vector		lookv		local
int		act=0		local
int		padID

message         trigger
end
# ========================================================================================
code
trigger:

	if( (GetSourceRef() == 120 + padID)) 
	{
	AttachThingToThingEx(pad, pattach, 0x8);
	}
	else
	if( (GetSourceRef() == 130 + padID)) 
	{
	AttachThingToThingEx(GetParam(0), pattach, 0x8);
	SetThingPos(GetParam(0), VectorAdd(GetThingPos(pad), '0.0 0.0 0.03'));
	}
	else
	if( (GetSourceRef() == 140 + padID)) 
	{
	SetThingPos(GetParam(0), VectorAdd(GetThingPos(pad), '0.0 0.0 0.04'));
	DetachThing(GetParam(0));
	StopThing(pattach);
	StopThing(GetParam(0));
	}
	else
	if( (GetSourceRef() == 150 + padID)) 
	{
	lookie = FireProjectile(GetParam(0), lookt, -1, -1, '0.0 0.0 0.0', '0 0 0', 1, 0x20, -1, -1);
	CreateThing(smoke, pattach);
	lookv = GetThingLVec(GetParam(0));
	SetThingLook(pad, lookv);
	SetThingLook(pattach, GetThingLVec(GetParam(0)));
	ApplyForce(pattach, VectorScale(GetThingLVec(lookie), 30));
	DestroyThing(lookie);
	}
	return;
end


No it's not for a project, just something made because of boredom... if you find them usefull, use them... if you use them credit me...
As you know, walkstructures can't be moved with applyforce();, so i attached thing pad with thing pattach, which is invisible throwable object without collide box.

Anyway, if someone finds what's wrong, tell me... thank you...

------------------
Life is like... skating... yeah, skating is a good example. You see someone skating and think "Hey, that looks like fun and easy!". You go and buy a skateboard and try, you get a few broken bones, asphalt-face and stuff... But hey, i'm not the one who gets hurt!
Last edited by mb; today at 10:55 AM.
2002-02-03, 10:58 AM #2
Whoa, how exactly does this one work? Hpow do you control a vehicle?
2002-02-03, 3:02 PM #3
Without actully examining the cogs, the only thing I see is you defined the player with 'Getlocalplayerthing()', which usually returns the host in MP.

So, remove that and replace it with 'Getsourceref()' under 'Activated'.

------------------
Success is the inverse relationship between effort, gain, and loss.
And when the moment is right, I'm gonna fly a kite.
2002-02-04, 6:24 AM #4
GetLocalPlayerThing() returns the host? No way. LEC uses that in the weapon cogs and the kylecog with no problem.

The problem you're thinking of is when you try to retreive the SourceRef or the SenderRef when the message does not have the reference; and so the variable assigned stays at 0.

------------------
Each cog better than the next
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2002-02-04, 6:49 AM #5
I think GetLocal works in kyle cogs, because it is assigned to a player. Thus it gets the proper local player, but what if the cog is attached to a surface, what is "GetLocalPlayerThing()" for the surface? So it just gets the host or "0". I think that's the problem.

------------------
http://millennium.massassi.net - Millennium
Sniper Arena! - Enhancement Pack!
2002-02-04, 6:55 AM #6
I don't see how your cogs are supposed to work together in MP. They are obviously not server/client.

It seems that everybody has the same pad and pattach. And on startup, both server and clients attach them together. Now since there's only one pad and pattach, is everybody supposed to pilot the same structure?

It is very bad practice to use SetThingPos() on the player. If the player is put outside of his sector, he's out of the game.

I don't see any code designed to sync everything up for a joining client. You'll need a join message to run SyncThingPos() and SyncThingAttachment(). And what was your MP problem exactly?

------------------
Each cog better than the next

[This message has been edited by SaberMaster (edited February 04, 2002).]
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2002-02-04, 6:59 AM #7
The "local player" is the player being controlled by the computer that ran the LocalPlayer verb - the local computer. Doesn't matter which cog the verb is in.

------------------
Each cog better than the next
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2002-02-04, 7:24 AM #8
I see.
Maybe LEC cogs are fine because they have getsourceref in the activated, so it always overrides the bad value.

Am I right here?

------------------
http://millennium.massassi.net - Millennium
Sniper Arena! - Enhancement Pack!
2002-02-04, 8:20 AM #9
Hrmph... It needs no SyncThingPosition(); or else because in MP, if ANYONE activates a bike, the host gets on it and controls it... And the others can see it... in SP it works just fine... anyway, if any cog-god would like to fix my damn messy cog, feel free to [http://forums.massassi.net/html/smile.gif]

Code:
flags=0x240
symbols
thing		pattach
thing		pad
thing		atac
thing		player		local
template	lookt=+ghost
template	smoke=+heavysmoke
vector		look		local
int		lookie		local
vector		lookv		local
vector		plalo		local
int		act=0		local
int		bikek		local
int		akti=0		local
int		origfla		local
sector		curr		local
int		heat=0		local
keyframe	bikesit
keyframe	bikeidle
int		padID
int		enkine		local
sound		whiner
sound		starter
sound		shutdown

message		startup
message         trigger
end
# ========================================================================================
code
startup:
	player = GetParam(0);
Return;

trigger:
	
	if( (GetSourceRef() == 120 + padID)) 
	{
	AttachThingToThingEx(pad, pattach, 0x8);
	AttachThingToThingEx(atac, pattach, 0x8);
	}
	else
	if( (GetSourceRef() == 130 + padID)) 
	{
	SetThingPos(player, VectorAdd(GetThingPos(pattach), '0.0 0.0 0.13'));
	AttachThingToThingEx(player, pattach, 0x8);
	bikek = PlayKey(player, bikesit, 1, 0x14);
	ParseArg(player, "maxheadpitch=-15.00");
	ParseArg(player, "minheadpitch=-17.50");
	PlaySoundThing(starter, player, 0.35, 1.0, 5.0,0x80);
	StopSound(enkine, 0.0);
	Sleep(GetSoundLen(enginest));
	enkine = PlaySoundThing(whiner, player, 0.35, 1.0, 5.0, 0x81);
	}
	else
	if( (GetSourceRef() == 140 + padID)) 
	{
	Print("WERKS!!!!");
	DetachThing(GetParam(0));
	StopKey(player, bikek, 0.0);
	StopThing(pattach);
	StopThing(player);
	ParseArg(player, "maxheadpitch=80.00");
	ParseArg(player, "minheadpitch=-80.00");
	SetThingPos(player, VectorAdd(GetThingPos(pattach), '0.15 0.15 0.15'));
	}
	else
	if( (GetSourceRef() == 150 + padID)) 
	{
	curr = GetThingSector(player);
	lookie = FireProjectile(player, lookt, -1, -1, '0.0 0.0 0.0', '0 0 0', 1, 0x20, -1, -1);
	//FireProjectile(atac, bikedama, -1, -1, '0.11 0.11 0.0', '0 0 0', 1, 0x20, -1, -1);
	lookv = GetThingLVec(GetParam(0));
	SetThingLook(pad, lookv);
	SetThingLook(atac, lookv);
	SetThingLook(pattach, GetThingLVec(lookie));
	if(IsInvActivated(player, 42) == 0 && IsThingCrouching(player) == 0)
	{
	ApplyForce(pattach, VectorScale(GetThingLVec(player), 3));
	CreateThing(smoke, pattach);
	akti = 0;
	heat = heat - 1;
	}
	else
	if(IsInvActivated(player, 42) == 0 && IsThingCrouching(player) != 0 && heat <= 500)
	{
	ApplyForce(pattach, VectorScale(GetThingLVec(player), 10));
	heat = heat + 5;
	}
	else
	if(IsInvActivated(player, 42) == 0 && IsThingCrouching(player) != 0 && heat >= 500)
	{
	Print("Engine overheat, cooling... Boost disabled...");
	}
	if(IsInvActivated(player, 42) == 1)
	{
		if(akti == 0)
		{
		akti = 1;
		StopThing(Pattach);
		}
		else
		if(akti == 1)
		{
		ApplyForce(pattach, VectorScale(GetThingLVec(player), 0.005));
		}
	}
	//CreateThing(firesmoke, atac);
	DestroyThing(lookie);
	StopSound(enkine, 0.0);
	PlaySoundThing(shutdown, player, 0.35, 1.0, 5.0,0x80);
	}
	

	return;
end


^^^Client cog^^^

Code:
symbols

thing		pattach
thing		pad
thing		player		local
template	lookt=+ghost
vector		look		local
int		lookie		local
vector		lookv		local
vector		plalo		local
int		act=0		local
int		padID

message	startup
message	activated
message	pulse
message killed

end

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

code
startup:
	player = GetSourceRef();
	SendTrigger(-1, 120 + padID, player, 0, 0, 0);
Return;
activated:

if(act == 0)
	{
	SendTrigger(-1, 130 + padID, player, 0, 0, 0);
	SetPulse(0.0125);
	act = 1;
	}
else
if(act == 1)
	{
	SetPulse(0.0);
	SendTrigger(-1, 140 + padID, player, 0, 0, 0);
	act = 0;
	}
Return;

killed:
if(player == GetSenderRef())
	{
	SendTrigger(-1, 140 + padID, player, 0, 0, 0);
	}
Return;

pulse:

	SendTrigger(-1, 150 + padID, player, 0, 0, 0);

Return;


end


^^^Server cog^^^

Yes, i modified them a bit...

------------------
Life is like... skating... yeah, skating is a good example. You see someone skating and think "Hey, that looks like fun and easy!". You go and buy a skateboard and try, you get a few broken bones, asphalt-face and stuff... But hey, i'm not the one who gets hurt!
Last edited by mb; today at 10:55 AM.
2002-02-05, 5:21 AM #10
I put together some templates and a test level to try your original cogs. And as I expected, only clients that joined after the piloting had begun had MP problems.

They saw the player jumping around behind the vehicle. And this happens because the player's attachment is not synced. I added this code to fix the problem:

Code:
join:
	SyncThingAttachment(attachplayer);
	SyncThingAttachment(pad);

Return;


There were other problems, but they were caused by the templates I used or easily-fixed code problems(two players pilot the same vehicle).

And in your next version of the cogs, you're trying to get a player handle from the first param and the source of the startup message. And you've mastered cog? [http://forums.massassi.net/html/rolleyes.gif]

Well, good luck on your project, Cavey. [http://forums.massassi.net/html/wink.gif]

------------------
Each cog better than the next
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2002-02-05, 6:03 AM #11
hehe, i tried SyncThing-- commands but i put them in wrong places [http://forums.massassi.net/html/biggrin.gif]

------------------
Life is like... skating... yeah, skating is a good example. You see someone skating and think "Hey, that looks like fun and easy!". You go and buy a skateboard and try, you get a few broken bones, asphalt-face and stuff... But hey, i'm not the one who gets hurt!
Last edited by mb; today at 10:55 AM.
2002-02-05, 6:49 AM #12
Quote:
<font face="Verdana, Arial" size="2">
And in your next version of the cogs, you're trying to get a player handle from the first param and the source of the startup message.</font>


Eh? I'm getting a player handle from only the first param... in the server side cog i'm geeting it from the source of the startup [http://forums.massassi.net/html/smile.gif]

Btw, what the heck is attachplayer? [http://forums.massassi.net/html/tongue.gif]

------------------
Life is like... skating... yeah, skating is a good example. You see someone skating and think "Hey, that looks like fun and easy!". You go and buy a skateboard and try, you get a few broken bones, asphalt-face and stuff... But hey, i'm not the one who gets hurt!
Last edited by mb; today at 10:55 AM.
2002-02-05, 7:02 AM #13
Startup does not have a source, sender, or params. It's a plain system message.

>Btw, what the heck is attachplayer?

attachplayer is the player who is attached to the vehicle. I know I don't show how he's defined in that example... I had a lot of changes. But you get the idea. [http://forums.massassi.net/html/wink.gif]

------------------
Each cog better than the next
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2002-02-05, 7:22 AM #14
Ooooh... [http://forums.massassi.net/html/smile.gif]

Show me the changes you made, please [http://forums.massassi.net/html/smile.gif]

I wanna know what i did wrong [http://forums.massassi.net/html/tongue.gif]

------------------
Life is like... skating... yeah, skating is a good example. You see someone skating and think "Hey, that looks like fun and easy!". You go and buy a skateboard and try, you get a few broken bones, asphalt-face and stuff... But hey, i'm not the one who gets hurt!
Last edited by mb; today at 10:55 AM.

↑ Up to the top!