Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Forum » Questions (player objects, stealth vehs)
Questions (player objects, stealth vehs) [message #413375] Mon, 07 December 2009 09:29 Go to next message
Hubba is currently offline  Hubba
Messages: 40
Registered: October 2009
Karma: 0
Recruit
Question 1: I have build commands on my server so now i have been wondering when you for example use !ramp which create a ramp. How can i make so the object belongs to a player-id? So it would store all objects a player has made in an array or something? Then when the user type !cleanup it would remove all the objects he have made.

Question 2: I have a "!ssv" command which sets the current vehicle a player is inside to stealth. Now i want to make so when an another player join the game later he should see them stealth. So i need somehow to add and store all the vehicles in an array so it would loop that array when the other play joins and set stealth to all these vehicles. But the problem is how could i make so when i type !ssv it would add the vehicle to the array? And how can i remove that vehicle from the array when it gets destroyed?

Now i don't know if arrays is the best way to do it. But if you have a better idea then please tell it Dont Get It ?

Code in spoilers.
!ramp
Toggle Spoiler

!ssv
Toggle Spoiler


Thanks,
Hubba
Re: Questions (player objects, stealth vehs) [message #413579 is a reply to message #413375] Wed, 09 December 2009 02:52 Go to previous messageGo to next message
reborn is currently offline  reborn
Messages: 3231
Registered: September 2004
Location: uk - london
Karma: 0
General (3 Stars)
Maybe add the player ID in the first element of a 2d Array, and then store the object id's of the GameObjects's 'they' created in the Second element of the 2D array.

However, I might look at Vector's if it was me (no, not the vectors used for x,y,z, it's kinda like an array but better because they're dynamic.

Hope this helps.



Re: Questions (player objects, stealth vehs) [message #413680 is a reply to message #413579] Thu, 10 December 2009 08:20 Go to previous messageGo to next message
Hubba is currently offline  Hubba
Messages: 40
Registered: October 2009
Karma: 0
Recruit
Thx for the reply. I looked at vectors and made this:

This is the 2d vector which should store all the player id and the objects.
 vector<vector<int> > vector2d ( 121, vector<int> ( 0 ) );


The input code i have now:
int a = Get_Player_ID(obj);
vector2d[a].push_back (1);

This will just add a new element with value "1" to the player-ids vector.


But now my question is: how can I add an ids to the objects I create?

[Updated on: Thu, 10 December 2009 08:24]

Report message to a moderator

Re: Questions (player objects, stealth vehs) [message #413681 is a reply to message #413375] Thu, 10 December 2009 08:43 Go to previous messageGo to next message
reborn is currently offline  reborn
Messages: 3231
Registered: September 2004
Location: uk - london
Karma: 0
General (3 Stars)
Hmm, it might be better to store all the object ID's of the GameObjects against the PlayerID.

I'm so busy now, but I will try to post some code soon.



Re: Questions (player objects, stealth vehs) [message #413682 is a reply to message #413681] Thu, 10 December 2009 09:00 Go to previous messageGo to next message
Hubba is currently offline  Hubba
Messages: 40
Registered: October 2009
Karma: 0
Recruit
reborn wrote on Thu, 10 December 2009 09:43

Hmm, it might be better to store all the object ID's of the GameObjects against the PlayerID.

I'm so busy now, but I will try to post some code soon.



Well i don't really get what you mean but what i posted works like this:

vector2d[0] <objects ids go here> // player id 0 objects...
vector2d[1] <objects ids go here> // player id 1 objects...
vector2d[2] <objects ids go here> // player id 2 objects...
etc..

[Updated on: Thu, 10 December 2009 09:01]

Report message to a moderator

Re: Questions (player objects, stealth vehs) [message #416529 is a reply to message #413375] Sat, 02 January 2010 14:05 Go to previous messageGo to next message
Hubba is currently offline  Hubba
Messages: 40
Registered: October 2009
Karma: 0
Recruit
Alright im still stuck with this. So i thought it would be a good idea to bump the thread.

The problem is How can i make an object to be stored as an id in the vector?

So when i do for example:
!ramp
It would create the object.
Then get the id of that obj and add it to the vector.
Then the vector would look like this Vector2d[playerid][1]
Then if we do the command again it would add a new element so it would be Vector2d[playerid][1,2] etc etc.

Then when i do !sellall i would just loop through the vector depending on the playerid and then do Commands->Destroy_Object on all the objects. But then again how would i be able to find the objects?.

I Hope someone can help because i don't know if is it possible to do way i just wrote up.


Re: Questions (player objects, stealth vehs) [message #416572 is a reply to message #413375] Sun, 03 January 2010 04:09 Go to previous messageGo to next message
reborn is currently offline  reborn
Messages: 3231
Registered: September 2004
Location: uk - london
Karma: 0
General (3 Stars)
To find the object...
typedef GameObject *(*_Find_Object) (int ObjectID);


The 2d vector idea sounds fine to me...



Re: Questions (player objects, stealth vehs) [message #416577 is a reply to message #413375] Sun, 03 January 2010 05:27 Go to previous message
Hubba is currently offline  Hubba
Messages: 40
Registered: October 2009
Karma: 0
Recruit
Thanks Reborn. Could someone check if this is right? It works but is this an ok way to do it?. Should i add something more?


I added these lines to my !ramp command
int playerid = Get_Player_ID(obj);

vector2d[playerid].push_back(Commands->Get_ID(turret)); // Turret = the object


And this is what the !sellall command looks like
class sellallChatCommand : public ChatCommandClass {
   void Triggered(int ID,const TokenClass &Text,int ChatType) {
	   GameObject *obj = Get_GameObj(ID);
	   int playerid = Get_Player_ID(obj);

	for (unsigned int i=0; i<vector2d[playerid].size(); i++) // Loop through all the object if there are any.
	{	
		Commands->Destroy_Object(Commands->Find_Object(vector2d[playerid][i])); 
	}
	
	vector2d[playerid].clear(); // clears all the elements in the vector.

   }
};
ChatCommandRegistrant<sellallChatCommand> sellallChatCommandReg("!sellall",CHATTYPE_ALL,0,GAMEMODE_AOW);

[Updated on: Sun, 03 January 2010 05:28]

Report message to a moderator

Previous Topic: A few skins
Next Topic: C++ code help please.
Goto Forum:
  


Current Time: Sat Dec 21 04:31:26 MST 2024

Total time taken to generate the page: 0.00811 seconds