switch player question?

Posted By: lomeniki

switch player question? - 06/29/06 13:26

Hi,
Is it posible to replace player with another one
(eg. player1.mdl with player2.mdl) in the same room?

I`d like(imagine) to switch player with:
right mouse click to produce some pannel with buttons(player names)
so i can choose on what player i want.( and reverse option ofcourse)

I am completly noob in scripting .
I need complete code with explanation where to put it and/or where to atach that.
That is (i think) the only code that i need for my small game.
Please help
Posted By: Claus_N

Re: switch player question? - 06/29/06 14:03

For switching the player model, you should use ent_morph. Check out the manual
Sorry, haven't got time for an example right now.. :/
Posted By: lomeniki

Re: switch player question? - 06/29/06 15:35

I read about ent_morph thing ,
but everything is messed up in my head(where,when,why???)
Someone else...please help,this is the only code i need (complete ofcourse).
For everything else i`ll use templates.Please,please help.
Posted By: Claus_N

Re: switch player question? - 06/29/06 16:59

I'm back

Try this code. (Not tested, but just post any errors)
Code:
/////////////////////////////////////////
// On mouse-over
bmap pl1_hover = <YOUR_BMAP>;
bmap pl2_hover = <YOUR_BMAP>;
bmap pl3_hover = <YOUR_BMAP>;
bmap pl4_hover = <YOUR_BMAP>;
// Normal
bmap pl1_normal = <YOUR_BMAP>;
bmap pl2_normal = <YOUR_BMAP>;
bmap pl3_normal = <YOUR_BMAP>;
bmap pl4_normal = <YOUR_BMAP>;
// Other bmaps
bmap cancel_but = <YOUR_BMAP>;
/////////////////////////////////////////
// Player models
string pl1_mdl = <MODEL>;
string pl2_mdl = <MODEL>;
string pl3_mdl = <MODEL>;
string pl4_mdl = <MODEL>;
string* ptr_string; // String pointer
/////////////////////////////////////////
// Constants
define numStrings,4;
/////////////////////////////////////////
// Variables
var ptrs_set = 0;
var string_ptrs[numStrings];
/////////////////////////////////////////
// Function prototypes
function plSelect(but,pan);
function plSelect_cancel();
/////////////////////////////////////////
panel plSelectionPan
{
flags = refresh;
button = 20,20,pl1_hover,pl1_normal,pl1_hover,plSelect,null,null;
button = 20,50,pl2_hover,pl2_normal,pl2_hover,plSelect,null,null;
button = 20,80,pl3_hover,pl3_normal,pl3_hover,plSelect,null,null;
button = 20,110,pl4_hover,pl4_normal,pl4_hover,plSelect,null,null;
button = 20,140,pl4_hover,pl4_normal,pl4_hover,plSelect,null,null;
button = 20,170,cancel_but,cancel_but,cancel_but,plSelect_cancel,null,null;
}
/////////////////////////////////////////
function setStrings()
{
string_ptrs[0] = handle(pl1_mdl);
string_ptrs[1] = handle(pl2_mdl);
string_ptrs[2] = handle(pl3_mdl);
string_ptrs[3] = handle(pl4_mdl);
ptrs_set = 1;
}
/////////////////////////////////////////
function plSelect(but,pan)
{
if(!player) {return;}

if(!ptrs_set) {setStrings();}

if(but <= 0 || but > numStrings) {return;}

ptr_string = ptr_for_handle(string_ptrs[but - 1]);

ent_morph(player,ptr_string);

plSelectionPan.visible = off;
}
/////////////////////////////////////////
function plSelect_cancel()
{
plSelectionPan.visible = off;
}
/////////////////////////////////////////
function showPlslPan()
{
plSelectionPan.pos_x = (screen_size.x - bmap_width(plSelectionPan.bmap)) / 2;
plSelectionPan.pos_y = (screen_size.y - bmap_height(plSelectionPan.bmap)) / 2;
plSelectionPan.visible = on;
}

on_mouse_right = showPlslPan;
/////////////////////////////////////////



Save it as player_selection.wdl, and add this to the includes in your level's WDL (LEVELNAME.wdl) file:
include <player_selection.wdl>;
Posted By: lomeniki

Re: switch player question? - 06/29/06 17:31

Thank you very much.
I`ll try ,then i`ll post results
Posted By: lomeniki

Re: switch player question? - 06/29/06 19:25

...made buttons...placed them in level folder...include code...

Stuck in run level.I don`t no what is this error and what to do next:

Error E1515
Invalid arguments in showPlslPan: plSelectionPan.ps_x=(screen_size.x-bmap_width(plSelectionPan.bmap))/2
Next error is:
Crash in showPlslPan...

What to replace with what?
Posted By: Claus_N

Re: switch player question? - 06/29/06 20:16

Oh sry, forgot this one

Code:
bmap plSelectMap = <YOUR_BMAP>;

panel plSelectionPan
{
bmap = plSelectMap;
flags = refresh;
button = 20,20,pl1_hover,pl1_normal,pl1_hover,plSelect,null,null;
button = 20,50,pl2_hover,pl2_normal,pl2_hover,plSelect,null,null;
button = 20,80,pl3_hover,pl3_normal,pl3_hover,plSelect,null,null;
button = 20,110,pl4_hover,pl4_normal,pl4_hover,plSelect,null,null;
button = 20,140,pl4_hover,pl4_normal,pl4_hover,plSelect,null,null;
button = 20,170,cancel_but,cancel_but,cancel_but,plSelect_cancel,null,null;
}


That should fix it... But one thing I noticed in the error msg u wrote:
Quote:

Invalid arguments in showPlslPan: plSelectionPan.ps_x=(screen_size.x-bmap_width(plSelectionPan.bmap))/2



should've been pos_x, but that's right in the code I posted, so maybe u just forgot the 'o' when writing the error message.. ;P
Posted By: lomeniki

Re: switch player question? - 06/29/06 21:06

Thank you,
first, ps_x is my writing mistake,sorry.
When right mouse click i`ve got the background with buttons,super:)
But i lost mouse poiter so now i am unable to highlite or click on buttons.
I use A5_template_project in my test.wdl.
When "uninclude" player_selection.wdl line, in test.wdl ,
i get mouse pointer back.
What to do next?
Posted By: Claus_N

Re: switch player question? - 06/29/06 21:36

Try this

Code:
function showPlslPan()
{
plSelectionPan.pos_x = (screen_size.x - bmap_width(plSelectionPan.bmap)) / 2;
plSelectionPan.pos_y = (screen_size.y - bmap_height(plSelectionPan.bmap)) / 2;
plSelectionPan.visible = on;
mouse_mode = 2;
}


Posted By: lomeniki

Re: switch player question? - 06/29/06 21:46

Do not work.
Same situation like before.

oops,not like before.
Before the player walk forward when i click rmb ,now nothing happens
& when i hit "esc" button to quit game, lost higlite so must count buttons
to hit the good one.
Posted By: Claus_N

Re: switch player question? - 06/29/06 21:54

Well... Then try calling the "mouse_toggle" function instead:

Code:
function showPlslPan()
{
plSelectionPan.pos_x = (screen_size.x - bmap_width(plSelectionPan.bmap)) / 2;
plSelectionPan.pos_y = (screen_size.y - bmap_height(plSelectionPan.bmap)) / 2;
plSelectionPan.visible = on;
mouse_toggle();
}


Posted By: lomeniki

Re: switch player question? - 06/29/06 22:28

mouse_togle work:) SUPER

But now ,when i switch mdl, i can move it but player animation is gone(walk,jump...)

Second(not so important), i must click twice to get pointer (1-st for pannel,
then for pointer) & when rmb click player figure start to "move" forward.Is it
posible to stop any movments when switching player?

For this testing i use 5 cbabe.mdls with diferent texture.1-st is the original
( and placed in level),
and other 4 are in the level folder.
P.S.Thanks man
Posted By: Claus_N

Re: switch player question? - 06/29/06 22:41

While looking at the mouse_toggle function (menu.wdl), I found out, that you should just do it this way

Code:
function showPlslPan()
{
plSelectionPan.pos_x = (screen_size.x - bmap_width(plSelectionPan.bmap)) / 2;
plSelectionPan.pos_y = (screen_size.y - bmap_height(plSelectionPan.bmap)) / 2;
plSelectionPan.visible = on;
mouse_mode = 2;
mouse_on();

}



