Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Forum » Write to ini with Kill script using player's nick and join function not working right
Write to ini with Kill script using player's nick and join function not working right [message #379208] Wed, 08 April 2009 00:58 Go to next message
whtdrgnpl is currently offline  whtdrgnpl
Messages: 17
Registered: July 2007
Karma: 0
Recruit
Well first off about the ssgm join function it's not forcing me to Nod, I set it to team all commanders to nod but when I joined I was either GDI or Nod Huh but it does display that they are a commander. This is the script:

DLLEXPORT void SSGM_Player_Join_Hook(int ID, const char *Nick) {
	   DWORD WINAPI GetPrivateProfileString(
      __in   LPCTSTR lpAppName,
      __in   LPCTSTR lpKeyName,
      __in   LPCTSTR lpDefault,
      __out  LPTSTR lpReturnedString,
      __in   DWORD nSize,
      __in   LPCTSTR lpFileName
   );
   BOOL WINAPI WritePrivateProfileString(
      __in  LPCTSTR lpAppName,
      __in  LPCTSTR lpKeyName,
      __in  LPCTSTR lpString,
      __in  LPCTSTR lpFileName
   );
   char side[256];
   Console_Input(StrFormat("msg Welcome to whtdrgnpl's RTS [Beta Test Server], %s. Type !commands for extra commands.",Nick).c_str());
   GetPrivateProfileString("Profession", Nick, "commander", side, 256, "C:\\westwood\\RenegadeFDS\\Server\\Professions.ini");
   if (strncmp(side,"commander",3)==0) {
     Console_Input(StrFormat("team2 %d 0",ID).c_str());
     Console_Input(StrFormat("msg %s is a commander",Nick).c_str());
   }
   else{
	if (strncmp(side,"mercenary",3)==0) {
		Console_Input(StrFormat("team2 %d -1",ID).c_str());
		Console_Input(StrFormat("msg %s is a merc",Nick).c_str());
	}
	else{
		if (strncmp(side,"militia",3)==0) {
			Console_Input(StrFormat("team2 %d 1",ID).c_str());
			Console_Input(StrFormat("msg %s is in the militia",Nick).c_str());
		}
		else {
			Console_Input(StrFormat("team2 %d -2",ID).c_str());
			Console_Input(StrFormat("msg %s has no profession",Nick).c_str());
			}
	}
   }
}


the merc one works though and I'm pretty sure the no profession one does too though I haven't tested it... haven't tested militia either :/ but ya Commander doesn't force em to Nod for some odd reason....

Ok, about the Kill script, I thought I might have found a way to make it get the original owners nick by doing this:

In the chat command I made it write to an ini like this:

Builder.ini
[Builder]
123124=whtdrgnpl


That works fine. Then on the timer it reads that by finding the ID of the object it's attached to in the ini file to get the nickname and write to 2 ini files like this:

ID1
[BuildingID]
2131224=whtdrgnpl


ID2
[BuildingID]
2131224=NCY


then on a single kill script it would read those 2 ini files to get who built it and what the building is so it can write to the main buildings.ini file to subtract 1 from it when it dies so if I had only one cy then it dies the buildings.ini for NCY would be this:

[whtdrgnpl]
NCY=0


but the problem is the timer and kill script parts aren't retrieving any of the info and they're just writing a blank entry where my nick should be and on the kill script it writes a blank entry where my nick and NYC should be. Here's the timer and kill scripts:

