Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,643 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Text Talking with NPC's #339760
08/29/10 05:47
08/29/10 05:47
Joined: Mar 2006
Posts: 59
O
ozziedave Offline OP
Junior Member
ozziedave  Offline OP
Junior Member
O

Joined: Mar 2006
Posts: 59
This is just a simple example of lite c code for text conversations with NPC's, can also be used for objects.

var anim_percentage = 0;

STRING* player_message_str = "#100"; // the message can have up to 100 characters

STRING* npc_message_str = "#100"; // the message can have up to 100 characters


FONT* adventure_font = "adventure.bmp"; // This Font is a bitmap placed in the folder with your Level Files.
// you should have a few bitmap font images with 3DGS
// pick different coloured fonts for good effect.

FONT* arial_font = "Arial#20b";



//SOUND* message_wav = "message.wav";


TEXT* player_message_txt =

{

pos_x = 200;

pos_y = 20;

string(player_message_str);

red = 255;

font(arial_font);

flags = SHOW;

}


TEXT* npc_message_txt =

{

pos_x = 200;

pos_y = 60;

string(npc_message_str);

red = 255;

font(adventure_font);

flags = SHOW;

}



function player_msg_show(STRING* message, duration)

{

str_cpy((player_message_txt.pstring)[0], message);

player_message_txt.flags |= SHOW; // display the message

//snd_play(message_wav, 70, 0);

wait (-duration); // for the specified number of seconds

player_message_txt.flags &= ~SHOW; // and then hide the message

}




function npc_msg_show(STRING* message, duration)

{

str_cpy((npc_message_txt.pstring)[0], message);

npc_message_txt.flags |= SHOW; // display the message

//snd_play(message_wav, 70, 0);

wait (-duration); // for the specified number of seconds

npc_message_txt.flags &= ~SHOW; // and then hide the message

}


function npc_move()

{
while (anim_percentage < 40) // the loop runs until the "idle" animation percentage reaches 100%
// lower percentage if you want movement to stop when talking stops

{

ent_animate(my, "idle", anim_percentage, NULL); // set the animation you want here "idle", "stand" or whatever

anim_percentage += 0.1 * time_step; // controls the animation speed

wait (1);

}

anim_percentage = 0;
}





action NPC_Merchant() // attach to your NPC

{

// use a wave file with speach if you want to

//SOUND* advice_wav = "advice.wav";

//PLACE ALL OF THE REQUIRED SPEECH TEXT IN THIS ACTION SECTION - YOU COULD USE A DIFFERENT ACTION SECTION
//FOR EACH NPC THAT YOU WANT TO SPEAK INCLUDING TEXT FOR OBJECTS.

while (!player) {wait (1);}

while (vec_dist (player.x, my.x) > 130) {wait (1);} // wait until the player comes really close to the NPC

npc_move();

player_msg_show("CHUCK.. what have you got to sell trader", 6); // 6 is the length of time the text is on the screen
// increase for longer times

wait (-4); // length of time between messages - increase or decreas as required


npc_msg_show("TRADER.. how much Dirham do you have sir", 4);

wait (-4);


player_msg_show("CHUCK.. give me your best price for that ruby encrusted sword", 6);

wait (-4);


npc_msg_show("TRADER.. sorry that item is not for sale.", 4);



}

Re: Text Talking with NPC's [Re: ozziedave] #339761
08/29/10 06:30
08/29/10 06:30
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Dirham? Where are you from laugh UAE? Any way, good contribution, thank you.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1