I have no clue atm about what happened to the animations :S
Maybe your other models don't have those animations..?? (I know it's the same model just with different skins... But that's the only reason I can think of right now )

I don't know how to avoid the movement...
Post in the templates forum about that
Posted By: lomeniki

Re: switch player question? - 06/29/06 23:07

1000x Thanks

For mdl`s you were right.i checked them -there are frames but when i played them
nothing happens.I done something wrong(but i only change skin)
& save them as mdl5.

2 more:
How to add some wav`s (for each button when highlited so we hear player
names...)
& and little transparency for background and butons.
Can they be a tga with alpha ch.(or some your sugestion for better pic format)?

P.S.If you haven`t time now i`ll wait.Thanks anyway.

Edit: I checked original cbabe.mdl in MED.It`s a mdl4 file, and i only have
mdl5 & mdl7 save option.
Q:Can A5_template work with mdl5 or 7?
Posted By: Claus_N

Re: switch player question? - 06/30/06 08:50

For the sound:
Code:
/////////////////////////////////////////
sound pl1_snd = <SOUND>;
sound pl2_snd = <SOUND>;
sound pl3_snd = <SOUND>;
sound pl4_snd = <SOUND>;

function pl_sound(but,pan)
{
if(but == 1) {snd_play(pl1_snd,100,10);}
if(but == 2) {snd_play(pl2_snd,100,10);}
if(but == 3) {snd_play(pl3_snd,100,10);}
if(but == 4) {snd_play(pl4_snd,100,10);}
}

/////////////////////////////////////////
panel plSelectionPan
{
flags = refresh;
button = 20,20,pl1_hover,pl1_normal,pl1_hover,plSelect,null,pl_sound;
button = 20,50,pl2_hover,pl2_normal,pl2_hover,plSelect,null,pl_sound;
button = 20,80,pl3_hover,pl3_normal,pl3_hover,plSelect,null,pl_sound;
button = 20,110,pl4_hover,pl4_normal,pl4_hover,plSelect,null,pl_sound;
button = 20,140,pl4_hover,pl4_normal,pl4_hover,plSelect,null,pl_sound;
button = 20,170,cancel_but,cancel_but,cancel_but,plSelect_cancel,null,null;
}
/////////////////////////////////////////



Yep, you need to use a tga with alpha channel (Or setting transparent and the alpha value of the panel, though I'd recommend using an alpha channel)

I don't know much about the model formats. I think you should use mdl7, but I dunno.
Posted By: lomeniki

Re: switch player question? - 06/30/06 11:33

Thanks, code work.Maybe some sound to cancel button.

How about som modification of sound code:
I`ll need sound to play, only when the mouse pointer is over the buton then stop
This is because i have sounds about 2sec lenth.
When i circle trough the buttons(to choice player) the sound became messy.
(first sound is still hearing while the second is playing,then third...)

I allso wish some other sound, when button click(player said something).

About your general code:
When i switch(make pl choice) pannel disapier.Is it posible for the mouse pointer allso.
This is important because, when mouse pointer is still on screen,
i am only able to navigate with keyboard.
Posted By: Claus_N

Re: switch player question? - 06/30/06 14:13

Okay, this should do it. It doesn't stop the sound when the mouse is moved away from the buttons, but it stops the previous sound when you move the mouse over another button.
Code:
/////////////////////////////////////////
sound pl1_snd = <SOUND>;
sound pl2_snd = <SOUND>;
sound pl3_snd = <SOUND>;
sound pl4_snd = <SOUND>;
sound cancel_snd = <SOUND>;

var_nsave pl_snd_handle;


function pl_sound(but,pan)
{
if(pl_snd_handle != 0)
{
snd_stop(pl_snd_handle);
}

if(but == 1) {pl_snd_handle = snd_play(pl1_snd,100,10);}
if(but == 2) {pl_snd_handle = snd_play(pl2_snd,100,10);}
if(but == 3) {pl_snd_handle = snd_play(pl3_snd,100,10);}
if(but == 4) {pl_snd_handle = snd_play(pl4_snd,100,10);}
if(but == 5) {pl_snd_handle = snd_play(cancel_snd,100,10);}
}
/////////////////////////////////////////
panel plSelectionPan
{
flags = refresh;
button = 20,20,pl1_hover,pl1_normal,pl1_hover,plSelect,null,pl_sound;
button = 20,50,pl2_hover,pl2_normal,pl2_hover,plSelect,null,pl_sound;
button = 20,80,pl3_hover,pl3_normal,pl3_hover,plSelect,null,pl_sound;
button = 20,110,pl4_hover,pl4_normal,pl4_hover,plSelect,null,pl_sound;
button = 20,140,pl4_hover,pl4_normal,pl4_hover,plSelect,null,pl_sound;
button = 20,170,cancel_but,cancel_but,cancel_but,plSelect_cancel,null,pl_sound;
}
/////////////////////////////////////////



Code:
/////////////////////////////////////////
sound pl1_sel_snd = <SOUND>;
sound pl2_sel_snd = <SOUND>;
sound pl3_sel_snd = <SOUND>;
sound pl4_sel_snd = <SOUND>;
sound cancel_sel_snd = <SOUND>;


function plSelect(but,pan)
{
if(!player) {return;}

if(!ptrs_set) {setStrings();}

if(but <= 0 || but > numStrings) {return;}

ptr_string = ptr_for_handle(string_ptrs[but - 1]);

ent_morph(player,ptr_string);

if(pl_snd_handle != 0)
{
snd_stop(pl_snd_handle);
}
if(but == 1) {pl_snd_handle = snd_play(pl1_sel_snd,100,10);}
if(but == 2) {pl_snd_handle = snd_play(pl2_sel_snd,100,10);}
if(but == 3) {pl_snd_handle = snd_play(pl3_sel_snd,100,10);}
if(but == 4) {pl_snd_handle = snd_play(pl4_sel_snd,100,10);}
if(but == 5) {pl_snd_handle = snd_play(cancel_sel_snd,100,10);}


plSelectionPan.visible = off;

mouse_mode = 0;
}
/////////////////////////////////////////


Posted By: lomeniki

Re: switch player question? - 06/30/06 20:24

Everything work exept when cick "cancel button" there is no sound.

Here is the code so far, so you can check it.
Is this good to place "sound comand" in 2 diferent places?

Code:
/////////////////////////////////////////
// On mouse-over
bmap pl1_hover = <pl1-h.bmp>;
bmap pl2_hover = <pl2-h.bmp>;
bmap pl3_hover = <pl3-h.bmp>;
bmap pl4_hover = <pl4-h.bmp>;
// Normal
bmap pl1_normal = <play1.bmp>;
bmap pl2_normal = <play2.bmp>;
bmap pl3_normal = <play3.bmp>;
bmap pl4_normal = <play4.bmp>;
// Other bmaps
bmap cancel_but = <cancel.bmp>;
bmap plSelectMap = <backg.bmp>;
/////////////////////////////////////////
// Player models
string pl1_mdl = <pl1.mdl>;
string pl2_mdl = <pl2.mdl>;
string pl3_mdl = <pl3.mdl>;
string pl4_mdl = <pl4.mdl>;
string* ptr_string; // String pointer
/////////////////////////////////////////
// Constants
define numStrings,4;
/////////////////////////////////////////
// Variables
var ptrs_set = 0;
var string_ptrs[numStrings];
/////////////////////////////////////////
// Function prototypes
function plSelect(but,pan);
function plSelect_cancel();
/////////////////////////////////////////
//Sound settings
sound pl1_snd = <c1.wav>;
sound pl2_snd = <c2.wav>;
sound pl3_snd = <c3.wav>;
sound pl4_snd = <c4.wav>;
sound cancel_snd = <cancel.wav>;

var_nsave pl_snd_handle;

