SOLVED: Script help

Toranks

Active member
How I can change a weapon via script?

I am trying to change the model of the first available player to a specific model, and change the rest of the players to a weapon that is actually an invisible box. The problem I find is only the first player remains with the model changed, the rest stays in its original weapon, not weapon 8 as I wanted.
I don't know what step I am doing wrong, can you help me?

PD: Using
Code:
	changeplayerproperty(1, "weapon", 8);
that doesn't work neither


Code:
name	1pryoturt
type	none
nolife	1
antigravity 100
shadow  0
offscreenkill	80000

script @script
void main()
{
    void self = getlocalvar("self");
    char Name = getentityproperty(self,"name");
    int HP = getentityproperty(self,"health");
    int P1 = getplayerproperty(0, "entity");
    int P2 = getplayerproperty(1, "entity");
    int P3 = getplayerproperty(2, "entity");

	void anim1 = getentityproperty(P1,"animationID");
	void anim2 = getentityproperty(P2,"animationID");
	void anim3 = getentityproperty(P3,"animationID");

	changeopenborvariant("nojoin", 1);

	if (P1 != NULL())
	{
	changeentityproperty(P1, "model", Name, 1);
	changeentityproperty(P1, "defaultname", Name);
	changeentityproperty(P2, "stealth", 8);
	changeentityproperty(P3, "stealth", 8);
	changeentityproperty(P2, "weapon", 8);
	changeentityproperty(P3, "weapon", 8);
    bindentity(P2, P1);
    bindentity(P3, P1);
	}
	else if (P2 != NULL())
	{
	changeentityproperty(P2, "model", Name, 1);
	changeentityproperty(P2, "defaultname", Name);
	changeentityproperty(P3, "stealth", 8);
	changeentityproperty(P3, "weapon", 8);
    bindentity(P3, P2);
	}
	else if (P3 != NULL())
	{
	changeentityproperty(P3, "model", Name, 1);
	changeentityproperty(P3, "defaultname", Name);
	}

	if (anim1 == openborconstant("ANI_SPAWN"))
	{
	changeentityproperty(P1, "health", HP);
	}
	else if (anim2 == openborconstant("ANI_SPAWN"))
	{
	changeentityproperty(P2, "health", HP);
	}
	else if (anim3 == openborconstant("ANI_SPAWN"))
	{
	changeentityproperty(P3, "health", HP);
	}
}
@end_script


anim 	idle
@script
	void self = getlocalvar("self");
	if(frame >= 1)
	{
	killentity(self);
	}
@end_script
	loop	1
	delay	3
	offset	1 1
	frame	data/chars/misc/empty.gif
	frame	data/chars/misc/empty.gif



SOLVED DEFINITIVE CODE:
Code:
name	1pryoturt
type	none
nolife	1
antigravity 100
shadow  0
offscreenkill	80000



