Home » Renegade Discussions » Mod Forum » Stealth command help
Stealth command help [message #407893] |
Wed, 21 October 2009 10:49 |
Hubba
Messages: 40 Registered: October 2009
Karma: 0
|
Recruit |
|
|
Hey! How do i make so that people who joins the game after someone has bought a stealth suit for his char/veh still will see them stealthed?
Here is my command.
class StealthChatCommand : public ChatCommandClass {
void Triggered(int ID,const TokenClass &Text,int ChatType) {
GameObject *obj = Get_GameObj(ID);
float Credits = Commands->Get_Money(obj);
if(Credits >= 1000){
Commands->Give_Money(obj,-1000,false);
char message[256];
sprintf(message,"msg %s bought a Stealthsuit", Get_Player_Name_By_ID(ID));
Console_Input(message);
Commands->Enable_Stealth(obj,true);
}
else {
Console_Input(StrFormat("ppage %d You need $1000.",Get_Player_ID(obj)).c_str());
}
}
};
ChatCommandRegistrant<StealthChatCommand> StealthChatCommandReg("!ss",CHATTYPE_ALL,0,GAMEMODE_AOW);
[Updated on: Thu, 22 October 2009 12:57] Report message to a moderator
|
|
|
|
|
|
|
|
|
Re: Stealth command help [message #407939 is a reply to message #407923] |
Wed, 21 October 2009 18:26 |
|
YazooGang
Messages: 742 Registered: August 2008 Location: US
Karma: 0
|
Colonel |
|
|
Reattaching the script when player joins is a hard thing i would ignore that.
Here is what i got and hope it works!
I havent compiled or tested this so please tell me if somethings word ok?
Ok, so what this does is when you type in command !ss it takes your money and attaches you a "Hubba_Stealth" scripts. The script is a timer and what this does is activates a timer that is over in 0.01 and it enables Stealth event in your character and then it starts another timer that is over in 3 seconds. So, why is the first one 0.01(sec) and this one is 3(sec) because when you type in !ss you will have to wait 3 seconds to have a stealth event. So now when you type in !ss you will have it in less than a second. So, then when 3 seconds is over it will give you stealth effect again replace or whatever the original one and start another time. This will loop untill you die. So, when a person joins, your chars stealth will be enabled in every 3 seconds and that new person will see you as a stealth soldier. Good luck!
gmmain.CPP (replace the original command with this)
class StealthChatCommand : public ChatCommandClass {
void Triggered(int ID,const TokenClass &Text,int ChatType) {
GameObject *obj = Get_GameObj(ID);
float Credits = Commands->Get_Money(obj);
if(Credits >= 1000){
Commands->Give_Money(obj,-1000,false);
char message[256];
sprintf(message,"msg %s bought a Stealthsuit", Get_Player_Name_By_ID(ID));
Console_Input(message);
//Commands->Enable_Stealth(obj,true);
Commands->Attach_Script(obj,"Hubba_Stealth","");
}
else {
Console_Input(StrFormat("ppage %d You need $1000.",Get_Player_ID(obj)).c_str());
}
}
};
ChatCommandRegistrant<StealthChatCommand> StealthChatCommandReg("!ss",CHATTYPE_ALL,0,GAMEMODE_AOW);
gmmain.CPP - add this also
void Hubba_Stealth::Created(GameObject *obj)
{
Commands->Start_Timer(obj,this,0.01,1);
}
void Hubba_Stealth::Timer_Expired(GameObject *obj,int number)
{
if (number == 1){
Commands->Enable_Stealth(obj,true);
Commands->Start_Timer(obj,this,3,1);
}
}
ScriptRegistrant<Hubba_Stealth> Hubba_Stealth_Registrant("Hubba_Stealth","");
gmmain.H - add this also, its for the script Hubba_Stealth
class Hubba_Stealth : public ScriptImpClass {
void Created(GameObject *obj);
void Timer_Expired(GameObject *obj,int number);
};
And last thing is to test it out. If it works have fun, no credits needed.
|
|
|
Re: Stealth command help [message #407948 is a reply to message #407939] |
Wed, 21 October 2009 20:41 |
Hubba
Messages: 40 Registered: October 2009
Karma: 0
|
Recruit |
|
|
YazooGang wrote on Wed, 21 October 2009 20:26 | Reattaching the script when player joins is a hard thing i would ignore that.
Here is what i got and hope it works!
I havent compiled or tested this so please tell me if somethings word ok?
Ok, so what this does is when you type in command !ss it takes your money and attaches you a "Hubba_Stealth" scripts. The script is a timer and what this does is activates a timer that is over in 0.01 and it enables Stealth event in your character and then it starts another timer that is over in 3 seconds. So, why is the first one 0.01(sec) and this one is 3(sec) because when you type in !ss you will have to wait 3 seconds to have a stealth event. So now when you type in !ss you will have it in less than a second. So, then when 3 seconds is over it will give you stealth effect again replace or whatever the original one and start another time. This will loop untill you die. So, when a person joins, your chars stealth will be enabled in every 3 seconds and that new person will see you as a stealth soldier. Good luck!
gmmain.CPP (replace the original command with this)
class StealthChatCommand : public ChatCommandClass {
void Triggered(int ID,const TokenClass &Text,int ChatType) {
GameObject *obj = Get_GameObj(ID);
float Credits = Commands->Get_Money(obj);
if(Credits >= 1000){
Commands->Give_Money(obj,-1000,false);
char message[256];
sprintf(message,"msg %s bought a Stealthsuit", Get_Player_Name_By_ID(ID));
Console_Input(message);
//Commands->Enable_Stealth(obj,true);
Commands->Attach_Script(obj,"Hubba_Stealth","");
}
else {
Console_Input(StrFormat("ppage %d You need $1000.",Get_Player_ID(obj)).c_str());
}
}
};
ChatCommandRegistrant<StealthChatCommand> StealthChatCommandReg("!ss",CHATTYPE_ALL,0,GAMEMODE_AOW);
gmmain.CPP - add this also
void Hubba_Stealth::Created(GameObject *obj)
{
Commands->Start_Timer(obj,this,0.01,1);
}
void Hubba_Stealth::Timer_Expired(GameObject *obj,int number)
{
if (number == 1){
Commands->Enable_Stealth(obj,true);
Commands->Start_Timer(obj,this,3,1);
}
}
ScriptRegistrant<Hubba_Stealth> Hubba_Stealth_Registrant("Hubba_Stealth","");
gmmain.H - add this also, its for the script Hubba_Stealth
class Hubba_Stealth : public ScriptImpClass {
void Created(GameObject *obj);
void Timer_Expired(GameObject *obj,int number);
};
And last thing is to test it out. If it works have fun, no credits needed.
|
Yep it works . Thanks alot for helping me out and telling how the script work I will learn lots from this
[Updated on: Wed, 21 October 2009 20:44] Report message to a moderator
|
|
|
|
|
Re: Stealth command help [Solved] [message #407971 is a reply to message #407893] |
Thu, 22 October 2009 06:12 |
|
reborn
Messages: 3231 Registered: September 2004 Location: uk - london
Karma: 0
|
General (3 Stars) |
|
|
If you decide to carry on use YazooGang's timer example, then I encourage you to take the actual timer itself down from 0.01f to say 0.5f. It's not really neccessary to have it loop like that every 0.01 seconds...
I would however like to encourage you to consider making a global array for the players...
bool IsPlayerStealth[128]; // global array
On the level_loaded event I would for loop through the array and set all the elements to false (just to make sure they are all false at the start of the map).
for (int i = 1; i < 128; i++){
IsPlayerStealth[i] = false;
}
You would need to set the players to true in this array when they become stealth, and false when they die. I would do something like this:
class StealthChatCommand : public ChatCommandClass {
void Triggered(int ID,const TokenClass &Text,int ChatType) {
GameObject *obj = Get_GameObj(ID);
float Credits = Commands->Get_Money(obj);
if(Credits >= 1000){
Commands->Give_Money(obj,-1000,false);
char message[256];
sprintf(message,"msg %s bought a Stealthsuit", Get_Player_Name_By_ID(ID));
Console_Input(message);
//Commands->Enable_Stealth(obj,true);
Commands->Attach_Script(obj,"Hubba_Stealth","");
}
else {
Console_Input(StrFormat("ppage %d You need $1000.",ID).c_str());
}
}
};
ChatCommandRegistrant<StealthChatCommand> StealthChatCommandReg("!ss;!StealthSuit;!SS;!stealthsuit",CHATTYPE_ALL,0,GAMEMODE_AOW);
void Hubba_Stealth::Created(GameObject *obj)
{
Commands->Enable_Stealth(obj,true);
IsStealthPlayer[Get_Player_ID(obj)] = true;
}
void Hubba_Stealth::Killed(GameObject *obj,GameObject *shooter)
{
IsStealthPlayer[Get_Player_ID(obj)] = false;
}
ScriptRegistrant<Hubba_Stealth> Hubba_Stealth_Registrant("Hubba_Stealth","");
class Hubba_Stealth : public ScriptImpClass {
void Created(GameObject *obj);
void Killed(GameObject *obj,GameObject *shooter);
};
Then on the player join event, you would do a similar loop to the level_loaded event, and just loop through the array, and if any of them are true, then apply the stealth tot hem again...
for (int i = 1; i < 128; i++){
if(IsPlayerStealth[i] == true){
Commands->Enable_Stealth(Get_GameObj(i),true);
}
}
Plus, this way you have a method of keeping track of who is currently stealthed, meaning you could add more functionaility.. You could add a command like !currentlystealthed, and it messages you who is stealthed...
Or you could add a conditional to your chat command, so if they are already stealthed, it pages them saying they are already stealthed.
I'm not fond of these sort of comamnds really if I am honest, but perhaps if you must do this, you could at least ensure the HON is alive, or they are at least a Nod player?
[Updated on: Thu, 22 October 2009 06:13] Report message to a moderator
|
|
|
|
|
|
|
Re: Stealth command help [message #408010 is a reply to message #407893] |
Thu, 22 October 2009 13:19 |
|
reborn
Messages: 3231 Registered: September 2004 Location: uk - london
Karma: 0
|
General (3 Stars) |
|
|
You would need to post your code, what I posted should work.
You may have added the code in the wrong place or something :-/
|
|
|
Re: Stealth command help [message #408011 is a reply to message #408010] |
Thu, 22 October 2009 13:27 |
Hubba
Messages: 40 Registered: October 2009
Karma: 0
|
Recruit |
|
|
reborn wrote on Thu, 22 October 2009 15:19 | You would need to post your code, what I posted should work.
You may have added the code in the wrong place or something :-/
|
I added the join code to "void Player_Join_Hook(int i,const char *Nick)"
Added the level_loaded code to "void Level_Loaded()"
"bool IsPlayerStealth[128]; // global array" is in global scope.
class Hubba_Stealth : public ScriptImpClass {
void Created(GameObject *obj);
void Killed(GameObject *obj,GameObject *shooter);
};
added that to gmmain.h
And the rest should be fine. I'm pretty sure everyting else is right but is the join code in right place?
[Updated on: Thu, 22 October 2009 13:28] Report message to a moderator
|
|
|
Re: Stealth command help [message #408012 is a reply to message #407893] |
Thu, 22 October 2009 13:38 |
|
reborn
Messages: 3231 Registered: September 2004 Location: uk - london
Karma: 0
|
General (3 Stars) |
|
|
And you changed the chat hook?
You should post the code really. To be honest, I was writing that at work from my head, it was more to give you the direction than anything else...
|
|
|
|
Re: Stealth command help [message #408016 is a reply to message #408012] |
Thu, 22 October 2009 13:44 |
Hubba
Messages: 40 Registered: October 2009
Karma: 0
|
Recruit |
|
|
reborn wrote on Thu, 22 October 2009 15:38 | And you changed the chat hook?
You should post the code really. To be honest, I was writing that at work from my head, it was more to give you the direction than anything else...
|
Join_hook
void Player_Join_Hook(int i,const char *Nick) {
for (int a = 1; a < 128; a++){
if(IsPlayerStealth[a] == true){
Commands->Enable_Stealth(Get_GameObj(a),true);
}
}
VetAddPlayer(i);
if (!Data->Plugins.empty()) {
std::vector<PluginInfo*>::const_iterator it;
for (it = Data->Plugins.begin();it != Data->Plugins.end(); ++it) {
if ((*it)->Type == Plugin) {
if ((*it)->PlayerJoinHookHandle) {
(*it)->PlayerJoinHookHandle(i,Nick);
}
}
}
}
if (Settings->GameMode == 2) {
CTF_Player_Join(i);
}
}
Level_loaded
void Level_Loaded() {
strncpy(Data->CurrMap,The_Game()->MapName,29);
Settings->Load();
Attach_Script_All_Buildings_Team(2,"MDB_SSGM_Building","",true);
Attach_Script_All_Turrets_Team(2,"MDB_SSGM_Base_Defense","",true);
for (int a = 1; a < 128; a++){
IsPlayerStealth[a] = false;
}
if (Settings->EnableNewCrates) {
Crate_Level_Loaded();
}
if (Settings->Gamelog) {
Gamelog_Level_Loaded();
}
if (Settings->GameMode == 2) {
CTF_Level_Loaded();
}
if (Settings->LogPlayerPurchase) {
Data->PlayerPurchaseHookID = AddCharacterPurchaseMonHook(SSGM_Purchase_Hook,0);
}
if (Settings->LogPowerupPurchase) {
Data->PowerupPurchaseHookID = AddPowerupPurchaseMonHook(SSGM_Purchase_Hook,0);
}
if (Settings->LogVehiclePurchase) {
Data->VehiclePurchaseHookID = AddVehiclePurchaseMonHook(SSGM_Purchase_Hook,0);
}
if (!Data->Plugins.empty()) {
std::vector<PluginInfo*>::const_iterator it;
for (it = Data->Plugins.begin();it != Data->Plugins.end(); ++it) {
if ((*it)->Type == Plugin) {
if ((*it)->LevelLoadedHookHandle) {
(*it)->LevelLoadedHookHandle();
}
}
}
}
}
Gmmain.h
class Hubba_Stealth : public ScriptImpClass {
void Created(GameObject *obj);
void Killed(GameObject *obj,GameObject *shooter);
};
The command:
class StealthChatCommand : public ChatCommandClass {
void Triggered(int ID,const TokenClass &Text,int ChatType) {
GameObject *obj = Get_GameObj(ID);
float Credits = Commands->Get_Money(obj);
if(Credits >= 1000){
Commands->Give_Money(obj,-1000,false);
char message[256];
sprintf(message,"msg %s bought a Stealthsuit", Get_Player_Name_By_ID(ID));
Console_Input(message);
//Commands->Enable_Stealth(obj,true);
Commands->Attach_Script(obj,"Hubba_Stealth","");
}
else {
Console_Input(StrFormat("ppage %d You need $1000.",ID).c_str());
}
}
};
ChatCommandRegistrant<StealthChatCommand> StealthChatCommandReg("!ss;!StealthSuit;!SS;!stealthsuit",CHATTYPE_ALL,0,GAMEMODE_AOW);
void Hubba_Stealth::Created(GameObject *obj)
{
Commands->Enable_Stealth(obj,true);
IsPlayerStealth[Get_Player_ID(obj)] = true;
}
void Hubba_Stealth::Killed(GameObject *obj,GameObject *shooter)
{
IsPlayerStealth[Get_Player_ID(obj)] = false;
}
ScriptRegistrant<Hubba_Stealth> Hubba_Stealth_Registrant("Hubba_Stealth","");
[Updated on: Thu, 22 October 2009 20:48] Report message to a moderator
|
|
|
Re: Stealth command help [message #408061 is a reply to message #407893] |
Fri, 23 October 2009 03:46 |
|
reborn
Messages: 3231 Registered: September 2004 Location: uk - london
Karma: 0
|
General (3 Stars) |
|
|
It looks like it should work, I don't know why it isn't.
If I have some time Sunday morning I will take a proper look.
You seem to grasp what I was saying though, you've added it to the correct places, perhaps you might like to try yourself, too?
|
|
|
Re: Stealth command help [message #408070 is a reply to message #407893] |
Fri, 23 October 2009 04:52 |
|
Just to let everyone know, stealth has been improved in 4.0 to work better.
Jonathan Wilson aka Jonwil
Creator and Lead Coder of the Custom scripts.dll
Renegade Engine Guru
Creator and Lead Coder of TT.DLL
Official member of Tiberian Technologies
|
|
|
|
|
Goto Forum:
Current Time: Sun Dec 15 08:45:56 MST 2024
Total time taken to generate the page: 0.01252 seconds
|