Assigning any name to a character in-engine

mishadude

New member
Hi, everyone. I'm preparing to a develop a game that simulates my day job for mine and my colleagues's training purposes (nothing exciting, believe me  :)). I needed a function that would let me and my peers to change their name in-engine, typing it character by character, to let them use their own name without paxploding and coding anything. So I tried making my own

1) First, you need to have "letterA", "letterB", etc. enemies (make sure to give them "nomove 1 1" and big health value) with following scripts in their pain anims.
Code:
@script
void p1name = getglobalvar("p1name");

if (p1name == NULL()) {
setglobalvar ("p1name","A");
}
else
{
setglobalvar ("p1name", p1name + "A");
}
@end_script
or
Code:
@script
void p1name = getglobalvar("p1name");

if (p1name == NULL()) {
setglobalvar ("p1name","B");
}
else
{
setglobalvar ("p1name", p1name + "B");
}
@end_script
and so on

You can make their idle and pain anims images of the corresponding letters, or give each of them the following ondrawscript naming.c like this
Code:
void main()
{
void self = getlocalvar("self"); //Get calling entity.
void p1name = getglobalvar("p1name");
char name = getentityproperty(self, "name"); //get entity name.
float z = getentityproperty(self, "z"); //get entity z value.
float x = getentityproperty(self, "x"); //get entity x value.
if (name == "letterA"){
drawstring (x-1, z-50, 3, "A");}
else if (name == "letterB"){
drawstring (x-1, z-50, 3, "B");}
else if (name == "letterC"){
drawstring (x-1, z-50, 3, "C");}
else if (name == "letterD"){
drawstring (x-1, z-50, 3, "D");}
else if (name == "letterE"){
drawstring (x-1, z-50, 3, "E");}
else if (name == "letterF"){
drawstring (x-1, z-50, 3, "F");}
else if (name == "letterG"){
drawstring (x-1, z-50, 3, "G");}
else if (name == "letterH"){
drawstring (x-1, z-50, 3, "H");}
else if (name == "letterI"){
drawstring (x-1, z-50, 3, "I");}
else if (name == "letterJ"){
drawstring (x-1, z-50, 3, "J");}
else if (name == "letterK"){
drawstring (x-1, z-50, 3, "K");}
else if (name == "letterL"){
drawstring (x-1, z-50, 3, "L");}
else if (name == "letterM"){
drawstring (x-1, z-50, 3, "M");}
else if (name == "letterN"){
drawstring (x-1, z-50, 3, "N");}
else if (name == "letterO"){
drawstring (x-1, z-50, 3, "O");}
else if (name == "letterP"){
drawstring (x-1, z-50, 3, "P");}
else if (name == "letterQ"){
drawstring (x-1, z-50, 3, "Q");}
else if (name == "letterR"){
drawstring (x-1, z-50, 3, "R");}
else if (name == "letterS"){
drawstring (x-1, z-50, 3, "S");}
else if (name == "letterT"){
drawstring (x-1, z-50, 3, "T");}
else if (name == "letterU"){
drawstring (x-1, z-50, 3, "U");}
else if (name == "letterV"){
drawstring (x-1, z-50, 3, "V");}
else if (name == "letterW"){
drawstring (x-1, z-50, 3, "W");}
else if (name == "letterX"){
drawstring (x-1, z-50, 3, "X");}
else if (name == "letterY"){
drawstring (x-1, z-50, 3, "Y");}
else if (name == "letterZ"){
drawstring (x-1, z-50, 3, "Z");}
}

Then, you should give the player character, who you want to be able to change their name and keep this name througout the set, this spawn anim script
Code:
@script
void self = getlocalvar("self");
void p1name = getglobalvar("p1name");
if (p1name != NULL())
{
changeentityproperty (self, "name", p1name);
}
@end_script

Next, create a special "naming.txt" level and set it as the first level (after the first select screen where the character can be chosen, assuming you use select screens of course), spawn all the letters on your starting level screen in different places in the level and also an endlevel item

Next,

Then start the game, choose the renameable character, go to that starting level and start hitting the letters in order of your character's name ( For example, hit "M", "I", "K", "E" to get my real name, Mike :)).

Touch the endlevel to go to the next level

That's it! Now your character's name is displayed the way you intended it to on all levels

Side note: You may wish to set up a drawstring command displaying p1name's current value to make sure you don't mess up the input or even put a script in the letters' pain anim to change the player's name with every hit for the same effect. Also, it's recommended to add an "erase" "button" that clears the globalvar's value to start again if you do mess up

Ok, It's my first attempt to bring something new to OpenBOR. Please don't be too harsh on me if you think my idea is stupid. I'm just a noob with good intentions :). Also, kimono has tested it already, so he can vouch for it working.

Play as Moonwalker in the "Streets of Nigtmare" set https://drive.google.com/file/d/1QKQAYpfw82rbo9dKe8i4qssRGhY6VO55/view?usp=sharing