Timer:
void NodCYTimer::Timer_Expired(GameObject *obj, int number) {
	DWORD WINAPI GetPrivateProfileString(
	__in   LPCTSTR lpAppName,
	__in   LPCTSTR lpKeyName,
	__in   LPCTSTR lpDefault,
	__out  LPTSTR lpReturnedString,
	__in   DWORD nSize,
	__in   LPCTSTR lpFileName
	);
	BOOL WINAPI WritePrivateProfileString(
	__in  LPCTSTR lpAppName,
	__in  LPCTSTR lpKeyName,
	__in  LPCTSTR lpString,
	__in  LPCTSTR lpFileName
	);
	char ncyid[16];
	sprintf(ncyid, "%d", Commands->Get_ID(obj));
	Vector3 position;
	position = Commands->Get_Position(obj);
		if (number == 1){
			position.Z += 1.0f;
			GameObject *ncy = Commands->Create_Object("Invisible_Object",position);
			Commands->Set_Model(ncy, "enc_ncon");
			Commands->Set_Player_Type(ncy,0);
			Commands->Attach_Script(ncy,"NodCYBuildupTimer","");
		}
		if (number == 2){
			position.Z += 2.0f;
			GameObject *ncy = Commands->Create_Object("Invisible_Object",position);
			Commands->Set_Model(ncy, "enc_ncon");
			Commands->Set_Player_Type(ncy,0);
			Commands->Attach_Script(ncy,"NodCYBuildupTimer","");
		}
		if (number == 3){
			position.Z += 3.0f;
			GameObject *ncy = Commands->Create_Object("Invisible_Object",position);
			Commands->Set_Model(ncy, "enc_ncon");
			Commands->Set_Player_Type(ncy,0);
			Commands->Attach_Script(ncy,"NodCYBuildupTimer","");
		}
		if (number == 4){
			position.Z += 4.0f;
			GameObject *ncy = Commands->Create_Object("Invisible_Object",position);
			Commands->Set_Model(ncy, "enc_ncon");
			Commands->Set_Player_Type(ncy,0);
			Commands->Attach_Script(ncy,"NodCYBuildupTimer","");
		}
		if (number == 5){
			position.Z += 5.0f;
			GameObject *ncy = Commands->Create_Object("Invisible_Object",position);
			Commands->Set_Model(ncy, "enc_ncon");
			Commands->Set_Player_Type(ncy,0);
			Commands->Attach_Script(ncy,"NodCYBuildupTimer","");
		}
		if (number == 6){
			position.Z += 6.0f;
			GameObject *ncy = Commands->Create_Object("Invisible_Object",position);
			Commands->Set_Model(ncy, "enc_ncon");
			Commands->Set_Player_Type(ncy,0);
			Commands->Attach_Script(ncy,"NodCYBuildupTimer","");
		}
		if (number == 7){
			position.Z += 7.0f;
			GameObject *ncy = Commands->Create_Object("Invisible_Object",position);
			Commands->Set_Model(ncy, "enc_ncon");
			Commands->Set_Player_Type(ncy,0);
			Commands->Attach_Script(ncy,"NodCYBuildupTimer","");
		}
		if (number == 8){
			position.Z += 8.0f;
			GameObject *ncy = Commands->Create_Object("Invisible_Object",position);
			Commands->Set_Model(ncy, "enc_ncon");
			Commands->Set_Player_Type(ncy,0);
			Commands->Attach_Script(ncy,"NodCYBuildupTimer","");
		}
		if (number == 9){
			position.Z += 9.0f;
			GameObject *ncy = Commands->Create_Object("Invisible_Object",position);
			Commands->Set_Model(ncy, "enc_ncon");
			Commands->Set_Player_Type(ncy,0);
			Commands->Attach_Script(ncy,"NodCYBuildupTimer","");
		}
		if (number == 10){
			position.Z += 10.0f;
			GameObject *ncy = Commands->Create_Object("Invisible_Object",position);
			Commands->Set_Model(ncy, "enc_ncon");
			Commands->Set_Player_Type(ncy,0);
			Commands->Attach_Script(ncy,"NodCYBuildupTimer","");
		}
		if (number == 11){
			position.Z += 11.0f;
			GameObject *ncy = Commands->Create_Object("Invisible_Object",position);
			Commands->Set_Model(ncy, "enc_ncon");
			Commands->Set_Player_Type(ncy,0);
			Commands->Attach_Script(ncy,"NodCYBuildupTimer","");
		}
		if (number == 12){
			position.Z += 11.0f;
			GameObject *ncy = Commands->Create_Object("Invisible_Object",position);
			Commands->Set_Model(ncy, "enc_ncon");
			Commands->Set_Player_Type(ncy,0);
			Commands->Attach_Script(ncy,"NodCYBuildupTimer","");
		}
		if (number == 13){
			char *lpBuff = new char[256];
			char pName[256];
			GetPrivateProfileString("Builder", ncyid, "", lpBuff, 256, "C:\\westwood\\RenegadeFDS\\Server\\Builder.ini");
			char *lpBuff2 = new char[257];
			GetPrivateProfileString("BuildingID", "nick", pName, lpBuff2, 257, "C:\\westwood\\RenegadeFDS\\Server\\ID1.ini");
			char *lpBuff3 = new char[258];
			GetPrivateProfileString("BuildingID2", pName, "nick", lpBuff3, 258, "C:\\westwood\\RenegadeFDS\\Server\\ID2.ini");
			position.Z += 12.0f;
			GameObject *ncy = Commands->Create_Object("GDI Gunboat",position);
			Commands->Set_Model(ncy, "enc_ncon");
			Commands->Attach_Script(ncy,"Killed_Building_Script","");
			char ncyid2[16];
			sprintf(ncyid2, "%d", Commands->Get_ID(ncy));
			WritePrivateProfileString("BuildingID", ncyid2, pName,"C:\\westwood\\RenegadeFDS\\Server\\ID1.ini");
			WritePrivateProfileString("BuildingID2", ncyid2, "NCY","C:\\westwood\\RenegadeFDS\\Server\\ID2.ini");
			Commands->Set_Player_Type(ncy,0);
			Console_Input("snda m00bgwf_dsgn0004i1evag_snd.wav");
			Commands->Destroy_Object(obj);
		}
}


