Home » Renegade Discussions » Mod Forum » C++ help question
C++ help question [message #380533] |
Wed, 15 April 2009 16:56 |
|
Xpert
Messages: 1588 Registered: December 2005 Location: New York City
Karma: 0
|
General (1 Star) |
|
|
I'm trying to use a certain code that's in one .cpp file to be used in another .cpp file. How do I go about doing that?
I have this in gmmain.cpp
struct VeteranPlayers {
std::string PlayerName;
int VeteranPoints;
};
std::vector<VeteranPlayers> VetInfo;
int VetCheckPoints(int ID) {
if (!VetInfo.empty()) {
for (int i = 0; i < VetInfo.size(); i++) {
if (VetInfo[i].PlayerName == Get_Player_Name_By_ID(ID)) {
int Points;
Points = VetInfo[i].VeteranPoints;
return Points;
}
}
}
return 0;
}
I'm trying to get this to work also in gmscripts.cpp. Anyone can help me do that?
Creator of NetGuard, an IRC network regulator.
Developer of the CloudyServ 0.982-X project.
Developer of the CloudyServ Ren-X bot.
Part time streamer - https://twitch.tv/gg_wonder
|
|
|
Re: C++ help question [message #380548 is a reply to message #380533] |
Wed, 15 April 2009 18:24 |
Zuess
Messages: 16 Registered: August 2004
Karma: 0
|
Recruit |
|
|
in the .h file, create the structure.
Then whatever .cpp file you want to use your function in, do an
#include <original_file.h>
/* in gmmain.h */
struct VeteranPlayers {
std::string PlayerName;
int VeteranPoints;
};
std::vector<VeteranPlayers> VetInfo;
int VetCheckPoints(int ID);
in your code
#include <gmain.h>
void whateverfunction(int ID)
{
int points = VetCheckPoints{ID);
/* DO SOMETHING */
}
Ill double check my syntax when I get home
|
|
|
|
Re: C++ help question [message #380774 is a reply to message #380765] |
Thu, 16 April 2009 20:54 |
nopol10
Messages: 1043 Registered: February 2005 Location: Singapore
Karma: 0
|
General (1 Star) |
|
|
In the cpp file where you want to call VetCheckPoints, put in the line
extern int VetCheckPoints(int ID);
nopol10=Nopol=nopol(GSA)
|
|
|
Re: C++ help question [message #380792 is a reply to message #380533] |
Fri, 17 April 2009 04:02 |
|
reborn
Messages: 3231 Registered: September 2004 Location: uk - london
Karma: 0
|
General (3 Stars) |
|
|
If you're trying to migrate this back into SSGM because you want it to work with vehicles then I would suggest keeping it as a plugin.
You could add a void reb_vet_System::Custom(GameObject *obj, int message, int param, GameObject *sender) {
And on the custom check to see if they entered a vehicle.
On the objecthookcall vehicles are already hooked in that plug-in, you could attach a vet script similar to that of the player version to vehicles there. But don't forget people will try to exploit this as much as possible... (If they get in the vehicle and set it's hea;th/armor higher, remember to set it back when they exit).
|
|
|
Re: C++ help question [message #380840 is a reply to message #380533] |
Fri, 17 April 2009 11:58 |
|
Xpert
Messages: 1588 Registered: December 2005 Location: New York City
Karma: 0
|
General (1 Star) |
|
|
I'm not bothered by the health and armor. I'm trying to recreate the mod that we use on our server. There were too many modifications for me to keep it as a plugin because it required so much stuff from my main code. I edited the veteran system a lot and even had it work for CTF mode flag events.
This is what I'm trying to pull off. Maybe you can get the idea. I placed this in gmscripts.cpp
void MDB_SSGM_Vehicle::Custom(GameObject *obj, int message, int param, GameObject *sender) {
int Points;
Points = VetCheckPoints(Get_Player_ID(sender));
float health = Commands->Get_Max_Health(obj);
float armor = Commands->Get_Shield_Strength(obj);
if (message == CUSTOM_EVENT_VEHICLE_ENTER) {
if (Settings->EnableVehOwn && Get_Vehicle_Owner(obj) == sender && !Find_My_Veh(sender)) {
Commands->Attach_Script(obj,"MDB_SSGM_Vehicle_Owner",StrFormat("%d,%d",Commands->Get_ID(sender),Get_Object_Type(sender)).c_str());
Console_Input(StrFormat("ppage %d Your vehicle has been auto-bound to you. Use !unbind to relinquish ownership. Use !lock to prevent your teammates from stealing the vehicle.",Get_Player_ID(sender)).c_str());
if (Points >= 120) {
Set_Max_Health(obj, health*1.40f);
Set_Max_Shield_Strength(obj, armor*1.40f);
Attach_Script_Once(obj,"c_Regen","3,1,8");
}
else if (Points >= 90 && Points < 120) {
Set_Max_Health(obj, health*1.30f);
Set_Max_Shield_Strength(obj, armor*1.30f);
Attach_Script_Once(obj,"c_Regen","4,1,6");
}
else if (Points >= 60 && Points < 90) {
Set_Max_Health(obj, health*1.20f);
Set_Max_Shield_Strength(obj, armor*1.20f);
Attach_Script_Once(obj,"c_Regen","4,1,4");
}
else if (Points >= 30 && Points < 60) {
Set_Max_Health(obj, health*1.10f);
Set_Max_Shield_Strength(obj, armor*1.10f);
Attach_Script_Once(obj,"c_Regen","4,1,2");
}
Commands->Set_Health(obj, Commands->Get_Max_Health(obj));
Commands->Set_Shield_Strength(obj, Commands->Get_Max_Shield_Strength(obj));
}
}
}
This is what I'm trying to do thus why I'm asking how to use a function from another cpp file. And I'm having no luck right now because I'm having crash issues or code errors.
Creator of NetGuard, an IRC network regulator.
Developer of the CloudyServ 0.982-X project.
Developer of the CloudyServ Ren-X bot.
Part time streamer - https://twitch.tv/gg_wonder
|
|
|
|
Re: C++ help question [message #380850 is a reply to message #380841] |
Fri, 17 April 2009 13:05 |
Genesis2001
Messages: 1397 Registered: August 2006
Karma: 0
|
General (1 Star) |
|
|
reborn wrote on Fri, 17 April 2009 12:44 | If you need to use the function from another .cpp file then add
before you use the function.
If you're really struggling, then hit me up on MSN and i'll remote to you.
Would be nice if you considered releasing what you've made.
|
This is what headers are for ... lol
<3 Master Includes file!
|
|
|
|
Re: C++ help question [message #381736 is a reply to message #380533] |
Tue, 21 April 2009 14:03 |
|
Xpert
Messages: 1588 Registered: December 2005 Location: New York City
Karma: 0
|
General (1 Star) |
|
|
Okay, I'm completely stomped. I tried so many things and still end up back to square one. This time I went to debug the scripts.dll. It points to 2 parts of the code and it makes no sense to me.
GMMAIN.CPP
struct VeteranPlayers {
std::string PlayerName;
int VeteranPoints;
};
std::vector<VeteranPlayers> VetInfo;
int VetCheckPoints(int ID) {
if (!VetInfo.empty()) {
for (int i = 0; i < VetInfo.size(); i++) {
HERE --> if (VetInfo[i].PlayerName == Get_Player_Name_By_ID(ID)) {
int Points;
Points = VetInfo[i].VeteranPoints;
return Points;
}
}
}
return 0;
}
GMMAIN.H
int VetCheckPoints(int ID);
GMSCRIPTS.CPP
void MDB_SSGM_Vehicle::Custom(GameObject *obj, int message, int param, GameObject *sender) {
HERE -->int Points = VetCheckPoints(Get_Player_ID(sender));
float health = Commands->Get_Max_Health(obj);
float armor = Commands->Get_Shield_Strength(obj);
if (message == CUSTOM_EVENT_VEHICLE_ENTER) {
if (Settings->EnableVehOwn && Get_Vehicle_Owner(obj) == sender && !Find_My_Veh(sender)) {
Commands->Attach_Script(obj,"MDB_SSGM_Vehicle_Owner",StrFormat("%d,%d",Commands->Get_ID(sender),Get_Object_Type(sender)).c_str());
Console_Input(StrFormat("ppage %d Your vehicle has been auto-bound to you. Use !unbind to relinquish ownership. Use !lock to prevent your teammates from stealing the vehicle.",Get_Player_ID(sender)).c_str());
if (Points >= 120) {
Set_Max_Health(obj, health*1.40f);
Set_Max_Shield_Strength(obj, armor*1.40f);
Commands->Set_Health(obj, Commands->Get_Max_Health(obj));
Commands->Set_Shield_Strength(obj, Commands->Get_Max_Shield_Strength(obj));
Attach_Script_Once(obj,"cAMpa_Regen","3,1,8");
}
else if (Points >= 90 && Points < 120) {
Set_Max_Health(obj, health*1.30f);
Set_Max_Shield_Strength(obj, armor*1.30f);
Commands->Set_Health(obj, Commands->Get_Max_Health(obj));
Commands->Set_Shield_Strength(obj, Commands->Get_Max_Shield_Strength(obj));
Attach_Script_Once(obj,"cAMpa_Regen","4,1,6");
}
else if (Points >= 60 && Points < 90) {
Set_Max_Health(obj, health*1.20f);
Set_Max_Shield_Strength(obj, armor*1.20f);
Commands->Set_Health(obj, Commands->Get_Max_Health(obj));
Commands->Set_Shield_Strength(obj, Commands->Get_Max_Shield_Strength(obj));
Attach_Script_Once(obj,"cAMpa_Regen","4,1,4");
}
else if (Points >= 30 && Points < 60) {
Set_Max_Health(obj, health*1.10f);
Set_Max_Shield_Strength(obj, armor*1.10f);
Commands->Set_Health(obj, Commands->Get_Max_Health(obj));
Commands->Set_Shield_Strength(obj, Commands->Get_Max_Shield_Strength(obj));
Attach_Script_Once(obj,"cAMpa_Regen","4,1,2");
}
}
}
}
When I debugged it, it pointed to the parts I put "HERE -->" above, as being the problem.
I don't know what to do. This is frustrating me >.>
Creator of NetGuard, an IRC network regulator.
Developer of the CloudyServ 0.982-X project.
Developer of the CloudyServ Ren-X bot.
Part time streamer - https://twitch.tv/gg_wonder
[Updated on: Tue, 21 April 2009 14:05] Report message to a moderator
|
|
|
|
|
|
Re: C++ help question [message #382011 is a reply to message #381848] |
Wed, 22 April 2009 16:20 |
|
Xpert
Messages: 1588 Registered: December 2005 Location: New York City
Karma: 0
|
General (1 Star) |
|
|
Omg, I f-ing love you. THANK YOU! It works YAY =D
Creator of NetGuard, an IRC network regulator.
Developer of the CloudyServ 0.982-X project.
Developer of the CloudyServ Ren-X bot.
Part time streamer - https://twitch.tv/gg_wonder
|
|
|
Goto Forum:
Current Time: Mon Dec 30 05:43:33 MST 2024
Total time taken to generate the page: 0.01100 seconds
|