function pl_sound(but,pan)
{
if(pl_snd_handle != 0)
{
snd_stop(pl_snd_handle);
}
if(but == 1) {pl_snd_handle = snd_play(pl1_snd,100,10);}
if(but == 2) {pl_snd_handle = snd_play(pl2_snd,100,10);}
if(but == 3) {pl_snd_handle = snd_play(pl3_snd,100,10);}
if(but == 4) {pl_snd_handle = snd_play(pl4_snd,100,10);}
if(but == 5) {pl_snd_handle = snd_play(cancel_snd,100,10);}
}
/////////////////////////////////////////
panel plSelectionPan
{
bmap = plSelectMap;
flags = refresh;
button = 20,20,pl1_hover,pl1_normal,pl1_hover,plSelect,null,pl_sound;
button = 20,60,pl2_hover,pl2_normal,pl2_hover,plSelect,null,pl_sound;
button = 20,100,pl3_hover,pl3_normal,pl3_hover,plSelect,null,pl_sound;
button = 20,140,pl4_hover,pl4_normal,pl4_hover,plSelect,null,pl_sound;
button = 20,180,cancel_but,cancel_but,cancel_but,plSelect_cancel,null,pl_sound;
}
/////////////////////////////////////////
function setStrings()
{
string_ptrs[0] = handle(pl1_mdl);
string_ptrs[1] = handle(pl2_mdl);
string_ptrs[2] = handle(pl3_mdl);
string_ptrs[3] = handle(pl4_mdl);
ptrs_set = 1;
}
/////////////////////////////////////////
sound pl1_sel_snd = <sel1.wav>;
sound pl2_sel_snd = <sel2.wav>;
sound pl3_sel_snd = <sel3.wav>;
sound pl4_sel_snd = <sel4.wav>;
sound cancel_sel_snd = <selcan.wav>;

function plSelect(but,pan)
{
if(!player) {return;}

if(!ptrs_set) {setStrings();}

if(but <= 0 || but > numStrings) {return;}

ptr_string = ptr_for_handle(string_ptrs[but - 1]);

ent_morph(player,ptr_string);

if(pl_snd_handle != 0)
{
snd_stop(pl_snd_handle);
}
if(but == 1) {pl_snd_handle = snd_play(pl1_sel_snd,100,10);}
if(but == 2) {pl_snd_handle = snd_play(pl2_sel_snd,100,10);}
if(but == 3) {pl_snd_handle = snd_play(pl3_sel_snd,100,10);}
if(but == 4) {pl_snd_handle = snd_play(pl4_sel_snd,100,10);}
if(but == 5) {pl_snd_handle = snd_play(cancel_sel_snd,100,10);}

plSelectionPan.visible = off;

mouse_mode = 0;
}
/////////////////////////////////////////
function plSelect_cancel()
{
plSelectionPan.visible = off;
mouse_mode = 0;
}
/////////////////////////////////////////
function showPlslPan()
{
plSelectionPan.pos_x = (screen_size.x - bmap_width(plSelectionPan.bmap)) / 2;
plSelectionPan.pos_y = (screen_size.y - bmap_height(plSelectionPan.bmap)) / 2;
plSelectionPan.visible = on;
mouse_mode = 2;
mouse_on();
}

on_mouse_right = showPlslPan;
/////////////////////////////////////////
Posted By: Claus_N

Re: switch player question? - 07/02/06 17:38

Moved the line:
if(but == 5) {pl_snd_handle = snd_play(cancel_sel_snd,100,10);}
from function plSelect, to function plSelect_cancel, and modified it a bit.

Quote:

Is this good to place "sound comand" in 2 diferent places?



That might be a matter of taste. I (and most others, I think) prefer the variable/bmap/sound/etc. definitions in the beginning/start of the script

Code:
/////////////////////////////////////////
// On mouse-over
bmap pl1_hover = <pl1-h.bmp>;
bmap pl2_hover = <pl2-h.bmp>;
bmap pl3_hover = <pl3-h.bmp>;
bmap pl4_hover = <pl4-h.bmp>;
// Normal
bmap pl1_normal = <play1.bmp>;
bmap pl2_normal = <play2.bmp>;
bmap pl3_normal = <play3.bmp>;
bmap pl4_normal = <play4.bmp>;
// Other bmaps
bmap cancel_but = <cancel.bmp>;
bmap plSelectMap = <backg.bmp>;
/////////////////////////////////////////
// Player models
string pl1_mdl = <pl1.mdl>;
string pl2_mdl = <pl2.mdl>;
string pl3_mdl = <pl3.mdl>;
string pl4_mdl = <pl4.mdl>;
string* ptr_string; // String pointer
/////////////////////////////////////////
// Constants
define numStrings,4;
/////////////////////////////////////////
// Variables
var ptrs_set = 0;
var string_ptrs[numStrings];

var_nsave pl_snd_handle;
/////////////////////////////////////////
// Function prototypes
function plSelect(but,pan);
function plSelect_cancel();
/////////////////////////////////////////
//Sound settings
sound pl1_snd = <c1.wav>;
sound pl2_snd = <c2.wav>;
sound pl3_snd = <c3.wav>;
sound pl4_snd = <c4.wav>;
sound cancel_snd = <cancel.wav>;

sound pl1_sel_snd = <sel1.wav>;
sound pl2_sel_snd = <sel2.wav>;
sound pl3_sel_snd = <sel3.wav>;
sound pl4_sel_snd = <sel4.wav>;
sound cancel_sel_snd = <selcan.wav>;
/////////////////////////////////////////
function pl_sound(but,pan)
{
if(pl_snd_handle != 0)
{
snd_stop(pl_snd_handle);
}
if(but == 1) {pl_snd_handle = snd_play(pl1_snd,100,10);}
if(but == 2) {pl_snd_handle = snd_play(pl2_snd,100,10);}
if(but == 3) {pl_snd_handle = snd_play(pl3_snd,100,10);}
if(but == 4) {pl_snd_handle = snd_play(pl4_snd,100,10);}
if(but == 5) {pl_snd_handle = snd_play(cancel_snd,100,10);}
}
/////////////////////////////////////////
panel plSelectionPan
{
bmap = plSelectMap;
flags = refresh;
button = 20,20,pl1_hover,pl1_normal,pl1_hover,plSelect,null,pl_sound;
button = 20,60,pl2_hover,pl2_normal,pl2_hover,plSelect,null,pl_sound;
button = 20,100,pl3_hover,pl3_normal,pl3_hover,plSelect,null,pl_sound;
button = 20,140,pl4_hover,pl4_normal,pl4_hover,plSelect,null,pl_sound;
button = 20,180,cancel_but,cancel_but,cancel_but,plSelect_cancel,null,pl_sound;
}
/////////////////////////////////////////
function setStrings()
{
string_ptrs[0] = handle(pl1_mdl);
string_ptrs[1] = handle(pl2_mdl);
string_ptrs[2] = handle(pl3_mdl);
string_ptrs[3] = handle(pl4_mdl);
ptrs_set = 1;
}
/////////////////////////////////////////
function plSelect(but,pan)
{
if(!player) {return;}

if(!ptrs_set) {setStrings();}

if(but <= 0 || but > numStrings) {return;}

ptr_string = ptr_for_handle(string_ptrs[but - 1]);

ent_morph(player,ptr_string);

if(pl_snd_handle != 0)
{
snd_stop(pl_snd_handle);
}
if(but == 1) {pl_snd_handle = snd_play(pl1_sel_snd,100,10);}
if(but == 2) {pl_snd_handle = snd_play(pl2_sel_snd,100,10);}
if(but == 3) {pl_snd_handle = snd_play(pl3_sel_snd,100,10);}
if(but == 4) {pl_snd_handle = snd_play(pl4_sel_snd,100,10);}

plSelectionPan.visible = off;

mouse_mode = 0;
}
/////////////////////////////////////////
function plSelect_cancel()
{
if(pl_snd_handle != 0)
{
snd_stop(pl_snd_handle);
}
pl_snd_handle = snd_play(cancel_sel_snd,100,10);

plSelectionPan.visible = off;
mouse_mode = 0;
}
/////////////////////////////////////////
function showPlslPan()
{
plSelectionPan.pos_x = (screen_size.x - bmap_width(plSelectionPan.bmap)) / 2;
plSelectionPan.pos_y = (screen_size.y - bmap_height(plSelectionPan.bmap)) / 2;
plSelectionPan.visible = on;
mouse_mode = 2;
mouse_on();
}

on_mouse_right = showPlslPan;
/////////////////////////////////////////


Posted By: lomeniki

Re: switch player question? - 07/02/06 22:06

Hi Claus,many stars for you and thank you man.Code works 100%:)
I was thinking about another code ,prety similar(maybe?) to this one
with some more advanced functions.
If/When you have time do it please.
It take me time to concept this, to be precise on what exactly i wont:

