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 → Getting Player Num.
Getting Player Num.
2004-04-15, 2:58 AM #1
Hi!
Making an interesting Trap here, but I can't seem to get the players for the trap.
Code:
# Players gets mines under their feet.
#
# By Edward
symbols

message		activated

thing		player		local

int		i		local

template	mines
template	magic

sound		magicsnd

surface		switch

int		on=0		local

thing		dummy		local

end
#
code
activated:
	If(GetSenderRef()!=switch) return;
	If(on==1) return;
	on=1;
	SetWallCel(switch,1);
	sleep(1);
	for(i=0; i<=GetNumPlayers(); i=i+1);
	{
		player=GetPlayerThing(i);
		dummy=CreateThing(magic,player);
		CaptureThing(dummy);
		AttachThingToThing(dummy,player);
		PlaySoundThing(magicsnd,player,1,-1,10,0x80);
	}
	sleep(0.1);
	for(i=0; i<=GetNumPlayers(); i=i+1);
	{
		player=GetPlayerThing(i);
		dummy=CreateThing(mines,player);
	}
	sleep(1);
	SetWallCel(switch,0);
	on=0;
return;
end

I know I'm doing something wrong here, but I can't figure it out. The switch activates, but nothing comes. Help!

/Edward
Edward's Cognative Hazards
2004-04-15, 7:41 AM #2
Try "i < GetNumPlayers();"; when PJB wrote a cog back whenever for a_person, "<= GetNumPlayers()" killed the cog.

Here's what I mean. You have "i <= GNP()" and # of players is 1. The player (the only one) is player thing 0. The loop executes and makes i=1. Since i (1) == GetNumPlayers() (which is also 1), the cog tries to get player thing 1 (which doesn't exist 'cause the only player thing is P.T. 0).

Hope you could understand that, and that changing <= to < will work.

------------------
Bond, Power, CA, The Force, Saber, IC, Epic, Oily Mexican Food, BG, /\ |> /\ /\/\, Sentences.
Now you know where I've been.

[This message has been edited by Darth Slaw (edited April 15, 2004).]
May the mass times acceleration be with you.
2004-04-15, 8:17 AM #3
No, that didn't work. I even tried i=-1;.

/Edward
Edward's Cognative Hazards
2004-04-15, 10:52 AM #4
Coupla things...

1) You dont need to run CaptureThing. The thing would have already been captured due to the fact that this cog created it.

2) Dont use '-1' as a min-distance when playing sounds. This will quote often cause the sound to be inaudible. Instead, set min-distance to '0'.

3) Put in a printed statement to see if the code is seeing any players...

Code:
# Players gets mines under their feet.
#
# By Edward
symbols
message activated
thing player		local
int i=0			local
template mines
template magic
sound magicsnd
surface switch
int on=0		local
thing dummy		local
end
code
activated:
	If(GetSenderRef()!=switch) return;
	If(on==1) return;
	on=1;
	SetWallCel(switch,1);
	sleep(1);
	for(i=0; i<=GetNumPlayers(); i=i+1);
	{
		player=GetPlayerThing(i);
		dummy=CreateThing(magic,player);
		AttachThingToThing(dummy,player);
		PlaySoundThing(magicsnd,player,1,0,10,0x80);
		print("Player got mine!");
		printint(player);
	}
	sleep(0.1);
	for(i=0; i<=GetNumPlayers(); i=i+1);
	{
		player=GetPlayerThing(i);
		dummy=CreateThing(mines,player);
	}
	sleep(1);
	SetWallCel(switch,0);
	on=0;
return;
end


------------------
I used to believe that we must fight the future, lest change come without our consent. I was wrong. The truth is that we must embrace the future, for only with change can we remain the same.
And when the moment is right, I'm gonna fly a kite.
2004-04-15, 12:42 PM #5
OK, the print worked. Player 24 got mine, but no magic template was created, magic sound came, no mine... According to JED, where I respawned, was walkplayer 94. But, what it did do is create a mine at the possition where walkplayer 24 is. Hm... *thinks 'till his mind is dust* I think there is something wrong in the way I asked for the thing...
I had a look at what I did in another COG where you could spectate through the eyes of
another player. There I put 32 players in the symbols, where I had to put in the walkplayer's thing number. An array. But I don't want all the players predefined in the symbols. I want to catch them on the spur of the moment. (' think I spelled that right...)

/Edward
Edward's Cognative Hazards
2004-04-15, 1:18 PM #6
okay, I copied the cog from GBK's post onto my comp and found two big errors.

FIRST AND MOST IMPORTANTLY, you need to remove the semicolons that are inconveniently placed after your for loops.

Next, as I pointed out, was that the <= in "i <= GNP()" needed to be < and not <=. If it was <=, the cog created the effects at all the players' positions but also at the next available walkplayer's position (walkplayer, NOT active player). That is why the mine was being created at player # 24's spot and (wait a second) not yours? [http://forums.massassi.net/html/confused.gif] Well, fix these two things and the cog works fine.

[This message has been edited by Darth Slaw (edited April 15, 2004).]
May the mass times acceleration be with you.
2004-04-15, 1:40 PM #7
No ; after for... Aye, that might do it. And away the problem went, precious! Fixed fixed fixed fixed! The Trap is SET!!! *dances around and presents Darth Slaw with a dead rabit*
OK, I went to far... Hay, what are you doing with that knife? Hey, get back! No! NO! AAAAAAAAAAAAAAARRRGH!
Edward's Cognative Hazards
2004-04-15, 1:49 PM #8
Yay! I've always wanted a dead rabbit! I know what I'm eating for supper tonight! [http://forums.massassi.net/html/biggrin.gif] [http://forums.massassi.net/html/wink.gif]

Anyway, I edited my post while you posted just now, Edward. Just so you know that I cleaned it up so the two errors that were in there were more clearly stated.

And thanks for the rabbit. [http://forums.massassi.net/html/smile.gif]

------------------
Bond, Power, CA, The Force, Saber, IC, Epic, Oily Mexican Food, BG, /\ |> /\ /\/\, Sentences.
Now you know where I've been.
May the mass times acceleration be with you.
2004-04-15, 9:02 PM #9
Geeze, I TOTALLY missed the semicolons. [http://forums.massassi.net/html/frown.gif]

------------------
I used to believe that we must fight the future, lest change come without our consent. I was wrong. The truth is that we must embrace the future, for only with change can we remain the same.
And when the moment is right, I'm gonna fly a kite.
2004-04-16, 8:25 AM #10
[http://blargh.mine.nu/test/169/7.gif] me <3 parsec [http://blargh.mine.nu/test/169/7.gif]

------------------
Bond, Power, CA, The Force, Saber, IC, Epic, Oily Mexican Food, BG, /\ |> /\ /\/\, Sentences.
Now you know where I've been.
May the mass times acceleration be with you.

↑ Up to the top!