script @script
void main()
{
    void self = getlocalvar("self");
    char Name = getentityproperty(self,"name");
    int HP = getentityproperty(self,"health");
    int MP = getentityproperty(self,"aggression");
    int P1 = getplayerproperty(0, "entity");
    int P2 = getplayerproperty(1, "entity");
    int P3 = getplayerproperty(2, "entity");

	void anim1 = getentityproperty(P1,"animationID");
	void anim2 = getentityproperty(P2,"animationID");
	void anim3 = getentityproperty(P3,"animationID");

	changeopenborvariant("nojoin", 1);

	if (P1 != NULL() && P2 != NULL() && P3 != NULL())
	{
	changeentityproperty(P1, "model", Name, 1);
	changeentityproperty(P1, "defaultname", Name);
	changeentityproperty(P2, "stealth", 8);
	changeentityproperty(P2, "model", "mrzero", 1);
	changeentityproperty(P3, "stealth", 8);
	changeentityproperty(P3, "model", "mrzero", 1);
    bindentity(P2, P1, 0, 0, 0, 0, 0);
    bindentity(P3, P1, 0, 0, 0, 0, 0);
	}
	else if (P1 != NULL() && P2 != NULL() && P3 == NULL())
	{
	changeentityproperty(P1, "model", Name, 1);
	changeentityproperty(P1, "defaultname", Name);
	changeentityproperty(P2, "stealth", 8);
	changeentityproperty(P2, "model", "mrzero", 1);
    bindentity(P2, P1, 0, 0, 0, 0, 0);
	}
	else if (P1 != NULL() && P2 == NULL() && P3 == NULL())
	{
	changeentityproperty(P1, "model", Name, 1);
	changeentityproperty(P1, "defaultname", Name);
	}
	else if (P1 != NULL() && P2 == NULL() && P3 != NULL())
	{
	changeentityproperty(P1, "model", Name, 1);
	changeentityproperty(P1, "defaultname", Name);
	changeentityproperty(P3, "stealth", 8);
	changeentityproperty(P3, "model", "mrzero", 1);
    bindentity(P3, P1, 0, 0, 0, 0, 0);
	}
	else if (P1 == NULL() && P2 != NULL() && P3 != NULL())
	{
	changeentityproperty(P2, "model", Name, 1);
	changeentityproperty(P2, "defaultname", Name);
	changeentityproperty(P3, "stealth", 8);
	changeentityproperty(P3, "model", "mrzero", 1);
    bindentity(P3, P2, 0, 0, 0, 0, 0);
	}
	else if (P1 == NULL() && P2 != NULL() && P3 == NULL())
	{
	changeentityproperty(P2, "model", Name, 1);
	changeentityproperty(P2, "defaultname", Name);
	}
	else if (P1 == NULL() && P2 == NULL() && P3 != NULL())
	{
	changeentityproperty(P3, "model", Name, 1);
	changeentityproperty(P3, "defaultname", Name);
	}

	if (anim1 == openborconstant("ANI_SPAWN"))
	{
	changeentityproperty(P1, "health", HP);
	changeentityproperty(P1, "mp", MP);
	}
	else if (anim2 == openborconstant("ANI_SPAWN"))
	{
	changeentityproperty(P2, "health", HP);
	changeentityproperty(P2, "mp", MP);
	}
	else if (anim3 == openborconstant("ANI_SPAWN"))
	{
	changeentityproperty(P3, "health", HP);
	changeentityproperty(P3, "mp", MP);
	}
}
@end_script



anim 	idle
@script
	void self = getlocalvar("self");
	if(frame >= 1)
	{
	killentity(self);
	}
@end_script
	loop	1
	delay	3
	offset	1 1
	frame	data/chars/misc/empty.gif
	frame	data/chars/misc/empty.gif
 
Toranks said:
How I can change a weapon via script?

I am trying to change the model of the first available player to a specific model, and change the rest of the players to a weapon that is actually an invisible box. The problem I find is only the first player remains with the model changed, the rest stays in its original weapon, not weapon 8 as I wanted.
I don't know what step I am doing wrong, can you help me?

PD: Using
Code:
	changeplayerproperty(1, "weapon", 8);
that doesn't work neither

I suggest to remove the "else" from each player script, because all 3 player function need to run at the same time as a independent process
Code:
script @script
void main()
{
    void self = getlocalvar("self");
    char Name = getentityproperty(self,"name");
    int HP = getentityproperty(self,"health");
    int P1 = getplayerproperty(0, "entity");
    int P2 = getplayerproperty(1, "entity");
    int P3 = getplayerproperty(2, "entity");

	void anim1 = getentityproperty(P1,"animationID");
	void anim2 = getentityproperty(P2,"animationID");
	void anim3 = getentityproperty(P3,"animationID");

	changeopenborvariant("nojoin", 1);

	if (P1 != NULL())
	{
	changeentityproperty(P1, "model", Name, 1);
	changeentityproperty(P1, "defaultname", Name);
	changeentityproperty(P2, "stealth", 8);
	changeentityproperty(P3, "stealth", 8);
	changeentityproperty(P2, "weapon", 8);
	changeentityproperty(P3, "weapon", 8);
    bindentity(P2, P1);
    bindentity(P3, P1);
	}
	if (P2 != NULL())
	{
	changeentityproperty(P2, "model", Name, 1);
	changeentityproperty(P2, "defaultname", Name);
	changeentityproperty(P3, "stealth", 8);
	changeentityproperty(P3, "weapon", 8);
    bindentity(P3, P2);
	}
	if (P3 != NULL())
	{
	changeentityproperty(P3, "model", Name, 1);
	changeentityproperty(P3, "defaultname", Name);
	}

	if (anim1 == openborconstant("ANI_SPAWN"))
	{
	changeentityproperty(P1, "health", HP);
	}
	if (anim2 == openborconstant("ANI_SPAWN"))
	{
	changeentityproperty(P2, "health", HP);
	}
	if (anim3 == openborconstant("ANI_SPAWN"))
	{
	changeentityproperty(P3, "health", HP);
	}
}
@end_script
 
