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 |
|
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 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
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:
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 |
|
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 #379342 is a reply to message #379208] |
Thu, 09 April 2009 01:02 |
|
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 and isn't building initialized here? O.o
char building[256];
GetPrivateProfileString("BuildingID2", buildingid, "N", lpBuff2, 256, "C:\\westwood\\RenegadeFDS\\Server\\ID2.ini")
|
|
|
|
|
|
|
|
|
|
Goto Forum:
Current Time: Fri Nov 01 03:22:17 MST 2024
Total time taken to generate the page: 0.00776 seconds
|