Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Forum » Scripting Help
Scripting Help [message #418187] Fri, 22 January 2010 11:43 Go to next message
Gen_Blacky is currently offline  Gen_Blacky
Messages: 3250
Registered: September 2006
Karma: 1
General (3 Stars)
Can some one give me an example of how to create an object on a certain map with c++. I want to create a couple of script zones with different xyz locations on each map.

http://s18.postimage.org/jc6qbn4k9/bricks3.png

[Updated on: Sat, 23 January 2010 03:00]

Report message to a moderator

Re: Vector3 pos [message #418210 is a reply to message #418187] Fri, 22 January 2010 16:31 Go to previous messageGo to next message
Sir Kane
Messages: 1701
Registered: March 2003
Location: Angerville
Karma: 0
General (1 Star)
Vector3(100.0f, 200.0f, 0.0)

Proud N9500 and proud N6270 user. Creator of the IEE libraries (original bhs.dll) and the RB series software.
http://n00bstories.com/image.fetch.php?id=1189992501http://www.n00bstories.com/image.fetch.php?id=1257492907
Re: Vector3 pos [message #418235 is a reply to message #418187] Fri, 22 January 2010 22:16 Go to previous messageGo to next message
zunnie is currently offline  zunnie
Messages: 2959
Registered: September 2003
Location: Netherlands
Karma: 0
General (2 Stars)

http://apb.pastebin.com/d4732d748

Thats how i do it...


https://multiplayerforums.com/uploads/monthly_2018_03/TCW2_Signature.png.6236a0dbc6e1e53472a18fe8cd15e47b.png
Re: Vector3 pos [message #418238 is a reply to message #418187] Fri, 22 January 2010 23:10 Go to previous messageGo to next message
Gen_Blacky is currently offline  Gen_Blacky
Messages: 3250
Registered: September 2006
Karma: 1
General (3 Stars)
Thank you how would i set the size of the script zone and did I use the xyz cords wrong.

GameObject *zone = Commands->Create_Object("Script_Zone_All",Vector3(-83.531f,-89.294f,-0.589f));

How do i use

Attach_Script_Once
or
Attach_Script

with more then 3 peramters ?

Would i do it like this ?
Commands->Attach_Script(zone,"script",team,msg);


http://s18.postimage.org/jc6qbn4k9/bricks3.png

[Updated on: Fri, 22 January 2010 23:14]

Report message to a moderator

Re: Vector3 pos [message #418243 is a reply to message #418187] Sat, 23 January 2010 02:57 Go to previous messageGo to next message
Gen_Blacky is currently offline  Gen_Blacky
Messages: 3250
Registered: September 2006
Karma: 1
General (3 Stars)
Can some one tell me why this chat command isn't working correctly> I don't understand how gdiplayer == nodplayer does not = even teams.

class TeamChangeChatCommand : public ChatCommandClass 
{
	void Triggered(int ID,const TokenClass &Text,int ChatType) 
	{
		GameObject *obj = Get_GameObj(ID);
		int gdiPlayers = (Tally_Team_Size(1));
		int nodPlayers = (Tally_Team_Size(0));
		int team = Get_Object_Type(obj);
		if (team == 1) 
		{
			printf("GDI\n");
			nodPlayers++;
			if (nodPlayers < gdiPlayers) 
			{
				printf("Change Team GDI to Nod\n");
				Change_Team_By_ID(ID,0);
				char message[256];
				sprintf(message,"msg Player %s has changed to Team Nod to make the teams even.", Get_Player_Name_By_ID(ID));
				Console_Input(message);
			}
			else if (nodPlayers == 0)
			{
				char message[256];
				sprintf(message,"msg You are the only player on GDI", Get_Player_Name_By_ID(ID));
				Console_Input(message);
			}
			else if (nodPlayers == gdiPlayers)
			{
				char message[256];
				sprintf(message,"msg Teams are Even", Get_Player_Name_By_ID(ID));
				Console_Input(message);
				//Console_Input(StrFormat("msg Teams are Even.",Get_Player_ID(obj)).c_str();
			}
			else 
			{
				//Console_Input(StrFormat("msg Sorry GDI doesn't have enough Players!.",Get_Player_ID(obj)).c_str();
				char message[256];
				sprintf(message,"msg Sorry GDI doesn't have enough Players!", Get_Player_Name_By_ID(ID));
				Console_Input(message);
			}
	
		}
		if (team == 0) 
		{
			printf("NOD\n");
			gdiPlayers++;
			if (gdiPlayers < nodPlayers) 
			{
				printf("Change Team Nod to GDI\n");
				Change_Team_By_ID (ID,1);
				char message[256];
				sprintf(message,"msg Player %s has changed to Team GDI to make the teams even.", Get_Player_Name_By_ID(ID));
				Console_Input(message);
			}
			else if (gdiPlayers == 0)
			{
				char message[256];
				sprintf(message,"msg You are the only player on Nod.", Get_Player_Name_By_ID(ID));
				Console_Input(message);
				//Console_Input(StrFormat("msg You are the only player on Nod.",Get_Player_ID(obj)).c_str();
			}
			else if (gdiPlayers == nodPlayers)
			{
				char message[256];
				sprintf(message,"msg Teams are Even", Get_Player_Name_By_ID(ID));
				Console_Input(message);
			}
			else 
			{
				//Console_Input(StrFormat("msg Sorry NOD doesn't have enough Players!.",Get_Player_ID(obj)).c_str();
				char message[256];
				sprintf(message,"msg Sorry NOD doesn't have enough Players!", Get_Player_Name_By_ID(ID));
				Console_Input(message);
			}
		}
	}
};
ChatCommandRegistrant<TeamChangeChatCommand> TeamChangeChatCommandReg("!TeamChange;!tc;!switch;",CHATTYPE_TEAM,0,GAMEMODE_ALL);


index.php?t=getfile&id=12378&private=0


http://s18.postimage.org/jc6qbn4k9/bricks3.png

[Updated on: Sat, 23 January 2010 02:58]

Report message to a moderator

Re: Scripting Help [message #418244 is a reply to message #418187] Sat, 23 January 2010 03:39 Go to previous messageGo to next message
Omar007 is currently offline  Omar007
Messages: 1711
Registered: December 2007
Location: Amsterdam
Karma: 0
General (1 Star)
@Your script zone questions;
Gen_Blacky wrote on Sat, 23 January 2010 07:10

Thank you how would i set the size of the script zone and did I use the xyz cords wrong.

GameObject *zone = Commands->Create_Object("Script_Zone_All",Vector3(-83.531f,-89.294f,-0.589f));

How do i use

Attach_Script_Once
or
Attach_Script

with more then 3 peramters ?

Would i do it like this ?
Commands->Attach_Script(zone,"script",team,msg);

The use of the Vector3 seems OK. You just have to make sure the coords are right Wink
Also im not sure it works with creating script zones. It does work with PhysicalGameObjects. Never tried it on zones
I dont know how you can set the size, sorry

Attach_Script_Once(obj,"script","param1,param2,param3");
Commands->Attach_Script(obj,"script","param1,param2,param3");


@Your code;

Well the first thing i dont get is why you would increase nodplayers when GDI uses the command;
		if (team == 1) 
		{
			printf("GDI\n");
			nodPlayers++;
		....

and gdiplayers when nod uses it.
		if (team == 0) 
		{
			printf("NOD\n");
			gdiPlayers++;
		....


No wonder it says TEAMS EVEN when you used !tc on Nod. GDI had only 1 player and Nod 2 but you increased GDI first meaning both teams have 2 according to your code

This piece of code is in both teams useless because you increased it by 1 first AND becasue you check for gdiPlayers < nodPlayers first it will never reach this.
else if (gdiPlayers == 0) //or nodPlayers  in GDI ;)
			{
				char message[256];
				sprintf(message,"msg You are the only player on Nod.", Get_Player_Name_By_ID(ID));
				Console_Input(message);
				//Console_Input(StrFormat("msg You are the only player on Nod.",Get_Player_ID(obj)).c_str();
			}

And you are letting it say 'You are the only player on Nod/GDI' while you didnt even checked for that Razz

What i would do is remove
nodPlayers++;
gdiPlayers++;


and change
else if (gdiPlayers == 0) //or nodPlayers  in GDI ;)
			{
				char message[256];
				sprintf(message,"msg You are the only player on Nod.", Get_Player_Name_By_ID(ID));
				Console_Input(message);
				//Console_Input(StrFormat("msg You are the only player on Nod.",Get_Player_ID(obj)).c_str();
			}


To
else if (gdiPlayers == 0 && nodPlayers == 1) //or nodPlayers && gdiPlayers in GDI ;)
			{
				char message[256];
				sprintf(message,"msg You are the only player on Nod.", Get_Player_Name_By_ID(ID));
				Console_Input(message);
				//Console_Input(StrFormat("msg You are the only player on Nod.",Get_Player_ID(obj)).c_str();
			}

and put this as the first action (before the if(gdiPlayers < nodPlayers))

Or just leave it out. Why wouldnt the player have rights to swap when he is the only one?

I hope this helped you Wink


http://tiberiumredux.omarpakker.nl/Old Unused Parts/Plaatjes/PromoteBanner_Hades_small.jpg

[Updated on: Sat, 23 January 2010 04:05]

Report message to a moderator

Re: Scripting Help [message #418271 is a reply to message #418187] Sat, 23 January 2010 11:52 Go to previous messageGo to next message
Gen_Blacky is currently offline  Gen_Blacky
Messages: 3250
Registered: September 2006
Karma: 1
General (3 Stars)
thank you I forgot about that I increased the team size. It works now but now if one team has one more player then the other team they can switch teams. How would I check if the other team has 1 more player then the other team. Thats why I originally added
nodPlayers++;
gdiPlayers++;

So if the other team had +1 it wouldn't switch teams.
Then added even teams and one player later.


http://s18.postimage.org/jc6qbn4k9/bricks3.png

[Updated on: Sat, 23 January 2010 11:55]

Report message to a moderator

Re: Scripting Help [message #418277 is a reply to message #418271] Sat, 23 January 2010 13:01 Go to previous messageGo to next message
Omar007 is currently offline  Omar007
Messages: 1711
Registered: December 2007
Location: Amsterdam
Karma: 0
General (1 Star)
Gen_Blacky wrote on Sat, 23 January 2010 19:52

thank you I forgot about that I increased the team size. It works now but now if one team has one more player then the other team they can switch teams. How would I check if the other team has 1 more player then the other team. Thats why I originally added
nodPlayers++;
gdiPlayers++;

So if the other team had +1 it wouldn't switch teams.
Then added even teams and one player later.


if(nodPlayers < gdiPlayers - 1)
{
//dont swap -> nod only has 1 player more
}

if(gdiPlayers < nodPlayers - 1)
{
//dont swap -> gdi only has 1 player more
}


http://tiberiumredux.omarpakker.nl/Old Unused Parts/Plaatjes/PromoteBanner_Hades_small.jpg
Re: Scripting Help [message #418283 is a reply to message #418277] Sat, 23 January 2010 15:20 Go to previous messageGo to next message
Gen_Blacky is currently offline  Gen_Blacky
Messages: 3250
Registered: September 2006
Karma: 1
General (3 Stars)
Omar007 wrote on Sat, 23 January 2010 21:01

Gen_Blacky wrote on Sat, 23 January 2010 19:52

thank you I forgot about that I increased the team size. It works now but now if one team has one more player then the other team they can switch teams. How would I check if the other team has 1 more player then the other team. Thats why I originally added
nodPlayers++;
gdiPlayers++;

So if the other team had +1 it wouldn't switch teams.
Then added even teams and one player later.


if(nodPlayers < gdiPlayers - 1)
{
//dont swap -> nod only has 1 player more
}

if(gdiPlayers < nodPlayers - 1)
{
//dont swap -> gdi only has 1 player more
}


I tired that but it didn't work. I got it working though by checking for the difference. Thanks for the help.

class TeamChangeChatCommand : public ChatCommandClass 
{
	void Triggered(int ID,const TokenClass &Text,int ChatType) 
	{
		if(!PluginSettings->TeamChange){return;}
		GameObject *obj = Get_GameObj(ID);
		int difference = 0;
		int gdiPlayers = (Tally_Team_Size(1));
		int nodPlayers = (Tally_Team_Size(0));
		int team = Get_Object_Type(obj);


		if (team == 1) 
		{
			if (gdiPlayers - nodPlayers )
			{
				difference = gdiPlayers - nodPlayers;
			}
			else if (gdiPlayers == 1)
			{
				Console_Input(StrFormat("ppage %d You are the only player on GDI.",Get_Player_ID(obj)).c_str()); 
			}
			else if (difference == 1)
			{
				char message[256];
				sprintf(message,"msg GDI has only one more player then NOD No need to Switch.", Get_Player_Name_By_ID(ID));
				Console_Input(message);
			}
			else if (nodPlayers == gdiPlayers)
			{
				char message[256];
				sprintf(message,"msg Teams are Even", Get_Player_Name_By_ID(ID));
				Console_Input(message);
			}
			
			else if (nodPlayers < gdiPlayers + 1) 
			{
				printf("Change Team GDI to Nod\n");
				Change_Team_By_ID(ID,0);
				char message[256];
				sprintf(message,"msg Player %s has changed to Team Nod to make the teams even.", Get_Player_Name_By_ID(ID));
				Console_Input(message);
			}
			else 
			{
				char message[256];
				sprintf(message,"msg Sorry GDI doesn't have enough Players!", Get_Player_Name_By_ID(ID));
				Console_Input(message);
			}
	
		}
		if (team == 0) 
		{
			if (nodPlayers == 1)
			{
				Console_Input(StrFormat("ppage %d You are the only player on NOD.",Get_Player_ID(obj)).c_str()); 
			}
			else if (nodPlayers - gdiPlayers  )
			{
				difference = nodPlayers - gdiPlayers;
			}
			if (difference == 1)
			{
				char message[256];
				sprintf(message,"msg Nod has only one more player then GDI No need to Switch.", Get_Player_Name_By_ID(ID));
				Console_Input(message);
			}
			else if (gdiPlayers == nodPlayers)
			{
				char message[256];
				sprintf(message,"msg Teams are Even", Get_Player_Name_By_ID(ID));
				Console_Input(message);
			}
			else if (gdiPlayers < nodPlayers + 1)
			{
				printf("Change Team Nod to GDI\n");
				Change_Team_By_ID (ID,1);
				char message[256];
				sprintf(message,"msg Player %s has changed to Team GDI to make the teams even.", Get_Player_Name_By_ID(ID));
				Console_Input(message);
			}
			else 
			{
				char message[256];
				sprintf(message,"msg Sorry NOD doesn't have enough Players!", Get_Player_Name_By_ID(ID));
				Console_Input(message);
			}
		}
	}
};
ChatCommandRegistrant<TeamChangeChatCommand> TeamChangeChatCommandReg("!TeamChange;!tc;!switch;",CHATTYPE_TEAM,0,GAMEMODE_ALL);


http://s18.postimage.org/jc6qbn4k9/bricks3.png

[Updated on: Sat, 23 January 2010 15:21]

Report message to a moderator

Re: Scripting Help [message #418284 is a reply to message #418187] Sat, 23 January 2010 15:23 Go to previous messageGo to next message
Omar007 is currently offline  Omar007
Messages: 1711
Registered: December 2007
Location: Amsterdam
Karma: 0
General (1 Star)
My way will only work if you put it on top if the else-if stack Wink

But your way is good too Thumbs Up


http://tiberiumredux.omarpakker.nl/Old Unused Parts/Plaatjes/PromoteBanner_Hades_small.jpg
Re: Scripting Help [message #418326 is a reply to message #418187] Sat, 23 January 2010 22:18 Go to previous messageGo to next message
Gen_Blacky is currently offline  Gen_Blacky
Messages: 3250
Registered: September 2006
Karma: 1
General (3 Stars)
Im making a plugin and im trying to attach no falling damage script to players but its not working. Am I attaching the script to the player obj correctly.

void ObjectHookCall(void *data,GameObject *obj) {
	if(!PluginSettings->CreditSystem){return;}
		if(Commands->Is_A_Star(obj)){
			//Attach_Script_Once(obj,"Money","");
			int PlayerID;
			PlayerID = Get_Player_ID(obj);
			printf("Player Money Added\n");
			Set_Money(PlayerID,0);
			Commands->Give_Money(obj,1000,false);
		}
	if(!PluginSettings->NoFallingDamage){return;}
		if(Commands->Is_A_Star(obj)){
			Attach_Script_Once(obj,"M00_No_Falling_Damage_DME","0");
			printf("No Damge Script Attached\n");
		}
	if(!PluginSettings->DropItem){return;}
		if(Commands->Is_A_Star(obj)){
				Attach_Script_Once(obj,"Player","");
				printf("Player Script Aattached\n");
		}
	if(!PluginSettings->NoReload){return;}
		Attach_Script_Once(obj,"NoReload","");
}




http://s18.postimage.org/jc6qbn4k9/bricks3.png
Re: Scripting Help [message #418341 is a reply to message #418187] Sun, 24 January 2010 03:38 Go to previous messageGo to next message
Omar007 is currently offline  Omar007
Messages: 1711
Registered: December 2007
Location: Amsterdam
Karma: 0
General (1 Star)
Well idk if the setting Credit System is put on 'false' because if it is it will break off your whole code (return; Wink )

Why not do:
if(PluginSettings->CreditSystem && Commands->Is_A_Star(obj)){
        //Attach_Script_Once(obj,"Money","");
	int PlayerID;
	PlayerID = Get_Player_ID(obj);
	printf("Player Money Added\n");
	Set_Money(PlayerID,0);
	Commands->Give_Money(obj,1000,false);
}

Same for the others ofcource:
if(PluginSettings->NoFallingDamage && Commands->Is_A_Star(obj)){
			Attach_Script_Once(obj,"M00_No_Falling_Damage_DME","0");
	printf("No Damge Script Attached\n");
}

if(PluginSettings->DropItem && Commands->Is_A_Star(obj)){
				Attach_Script_Once(obj,"Player","");
		printf("Player Script Aattached\n");
}
if(PluginSettings->NoReload)
{
	Attach_Script_Once(obj,"NoReload","");
}


http://tiberiumredux.omarpakker.nl/Old Unused Parts/Plaatjes/PromoteBanner_Hades_small.jpg

[Updated on: Sun, 24 January 2010 03:42]

Report message to a moderator

Re: Scripting Help [message #418362 is a reply to message #418187] Sun, 24 January 2010 12:07 Go to previous messageGo to next message
Gen_Blacky is currently offline  Gen_Blacky
Messages: 3250
Registered: September 2006
Karma: 1
General (3 Stars)
yea i didn't really think about that thank works now.

http://s18.postimage.org/jc6qbn4k9/bricks3.png
Re: Scripting Help [message #418391 is a reply to message #418187] Sun, 24 January 2010 16:47 Go to previous messageGo to next message
Gen_Blacky is currently offline  Gen_Blacky
Messages: 3250
Registered: September 2006
Karma: 1
General (3 Stars)
how would I block the refinery building controller credit tick rate? or change the refinery tick rate in c++? do I have to make a hook for the refinery building controller?

http://s18.postimage.org/jc6qbn4k9/bricks3.png

[Updated on: Sun, 24 January 2010 16:50]

Report message to a moderator

Re: Scripting Help [message #418449 is a reply to message #418187] Mon, 25 January 2010 14:50 Go to previous messageGo to next message
Gen_Blacky is currently offline  Gen_Blacky
Messages: 3250
Registered: September 2006
Karma: 1
General (3 Stars)
I made this Team change message system and Force team change if teams have 3 or more players. It works but is it proper to attach it to the level load hook.


void tctimer::Created(GameObject *obj){
	Commands->Start_Timer(obj,this,30.0f,1);
	Commands->Start_Timer(obj,this,200.0f,2);
	Commands->Start_Timer(obj,this,8.0f,3);
}


void tctimer::Timer_Expired(GameObject *obj,int number){
	if(PluginSettings->TeamChange)
	{
		//printf("TC Timer Expired\n");
		int difference = 0;
		int gdiPlayers = (Tally_Team_Size(1));
		int nodPlayers = (Tally_Team_Size(0));
		int teamnod = 0;
		int teamgdi = 1;
		GameObject *ato = Find_First_Player(teamnod);
		GameObject *ato2 = Find_First_Player(teamgdi);
		int ID = Get_Player_ID(ato);
		int ID2 = Get_Player_ID(ato2);
		if (gdiPlayers - nodPlayers )
		{
			difference = gdiPlayers - nodPlayers;
			//printf("Player difference %d\n",difference);
		}
		if(number == 1)
		{
			if (difference >= 2)
			{
				Console_Input(StrFormat("msg Use the Team Change Chat Comamnd !tc to switch Teams").c_str());
			}
			if (difference <= -2)
			{
				Console_Input(StrFormat("msg Use the Team Change Chat Comamnd !tc to switch Teams").c_str());
			}
			Commands->Start_Timer(obj,this,30.0f,1);
		}
		else if(number == 2)
		{
			if (difference >= 2)
			{
				Console_Input(StrFormat("msg What are you doing idiots Even The Teams.").c_str());
			}
			if (difference <= -2)
			{
				Console_Input(StrFormat("msg What are you doing idiots Even The Teams.").c_str());
			}
			Commands->Start_Timer(obj,this,200.0f,2);
		}
		//auto switch
		else if(number == 3)
		{
			if (difference <= -3)
			{
				Change_Team_By_ID(ID,1);
				Console_Input(StrFormat("msg Force Team Change Engaged %s Switched to team GDI ",Get_Player_Name_By_ID(ID)).c_str());
			}
			if (difference >= 3)
			{
				Change_Team_By_ID(ID2,0);
				Console_Input(StrFormat("msg Force Team Change Engaged %s Switched to team Nod ",Get_Player_Name_By_ID(ID2)).c_str());
			}
			Commands->Start_Timer(obj,this,15.0f,3);
		}
	}
}


extern "C" {
	DLLEXPORT void SSGM_Level_Loaded_Hook() {
		PluginSettings->Load();
		if(PluginSettings->TeamChange)
		{
			GameObject *temp = Commands->Create_Object("Invisible_Object",Vector3(0.0f,0.0f,0.0f));
			Commands->Attach_Script(temp,"tctimer","");
		}
	}
}


http://s18.postimage.org/jc6qbn4k9/bricks3.png
Re: Scripting Help [message #418451 is a reply to message #418187] Mon, 25 January 2010 15:31 Go to previous messageGo to next message
cAmpa is currently offline  cAmpa
Messages: 597
Registered: March 2006
Karma: 0
Colonel
Wtf are u doing.

Bückstabü!
Re: Scripting Help [message #418453 is a reply to message #418187] Mon, 25 January 2010 15:55 Go to previous messageGo to next message
Sladewill is currently offline  Sladewill
Messages: 291
Registered: January 2009
Location: United Kingdom
Karma: 0
Recruit

messy, many why not check on players join and leave event, then the teams will always be even and will not need checking.

FT-Owners - Sladewill,Snazy2007,Willdy
http://FT-Gaming.com for more info...
Re: Scripting Help [message #418626 is a reply to message #418451] Wed, 27 January 2010 07:06 Go to previous messageGo to next message
Hex is currently offline  Hex
Messages: 858
Registered: March 2004
Karma: 0
Colonel
cAmpa wrote on Mon, 25 January 2010 22:31

Wtf are u doing.


qtt


goztow wrote on Tue, 11 May 2010 08:00

If we had to ban all who ever cheated or ever created a cheat (obj3cts and such) then I don't think there would be many members left here (sad fact).


reborn wrote on Fri, 29 January 2010 23:37

std is for pro's. Razz
Re: Scripting Help [message #418628 is a reply to message #418449] Wed, 27 January 2010 07:34 Go to previous messageGo to next message
reborn is currently offline  reborn
Messages: 3231
Registered: September 2004
Location: uk - london
Karma: 0
General (3 Stars)
I'm pretty sure he is trying to make a team balance plug-in, but the code is flawed.
If I was you, I would change the system to work on the player join and player leave event. This way, you can do away with the timer event checks.
Also, if you are auto team changing people because they have not used your team change chat command (which by the way should have a conditional check on a global boolean that is set by the code you'll write on the join/leave events) then really instead of just choosing the first dude on the team, have a bit of logic to who is switched... Base it on game duration time, score, kills or something like that.
If you need help with this, please say so.



Re: Scripting Help [message #418658 is a reply to message #418187] Wed, 27 January 2010 11:09 Go to previous messageGo to next message
Gen_Blacky is currently offline  Gen_Blacky
Messages: 3250
Registered: September 2006
Karma: 1
General (3 Stars)
I tested it in all possible scenarios and it works without problems but I guess its kind of crazy to have 3 timers consistently running. It just warns players that there are more then 2 people on another team and if for some reason the teams get more then 3 it auto switches the last person who joined the team with more players. I couldn't think of better way to check the teams. If you are willing to help please do so. Everyone told me to do the same thing as you have but im not sure what to check for.

http://s18.postimage.org/jc6qbn4k9/bricks3.png
Re: Scripting Help [message #418702 is a reply to message #418187] Wed, 27 January 2010 17:52 Go to previous messageGo to next message
reborn is currently offline  reborn
Messages: 3231
Registered: September 2004
Location: uk - london
Karma: 0
General (3 Stars)
Tell me if this works, I have not tested it... If it does, then I'll release it properly...

TeamReBalancer.ccp
#include "scripts.h"
#include <stdarg.h>
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
#include "engine.h"
#include "gmmain.h"
#include "TeamReBalancer.h"

trbSettingsStruct *trbSettings = 0;
bool maploading, cannodchange, cangdichange = false;
int gdiflag, nodflag = 0;

void trbSettingsStruct::Load() {
	SettingsLoader::Load();
LoadInt(min,"MinimumPlayerDifferential");
LoadInt(time,"TimeAllowedForVolunteer");
}




void Plugin_Load() {
	trbSettings = new trbSettingsStruct("teamrebalancer.ini");
}
// Our own get team player count function, as the existing one is actually broken...
int reb_Get_Team_Player_Count(int Team)
{
	int Total = 0;
	GenericSLNode *x = BaseGameObjList->HeadNode;
	while (x)
	{
		GameObject *o = (GameObject *)x->NodeData;
		if (o && Commands->Is_A_Star(o))
		{
			if (Get_Team(Get_Player_ID(o)) == Team)
			{
			Total++;
		}
		}
		x = x->NodeNext;
	}
	return Total;
}




void Plugin_Unload() {
	delete trbSettings;
}

void reteam(){
	if(maploading == false){ // Make sure the map isn't loading
		// Get the team sizes
		int gdisize = reb_Get_Team_Player_Count(1);
		int nodsize = reb_Get_Team_Player_Count(0);
			if(nodsize - gdisize >= trbSettings->min || gdisize - nodsize >= trbSettings->min){ 
				// One team has more than the allowed differential
				if(nodsize > gdisize){ // Need to move a Nod player to GDI
					if(cannodchange == true){ 
						// means there is already a need rebalance, so sets a flag to make sure the old timer doesn't cut off the new one
						nodflag++;
					}
					cannodchange = true;
					GameObject *thingy = Commands->Create_Object("Invisible_Object",Vector3(0.0f,0.0f,0.0f));
					Commands->Attach_Script(thingy,"g_volunteer_timer","");
					Console_Input(StrFormat("msg Nod have more players on their team than the server owner deems to be fair, if you're on team Nod and want to change teams, please type \"!balance\". Nod players have %i seconds to volunteer before the server chooses a player for them.", trbSettings->time).c_str());
				}
				else{ // Need to move a GDI player to Nod
					if(cangdichange == true){ 
						// means there is already a need rebalance, so sets a flag to make sure the old timer doesn't cut off the new one
						gdiflag++;
					}
					cangdichange = true;
					GameObject *thingy = Commands->Create_Object("Invisible_Object",Vector3(0.0f,0.0f,0.0f));
					Commands->Attach_Script(thingy,"n_volunteer_timer","");
					Console_Input(StrFormat("msg GDI have more players on their team than the server owner deems to be fair, if you're on team GDI and want to change teams, please type \"!balance\". GDI players have %i seconds to volunteer before the server chooses a player for them.", trbSettings->time).c_str());
				}
			}
	}
	else{
		// Nothing, the map is loading so don't fuck up the player stats board at the end of the map.
		// I only included this else to show you why I made the conditional in the first place really.
	}
}

void g_volunteer_timer::Created(GameObject *obj){
	Commands->Start_Timer(obj,this,(float)trbSettings->time,1);
}

void g_volunteer_timer::Timer_Expired(GameObject *obj,int number){
	if(number == 1){
		if(gdiflag == 0){ //make sure this is the only active timer, so as not to stop a later one prematurely.
			if(cangdichange == true){ // make sure no one has volunteered already using the chat command
				int iterations = 0;
				int score = 0;
				GameObject *volunteer;
			GenericSLNode *x = BaseGameObjList->HeadNode;
			while (x){
				GameObject *o = (GameObject *)x->NodeData;
				if (o && Commands->Is_A_Star(o) && Get_Team(Get_Player_ID(o)) == 1){
					if(iterations == 0){
						score = (int)Get_Score(Get_Player_ID(o));
						volunteer = o;
					}
					else{
						int newscore = (int)Get_Score(Get_Player_ID(o));
							if(newscore < score){
								score = newscore;
								volunteer = o;
							}
						}
					}
					iterations++;
					x = x->NodeNext;
				}
			Change_Player_Team(volunteer,false,false,true);
			}
			cangdichange = false;
			reteam();
		}
		gdiflag--;
	}
}

ScriptRegistrant<g_volunteer_timer> g_volunteer_timer_Registrant("g_volunteer_timer","");

void n_volunteer_timer::Created(GameObject *obj){
	Commands->Start_Timer(obj,this,(float)trbSettings->time,1);
}

void n_volunteer_timer::Timer_Expired(GameObject *obj,int number){
	if(number == 1){
		if(nodflag == 0){ //make sure this is the only active timer, so as not to stop a later one prematurely.
			if(cannodchange == true){ // make sure no one has volunteered already using the chat command
				int iterations = 0;
				int score = 0;
				GameObject *volunteer;
			GenericSLNode *x = BaseGameObjList->HeadNode;
			while (x){
				GameObject *o = (GameObject *)x->NodeData;
				if (o && Commands->Is_A_Star(o) && Get_Team(Get_Player_ID(o)) == 0){
					if(iterations == 0){
						score = (int)Get_Score(Get_Player_ID(o));
						volunteer = o;
					}
					else{
						int newscore = (int)Get_Score(Get_Player_ID(o));
							if(newscore < score){
								score = newscore;
								volunteer = o;
							}
						}
					}
					iterations++;
					x = x->NodeNext;
			}
			Change_Player_Team(volunteer,false,false,true);
			}
			cannodchange = false;
			reteam();
		}
		nodflag--;
	}
}

ScriptRegistrant<n_volunteer_timer> n_volunteer_timer_Registrant("n_volunteer_timer","");


class balanceChatCommand : public ChatCommandClass {
	void Triggered(int ID,const TokenClass &Text,int ChatType){
		int team = Get_Team(ID);
		if(team == 1 && cangdichange == true){
			Change_Player_Team(Get_GameObj(ID),false,false,true);
			Console_Input(StrFormat("msg Player %s has changed teams to rebalance the game.",Get_Player_Name(Get_GameObj(ID))).c_str());
			Console_Input(StrFormat("ppage %d You have volunteered to balance the game and changed teams.",ID).c_str());
			cangdichange = false;
			reteam();
		}
		else if(team == 0 && cannodchange == true){
			Change_Player_Team(Get_GameObj(ID),false,false,true);
			Console_Input(StrFormat("msg Player %s has changed teams to rebalance the game.",Get_Player_Name(Get_GameObj(ID))).c_str());
			Console_Input(StrFormat("ppage %d You have volunteered to balance the game and changed teams.",ID).c_str());
			cannodchange = false;
			reteam();
		}
		else{
			Console_Input(StrFormat("ppage %d You do not need to balance the teams right now.",ID).c_str());
		}
	}
};
ChatCommandRegistrant<balanceChatCommand> balanceChatCommandReg("!Balance;!balance;!BALANCE",CHATTYPE_ALL,0,GAMEMODE_ALL);

extern "C" {



DLLEXPORT void SSGM_Player_Leave_Hook(int ID) {
reteam();
}


DLLEXPORT void SSGM_Player_Join_Hook(int ID, const char *Nick) {
	int gdisize = reb_Get_Team_Player_Count(1);
	int nodsize = reb_Get_Team_Player_Count(0);
	if(nodsize - gdisize < trbSettings->min && cannodchange == true){ 
		cannodchange = false;
		Console_Input(StrFormat("msg Nod's team no longer needs balancing now that %s has joined.", Nick).c_str());
	}
	else if(gdisize - nodsize < trbSettings->min && cangdichange == true){
		cangdichange = false;
		Console_Input(StrFormat("msg GDI's team no longer needs balancing now that %s has joined.", Nick).c_str());
	}
}

DLLEXPORT void SSGM_Level_Loaded_Hook() {
	trbSettings->Load();
maploading, cangdichange, cannodchange = false;
gdiflag, nodflag = 0;
}

DLLEXPORT void SSGM_GameOver_Hook() {
maploading = true;
}


}


TeamReBalancer.h
#include "gmsettingsclass.h"

#define PluginName "reborn's team rebalancer plugin"
#define PluginVersion "1.0"

struct trbSettingsStruct : public virtual SettingsLoader {
	trbSettingsStruct(const char *ININame) : SettingsLoader(ININame) {
		min = 0;
		time = 30;
	}

	void Load();
	int min, time;
};

void Plugin_Load();

int reb_Get_Team_Player_Count(int Team);

void reteam();

class g_volunteer_timer : public ScriptImpClass {
	void Created(GameObject *obj);
	void Timer_Expired(GameObject *obj,int number);
};

class n_volunteer_timer : public ScriptImpClass {
	void Created(GameObject *obj);
	void Timer_Expired(GameObject *obj,int number);
};

void Plugin_Unload();



teamrebalancer.ini
Quote:


[General]

; This plugin is designed to rebalance teams when players leave and cause an imbalance.

; This setting defines how many more players on One team must a side have before the code takes effect.
; DO NOT set this to 0! The default is 2, and that's a good number, I wouldn't set it any lower.
MinimumPlayerDifferential = 2

; This setting defines how long a team has to volunteer to !balance before the server does it for them. The time is in seconds.
TimeAllowedForVolunteer = 30




Re: Scripting Help [message #418724 is a reply to message #418187] Thu, 28 January 2010 02:44 Go to previous messageGo to next message
Hex is currently offline  Hex
Messages: 858
Registered: March 2004
Karma: 0
Colonel
std biatch Razz

goztow wrote on Tue, 11 May 2010 08:00

If we had to ban all who ever cheated or ever created a cheat (obj3cts and such) then I don't think there would be many members left here (sad fact).


reborn wrote on Fri, 29 January 2010 23:37

std is for pro's. Razz
Re: Scripting Help [message #418747 is a reply to message #418724] Thu, 28 January 2010 10:31 Go to previous messageGo to next message
raven
Messages: 595
Registered: January 2007
Location: Toronto, Ontario
Karma: 0
Colonel
Hex wrote on Thu, 28 January 2010 03:44

std biatch Razz


you can't talk! you used to be one too


-Jelly Administrator
-Exodus Administrator
Re: Scripting Help [message #418821 is a reply to message #418187] Fri, 29 January 2010 16:37 Go to previous messageGo to next message
reborn is currently offline  reborn
Messages: 3231
Registered: September 2004
Location: uk - london
Karma: 0
General (3 Stars)
std is for pro's. Razz


GenBlacky, did it work you bugger? I wanted to release this based on your feed-back. Smile



Re: Scripting Help [message #418824 is a reply to message #418187] Fri, 29 January 2010 17:52 Go to previous messageGo to previous message
Gen_Blacky is currently offline  Gen_Blacky
Messages: 3250
Registered: September 2006
Karma: 1
General (3 Stars)
you got an error

error C2220: warning treated as error - no 'executable' file generated

warning C4701: potentially uninitialized local variable 'volunteer' used

warning C4701: potentially uninitialized local variable 'volunteer' used

"Change_Player_Team(volunteer,false,false,true);"

I changed it but it still didn't work. Cool Idea for a teamchange system. I want mine to work differently but thanks for sharing your code. now that that I understand what everyone was talking about the "join and leave hook events" I can make mine work differently so it doesn't use a timer.

  • Attachment: reborn.jpg
    (Size: 365.26KB, Downloaded 40 times)


http://s18.postimage.org/jc6qbn4k9/bricks3.png
Previous Topic: how to add startup spawners and spawners etc!!! help!
Next Topic: Cables of the transport.
Goto Forum:
  


Current Time: Thu May 23 12:02:15 MST 2024

Total time taken to generate the page: 1.47620 seconds