Command and Conquer: Renegade Official Forums - RDF feed
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
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);
my guess is to reatach the script whenever anyone joins
ErroR wrote on Wed, 21 October 2009 13:09 my guess is to reatach the script whenever anyone joins Thanks for the reply. Could you tell me more how to reatach the script when a player join? I'm pretty new to this.
If you know, that "Enable_Stealth" command isnt the solid stealth event thats from renegade. Like thats made in the latest scripts and stuff. The current scripts are made by the community so there are several bugs. Like person running original or old scripts wont see the stealth effect and that join ect problem. I guess for a better version of the "Enable_Stealth" you would have to wait until scripts 4.0 since everyone needs that to play the future renegade.
Hubba wrote on Wed, 21 October 2009 21:47 ErroR wrote on Wed, 21 October 2009 13:09 my guess is to reatach the script whenever anyone joins Thanks for the reply. Could you tell me more how to reatach the script when a player join? I'm pretty new to this. sorry, know nothing about coding/scripting
YazooGang wrote on Wed, 21 October 2009 14:48 If you know, that "Enable_Stealth" command isnt the solid stealth event thats from renegade. Like thats made in the latest scripts and stuff. The current scripts are made by the community so there are several bugs. Like person running original or old scripts wont see the stealth effect and that join ect problem. I guess for a better version of the "Enable_Stealth" you would have to wait until scripts 4.0 since everyone needs that to play the future renegade. Thanks for the reply Yes I know that people with scripts lower than 2.9 will see them anyway. But let says the person who joins the game have scripts 2.9 or higher. How could i attach the script to him on join? I want to learn this because it could be usefull for other thing too ErroR wrote on Wed, 21 October 2009 13:54 sorry, know nothing about coding/scripting Thanks anyway
well if you are using ssgm just find where the player joins and reattach the script to those players i don't know much about scripting, maybe someone else with more experience can explain better.
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.
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
cAmpa wrote on Thu, 22 October 2009 02:22 Wow, nice traffic abusing. If your saying something about my code then you must know that i'm not a proffecional coder.
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?
reborn wrote on Thu, 22 October 2009 07:12 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... Timers don't time right anyways, and it won't loop at 0.01, it just doesn't get that fast, I'd assume someone put a cap on it somewhere.
To reborn, dude your code is way better than mine so dont waste time comparing mine to yours, just release yours.
YazooGang wrote on Thu, 22 October 2009 14:49 To reborn, dude your code is way better than mine so dont waste time comparing mine to yours, just release yours. Do not put yourself down, you was willing to help and gave a solution that worked. Besides, my method isn't that much better really and truly, and I was doing it the same way you just suggested to Hubba not so long ago.
reborn wrote on Thu, 22 October 2009 14:12 (...) Thanks reborn for your reply. But your code doesn't seem to work? When another player joins they will see them un-stealthed. There was also a small typo "IsStealthPlayer" should be "IsPlayerStealth". I Hope we can find out why it doesn't work I tried to look but I can't find anything wrong
You would need to post your code, what I posted should work. You may have added the code in the wrong place or something :-/
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?
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...
You could also use Server Renegade Resurrection Software, it should fix this bug.
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","");
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?
Just to let everyone know, stealth has been improved in 4.0 to work better.
jonwil wrote on Fri, 23 October 2009 06:52 Just to let everyone know, stealth has been improved in 4.0 to work better. Nice thanks!
Okey i have been trying to get it work but i dont know what is wrong. I changed my level_load code to: char message[256]; for (int a = 0; a < 128; a++){ IsPlayerStealth[a] = false; sprintf(message,"msg Set all to false",""); Console_Input(message); The message was just to see if it acctully load that part. I see the messages in console. Then I changed join_hook For (int a = 0; a < 128; a++){ if(IsPlayerStealth[a] == false){ Commands->Enable_Stealth(Get_GameObj(a),true); char message[256]; sprintf(message,"msg Set stealth to all true",""); Console_Input(message); } I get the "Set stealth to all true" 128 times in console when some1 joins. But ofcourse you dont get stealth when you join because you change character to "GDI Soldier or Nod Soldier" after the stealth code. But then if another player joins he should see the other guy stealth since "isPlayerStealth" is still false to the first guy. Now i'm really confused this should work... Btw when is script 4.0 gonna be realesed?
Hubba wrote on Sat, 24 October 2009 14:44 Okey i have been trying to get it work but i dont know what is wrong. I changed my level_load code to: char message[256]; for (int a = 0; a < 128; a++){ IsPlayerStealth[a] = false; sprintf(message,"msg Set all to false",""); Console_Input(message); The message was just to see if it acctully load that part. I see the messages in console. Then I changed join_hook For (int a = 0; a < 128; a++){ if(IsPlayerStealth[a] == false){ char message[256]; sprintf(message,"msg Set stealth to all true",""); Console_Input(message); Commands->Enable_Stealth(Get_GameObj(a),true); } I get the "Set stealth to all true" 128 times in console when some1 joins. But ofcourse you dont get stealth when you join because you change character to "GDI Soldier or Nod Soldier" after the stealth code. But then if another player joins he should see the other guy stealth since "isPlayerStealth" is still false to the first guy. Now i'm really confused this should work... Btw when is script 4.0 gonna be realesed? It will work and probably crash. Quote: GameObject *obj = Get_GameObj(a); if (obj) { Commands->Enable_Stealth(obj,true); }
Hmm... Ok got it to work like this: player 1 joins the game and is Un-Stealthed player 2 joins the game and player 1 gets a Stealth suit But player 2 can still see player 1 un-stealthed. Why? EDIT: added the join_hook as a command and it works. So the problem is that player 1 gets the stealth suit. Because player 2 joins the game but the script goes on before player 2 is inside the game. So now i need a way to make players to be inside the game before the script start... hm. Any1 got any ideas?
Hmmm... still can't get it to work. But does anyone know this? I want to check the current character a player has. I thought something like this: if (obj = "CnC_Nod_Minigunner_0") { ... } Are there a site with all the functions/methods like Get_Player_ID, Get_Player_Name, Get_Player_Name_By_ID etc etc... ?
The method I posted should work, I just did not have time this morning to go through it. I would try to focus on the method I suggested rather than string comparisons. What you would need to do BTW for the method you was just trying is get_preset_name, or something to that effect, then strstr. http://www.cplusplus.com/reference/clibrary/cstring/strstr/
reborn wrote on Sun, 25 October 2009 14:44 The method I posted should work, I just did not have time this morning to go through it. I would try to focus on the method I suggested rather than string comparisons. What you would need to do BTW for the method you was just trying is get_preset_name, or something to that effect, then strstr. http://www.cplusplus.com/reference/clibrary/cstring/strstr/ The problem is that the script goes on before the player is ingame. If the script would execute first when the player has fully loaded the game it would work i think.
So you're saying that they need to actually have a GameObject themselves before you use the stealth command on someone else? In that case you could still do it on player join, just make sure you do a conditional like: if(Get_GameObj(ID)){ // The player that joined has a GameObject, so i'll do my little loop here now... //my loop } else{ // That slow ass loading fucker doesn't have a GameOnbject yet // So I will create an object myself here, and attach a script to it that has a timer on it. //define and initialise the pos here Vector3 pos; pos.X = 0.0f; pos.Y = 0.0f; pos.Z = 0.0f; //Code here to create a gameobject, something like GameObject *invis = Commands->Create_Object("InvisObject", pos); //attach script to the object here } Your script should basically just have a created and timer_expired event that loops every 0.5 seconds or whatever, and each iteration of it should check to see if that player ID has a gameobject yet, if it does, then do the loop to -re-set the players to stealth, if not, then do the Command->start_timer to continue the loop again...
SSGM has a script called MDB_SSGM_Player or something along that line that gets attached to every player GameObject, maybe you could try editing from there.
nopol10 wrote on Sun, 25 October 2009 19:08 SSGM has a script called MDB_SSGM_Player or something along that line that gets attached to every player GameObject, maybe you could try editing from there. Or attach your own script from the object hook to players (just like the script nopol mentioned) that has a static bool firstspawn; variable. So on the ::Created event you have a switch like set-up... void hubbaplayer::Created(GameObject *obj){ staticbool firstspawn = false; if(firstspawn == false){ // Code will only be called once when the player joins // Do the loop here firstspawn = true; } }
reborn wrote on Mon, 26 October 2009 00:35 nopol10 wrote on Sun, 25 October 2009 19:08 SSGM has a script called MDB_SSGM_Player or something along that line that gets attached to every player GameObject, maybe you could try editing from there. Or attach your own script from the object hook to players (just like the script nopol mentioned) that has a static bool firstspawn; variable. So on the ::Created event you have a switch like set-up... void hubbaplayer::Created(GameObject *obj){ staticbool firstspawn = false; if(firstspawn == false){ // Code will only be called once when the player joins // Do the loop here firstspawn = true; } } Ok now the player is "inside" the game before the script starts but it still wont work. For example: Player1 joins the game the script will set stealth suit to all players (i dont know why player1 dosent get one) Player2 join the game after player1. Player1 get then a stealth suit and player2 wont get one. But player2 can still see player1 un-stealthed. Now i dont know what to do...
I've kinda lost the plot with what it is you're doing now... Basically you want a command that allows a player to purchase a stealth suit? You seem to of changed what your final goal is somewhere along the thread, unless I am reading your posts incorrectly?
i think it goes like this A player goes and buys a stealth suit, he leaves but comes back to the game with the stealth suit i think that is what he wants
reborn wrote on Mon, 26 October 2009 19:44 I've kinda lost the plot with what it is you're doing now... Basically you want a command that allows a player to purchase a stealth suit? You seem to of changed what your final goal is somewhere along the thread, unless I am reading your posts incorrectly? The thing i want is when a player buys a stealth suit using command !ss. And then if another player joins the game AFTER the first player have bought the stealth suit then he should see the first guy stealth. But I have skipped the whole command thing for now. Just to make it as simple as possible. Because i can easily add that in if i get this first thing to work: So this is what i have: Global array bool IsPlayerStealth[128]; // global array Level_load hook sets IsPlayerStealth to false to all players. for (int a = 0; a < 128; a++){ IsPlayerStealth[a] = false; } Then in join_hook if IsPlayerStealth == false (which all players are) then it will add stealth suit to all of them. for (int a = 0; a < 128; a++){ if(IsPlayerStealth[a] == false){ Commands->Enable_Stealth(Get_GameObj(a),true); } } But the problem is as i explained in the example before is that The other player that joins the game after the first player still will see the other player un-stealthed even if he gets a Stealth_suit. + I have also tried to use ObjectHookCall so the script gets called after the player is ingame. But that wont work either.
Why do you not just change the player to the SBH preset, and then re-grant them all the weapons and amount of ammo they previously had, and set there health/armor to what it was too? This way it just looks like a smooth transitional state change, and everyone see's them as stealth, even the non-scripts.dll users.
reborn wrote on Mon, 26 October 2009 13:43 Why do you not just change the player to the SBH preset, and then re-grant them all the weapons and amount of ammo they previously had, and set there health/armor to what it was too? This way it just looks like a smooth transitional state change, and everyone see's them as stealth, even the non-scripts.dll users. Yes i know but i dont want them to turn into the Shb preset... And i know it should work somehow for example it works on the "wittebolx" server if you have ever played. Well i guess i have to ask witte if he could share the way he do it.
Attach a script to the player who has a stealth suit that Enable_Stealth on them every few seconds through a timer event. That's a cheap method of doing it.
nopol10 wrote on Mon, 26 October 2009 18:31 Attach a script to the player who has a stealth suit that Enable_Stealth on them every few seconds through a timer event. That's a cheap method of doing it. That's not a great idea. He would be better pursuing and debugging the array method and re-applying when they join.
How can i add this to my join hook: GameObject *obj = Get_GameObj(ID); Attach_Script_Once(obj,"Test_hubba",""); Without getting errors? I need to declare the "ID" somehow. When my join_hook looks like this: void Player_Join_Hook(int i,const char *Nick) { 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); } }
'i' in the join hooks function argument list is actually the ID. However, I would be super careful assuming they have a GameObject * at that point... Better to do: if(Get_GameObj(i)){ //attach the script to the player } else{ //create an object yourself, then attach the script to that object which waits until the player has a gameobject and has loaded (like discussed earlier). }
reborn wrote on Tue, 27 October 2009 11:11 'i' in the join hooks function argument list is actually the ID. However, I would be super careful assuming they have a GameObject * at that point... Better to do: if(Get_GameObj(i)){ //attach the script to the player } else{ //create an object yourself, then attach the script to that object which waits until the player has a gameobject and has loaded (like discussed earlier). } Like : if(Get_GameObj(i)){ Attach_Script_Once(i,"Test_hubba",""); } ? error C2664: 'Attach_Script_Once' : cannot convert parameter 1 from 'int' to 'GameObject *' 1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Hubba wrote on Tue, 27 October 2009 13:18 Like : if(Get_GameObj(i)){ Attach_Script_Once(i,"Test_hubba",""); } ? No, like: if(Get_GameObj(i)){ Attach_Script_Once(Get_GameObj(i),"Test_hubba",""); } else{ //create an object yourself, then attach the script to that object which waits until the player has a gameobject and has loaded (like discussed earlier). } or: GameObject *playerobject = Get_GameObj(i); if(playerobject){ Attach_Script_Once(playerobject,"Test_hubba",""); } else{ //create an object yourself, then attach the script to that object which waits until the player has a gameobject and has loaded (like discussed earlier). }
Thanks that works and i know that i have to make an object. So in ur earlier post you said i had to make something like this: else { Vector3 pos; pos.X = 0.0f; pos.Y = 0.0f; pos.Z = 0.0f; GameObject *invis = Commands->Create_Object("InvisObject", pos); //Attach script to check if gameobject exists } Now i just how to think how to make the script for that. EDIT------------------------------------------------------------- Shit i got already a problem. The script wont attach to the invis object. else { Vector3 pos; pos.X = 0.0f; pos.Y = 0.0f; pos.Z = 0.0f; GameObject *invis = Commands->Create_Object("InvisObject", pos); Attach_Script_Once(invis,"Test_hubba1",""); }
It absolutely will attach to an invis object. Did you remember the scripts registrant? //edit I see what you're doing wrong.. It's "Invisible_Object", not "Invis_Object".
reborn wrote on Tue, 27 October 2009 13:29 It absolutely will attach to an invis object. Did you remember the scripts registrant? //edit I see what you're doing wrong.. It's "Invisible_Object", not "Invis_Object". That did the trick. Okey i got it work. But i want you to take a look: Join_hook if(Get_GameObj(i)){ Attach_Script_Once(Get_GameObj(i),"Test_hubba",""); } else { Vector3 pos; pos.X = 0.0f; pos.Y = 0.0f; pos.Z = 0.0f; GameObject *invis = Commands->Create_Object("Invisible_Object", pos); Attach_Script_Once(invis,"Test_hubba1",""); Test_hubba1 void Test_hubba1::Created(GameObject *obj){ Commands->Start_Timer(obj,this,1.0f,1); } void Test_hubba1::Timer_Expired(GameObject *obj,int ID) { if(Get_GameObj(ID)){ for (int a = 0; a < 128; a++){ if(IsPlayerStealth[a] == true){ Commands->Enable_Stealth(Get_GameObj(a),true); } } } else { Attach_Script_Once(obj,"Test_hubba1",""); } } Test_hubba void Test_hubba::Created(GameObject *obj){ Commands->Start_Timer(obj,this,5.0f,1); } void Test_hubba::Timer_Expired(GameObject *obj,int number) { if (number == 1){ for (int a = 0; a < 128; a++){ if(IsPlayerStealth[a] == true){ Commands->Enable_Stealth(Get_GameObj(a),true); } } } } Now it depends on how fast you load. If i put in hubba_test1 the timer to for example 0.5 then it would be way to fast. But 1.0 works for me. But if we got a really slow player then it wouldnt work? Well i could put the timer to like 5.0 like i have in hubba_test then i would get most of the players. Yes i dont really know if i coded anything right in hubba_test1 so if you could take a look it would be nice.
Hubba wrote on Tue, 27 October 2009 15:10 reborn wrote on Tue, 27 October 2009 13:29 It absolutely will attach to an invis object. Did you remember the scripts registrant? //edit I see what you're doing wrong.. It's "Invisible_Object", not "Invis_Object". That did the trick. Okey i got it work. But i want you to take a look: Join_hook if(Get_GameObj(i)){ Attach_Script_Once(Get_GameObj(i),"Test_hubba",""); } else { Vector3 pos; pos.X = 0.0f; pos.Y = 0.0f; pos.Z = 0.0f; GameObject *invis = Commands->Create_Object("Invisible_Object", pos); Attach_Script_Once(invis,"Test_hubba1",""); Test_hubba1 void Test_hubba1::Created(GameObject *obj){ Commands->Start_Timer(obj,this,1.0f,1); } void Test_hubba1::Timer_Expired(GameObject *obj,int ID) { if(Get_GameObj(ID)){ for (int a = 0; a < 128; a++){ if(IsPlayerStealth[a] == true){ Commands->Enable_Stealth(Get_GameObj(a),true); } } } else { Attach_Script_Once(obj,"Test_hubba1",""); } } Test_hubba void Test_hubba::Created(GameObject *obj){ Commands->Start_Timer(obj,this,5.0f,1); } void Test_hubba::Timer_Expired(GameObject *obj,int number) { if (number == 1){ for (int a = 0; a < 128; a++){ if(IsPlayerStealth[a] == true){ Commands->Enable_Stealth(Get_GameObj(a),true); } } } } Now it depends on how fast you load. If i put in hubba_test1 the timer to for example 0.5 then it would be way to fast. But 1.0 works for me. But if we got a really slow player then it wouldnt work? Well i could put the timer to like 5.0 like i have in hubba_test then i would get most of the players. Yes i dont really know if i coded anything right in hubba_test1 so if you could take a look it would be nice. hubba_test1 is not correct, infact it's wrong on several levels... I am watching a movie and do not have time to correct it for you right now. However, the following is something that when I was first looking at the API and trying to figure shit out, I would of appreciated someone showing me... void Test_hubba1::Created(GameObject *obj){ Commands->Start_Timer(obj,this,1.0f,1); //number 1 at the end is kinda like a unique timer event... } void Test_hubba1::Timer_Expired(GameObject *obj,int number){ if(number == 1){ // this here is your number 1 from the previous comment // do some crap here, check if the dude has a GameObject yet... Commands->Start_Timer(obj,this,1.0f,1); // omg, it will loop again every second forever... } } void Test_hubba1::Created(GameObject *obj){ Commands->Start_Timer(obj,this,1.0f,1); Commands->Start_Timer(obj,this,10.0f,2); Commands->Start_Timer(obj,this,50.0f,3); } void Test_hubba1::Timer_Expired(GameObject *obj,int number){ if(number == 1){// this is triggered after a seconds... } else if(number == 2){// this is triggered after 10 seconds... } else if(number == 3){// this is triggered after 50 seconds... } } void Test_hubba1::Created(GameObject *obj){ Commands->Start_Timer(obj,this,1.0f,1); //number 1 at the end is kinda like a unique timer event... } void Test_hubba1::Timer_Expired(GameObject *obj,int number){ if(number == 1){ if(1 == 1){ // Just an example conditional.. you could for example check to see if the player is a gameobject here!!! :0 printf("1 equals 1"); Commands->Start_Timer(obj,this,1.0f,1); } else{// one does not equal 1, this is a break in the timer loop... The conditional does not pass, and there is no timer start in this statment } } }
I still think it would be better to do this on the players Created event, no need for the timers then... It's a bit better in my opinion. bool firstspawn[128]; //global array bool IsPlayerStealth[128]; // global array void Player_Join_Hook(int i,const char *Nick) { firstspawn[i] = true; IsPlayerStealth[i] = false; // etc etc etc Then in the object hook, where it attaches the SSGM player script, also attach Hubba_Player (or whatever)... void Hubba_Player::Created(GameObject *obj){ if(firstspawn[Get_Player_ID(obj)] == true){ for (int i = 1; i < 128; i++){ if(IsPlayerStealth[i] == true && Get_GameObj(i)){ Commands->Enable_Stealth(Get_GameObj(i),true); } } firstspawn[Get_Player_ID(obj)] = false; } 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); }; Also, who are you? It is not often that someone new comes to these forums who starts picking up the API.
Hmm... I tried what you posted above. But it didn't work. So i putted a 2 secound delay on the script and then it worked. I dont see way how to fix this other than with timers? And it doesnt really matters if there is a dealy. And who am I? I'm just a random player that thought it would be intresting to try to script
Perhaps there is an issue with the actual stealth comamnd then. I haven't really looked at it. The important thing with timers is that you should try to not have them looping all the time and keep re-attaching scripts. It's not ideal. I'm glad you got it working though! We got there in the end buddy! Why don't you try making the command only work for Nod players, and only work if the Hand of Nod is not dead..?
reborn wrote on Wed, 28 October 2009 09:19 Perhaps there is an issue with the actual stealth comamnd then. I haven't really looked at it. The important thing with timers is that you should try to not have them looping all the time and keep re-attaching scripts. It's not ideal. I'm glad you got it working though! We got there in the end buddy! Why don't you try making the command only work for Nod players, and only work if the Hand of Nod is not dead..? There is only a few issues left When the charachter buys another char using PT or kill himself will make the IsplayerStealth still to be true. (if the player bought a stealth suit earlier in the game.) Is there a way to see if the char has been changed?
Chage Hubba_Player to this: void Hubba_Player::Created(GameObject *obj){ IsPlayerStealth[Get_Player_ID(obj)] = false; //This line ensures that when a player is spawned (including new purchases) the array is updated to not include them as a stealth player, which is why you was getting that glitch. if(firstspawn[Get_Player_ID(obj)] == true){ for (int i = 1; i < 128; i++){ if(IsPlayerStealth[i] == true && Get_GameObj(i)){ Commands->Enable_Stealth(Get_GameObj(i),true); } } firstspawn[Get_Player_ID(obj)] = false; } Please consider adding conditions for making sure the player is team Nod and they Hand Of Nod must be alive for the command to work. I am not keen on these commands really, I hope you at least consider this... Now come on... Who are you?
reborn wrote on Wed, 28 October 2009 11:31 Chage Hubba_Player to this: void Hubba_Player::Created(GameObject *obj){ IsPlayerStealth[Get_Player_ID(obj)] = false; //This line ensures that when a player is spawned (including new purchases) the array is updated to not include them as a stealth player, which is why you was getting that glitch. if(firstspawn[Get_Player_ID(obj)] == true){ for (int i = 1; i < 128; i++){ if(IsPlayerStealth[i] == true && Get_GameObj(i)){ Commands->Enable_Stealth(Get_GameObj(i),true); } } firstspawn[Get_Player_ID(obj)] = false; } Please consider adding conditions for making sure the player is team Nod and they Hand Of Nod must be alive for the command to work. I am not keen on these commands really, I hope you at least consider this... Now come on... Who are you? I just want to say this that I really appreciate that you took time for helping me out. I have learned lots from you. Thanks reborn! And Thanks to everyone else that tried to help And who i am? Sorry but what answer do you want on this lol? I'm just a renegade player. I wanted to try how hard scripting could be. I got inspired while playing on all this modded servers I still got millons of other questions lol. But maybe I will ask them another day.
It's just rare to see someone join randomly, and start diving into the renegade API. In fact, it's rare to see someone new period now. I'm always pleased to see a new person come along, especially when they take to modding in this way. I did not mind helping, you picked it all up pretty quickly really.
reborn wrote on Wed, 28 October 2009 12:17 It's just rare to see someone join randomly, and start diving into the renegade API. In fact, it's rare to see someone new period now. I'm always pleased to see a new person come along, especially when they take to modding in this way. I did not mind helping, you picked it all up pretty quickly really. There is bound to be the random occurrence of ren players that want to start their own servers, Ren isn't dead YET. From what I've seen most ren players are excellent at asking questions when they need help, and from my experience, if they are shy, they usually bounce someone an IM. Now the real question should be whether or not any of these new people will stick around? lol