This doesn't work... still unchanged weapon

The "else" is to check successively if there is player 1, 2, and 3. If there is 1, 2 and 3, 2 and 3 should change their weapon to 8, become stealth and link to player 1. If they are only 2 and 3, the 2 changes model and the 3 becomes stealth and is linked to 2. If there is only 3, just change the model.

 
Toranks said:
This doesn't work... still unchanged weapon

The "else" is to check successively if there is player 1, 2, and 3. If there is 1, 2 and 3, 2 and 3 should change their weapon to 8, become stealth and link to player 1. If they are only 2 and 3, the 2 changes model and the 3 becomes stealth and is linked to 2. If there is only 3, just change the model.
Yeah now I understand better, is a little more complex than I thought. Have you tried to write all players combinations using "player1 && player2" instead of using "player1 else player2" like you said? Something like this:

"player1 && player2" = execute function 1
"player1 && player3" = execute function 2
"player2 && player3" = execute function 3
"player1 && player2 && player3" = execute function 4

Or maybe force the player 2 to check the player 1 and the player 3 to check player 2. And then, they will choose between two functions, one if the checked player is present or another if is not present. You can use the same script for all characters by checking the "self, playerindex" instead of "getplayer property, entity", and your action will be according to your current player index number.

Another suggestion is to write this script in an event, like "ondraw.c" or any other. However, I will test your script in my game to see how it works.
 
I have tried to extend the conditions but the same thing still happens to me. Everything seems to work with both the previous script and actual script, except the change of weapon. That is the only problem. In addition, it blinks cyclically, changing from the default model to the weapon model 8 (an empty box)

I have recorded a video in case it helps identify the problem. The second player (a girl) is hidden and blinking behind the first player (the blond man in the center):


The new code, works the same:

Code:
script @script
void main()
{
    void self = getlocalvar("self");
    char Name = getentityproperty(self,"name");
    int HP = getentityproperty(self,"health");
    int MP = getentityproperty(self,"aggression");
    int P1 = getplayerproperty(0, "entity");
    int P2 = getplayerproperty(1, "entity");
    int P3 = getplayerproperty(2, "entity");

	void anim1 = getentityproperty(P1,"animationID");
	void anim2 = getentityproperty(P2,"animationID");
	void anim3 = getentityproperty(P3,"animationID");

	changeopenborvariant("nojoin", 1);

	if (P1 != NULL() && P2 != NULL() && P3 != NULL())
	{
	changeentityproperty(P1, "model", Name, 1);
	changeentityproperty(P1, "defaultname", Name);
	changeentityproperty(P2, "stealth", 8);
	changeentityproperty(P3, "stealth", 8);
	changeentityproperty(P2, "weapon", 8);
	changeentityproperty(P3, "weapon", 8);
    bindentity(P2, P1, 0, 0, 0, 0, 0);
    bindentity(P3, P1, 0, 0, 0, 0, 0);
	}
	else if (P1 != NULL() && P2 != NULL() && P3 == NULL())
	{
	changeentityproperty(P1, "model", Name, 1);
	changeentityproperty(P1, "defaultname", Name);
	changeentityproperty(P2, "stealth", 8);
	changeentityproperty(P2, "weapon", 8);
    bindentity(P2, P1, 0, 0, 0, 0, 0);
	}
	else if (P1 != NULL() && P2 == NULL() && P3 == NULL())
	{
	changeentityproperty(P1, "model", Name, 1);
	changeentityproperty(P1, "defaultname", Name);
	}
	else if (P1 != NULL() && P2 == NULL() && P3 != NULL())
	{
	changeentityproperty(P1, "model", Name, 1);
	changeentityproperty(P1, "defaultname", Name);
	changeentityproperty(P3, "stealth", 8);
	changeentityproperty(P3, "weapon", 8);
    bindentity(P3, P1, 0, 0, 0, 0, 0);
	}
	else if (P1 == NULL() && P2 != NULL() && P3 != NULL())
	{
	changeentityproperty(P2, "model", Name, 1);
	changeentityproperty(P2, "defaultname", Name);
	changeentityproperty(P3, "stealth", 8);
	changeentityproperty(P3, "weapon", 8);
    bindentity(P3, P2, 0, 0, 0, 0, 0);
	}
	else if (P1 == NULL() && P2 != NULL() && P3 == NULL())
	{
	changeentityproperty(P2, "model", Name, 1);
	changeentityproperty(P2, "defaultname", Name);
	}
	else if (P1 == NULL() && P2 == NULL() && P3 != NULL())
	{
	changeentityproperty(P3, "model", Name, 1);
	changeentityproperty(P3, "defaultname", Name);
	}

	if (anim1 == openborconstant("ANI_SPAWN"))
	{
	changeentityproperty(P1, "health", HP);
	changeentityproperty(P1, "mp", MP);
	}
	else if (anim2 == openborconstant("ANI_SPAWN"))
	{
	changeentityproperty(P2, "health", HP);
	changeentityproperty(P2, "mp", MP);
	}
	else if (anim3 == openborconstant("ANI_SPAWN"))
	{
	changeentityproperty(P3, "health", HP);
	changeentityproperty(P3, "mp", MP);
	}
}
@end_script