Hit the letters in the order of the name you wish to set, then touch the barrel. It will assign the name and get you to the actual first level

 
Okay, I can see the idea here

Can you port this system to smaller mod? so people don't have to download large file just to see this system
 
Something like this should be used when making a adventure game then all references in the story use the players name you set.  The custom level for setting the name should have used "setweap" option to force the player into a custom weapon model that looks like a pointer of some sort.

But still very nicely done.
 
msmalik681 said:
Something like this should be used when making a adventure game then all references in the story use the players name you set.  The custom level for setting the name should have used "setweap" option to force the player into a custom weapon model that looks like a pointer of some sort.

But still very nicely done.

Thank you. The goal here was not to make it perfect, but to just get it working. So that people who are interested in this could use this as a template and modify this according to their needs and\or personal taste :)
 
So, I would like to use it but do you need to have keyboard to use this? not every system has it.
I think it wold require some remixing and updates
 
bWWd said:
So, I would like to use it but do you need to have keyboard to use this? not every system has it.
I think it wold require some remixing and updates

No keyboard nesessary. You just run around punching letters and touch the endlevel (the barrel in this case) when you're done
 
No, there's no keyboard needed... that's the point.  I think this is a nice idea - kind of over-complicated on the implementation, but I love to see people experimenting and learning.

mishadude, for next time I'd recommend putting your character set into an array, and then drawing them to the screen directly using a grid. Then capture the player key and get character based on their location within the grid. Sounds harder than it is to do. You've already done the tough part by setting up the string building.

The advantage over your entity per character method is it will be far simpler and less resource intensive, plus you can replace characters on the fly and don't need to worry at all about arranging spawns. But either way, love the creative thinking.

DC
 
picked axel, hit the letters, got to the drum but my name was still axel.
I think it definitely needs more, also display of what you already have, i kinda hit blindly.
Ah ok , it works only with M Jackson, yeat it is cool but needs a limit of how long it could be , also definitely realtime display of what you already have.
Id to tally make a game where you would find a pet and name it , thats a cool feature to have but i would simplify it as much as i can.
I wonder if it can be done like my pause menu, you can paste it into any game and its quite simple, follow6 is when animation is waiting for you to touch it , when you touch it then menu appears, and you use arrows to swap between different choices:
Code:
anim	follow6
	loop	1
	offset	12 12
	bbox	0 0 0 0
	noreflect	1
	followanim	7
	attack	6 3 14 19 0 0 1 0 0 0
	hitfx	data/sounds/0.wav
	delay	20
	drawmethod	tintmode 4
	drawmethod	tintcolor 250_0_0
	frame	data/sprites/crypt.gif
	nodrawmethod	
	attack	0
	frame	data/sprites/crypt.gif
		
anim	follow7
	loop	0
	delay	5
	offset	8 14