Kill Script:
void Killed_Building_Script::Killed(GameObject *obj, GameObject *shooter){
	DWORD WINAPI GetPrivateProfileString(
	__in   LPCTSTR lpAppName,
	__in   LPCTSTR lpKeyName,
	__in   LPCTSTR lpDefault,
	__out  LPTSTR lpReturnedString,
	__in   DWORD nSize,
	__in   LPCTSTR lpFileName
	);
	BOOL WINAPI WritePrivateProfileString(
	__in  LPCTSTR lpAppName,
	__in  LPCTSTR lpKeyName,
	__in  LPCTSTR lpString,
	__in  LPCTSTR lpFileName
	);
	char *lpBuff = new char[256];
	int newamount = 1;
    int num = atoi(lpBuff);
    num -=  newamount;
    char buffer[50];
	char buildingid[16];
	sprintf(buildingid, "%d", Commands->Get_ID(obj));
    sprintf(buffer,"%d",num);
	char pName[256];
	GetPrivateProfileString("BuilderID", buildingid, "nick", lpBuff, 256, "C:\\westwood\\RenegadeFDS\\Server\\ID1.ini");
	char *lpBuff2 = new char[257];
	char building[257];
	GetPrivateProfileString("BuildingID2", buildingid, "N", lpBuff2, 257, "C:\\westwood\\RenegadeFDS\\Server\\ID2.ini");
	char *lpBuff3 = new char[258];
	GetPrivateProfileString(pName, building, "0", lpBuff3, 258, "C:\\westwood\\RenegadeFDS\\Server\\Buildings.ini");
	WritePrivateProfileString(pName, building, buffer, "C:\\westwood\\RenegadeFDS\\Server\\Buildings.ini");
}
ScriptRegistrant<Killed_Building_Script> Killed_Building_Script_Registrant("Killed_Building_Script","");