we have 4 diferent entity(mdl`s) on screen

-only when mouse over entity = enable right mouse click to call "atched" panel.
(when rmb click anywhere else= just show mouse pointer)
-when right mouse click over the entity(sound perhaps) = panell with 5
buttons apear(specific to that entity only)
(it`ll be very convinient for panel to be near the entity (not infront)
so we can see it)

-button click function= replace that mdl with another one,at diferent position
in the level(or the same position, we can edit position in the script)
This (position) thing is very important.
Include two sounds for each button (highlite and click)
When buton clicked=meny pannel disapear (we can call panel when right click
on the changed mdl only)

note: each entity(on screen) have 5 mdl`s to switch when we make choice in panel.

Mdl control:

- each of that 5 mdl`s have 6 sequence of animation inside
(idle,spin,bounce,open...).
Idle animation start inmediatly when we switch to that mdl.
Other sequence are "keyboard dependent"
Need 6 keys on keyboard(q,w,e,a,s,d for example) to call & loop those
sequences,only when specific model is on the screen.
Metod:
When nothing pressed= "idle" playing
When press & hold button "q" = coresponded animation play & loop
When button relesed = "idle" playing again

When press "q + Shift" button(we do not need to hold it presed enymore)=
"q" coresponded animation play & loop
When "q" button is presed and relesed again = "idle" animation is playing again


-------------------------------------------------------------------------------
Take your time
One more thanks.
Posted By: Claus_N

Re: switch player question? - 07/02/06 22:20

Np mate
It's getting quite late here.. I'll have a look at tomorrow
Posted By: lomeniki

Re: switch player question? - 07/03/06 00:37

When ever you like,it`s no rush
Cheers
Posted By: Claus_N

Re: switch player question? - 07/05/06 15:26

Hi again

The wireless connection I've used the last few days was very bad; and I couldn't get online at all yesterday :S
But well, now I'm at home again

I've made a script (tested with v6.31.4) that should do the most of what you want. I'll post it when I get from my laptop.
I think it'll need some changes to fit your needs, but then just tell what needs to get changed
Posted By: Claus_N

Re: switch player question? - 07/05/06 21:17

Okay, here ya go

(Sry for double-posting )

Click on an entity to "activate" it (the "active" ent will show another animation when you press "q"). Rightclick an ent to switch.
Code:
/////////////////////////////////////////
// Player Selection/Switching script
//
// (c) 2006 by Claus N.
// Nighthawk Arts
// www.nighthawk.dk
/////////////////////////////////////////
define anim_state,skill21;
define active,flag1;

// Define all your animation states below
define state_stand,0;
define state_walk,1;
define state_run,2;
define state_spin,3;
define state_bounce,4;
// Animation names
string anim_stand = "stand";
string anim_walk = "walk";
string anim_run = "run";
string anim_spin = "attack";
string anim_bounce = "bounce";
/////////////////////////////////////////
bmap selBG_map = <bg_pan.bmp>;
bmap but1_map = <but1.bmp>;
bmap but2_map = <but2.bmp>;
bmap but3_map = <but3.bmp>;
bmap but4_map = <but4.bmp>;
bmap but5_map = <but5.bmp>;
bmap butc_map = <cancel_but.bmp>;
bmap but1_over_map = <but1.bmp>;
bmap but2_over_map = <but2.bmp>;
bmap but3_over_map = <but3.bmp>;
bmap but4_over_map = <but4.bmp>;
bmap but5_over_map = <but5.bmp>;
bmap butc_over_map = <cancel_but.bmp>;
/////////////////////////////////////////
sound pl1_snd = <wham.wav>;
sound pl2_snd = <wham.wav>;
sound pl3_snd = <wham.wav>;
sound pl4_snd = <wham.wav>;
sound pl5_snd = <wham.wav>;
sound cancel_snd = <wham.wav>;
sound pl1_over_snd = <tap.wav>;
sound pl2_over_snd = <tap.wav>;
sound pl3_over_snd = <tap.wav>;
sound pl4_over_snd = <tap.wav>;
sound pl5_over_snd = <tap.wav>;
sound cancel_over_snd = <tap.wav>;
/////////////////////////////////////////
string pl1_mdl = <cbabe.mdl>;
string pl2_mdl = <woman.mdl>;
string pl3_mdl = <witch.mdl>;
string pl4_mdl = <elf.mdl>;
string pl5_mdl = <warlock.mdl>;
/////////////////////////////////////////
var_nsave snd_handle;
var actorHandle;
/////////////////////////////////////////
string level_str = <level.wmb>;
/////////////////////////////////////////
function butOver(but,pan);
function butClick(but,pan);
/////////////////////////////////////////
panel selectionPan
{
bmap = selBG_map;
flags = refresh;
button = 20,30,but1_map,but1_map,but1_over_map,butClick,null,butOver;
button = 20,60,but2_map,but2_map,but2_over_map,butClick,null,butOver;
button = 20,90,but3_map,but3_map,but3_over_map,butClick,null,butOver;
button = 20,120,but4_map,but4_map,but4_over_map,butClick,null,butOver;
button = 20,150,but5_map,but5_map,but5_over_map,butClick,null,butOver;
button = 20,180,butc_map,butc_map,butc_over_map,butClick,null,butOver;
}
/////////////////////////////////////////
function butOver(but,pan)
{
if(snd_handle != 0)
{
snd_stop(snd_handle);
}
if(but == 1) {snd_handle = snd_play(pl1_over_snd,100,10);}
if(but == 2) {snd_handle = snd_play(pl2_over_snd,100,10);}
if(but == 3) {snd_handle = snd_play(pl3_over_snd,100,10);}
if(but == 4) {snd_handle = snd_play(pl4_over_snd,100,10);}
if(but == 5) {snd_handle = snd_play(pl5_over_snd,100,10);}
if(but == 6) {snd_handle = snd_play(cancel_over_snd,100,10);}
}
/////////////////////////////////////////
function butClick(but,pan)
{
if(actorHandle == 0) {return;}
you = ptr_for_handle(actorHandle);
actorHandle = 0;
if(!you) {return;}

if(snd_handle != 0)
{
snd_stop(snd_handle);
}
if(but == 1) {snd_handle = snd_play(pl1_snd,100,10);ent_morph(you,pl1_mdl);}
if(but == 2) {snd_handle = snd_play(pl2_snd,100,10);ent_morph(you,pl2_mdl);}
if(but == 3) {snd_handle = snd_play(pl3_snd,100,10);ent_morph(you,pl3_mdl);}
if(but == 4) {snd_handle = snd_play(pl4_snd,100,10);ent_morph(you,pl4_mdl);}
if(but == 5) {snd_handle = snd_play(pl5_snd,100,10);ent_morph(you,pl5_mdl);}
if(but == 6) {snd_handle = snd_play(cancel_snd,100,10);}
selectionPan.visible = off;
}
/////////////////////////////////////////
// Call this function from "main()"!!
function init_mouse()
{
mouse_mode = 2;
mouse_on();
}
/////////////////////////////////////////
function selPan_Show(ent)
{
if(ent == 0) {return;}
you = ptr_for_handle(ent);
if(!you) {return;}

temp.x = you.x;
temp.y = you.y;
temp.z = you.z + you.min_z;

vec_to_screen(temp,camera);

selectionPan.pos_x = clamp(temp.x,0,screen_size.x - bmap_width(selectionPan.bmap));
selectionPan.pos_y = clamp(temp.y,0,screen_size.y - bmap_height(selectionPan.bmap));

actorHandle = ent;

selectionPan.visible = on;
}
/////////////////////////////////////////
function animateMe()
{
while(my)
{
if(my.anim_state == state_stand)
{
ent_animate(my,anim_stand,my.skill46,ANM_CYCLE);
my.skill46 += 2 * time;
}
if(my.anim_state == state_walk)
{
ent_animate(my,anim_walk,my.skill46,ANM_CYCLE);
my.skill46 += 6 * time;
}
if(my.anim_state == state_run)
{
ent_animate(my,anim_run,my.skill46,ANM_CYCLE);
my.skill46 += 10 * time;
}
if(my.anim_state == state_spin)
{
ent_animate(my,anim_spin,my.skill46,ANM_CYCLE);
my.skill46 += 8 * time;
}
if(my.anim_state == state_bounce)
{
ent_animate(my,anim_bounce,my.skill46,ANM_CYCLE);
my.skill46 += 8 * time;
}
my.skill46 %= 100;
wait(1);
}
}
/////////////////////////////////////////
function actorClicked
{
if(event_type == event_rightclick)
{
selPan_Show(handle(my));
}
if(event_type == event_click)
{
while(mouse_left) {wait(1);}
my.active = on;
while(!mouse_left) {wait(1);}
my.active = off;
}
}
/////////////////////////////////////////
action plActor
{
animateMe();
my.enable_click = on;
my.enable_rightclick = on;
my.event = actorClicked;
while(my)
{
if(my.active)
{
my.ambient = 100;
my.anim_state = state_stand;

if(key_q) {my.anim_state = state_spin;}
}
else
{
my.ambient = 0;
my.anim_state = state_stand;
}
wait(1);
}
}
/////////////////////////////////////////
on_mouse_right = init_mouse;
/////////////////////////////////////////


Posted By: lomeniki

Re: switch player question? - 07/06/06 00:50

Wow!It`s a looong one.Thanks:)
I`ll try to understand (test) this code & than i`ll post report(needs...)
Sory for no reply in short notice.I had power loss problem in whole building
where i live.
Code::)
---------------
if no electricity = no PC / no Internet
_____________________
Thank you one more time.

