PDA

View Full Version : Grab a bottle



Edward
09-15-2003, 10:34 AM
Hi!
I need a JK MP cog that, when I activate a bottle (or a set of 3 bottles), a new bottle is created by my hands and will follow me around. If I activate another person, he will get my bottle and the ability to pass it on. If I want to make the bottle disappear, then I have to return it to where I picked it out from. And I want to be able to create unlimitted bottles. No wait... Hm... Only 32 is needed. After all, only 32 players are allowed in JK.
Thanks...

/Edward
------------------
What is God? (http://forums.massassi.net/html/Forum1/HTML/030301.html)What is God? RF (http://forums.massassi.net/html/Forum10/HTML/000387.html)

[This message has been edited by Edward (edited September 15, 2003).]

Edward
09-18-2003, 12:53 AM
just keeping the topic 'alive'...

please, no rush...

DSLS_DeathSythe
09-18-2003, 07:17 PM
ive been trying to do this but i cant get it to work right.
here's the cog so far:

################################################## ########
# Jedi Knight Cog Script (JK)
#---------------------------------------------------------
# grabbottle00.COG
# Description
#---------------------------------------------------------
# Written By DSLS_DeathSythe
# This COG is NOT supported by LucasArts Entertainment Co.
################################################## ########
symbols
#---------------------------------------------------------
message startup
message activated
message pulse
message join

thing player=-1 local
thing sender_thng=-1 local

thing dummy=-1 local
thing bottle=-1
template bottle_tpl=-1

sound pickup_snd=-1
sound drop_snd=-1
sound pass_snd=-1

flex wait=0.25

int a=0 local
#---------------------------------------------------------
end
#================================================= ========
code
#---------------------------------------------------------
startup:
Sleep(1.0);
if(IsServer())
{
player = GetLocalPlayerThing();
CaptureThing(player);
SetPulse(wait);
}
return;
#---------------------------------------------------------
activated:
sender_thng = GetSenderRef();
player = GetSourceRef();

if(sender_thng == bottle)
{
if(GetThingFlags(player) & 0x4000000)
{
Print("stopping bottle...");
ClearThingFlags(player, 0x4000000);
PlaySoundThing(drop_snd, player, 1.0, -1, -1, 0x80);
return;
}
SetThingFlags(player, 0x4000000);
PlaySoundThing(pickup_snd, player, 1.0, -1, -1, 0x80);
}
else
{
Print("Player activated");
if(GetThingType(sender_thng) == 10)
{
if(!(GetThingFlags(sender_thng) & 0x4000000))
{
Print("bottle is switching players...");
SetThingFlags(sender_thng, 0x4000000);
ClearThingFlags(player, 0x4000000);
PlaySoundThing(pass_snd, player, 1.0, -1, -1, 0x80);
}
}
}
return;
#--------------------------------------------------------
pulse:
for(a=0; a<GetThingCount(); a=a+1)
{
if(GetThingType(a) == 10)
{
if(GetThingFlags(a) & 0x4000000)
{
dummy = FireProjectile(a, bottle_tpl, -1, -1, '0.01 0.05 0', '0 0 0', 0, 0x0, -1, -1);
SetLifeLeft(dummy, wait);
}
}
}
return;
#--------------------------------------------------------
join:
Print("Somone joined");
player = GetSenderRef();
CaptureThing(player);
return;
################################################## ########
end
heres the template for the bottle_tpl, the only parts that really matter are the 'timer' and 'collide'. put the 'bottle04' template thing in the level and list that as the bottle thing to go with this template, it will be the thing that is activated to start carring the bottle:

bottle04_2 _structure 3d=bottle4.3do size=0.080942 movesize=0.080942 timer=1.0 collide=0
what the cog does it set an unused/unknown thingflag when the player activates the bottle and then the pulse searches for all players with that flag and makes a bottle for them.
it uses 'FireProjectile' to make the bottle because i couldnt get the bottle to attach and stay in the same place on the player.
i tested it between my two comps and it seemed to work fine but the client couldnt pass the bottle to the server.
the server could pass the bottle to the client just fine.
i dont know why the server couldnt be activated and i didnt try it between any more comps to see if it worked between two clients.
other thing is there can only be one of these cogs running in the level. so you cant have two different types of bottles to activate.

if anyone has any ideas on how to fix it or a better ways of doing it try them and see if they work.
this is the best/easiest way i came up with, maybe it will give someone else an idea.

and my cog still has all the test 'Prints' in it so if you do decide to use it in your level you'll need to either delete them or comment them out.

------------------
Famous last words - "It seemed like a good idea at the time."

[This message has been edited by DSLS_DeathSythe (edited September 18, 2003).]

Stormtrooper
09-19-2003, 01:03 PM
Wouldn't it be easier to make the bottle an external weapon mesh (like a bottle put in the fist model) and use jksetweaponmesh() to give the player the bottle?

------------------
Look for my current project, The Force in Your Soul.
Last week I cudn't evn spel grajuat, but now I is one.

*Takes out his blaster and fires shots at the wall, the blastmarks leave the words "S-TROOPER WUZ 'ERE!!!"

Edward
09-20-2003, 12:57 AM
Well, haven't tried it yet but looking at it I'm having doubts about the following:

At the beginning you catch player to be server. Don't you think that the server should be like anyone else?

And if the player is server, don't you think you should have a test for player instead of just sender_thng?

Just curious...
But I think we need SaberMaster to have a look at this.

/Edward

Edward
09-20-2003, 02:15 AM
OK, just tried it out, and had a thought (if nobody can fix this "return bottle to server")... Server is the bartender and the clients will have to throw away their bottles when done.

And I think I'll make the bottle(s) a weapon mesh. Just so that I can edit the fists cog to drink instead of punch when they have a bottle.

And still, we wait for COG masters to show up and help us with our server problem.

/Edward
-----------------
"Jo du Anders. Har du hört vad Stockholmarna kallar läsk?"
"Nä..."
"Pysch..."
"Pysch?"
"Pysch!" öppnar en osynlig burk.
"*Fniss*.. Va' de håller på..."
ICA (http://www.ica.se/) Reklam (http://www.ica.se/downloads/ica_v31_Kraftpremiar.asf)

[This message has been edited by Edward (edited September 20, 2003).]

Edward
09-20-2003, 03:42 AM
Oh, any way I can have more bottles? I was thinking of having all 6 bottle types and depending on witch one I activate, I will get that type in my hands...

Yes, another thing... When I die, I still have the 4000000 flag. How should I implement it so that it is taken away when I die?

/Edward


[This message has been edited by Edward (edited September 20, 2003).]

DogSRoOL
09-20-2003, 02:30 PM
Something like this in kyle.cog perhaps:

killed:
ClearThingFlags(getSenderRef(), 0x4000000);

------------------
"The Just shall live by faith." - Galatians 3:11
To edit is human... To COG is divine!!
America is a giant horn-dog.

[Anoying posts] + 1.

DSLS_DeathSythe
09-21-2003, 03:30 PM
ok i think i have one that will work for you now.
it changes the weapon mesh so you will have to make a 3do for all the bottles.

heres the main cog that goes in the level:

################################################## ########
# Jedi Knight Cog Script (JK)
#---------------------------------------------------------
# grabbottle01.COG
#---------------------------------------------------------
# Written By DSLS_DeathSythe
# This COG is NOT supported by LucasArts Entertainment Co.
################################################## ########
symbols
#---------------------------------------------------------
message startup
message activated
message trigger
message timer
message newplayer

thing player=-1 local

thing act_sndr=-1 local
thing act_srce=-1 local

thing bottle=-1

model bottle_3do
model povbottle_3do

model fist_3do
model povfist_3do

int bin=100 local
int bottle_id=1
int bottle_inv=0 local

sound pickup_snd=-1
sound drop_snd=-1
sound pass_snd=-1
sound cant_snd=-1

int is_busy=0 local

int actbottle_trig=-122 local
int plyract_trig=-123 local
#---------------------------------------------------------
end
#================================================= ========
code
#---------------------------------------------------------
startup:

return;
#---------------------------------------------------------
activated:
if(GetSenderRef() != bottle)
return;
player = GetSourceRef();
bottle_inv = GetInv(player, 100);
if(bottle_inv == 0)
{
SetInv(player, bin, bottle_id);
SendTrigger(player, actbottle_trig, player, 1, bottle_3do, povbottle_3do);
PlaySoundThing(pickup_snd, player, 1.0, -1, -1, 0x80);
return;
}
else
if(bottle_inv == bottle_id)
{
SetInv(player, bin, 0);
SendTrigger(player, actbottle_trig, player, 2, fist_3do, povfist_3do);
PlaySoundThing(drop_snd, player, 1.0, -1, -1, 0x80);
return;
}
PlaySoundThing(cant_snd, player, 1.0, -1, -1, 0x80);
return;
#---------------------------------------------------------
trigger:
if(GetSourceRef() == plyract_trig)
{
if(GetInv(GetParam(0), 100) == bottle_id)
{
if(GetInv(GetParam(1), 100) != 0)
{
if(is_busy == 1)
return;
is_busy = 1;
SetTimerEx(0.1, 1, 0, 0);
PlaySoundThing(cant_snd, GetParam(0), 1.0, -1, -1, 0x80);
return;
}
if(is_busy == 1)
return;
is_busy = 1;
SetTimerEx(0.5, 1, 0, 0);
act_srce = GetParam(0);
act_sndr = GetParam(1);
SetTimerEx(0.0, 2, act_srce, 0);
SetTimerEx(0.0, 3, act_sndr, 0);
}
return;
}
return;
#---------------------------------------------------------
timer:
if(GetSenderID() == 1)
{
is_busy = 0;
return;
}
else
if(GetSenderID() == 2)
{
SetInv(GetParam(0), bin, 0);
SendTrigger(GetParam(0), actbottle_trig, GetParam(0), 2, fist_3do, povfist_3do);
PlaySoundThing(pass_snd, GetParam(0), 1.0, -1, -1, 0x80);
return;
}
else
if(GetSenderID() == 3)
{
SetInv(GetParam(0), bin, bottle_id);
SendTrigger(GetParam(0), actbottle_trig, GetParam(0), 1, bottle_3do, povbottle_3do);
PlaySoundThing(pickup_snd, GetParam(0), 1.0, -1, -1, 0x80);
return;
}
return;
#--------------------------------------------------------
newplayer:
player = GetSourceRef();
SetInv(player, 100, 0);
return;
################################################## ########
end
list the bottle thing that gets activated as the bottle, and list the 3dos that go with it as the bottle_3do & povbottle_3do.
the other important number to worry about is the bottle_id. it needs to be different each time you use the cog in your level.

the other cog you need is a kyle.cog.
just extract one from the res2.gob and put it in the cog folder.
this is the stuff you will need to add to the 'kyle.cog':

##########
//-New SYMBOLS for the KYLE.COG...
##########
message activated
message trigger

thing plyr_thng=-1 local
thing act_sndr=-1 local
thing act_srce=-1 local

int actbottle_trig=-122 local
int plyract_trig=-123 local
##########
//-New CODE for the KYLE.COG...
##########
#----------------------------------------
activated:
act_sndr = GetSenderRef();
act_srce = GetSourceRef();
SendTrigger(-1, plyract_trig, act_srce, act_sndr, 0, 0);
return;
#----------------------------------------
trigger:
if(GetSourceRef() == actbottle_trig)
{
plyr_thng = GetParam(0);
if(GetParam(1) == 1)
{
if(GetCurWeapon(plyr_thng) != 1)
{
SelectWeapon(plyr_thng, 1);
Sleep(0.7);
}
jkSetWeaponMesh(plyr_thng, GetParam(2));
jkSetPOVModel(plyr_thng, GetParam(3));
return;
}
else
if(GetParam(1) == 2)
{
jkSetWeaponMesh(plyr_thng, GetParam(2));
jkSetPOVModel(plyr_thng, GetParam(3));
return;
}
return;
}
return;
#----------------------------------------
just add that stuff and the kyle.cog is done.

with these cogs you can have as many different types of bottles as you want. just make sure to give each one a different 'bottle_id'.

i tested it between my two computers and i was able to pass the bottle back and forth between the two players.
one minor problem that i had and dont know why it happens is that the 3do that it gives the player sometimes (hardly ever) isnt the 3do its supposed to be, shouldnt be a big problem just getting rid of the bottle then getting a new one fixes it.

another problem is that if the player has a bottle and he switches weapons he looses the bottle 3do that he had and he cant get it back. unless he activates the bottle he had (puts the bottle back), then activates it again (picks the bottle up again).

try it and see if you like it.

------------------
Famous last words - "It seemed like a good idea at the time."

[This message has been edited by DSLS_DeathSythe (edited September 21, 2003).]

Edward
09-23-2003, 12:00 AM
Hm... Haven't tried your first COG yet, but I wonder, how does it allow me to select different bottles and we all have our own individual bottle types?
Just wondering, since I don't see it.