So is there anyway of fixing this? or do I have to do that a different way? It doesn't make much sense that this wouldn't work though seeing as how the
if (strncmp(side,"commander",3)==0) {
code works fine O.o

[Updated on: Wed, 08 April 2009 01:00]

Report message to a moderator

Re: Write to ini with Kill script using player's nick and join function not working right [message #379224 is a reply to message #379208] Wed, 08 April 2009 04:11 Go to previous messageGo to next message
jnz is currently offline  jnz
Messages: 3396
Registered: July 2006
Location: 30th century
Karma: 0
General (3 Stars)
Quote:


void Killed_Building_Script::Killed(GameObject *obj, GameObject *shooter){
       /*********why were those functions decs there? (compile error)***********/
	char *lpBuff = new char[256]; //MEMORY LEAK why even use the heap? use the stack instead (char lpBuff[256])
	int newamount = 1;
    int num = atoi(lpBuff); //USE OF UNINITIALIZED MEMORY (crash?)
    num -=  newamount;
    char buffer[50];
	char buildingid[16];
	sprintf(buildingid, "%d", Commands->Get_ID(obj)); //use %u for unsigned
    sprintf(buffer,"%d",num);
	char pName[256];
	GetPrivateProfileString("BuilderID", buildingid, "nick", lpBuff, 256, "C:\\westwood\\RenegadeFDS\\Server\\ID1.ini");
	char *lpBuff2 = new char[257]; //MEMORY LEAK why even use the heap? use the stack instead (char lpBuff2[256])
	char building[257];
	GetPrivateProfileString("BuildingID2", buildingid, "N", lpBuff2, 257, "C:\\westwood\\RenegadeFDS\\Server\\ID2.ini");
	char *lpBuff3 = new char[258]; //MEMORY LEAK why even use the heap? use the stack instead (char lpBuff3[256])
	GetPrivateProfileString(pName, building, "0", lpBuff3, 258, "C:\\westwood\\RenegadeFDS\\Server\\Buildings.ini"); //USE OF UNITIALIZED MEMORY (building)
	WritePrivateProfileString(pName, building, buffer, "C:\\westwood\\RenegadeFDS\\Server\\Buildings.ini"); //USE OF UNINITIALIZED MEMORY (building) 
}
ScriptRegistrant<Killed_Building_Script> Killed_Building_Script_Registrant("Killed_Building_Script","");




Re: Write to ini with Kill script using player's nick and join function not working right [message #379225 is a reply to message #379208] Wed, 08 April 2009 04:13 Go to previous messageGo to next message
jnz is currently offline  jnz
Messages: 3396
Registered: July 2006
Location: 30th century
Karma: 0
General (3 Stars)
if (strncmp(side,"commander",3)==0) {


This is also wrong, you can comparing "com" with side, not "commander".

Use
if(strcmp(side, "commander") == 0)
{
Re: Write to ini with Kill script using player's nick and join function not working right [message #379333 is a reply to message #379208] Wed, 08 April 2009 23:10 Go to previous messageGo to next message
whtdrgnpl is currently offline  whtdrgnpl
Messages: 17
Registered: July 2007
Karma: 0
Recruit
Still not forcing everyone to nod :/ and the ini's are still doing the samething.... only now the kill script writes it like this now

[Üþ]
Ü=-1

lol.... wtf o.O and ID1 still writes a blank name :/

also lol I put those functions decs there cause I thought I needed to Razz but thanks for that though
Re: Write to ini with Kill script using player's nick and join function not working right [message #379340 is a reply to message #379208] Wed, 08 April 2009 23:55 Go to previous messageGo to next message
jnz is currently offline  jnz
Messages: 3396
Registered: July 2006
Location: 30th century
Karma: 0
General (3 Stars)
If you fixed all that stuff that I commented then it would probably work.
Re: Write to ini with Kill script using player's nick and join function not working right [message #379342 is a reply to message #379208] Thu, 09 April 2009 01:02 Go to previous messageGo to next message
whtdrgnpl is currently offline  whtdrgnpl
Messages: 17
Registered: July 2007
Karma: 0
Recruit
Well I fixed all but these
Quote:

int num = atoi(lpBuff); //USE OF UNINITIALIZED MEMORY (crash?)
GetPrivateProfileString(pName, building, "0", lpBuff3, 256, "C:\\westwood\\RenegadeFDS\\Server\\Buildings.ini"); //USE OF UNITIALIZED MEMORY (building)
WritePrivateProfileString(pName, building, buffer, "C:\\westwood\\RenegadeFDS\\Server\\Buildings.ini"); //USE OF UNINITIALIZED MEMORY (building)
}

I don't get what's uninitialized on the first one Dont Get It and isn't building initialized here? O.o
char building[256];
GetPrivateProfileString("BuildingID2", buildingid, "N", lpBuff2, 256, "C:\\westwood\\RenegadeFDS\\Server\\ID2.ini")
Re: Write to ini with Kill script using player's nick and join function not working right [message #379350 is a reply to message #379208] Thu, 09 April 2009 05:08 Go to previous messageGo to next message
jnz is currently offline  jnz
Messages: 3396
Registered: July 2006
Location: 30th century
Karma: 0
General (3 Stars)
Highlight the part of this line:

GetPrivateProfileString("BuildingID2", buildingid, "N", lpBuff2, 256, "C:\\westwood\\RenegadeFDS\\Server\\ID2.ini")


Where "building" is passed to it.
Re: Write to ini with Kill script using player's nick and join function not working right [message #379375 is a reply to message #379208] Thu, 09 April 2009 12:41 Go to previous messageGo to next message
whtdrgnpl is currently offline  whtdrgnpl
Messages: 17
Registered: July 2007
Karma: 0
Recruit
Ok I found I forgot to change the 257 to 256 lol oops I changed it but now instead of that U it's writing a square where the NCY should be... Want me to post the updated script?
Re: Write to ini with Kill script using player's nick and join function not working right [message #379386 is a reply to message #379350] Thu, 09 April 2009 15:51 Go to previous messageGo to next message
jnz is currently offline  jnz
Messages: 3396
Registered: July 2006
Location: 30th century
Karma: 0
General (3 Stars)
RoShamBo wrote on Thu, 09 April 2009 13:08

Highlight the part of this line:

GetPrivateProfileString("BuildingID2", buildingid, "N", lpBuff2, 256, "C:\\westwood\\RenegadeFDS\\Server\\ID2.ini")


Where "building" is passed to it.

Re: Write to ini with Kill script using player's nick and join function not working right [message #379401 is a reply to message #379208] Thu, 09 April 2009 18:37 Go to previous messageGo to next message
whtdrgnpl is currently offline  whtdrgnpl
Messages: 17
Registered: July 2007
Karma: 0
Recruit
ok uh.... I give up, what do you mean by that? lol... Dont Get It
Re: Write to ini with Kill script using player's nick and join function not working right [message #379408 is a reply to message #379208] Thu, 09 April 2009 23:01 Go to previous messageGo to next message
jnz is currently offline  jnz
Messages: 3396
Registered: July 2006
Location: 30th century
Karma: 0
General (3 Stars)
To initialize it, you need to actually use it. No where in that line is it used.
Re: Write to ini with Kill script using player's nick and join function not working right [message #379410 is a reply to message #379408] Fri, 10 April 2009 00:11 Go to previous messageGo to next message
DynaFrom is currently offline  DynaFrom
Messages: 13
Registered: January 2009
Karma: 0
Recruit
RoShamBo wrote on Fri, 10 April 2009 01:01

To initialize it, you need to actually use it. No where in that line is it used.

hmmm, so you are the script's pro? Shocked Shocked
Re: Write to ini with Kill script using player's nick and join function not working right [message #379411 is a reply to message #379208] Fri, 10 April 2009 00:25 Go to previous message
whtdrgnpl is currently offline  whtdrgnpl
Messages: 17
Registered: July 2007
Karma: 0
Recruit
Oh that's what was wrong lol thanks so much.
I have another problem with the adding/subtracting to the ini file part of the script. It only wants to do -1, 0 and 1 values in it and refuses to go passed -1 and 1.

edit: uh wait nvm it's not even doing 0 it's just setting the value to -1 and 1...

[Updated on: Fri, 10 April 2009 15:45]

Report message to a moderator

Previous Topic: Glitch or No Glitch?
Next Topic: Mods
Goto Forum:
  


Current Time: Thu Oct 31 18:32:51 MST 2024

Total time taken to generate the page: 0.01239 seconds