P.S. Is this code working with 3DGS v6.22 ?
Posted By: Claus_N

Re: switch player question? - 07/06/06 10:40

Np

Quote:

P.S. Is this code working with 3DGS v6.22



Dunno; only tried with v6.31.4. But I think it does
Posted By: lomeniki

Re: switch player question? - 07/06/06 14:25

Hi, Claus ,you are genie! Ewerything works perfect, thank you very,very much
I need just a little "tuning" of this code for my game,whenever you have time.

-Once clicked rmb,i can`t swich mouse off at anytime/anywhere
(i need that anywhere on screen exept entity ofcourse).
By default(a5_template) switch mouse off is by press rmb again.

-When i click rmb(on entity) pnel apear(that`s ok- i asked that).
Is it posible to switchoff muose pointer and panel also,
whereever i click(lmb) on screen, exept in panel area?

-I need 4 more diferent sounds when click on entity with:
1. right mouse button
2. left mouse

3. when press "q" key (only this time, when relese "q" sound stop)
4. when entity is in "idle" position loop some sound.

- I found some z-material code (i tested it & suits my needs).
Originally posted by Dan Silverman.I changed only few "name related" things.
Can you add this code for our models (each of them use this material)?

Code:
_________________________________________________
function mtl_xzmaterijal_init
{
vec_set(mtl.emissive_blue,mat_model.emissive_blue);
vec_set(mtl.ambient_blue,mat_model.ambient_blue);
vec_set(mtl.diffuse_blue,mat_model.diffuse_blue);
vec_set(mtl.specular_blue,mat_model.specular_blue);
mtl.power=mat_model.power;
mtl.albedo=mat_model.albedo;
mtl.skill1=pixel_for_vec(vector(0,0,0),0,8888);//first was 128
}

material mtl_xzmaterijal
{
event=mtl_xzmaterijal_init;
effect=
"
texture entSkin1;
dword mtlSkill1;

technique xzmaterijal
{
pass p0
{
Texture[0]=<entSkin1>;
ZWriteEnable=True;
AlphaBlendEnable=True;//was False
AlphaTestEnable=True;
AlphaRef=<mtlSkill1>;
AlphaFunc=Greater;
CullMode=CCW;

ColorArg1[0]=Texture;
ColorOp[0]=Modulate2X;
ColorArg2[0]=Diffuse;
}
}
technique fallback{pass p0{}}
";
}

action zmaterial
{
my.transparent=off;
my.flare=off;
my.material=mtl_mojzmaterijal;
}
____________________________________________________________________

Cheers
Posted By: Claus_N

Re: switch player question? - 07/06/06 15:51

Okay, try this

Code:____________________________________________________________________________________________
/////////////////////////////////////////
// Player Selection/Switching script
//
// (c) 2006 by Claus N.
// Nighthawk Arts
// www.nighthawk.dk
/////////////////////////////////////////
define anim_state,skill21;
define active,flag1;

// Define all your animation states below
define state_stand,0;
define state_walk,1;
define state_run,2;
define state_spin,3;
define state_bounce,4;
// Animation names
string anim_stand = "stand";
string anim_walk = "walk";
string anim_run = "run";
string anim_spin = "attack";
string anim_bounce = "bounce";
/////////////////////////////////////////
bmap selBG_map = <bg_pan.bmp>;
bmap but1_map = <but1.bmp>;
bmap but2_map = <but2.bmp>;
bmap but3_map = <but3.bmp>;
bmap but4_map = <but4.bmp>;
bmap but5_map = <but5.bmp>;
bmap butc_map = <cancel_but.bmp>;
bmap but1_over_map = <but1.bmp>;
bmap but2_over_map = <but2.bmp>;
bmap but3_over_map = <but3.bmp>;
bmap but4_over_map = <but4.bmp>;
bmap but5_over_map = <but5.bmp>;
bmap butc_over_map = <cancel_but.bmp>;
/////////////////////////////////////////
sound pl1_snd = <wham.wav>;
sound pl2_snd = <wham.wav>;
sound pl3_snd = <wham.wav>;
sound pl4_snd = <wham.wav>;
sound pl5_snd = <wham.wav>;
sound cancel_snd = <wham.wav>;
sound pl1_over_snd = <tap.wav>;
sound pl2_over_snd = <tap.wav>;
sound pl3_over_snd = <tap.wav>;
sound pl4_over_snd = <tap.wav>;
sound pl5_over_snd = <tap.wav>;
sound cancel_over_snd = <tap.wav>;
sound ent_rightclick = <tap.wav>;
sound ent_leftclick = <tap.wav>;
sound sound_on_q = <tap.wav>;
sound sound_on_idle = <wham.wav>;
/////////////////////////////////////////
string pl1_mdl = <cbabe.mdl>;
string pl2_mdl = <woman.mdl>;
string pl3_mdl = <witch.mdl>;
string pl4_mdl = <elf.mdl>;
string pl5_mdl = <warlock.mdl>;
/////////////////////////////////////////
var_nsave snd_handle;
var actorHandle;
/////////////////////////////////////////
string level_str = <level.wmb>;
/////////////////////////////////////////
function butOver(but,pan);
function butClick(but,pan);
/////////////////////////////////////////
panel selectionPan
{
bmap = selBG_map;
flags = refresh;
button = 20,30,but1_map,but1_map,but1_over_map,butClick,null,butOver;
button = 20,60,but2_map,but2_map,but2_over_map,butClick,null,butOver;
button = 20,90,but3_map,but3_map,but3_over_map,butClick,null,butOver;
button = 20,120,but4_map,but4_map,but4_over_map,butClick,null,butOver;
button = 20,150,but5_map,but5_map,but5_over_map,butClick,null,butOver;
button = 20,180,butc_map,butc_map,butc_over_map,butClick,null,butOver;
}
/////////////////////////////////////////
function butOver(but,pan)
{
if(snd_handle != 0)
{
snd_stop(snd_handle);
}
if(but == 1) {snd_handle = snd_play(pl1_over_snd,100,10);}
if(but == 2) {snd_handle = snd_play(pl2_over_snd,100,10);}
if(but == 3) {snd_handle = snd_play(pl3_over_snd,100,10);}
if(but == 4) {snd_handle = snd_play(pl4_over_snd,100,10);}
if(but == 5) {snd_handle = snd_play(pl5_over_snd,100,10);}
if(but == 6) {snd_handle = snd_play(cancel_over_snd,100,10);}
}
/////////////////////////////////////////
function butClick(but,pan)
{
if(actorHandle == 0) {return;}
you = ptr_for_handle(actorHandle);
actorHandle = 0;
if(!you) {return;}

if(snd_handle != 0)
{
snd_stop(snd_handle);
}
if(but == 1) {snd_handle = snd_play(pl1_snd,100,10);ent_morph(you,pl1_mdl);}
if(but == 2) {snd_handle = snd_play(pl2_snd,100,10);ent_morph(you,pl2_mdl);}
if(but == 3) {snd_handle = snd_play(pl3_snd,100,10);ent_morph(you,pl3_mdl);}
if(but == 4) {snd_handle = snd_play(pl4_snd,100,10);ent_morph(you,pl4_mdl);}
if(but == 5) {snd_handle = snd_play(pl5_snd,100,10);ent_morph(you,pl5_mdl);}
if(but == 6) {snd_handle = snd_play(cancel_snd,100,10);}
selectionPan.visible = off;
}
/////////////////////////////////////////
// Call this function from "main()"!!
function init_mouse()
{
mouse_mode = 2;
mouse_on();
}
/////////////////////////////////////////
function selPan_Show(ent)
{
if(ent == 0) {return;}
you = ptr_for_handle(ent);
if(!you) {return;}

temp.x = you.x;
temp.y = you.y;
temp.z = you.z + you.min_z;

vec_to_screen(temp,camera);

selectionPan.pos_x = clamp(temp.x,0,screen_size.x - bmap_width(selectionPan.bmap));
selectionPan.pos_y = clamp(temp.y,0,screen_size.y - bmap_height(selectionPan.bmap));

actorHandle = ent;

selectionPan.visible = on;
}
/////////////////////////////////////////
function animateMe()
{
while(my)
{
if(my.anim_state == state_stand)
{
ent_animate(my,anim_stand,my.skill46,ANM_CYCLE);
my.skill46 += 2 * time;
}
if(my.anim_state == state_walk)
{
ent_animate(my,anim_walk,my.skill46,ANM_CYCLE);
my.skill46 += 6 * time;
}
if(my.anim_state == state_run)
{
ent_animate(my,anim_run,my.skill46,ANM_CYCLE);
my.skill46 += 10 * time;
}
if(my.anim_state == state_spin)
{
ent_animate(my,anim_spin,my.skill46,ANM_CYCLE);
my.skill46 += 8 * time;
}
if(my.anim_state == state_bounce)
{
ent_animate(my,anim_bounce,my.skill46,ANM_CYCLE);
my.skill46 += 8 * time;
}
my.skill46 %= 100;
wait(1);
}
}
/////////////////////////////////////////
function actorClicked
{
if(snd_handle != 0)
{
snd_stop(snd_handle);
}

if(event_type == event_rightclick)
{
snd_handle = snd_play(ent_rightclick,100,10);
selPan_Show(handle(my));
}
if(event_type == event_click)
{
snd_handle = snd_play(ent_leftclick,100,10);
while(mouse_left) {wait(1);}
my.active = on;
while(!mouse_left) {wait(1);}
my.active = off;
}
}
/////////////////////////////////////////
function mtl_xzmaterijal_init
{
vec_set(mtl.emissive_blue,mat_model.emissive_blue);
vec_set(mtl.ambient_blue,mat_model.ambient_blue);
vec_set(mtl.diffuse_blue,mat_model.diffuse_blue);
vec_set(mtl.specular_blue,mat_model.specular_blue);
mtl.power=mat_model.power;
mtl.albedo=mat_model.albedo;
mtl.skill1=pixel_for_vec(vector(0,0,0),0,8888);//first was 128
}