@script
	void self = getlocalvar("self");
	int iPIndex = getentityproperty(self,"playerindex"); //Get player index
	void right = playerkeys(iPIndex, 0, "moveright");
	void left = playerkeys(iPIndex, 0, "moveleft");
		void down = playerkeys(iPIndex, 0, "movedown");
			void up = playerkeys(iPIndex, 0, "moveup");
	void pick = playerkeys(iPIndex, 0, "attack");
	int	Cframe = getentityproperty(self,"animpos");
	if(frame>=1)
	{
	//settextobj(5,20,20,3,999999999,""+Cframe);
		if(Cframe==2 && right) {updateframe(self,4);}
	if(Cframe==5 && left) {updateframe(self,1);}
	if(Cframe==2 && down) {updateframe(self,11);}
	if(Cframe==5 && down) {updateframe(self,11);}
        if(Cframe==12 && up) {updateframe(self,4);}
        
	if(Cframe==2 && pick) {updateframe(self,7);}
	if(Cframe==5 && pick) {updateframe(self,9);}
	if(Cframe==12 && pick) {updateframe(self,14);}
	}
	@end_script	
	@cmd	changeentityproperty getlocalvar("self") "type" openborconstant("TYPE_TEXTBOX")
	@cmd	changeentityproperty getlocalvar("self") "subtype" openborconstant("SUBTYPE_NOSKIP")
	sound	data/sounds/laser2.wav
	frame	none #0
	sound	data/sounds/beep.wav
	frame	none #1
	@cmd	settextobj 0 420 260 2 -1 "MAKE_A_CHOICE:"
	@cmd	settextobj 1 680 150 0 -1 "BACK TO MAP"
	@cmd	settextobj 2 140 150 1 -1 "RESET ALL PROGRESS"
	@cmd	settextobj 4 460 180 0 -1 "CANCEL"
	frame	none #2
	@cmd	updateframe getlocalvar("self") 2
	frame	none #3
	sound	data/sounds/beep.wav
	frame	none #4
	@cmd	settextobj 0 420 260 2 -1 "MAKE_A_CHOICE:"
	@cmd	settextobj 1 680 150 1 -1 "BACK TO MAP"
	@cmd	settextobj 2 140 150 0 -1 "RESET ALL PROGRESS"
	@cmd	settextobj 4 460 180 0 -1 "CANCEL"
	frame	none #5
	@cmd	updateframe getlocalvar("self") 5
	frame	none #6
	delay	100
	sound	data/sounds/select.wav
	@cmd	settextobj 3 400 220 2 -1 "LETS_RESET_!" openborvariant("elapsed_time")+250
	@cmd	settextobj 0 400 220 1 -1 "_" 50
	@cmd	settextobj 1 400 220 1 -1 "_" 50
	@cmd	settextobj 2 400 220 1 -1 "_" 50
	@cmd	settextobj 4 400 220 1 -1 "_" 50
	frame	none #7
	@cmd	clearglobalvar()
	@cmd	jumptobranch "Nam" 1
	frame	none #8
	delay	100
	sound	data/sounds/select.wav
	@cmd	settextobj 3 400 220 2 -1 "LETS_GO_BACK_!" openborvariant("elapsed_time")+250
	@cmd	settextobj 0 400 220 1 -1 "_" 50
	@cmd	settextobj 1 400 220 1 -1 "_" 50
	@cmd	settextobj 2 400 220 1 -1 "_" 50
	@cmd	settextobj 4 400 220 1 -1 "_" 50
	frame	none #9
	@cmd	jumptobranch "mapb" 1
	frame	none #10
	delay	5
	sound	data/sounds/beep.wav
	frame	none #11
	@cmd	settextobj 0 420 260 2 -1 "MAKE_A_CHOICE:"
	@cmd	settextobj 1 680 150 0 -1 "BACK TO MAP"
	@cmd	settextobj 2 140 150 0 -1 "RESET ALL PROGRESS"
	@cmd	settextobj 4 460 180 1 -1 "CANCEL"
	frame	none #12
	@cmd	updateframe getlocalvar("self") 12
	frame	none #13
	sound	data/sounds/select.wav
	frame	none #14
	@cmd	settextobj 0 400 220 1 -1 "_" 50
	@cmd	settextobj 1 400 220 1 -1 "_" 50
	@cmd	settextobj 2 400 220 1 -1 "_" 50
	@cmd	settextobj 4 400 220 1 -1 "_" 50
	@cmd	setglobalvar("nomen", 1)
	@cmd	killentity getlocalvar("self")
	frame	none #15

So, id like to modify that kind of menu into name input and realtime display.
Woah.. theres definitely better way to do it than this, it could be done using just one entity and changing them by detecting amount of health in spawn animation:
Code:
know 	letterA	data/chars/letters/letterA.txt
know 	letterB	data/chars/letters/letterB.txt
know 	letterC	data/chars/letters/letterC.txt
know 	letterD	data/chars/letters/letterD.txt
know 	letterE	data/chars/letters/letterE.txt
know 	letterF	data/chars/letters/letterF.txt
know 	letterG	data/chars/letters/letterG.txt
know 	letterH	data/chars/letters/letterH.txt
know 	letterI	data/chars/letters/letterI.txt
know 	letterJ	data/chars/letters/letterJ.txt
know 	letterK	data/chars/letters/letterK.txt
know 	letterL	data/chars/letters/letterL.txt
know 	letterM	data/chars/letters/letterM.txt
know 	letterN	data/chars/letters/letterN.txt
know 	letterO	data/chars/letters/letterO.txt
know 	letterP	data/chars/letters/letterP.txt
know 	letterQ	data/chars/letters/letterQ.txt
know 	letterR	data/chars/letters/letterR.txt
know 	letterS	data/chars/letters/letterS.txt
know 	letterT	data/chars/letters/letterT.txt
know 	letterU	data/chars/letters/letterU.txt
know 	letterV	data/chars/letters/letterV.txt
know 	letterW	data/chars/letters/letterW.txt
know 	letterX	data/chars/letters/letterX.txt
know 	letterY	data/chars/letters/letterY.txt
know 	letterZ	data/chars/letters/letterZ.txt
know 	letterZ	data/chars/letters/doneT.txt

Any ideas how to do it in a most compact way possible using just one entity and one animation like i did it ? Or did anyone had this kind of compact menu where you could switch to different options using textobjects with script ? Cause i only know mine but maybe there is more sleaky way to do it.
I think it just needs one menu item where you could push up/down to change letter, and left/right to move back/forth or even without moving back.forth.when you would press up/down it would update the name anyway and display it for you.
Or maybe even changing and updating the actual name above the lifebar would be fine with change name property , that could work, you dont have to create another text box for this when its already there above lifebar.
Anyway, if you want the name to update in realtime, use this in every letter:
Code:
anim pain
@script
void P1 = getplayerproperty(0,"entity");  
void p1name = getglobalvar("p1name");

if (p1name == NULL()) {
setglobalvar ("p1name","A");
}
else
{
setglobalvar ("p1name", p1name + "A");
changeentityproperty(P1, "name", p1name );
}
@end_script
Also , it would be good to save the names to a txt file and bring them back when you play the next day.
 
Back
Top Bottom