PD: If I make the entity that invokes the script die as it did before (I erased it), the character stops blinking but keeps with the original model, not weapon model 8
PD2: I forgot to add  ", 0, 0, 0, 0, 0" to bindentity, but the problem persists, it is not related
 
Toranks said:
I have tried to extend the conditions but the same thing still happens to me. Everything seems to work with both the previous script and actual script, except the change of weapon. That is the only problem. In addition, it blinks cyclically, changing from the default model to the weapon model 8 (an empty box)

I have recorded a video in case it helps identify the problem. The second player (a girl) is hidden and blinking behind the first player (the blond man in the center):

The new code, works the same:

Code:
script @script
void main()
{
    void self = getlocalvar("self");
    char Name = getentityproperty(self,"name");
    int HP = getentityproperty(self,"health");
    int MP = getentityproperty(self,"aggression");
    int P1 = getplayerproperty(0, "entity");
    int P2 = getplayerproperty(1, "entity");
    int P3 = getplayerproperty(2, "entity");

	void anim1 = getentityproperty(P1,"animationID");
	void anim2 = getentityproperty(P2,"animationID");
	void anim3 = getentityproperty(P3,"animationID");

	changeopenborvariant("nojoin", 1);

	if (P1 != NULL() && P2 != NULL() && P3 != NULL())
	{
	changeentityproperty(P1, "model", Name, 1);
	changeentityproperty(P1, "defaultname", Name);
	changeentityproperty(P2, "stealth", 8);
	changeentityproperty(P3, "stealth", 8);
    bindentity(P2, P1, 0, 0, 0, 0, 0);
    bindentity(P3, P1, 0, 0, 0, 0, 0);
	}
	else if (P1 != NULL() && P2 != NULL() && P3 == NULL())
	{
	changeentityproperty(P1, "model", Name, 1);
	changeentityproperty(P1, "defaultname", Name);
	changeentityproperty(P2, "stealth", 8);
    bindentity(P2, P1, 0, 0, 0, 0, 0);
	}
	else if (P1 != NULL() && P2 == NULL() && P3 == NULL())
	{
	changeentityproperty(P1, "model", Name, 1);
	changeentityproperty(P1, "defaultname", Name);
	}
	else if (P1 != NULL() && P2 == NULL() && P3 != NULL())
	{
	changeentityproperty(P1, "model", Name, 1);
	changeentityproperty(P1, "defaultname", Name);
	changeentityproperty(P3, "stealth", 8);
    bindentity(P3, P1, 0, 0, 0, 0, 0);
	}
	else if (P1 == NULL() && P2 != NULL() && P3 != NULL())
	{
	changeentityproperty(P2, "model", Name, 1);
	changeentityproperty(P2, "defaultname", Name);
	changeentityproperty(P3, "stealth", 8);
    bindentity(P3, P2, 0, 0, 0, 0, 0);
	}
	else if (P1 == NULL() && P2 != NULL() && P3 == NULL())
	{
	changeentityproperty(P2, "model", Name, 1);
	changeentityproperty(P2, "defaultname", Name);
	}
	else if (P1 == NULL() && P2 == NULL() && P3 != NULL())
	{
	changeentityproperty(P3, "model", Name, 1);
	changeentityproperty(P3, "defaultname", Name);
	}

	if (anim1 == openborconstant("ANI_SPAWN"))
	{
	changeentityproperty(P1, "health", HP);
	changeentityproperty(P1, "mp", MP);
	}
	else if (anim2 == openborconstant("ANI_SPAWN"))
	{
	changeentityproperty(P2, "health", HP);
	changeentityproperty(P2, "mp", MP);
	}
	else if (anim3 == openborconstant("ANI_SPAWN"))
	{
	changeentityproperty(P3, "health", HP);
	changeentityproperty(P3, "mp", MP);
	}
}
@end_script