material mtl_xzmaterijal
{
event=mtl_xzmaterijal_init;
effect=
"
texture entSkin1;
dword mtlSkill1;

technique xzmaterijal
{
pass p0
{
Texture[0]=<entSkin1>;
ZWriteEnable=True;
AlphaBlendEnable=True;//was False
AlphaTestEnable=True;
AlphaRef=<mtlSkill1>;
AlphaFunc=Greater;
CullMode=CCW;

ColorArg1[0]=Texture;
ColorOp[0]=Modulate2X;
ColorArg2[0]=Diffuse;
}
}
technique fallback{pass p0{}}
";
}
/////////////////////////////////////////
action plActor
{
my.material=mtl_xzmaterijal;
animateMe();
my.enable_click = on;
my.enable_rightclick = on;
my.event = actorClicked;
while(my)
{
if(my.active)
{
my.ambient = 100;
my.anim_state = state_stand;

if(key_q)
{
my.anim_state = state_spin;
snd_stop(my.skill22);
if(!snd_playing(my.skill32))
{
my.skill32 = snd_loop(sound_on_q,100,10);
}
}
else
{
snd_stop(my.skill32);
if(!snd_playing(my.skill22))
{
my.skill22 = snd_loop(sound_on_idle,100,10);
}
}
}
else
{
snd_stop(my.skill22);
snd_stop(my.skill32);
my.ambient = 0;
my.anim_state = state_stand;
}
wait(1);
}
}
/////////////////////////////////////////
//on_mouse_right = init_mouse;
/////////////////////////////////////////
_________________________________________________________________________________________________

Quote:

-When i click rmb(on entity) pnel apear(that`s ok- i asked that).
Is it posible to switchoff muose pointer and panel also,
whereever i click(lmb) on screen, exept in panel area?



Eh, didn't get that...
Posted By: lomeniki

Re: switch player question? - 07/06/06 18:06

Sorry, my English eh....hm...

Like:
rmb on entity to change it> panel apear on screen,
i i click on panel buttons to change entity(ok we allready have that in your code)
But, when ((panel is on screen)) i (exidently or on purpose)click enywhere
else in the screen (not on panel),i would like for pannel and mouse pointer to disapear "automaticly"
Posted By: Claus_N

Re: switch player question? - 07/06/06 19:44

Okay, here ya go

Code:
/////////////////////////////////////////
// Player Selection/Switching script
//
// (c) 2006 by Claus N.
// Nighthawk Arts
// www.nighthawk.dk
/////////////////////////////////////////
define anim_state,skill21;
define active,flag1;

// Define all your animation states below
define state_stand,0;
define state_walk,1;
define state_run,2;
define state_spin,3;
define state_bounce,4;
// Animation names
string anim_stand = "stand";
string anim_walk = "walk";
string anim_run = "run";
string anim_spin = "attack";
string anim_bounce = "bounce";
/////////////////////////////////////////
bmap selBG_map = <bg_pan.bmp>;
bmap but1_map = <but1.bmp>;
bmap but2_map = <but2.bmp>;
bmap but3_map = <but3.bmp>;
bmap but4_map = <but4.bmp>;
bmap but5_map = <but5.bmp>;
bmap butc_map = <cancel_but.bmp>;
bmap but1_over_map = <but1.bmp>;
bmap but2_over_map = <but2.bmp>;
bmap but3_over_map = <but3.bmp>;
bmap but4_over_map = <but4.bmp>;
bmap but5_over_map = <but5.bmp>;
bmap butc_over_map = <cancel_but.bmp>;
/////////////////////////////////////////
sound pl1_snd = <wham.wav>;
sound pl2_snd = <wham.wav>;
sound pl3_snd = <wham.wav>;
sound pl4_snd = <wham.wav>;
sound pl5_snd = <wham.wav>;
sound cancel_snd = <wham.wav>;
sound pl1_over_snd = <tap.wav>;
sound pl2_over_snd = <tap.wav>;
sound pl3_over_snd = <tap.wav>;
sound pl4_over_snd = <tap.wav>;
sound pl5_over_snd = <tap.wav>;
sound cancel_over_snd = <tap.wav>;
sound ent_rightclick = <tap.wav>;
sound ent_leftclick = <tap.wav>;
sound sound_on_q = <tap.wav>;
sound sound_on_idle = <wham.wav>;
/////////////////////////////////////////
string pl1_mdl = <cbabe.mdl>;
string pl2_mdl = <woman.mdl>;
string pl3_mdl = <witch.mdl>;
string pl4_mdl = <elf.mdl>;
string pl5_mdl = <warlock.mdl>;
/////////////////////////////////////////
var_nsave snd_handle;
var actorHandle;
/////////////////////////////////////////
string level_str = <level.wmb>;
/////////////////////////////////////////
function butOver(but,pan);
function butClick(but,pan);
/////////////////////////////////////////
panel selectionPan
{
bmap = selBG_map;
flags = refresh;
button = 20,30,but1_map,but1_map,but1_over_map,butClick,null,butOver;
button = 20,60,but2_map,but2_map,but2_over_map,butClick,null,butOver;
button = 20,90,but3_map,but3_map,but3_over_map,butClick,null,butOver;
button = 20,120,but4_map,but4_map,but4_over_map,butClick,null,butOver;
button = 20,150,but5_map,but5_map,but5_over_map,butClick,null,butOver;
button = 20,180,butc_map,butc_map,butc_over_map,butClick,null,butOver;
}
/////////////////////////////////////////
function butOver(but,pan)
{
if(snd_handle != 0)
{
snd_stop(snd_handle);
}
if(but == 1) {snd_handle = snd_play(pl1_over_snd,100,10);}
if(but == 2) {snd_handle = snd_play(pl2_over_snd,100,10);}
if(but == 3) {snd_handle = snd_play(pl3_over_snd,100,10);}
if(but == 4) {snd_handle = snd_play(pl4_over_snd,100,10);}
if(but == 5) {snd_handle = snd_play(pl5_over_snd,100,10);}
if(but == 6) {snd_handle = snd_play(cancel_over_snd,100,10);}
}
/////////////////////////////////////////
function butClick(but,pan)
{
if(actorHandle == 0) {return;}
you = ptr_for_handle(actorHandle);
actorHandle = 0;
if(!you) {return;}

if(snd_handle != 0)
{
snd_stop(snd_handle);
}
if(but == 1) {snd_handle = snd_play(pl1_snd,100,10);ent_morph(you,pl1_mdl);}
if(but == 2) {snd_handle = snd_play(pl2_snd,100,10);ent_morph(you,pl2_mdl);}
if(but == 3) {snd_handle = snd_play(pl3_snd,100,10);ent_morph(you,pl3_mdl);}
if(but == 4) {snd_handle = snd_play(pl4_snd,100,10);ent_morph(you,pl4_mdl);}
if(but == 5) {snd_handle = snd_play(pl5_snd,100,10);ent_morph(you,pl5_mdl);}
if(but == 6) {snd_handle = snd_play(cancel_snd,100,10);}
selectionPan.visible = off;
}
/////////////////////////////////////////

function init_mouse()
{
if((mouse_pos.x < selectionPan.pos_x
|| mouse_pos.x > selectionPan.pos_x + bmap_width(selectionPan.bmap))
|| (mouse_pos.y < selectionPan.pos_y
|| mouse_pos.y > selectionPan.pos_y + bmap_height(selectionPan.bmap)))
{
selectionPan.visible = off;
}
mouse_toggle();
}

/////////////////////////////////////////
function selPan_Show(ent)
{
if(ent == 0) {return;}
you = ptr_for_handle(ent);
if(!you) {return;}

temp.x = you.x;
temp.y = you.y;
temp.z = you.z + you.min_z;

vec_to_screen(temp,camera);

selectionPan.pos_x = clamp(temp.x,0,screen_size.x - bmap_width(selectionPan.bmap));
selectionPan.pos_y = clamp(temp.y,0,screen_size.y - bmap_height(selectionPan.bmap));

actorHandle = ent;

selectionPan.visible = on;
}
/////////////////////////////////////////
function animateMe()
{
while(my)
{
if(my.anim_state == state_stand)
{
ent_animate(my,anim_stand,my.skill46,ANM_CYCLE);
my.skill46 += 2 * time;
}
if(my.anim_state == state_walk)
{
ent_animate(my,anim_walk,my.skill46,ANM_CYCLE);
my.skill46 += 6 * time;
}
if(my.anim_state == state_run)
{
ent_animate(my,anim_run,my.skill46,ANM_CYCLE);
my.skill46 += 10 * time;
}
if(my.anim_state == state_spin)
{
ent_animate(my,anim_spin,my.skill46,ANM_CYCLE);
my.skill46 += 8 * time;
}
if(my.anim_state == state_bounce)
{
ent_animate(my,anim_bounce,my.skill46,ANM_CYCLE);
my.skill46 += 8 * time;
}
my.skill46 %= 100;
wait(1);
}
}
/////////////////////////////////////////
function actorClicked
{
if(snd_handle != 0)
{
snd_stop(snd_handle);
}

if(event_type == event_rightclick)
{
snd_handle = snd_play(ent_rightclick,100,10);
selPan_Show(handle(my));
}
if(event_type == event_click)
{
snd_handle = snd_play(ent_leftclick,100,10);
while(mouse_left) {wait(1);}
my.active = on;
while(!mouse_left) {wait(1);}
my.active = off;
}
}
/////////////////////////////////////////
function mtl_xzmaterijal_init
{
vec_set(mtl.emissive_blue,mat_model.emissive_blue);
vec_set(mtl.ambient_blue,mat_model.ambient_blue);
vec_set(mtl.diffuse_blue,mat_model.diffuse_blue);
vec_set(mtl.specular_blue,mat_model.specular_blue);
mtl.power=mat_model.power;
mtl.albedo=mat_model.albedo;
mtl.skill1=pixel_for_vec(vector(0,0,0),0,8888);//first was 128
}

material mtl_xzmaterijal
{
event=mtl_xzmaterijal_init;
effect=
"
texture entSkin1;
dword mtlSkill1;

technique xzmaterijal
{
pass p0
{
Texture[0]=<entSkin1>;
ZWriteEnable=True;
AlphaBlendEnable=True;//was False
AlphaTestEnable=True;
AlphaRef=<mtlSkill1>;
AlphaFunc=Greater;
CullMode=CCW;

ColorArg1[0]=Texture;
ColorOp[0]=Modulate2X;
ColorArg2[0]=Diffuse;
}
}
technique fallback{pass p0{}}
";
}
/////////////////////////////////////////
action plActor
{
my.material=mtl_xzmaterijal;
animateMe();
my.enable_click = on;
my.enable_rightclick = on;
my.event = actorClicked;
while(my)
{
if(my.active)
{
my.ambient = 100;
my.anim_state = state_stand;

if(key_q)
{
my.anim_state = state_spin;
snd_stop(my.skill22);
if(!snd_playing(my.skill32))
{
my.skill32 = snd_loop(sound_on_q,100,10);
}
}
else
{
snd_stop(my.skill32);
if(!snd_playing(my.skill22))
{
my.skill22 = snd_loop(sound_on_idle,100,10);
}
}
}
else
{
snd_stop(my.skill22);
snd_stop(my.skill32);
my.ambient = 0;
my.anim_state = state_stand;
}
wait(1);
}
}
/////////////////////////////////////////
on_mouse_right = init_mouse;
/////////////////////////////////////////


Posted By: lomeniki

Re: switch player question? - 07/06/06 20:34

Thanks man,i`ll test it in a minute.
I noticed one more thing.
When start level,click rmb (mouse pointer apear),then click(rmb) on entity=
nothing happen.
When click rmb on entity again = panell apear.
Why must click two time?
Can it be only one click on entity for panel apearing?

Can you please add animation run (for example) for button "e" with some sound
for it.(like for "q" button,so i can add latter more buttons for diferent
animations ) I tried to do it by myself ,but got errors.

Edit: I tested your script.Everything works.One more thing:
When rmb click "enywhere else" (when panel is allready present) panel disapear=you do great job.
Is the same thing posible with left mouse button click ("enywhere else")?
To be more precise,can left and right mouse buton have the same function
in "pannel situation"?
Thanks again
Posted By: Claus_N

Re: switch player question? - 07/06/06 21:19

Quote:

I noticed one more thing.
When start level,click rmb (mouse pointer apear),then click(rmb) on entity=
nothing happen.
When click rmb on entity again = panell apear.
Why must click two time?
Can it be only one click on entity for panel apearing?



Yeah, I know :/
I tried inserting a "wait(1);" in the beginning of function init_mouse, but that didn't work very well...
I'll tell you if I find a solution

EDIT: Got it! Here ya go

Code:
function init_mouse()
{
if((mouse_pos.x < selectionPan.pos_x
|| mouse_pos.x > selectionPan.pos_x + bmap_width(selectionPan.bmap))
|| (mouse_pos.y < selectionPan.pos_y
|| mouse_pos.y > selectionPan.pos_y + bmap_height(selectionPan.bmap)))
{
selectionPan.visible = off;
}
wait(1);
mouse_toggle();
}



Quote:

Can you please add animation run (for example) for button "e" with some sound
for it.(like for "q" button,so i can add latter more buttons for diferent
animations ) I tried to do it by myself ,but got errors.



Sure

Code:
action plActor
{
my.material=mtl_xzmaterijal;
animateMe();
my.enable_click = on;
my.enable_rightclick = on;
my.event = actorClicked;
while(my)
{
if(my.active)
{
my.ambient = 100;
my.anim_state = state_stand;

if(key_q)
{
my.anim_state = state_spin;
snd_stop(my.skill22);
if(!snd_playing(my.skill32))
{
my.skill32 = snd_loop(sound_on_q,100,10);
}
}
else
{
if(key_e)
{
my.anim_state = state_bounce;
snd_stop(my.skill22);
if(!snd_playing(my.skill32))
{
my.skill32 = snd_loop(sound_on_e,100,10);
}
}
else
{

snd_stop(my.skill32);
if(!snd_playing(my.skill22))
{
my.skill22 = snd_loop(sound_on_idle,100,10);
}
}
}
}
else
{
snd_stop(my.skill22);
snd_stop(my.skill32);
my.ambient = 0;
my.anim_state = state_stand;
}
wait(1);
}
}


Posted By: lomeniki

Re: switch player question? - 07/06/06 21:31

Thanks Claus,
Please read "edit" in my previous post if you are still here.
Posted By: Claus_N

Re: switch player question? - 07/06/06 21:52

No problem

Code:
/////////////////////////////////////////
function check_panel()
{
if((mouse_pos.x < selectionPan.pos_x
|| mouse_pos.x > selectionPan.pos_x + bmap_width(selectionPan.bmap))
|| (mouse_pos.y < selectionPan.pos_y
|| mouse_pos.y > selectionPan.pos_y + bmap_height(selectionPan.bmap)))
{
selectionPan.visible = off;
}
}

function init_mouse()
{
check_panel();
wait(1);
mouse_toggle();
}
/////////////////////////////////////////

on_mouse_left = check_panel;


Posted By: lomeniki

Re: switch player question? - 07/06/06 22:08

I checked previous (now i`m checking this code)
About previous:Now one click works.
Oops,we lose mouse pointer when rmb on entity(panel apear but no pointer to
select)
Posted By: Claus_N

Re: switch player question? - 07/06/06 22:14

Code:
function actorClicked
{
if(snd_handle != 0)
{
snd_stop(snd_handle);
}

if(event_type == event_rightclick)
{
snd_handle = snd_play(ent_rightclick,100,10);
selPan_Show(handle(my));
wait(1);
mouse_mode = 2;
mouse_on();

}
if(event_type == event_click)
{
snd_handle = snd_play(ent_leftclick,100,10);
while(mouse_left) {wait(1);}
my.active = on;
while(!mouse_left) {wait(1);}
my.active = off;
}
}




Posted By: lomeniki

Re: switch player question? - 07/06/06 22:32

Checked:
Now we have mouse (ok)
1.Is it posible pointer to desapier when click on buuton(select in panel)
2.Pointer stay on screen when cick lmb "enywhere else" (when panel is on screen)
Is it posible pointer(lmb click) to desapier in that situation allso?
Thanks man
Posted By: Claus_N

Re: switch player question? - 07/06/06 22:43

Code:
function butClick(but,pan)
{
mouse_mode = 0;

if(actorHandle == 0) {return;}
you = ptr_for_handle(actorHandle);
actorHandle = 0;
if(!you) {return;}

if(snd_handle != 0)
{
snd_stop(snd_handle);
}
if(but == 1) {snd_handle = snd_play(pl1_snd,100,10);ent_morph(you,pl1_mdl);}
if(but == 2) {snd_handle = snd_play(pl2_snd,100,10);ent_morph(you,pl2_mdl);}
if(but == 3) {snd_handle = snd_play(pl3_snd,100,10);ent_morph(you,pl3_mdl);}
if(but == 4) {snd_handle = snd_play(pl4_snd,100,10);ent_morph(you,pl4_mdl);}
if(but == 5) {snd_handle = snd_play(pl5_snd,100,10);ent_morph(you,pl5_mdl);}
if(but == 6) {snd_handle = snd_play(cancel_snd,100,10);}
selectionPan.visible = off;
}



Change the event of the left mouse button:
Code:
on_mouse_left = init_mouse;


Was that how u meant?
Posted By: lomeniki

Re: switch player question? - 07/06/06 23:01

Allmoust perfect!
Now only one problem:
Pointer stays on screen when (lmb) button click (select in panel).
We wont to desapier.
Posted By: Claus_N

Re: switch player question? - 07/06/06 23:04

Okay, this does the job

Code:
function butClick(but,pan)
{
if(actorHandle == 0) {return;}
you = ptr_for_handle(actorHandle);
actorHandle = 0;
if(!you) {return;}

if(snd_handle != 0)
{
snd_stop(snd_handle);
}
if(but == 1) {snd_handle = snd_play(pl1_snd,100,10);ent_morph(you,pl1_mdl);}
if(but == 2) {snd_handle = snd_play(pl2_snd,100,10);ent_morph(you,pl2_mdl);}
if(but == 3) {snd_handle = snd_play(pl3_snd,100,10);ent_morph(you,pl3_mdl);}
if(but == 4) {snd_handle = snd_play(pl4_snd,100,10);ent_morph(you,pl4_mdl);}
if(but == 5) {snd_handle = snd_play(pl5_snd,100,10);ent_morph(you,pl5_mdl);}
if(but == 6) {snd_handle = snd_play(cancel_snd,100,10);}
selectionPan.visible = off;

wait(2);
mouse_mode = 0;

}


Posted By: lomeniki

Re: switch player question? - 07/06/06 23:37

Thank you,thank you, 1000x thank you.
Your code work 100%
Now, i`ll take time(1-2 days,maybe more maybe less) to experiment with this
code (change values...) to se what happens and ofcourse to learn something.
When i`ll have questions,i`ll ask you here.You allready helped me so mutch
in my "first steps" of learning.I think you also helped other users who readed
this topic, because we done it step by step(Q&A).
Cheers

P.S. Off topic : what about this "stars" below my user name.First i had none,then 5,then 3 today...Why 5 then 3,what i do wrong? Why 5, i did`t do anything to contribute?
Posted By: Claus_N

Re: switch player question? - 07/06/06 23:48

No problem mate, I'm glad I could help

Experimenting with the code is imo the best way to learn (and simply that way I learn c-script )

You had 0 stars when nobody had rated you. Then someone rated you 5 stars, therefore you got 5 stars. And now someone might have rated you a 1 or 2 stars, therefore you got 3 (average).
All I can tell is, that I haven't rated you at all
Posted By: lomeniki

Re: switch player question? - 07/06/06 23:53

Hahahaha,i know mate...i know
Thanks anyway
Posted By: lomeniki

Re: switch player question? - 07/13/06 05:59

Hi Claus_N,
I spend some of my time,(to learn from your script) and to make some
models,animations for my game.
Now i need some more advanced functions in your script.
So,here is what i need:
I made some "intermediate" animations that i want to put in beetwen 2 animatons.
For example when entity play stand animation,
i pres "q" button and entity start to play(&loop) "siting" animation.
But that switch from stand to sit is so quick and unnatural,so i made
some extra animation that "blending" from stand to sit.

When i pres "q" i need to put that "blend" animation to play 1x,
then "sit" animation loop.
When relesed "q" first some other "blend" animation,then stand animation play.
It would be nice some sounds atached to each of that "blend" animation.

P.S. There is some problem in script.
When i press "q" anim for "q" start,sound for "q" start.That`s ok.
But, when press "q" and not relesed, and then press "e" = anim for "e" play,
but sound still play for "q" and not for "e" button.
I`m not sure that i explained correctly,so please check that in your test level.
When you checked this i`ll have more advanced question.
For example:
We have 6 keys(q,w,e,a,s,d) and "idle" animation for our entity.
Press "q" ="blend" from "idle" to "q" 1x,then play&loop "q" animation.
Press "q" then "e" ="blend" from "q" to "e" 1x,then play&loop "e" animation.
Press "q" then "w" ="blend" from "q" to "w" 1x,then play&loop "w" animation.
Press "w" then "q" ="blend" from "w" to "q" 1x,then play&loop "q" animation.
Relese "q" = "blend" from "q" to "idle" 1x, then play&loop "idle" animation...
...and all combination for ech key
I use simple frame(vertex) animation for my entities so i`ll need this.
Thank you in advance.
Cheers
© 2023 lite-C Forums