PD: If I make the entity that invokes the script die as it did before (I erased it), the character stops blinking but keeps with the original model, not weapon model 8
PD2: I forgot to add  ", 0, 0, 0, 0, 0" to bindentity, but the problem persists, it is not related

You are looking for something like this?
https://www.youtube.com/watch?v=M7PLQT4h2TI

In this video I added a small script in Axel idle animation to make some tasks:

1) Change the P1 model to Axel Knife model
2) Change the P2 model to Apple model
3) Change the P3 model to Chicken model

Correct if I'm wrong, but when all 3 players are active, you are trying to change the P2 and P3 models by using "stealth" command? Because in your code I can find a script to change model only for P1, not for the other players. If you want to change the model for all 3 players, will need to repeat the same code to all players, like the script that I made in this video:
Code:
script @script
void main()
{
	void P1 = getplayerproperty(0, "entity");
	void P2 = getplayerproperty(1, "entity");
	void P3 = getplayerproperty(2, "entity");
	changeentityproperty(P1, "model", "Axel_Knife", 1);
	changeentityproperty(P2, "model", "Apple", 1);
	changeentityproperty(P3, "model", "Chicken", 1);
}
@end_script

And for "defaultname", it will be the same as the current model name. Maybe you are looking for change "alias", and to make it you will need to change "name" instead of  "defaultname".
 
I am trying to get all players except the lowest number player to change to weapon 8, which is an empty box model.
"stealth" serves to keep enemies from seeing or trying to chase that empty box.
I use Bindentity so that both player 2 and 3 remain in that empty and invisible box attached to 1 (so that the camera always follows player 1).
The only problem I experience is that the model of rest of players is not changed, it keeps blinking as seen in the video.

In other different scripts, this works perfectly:

Code:
	changeentityproperty(P2, "weapon", 8);

or

Code:
	changeentityproperty(1, "weapon", 8);


But not in this one in particular, for some reason I don't understand.
 
I have tried to change:

Code:
	changeentityproperty(P2, "weapon", 8);

with

Code:
	changeentityproperty(P2, "model", "mrzero", 1);

"mrzero" is the famous weapon 8, same for all characters. Now this works!! Thanks for the idea. I'm stupid for not trying that before xDDD

Although I still don't understand why "weapon" change does not works with this script on any stage but yes with another simpler scripts like the one you show me before even at that same stage. Bug, maybe?
 
Kratus said:
And for "defaultname", it will be the same as the current model name. Maybe you are looking for change "alias", and to make it you will need to change "name" instead of  "defaultname".

That has an explanation.
The entity that is invoked to execute the script (1pryoturt) have an alias assigned in the level file. Just like this:
Code:
spawn   1pryoturt
alias   ryoturt
health	100
aggression 100
coords  300 380
at      0

The script takes this alias (ryoturt) to generate its model, so I can reuse the same entity to do the same at different stages. On another stage where all the players get inside a tank, the tank is handled by player 1 while 2 and 3 remain binded to the tank thanks to bindentity, and invisible thanks to the "mrzero" weapon and the stealth property. I use the same script, but changing the name to the tank (alias tankpl), so player 1 becomes the tank (or 2 if there is no player 1, etc ...), and rest of the players dissapear but still there, alive.
The same happens below with other properties such as life and aggression, in case the model has different values than the original player, and can be done with any other property assigned in the stage file.

The original author of the script KILL all players other than the first available player. That caused the loss of ALL lives and 1 credit from all players except the first. It seemed like a dirty solution and I've been looking for an alternative all day, which I've finally solved thanks to your ideas :D
 
Nice! I'm glad that I can help, it seems to be a pretty cool game you are doing.
About the weapon/model change by script, I think that it can have a few bugs
 
Back
Top Bottom