Change ID
by Robert Stewart · in RTS Starter Kit · 02/17/2005 (8:11 pm) · 12 replies
I was wondering if there war a simple way of changing the ID of a RTSUnit?
About the author
#2
Edit: Ok fine, i was shooting for a way to spawn a unit, save there id onto the server, load it back up with the server, I dont think i need it to work that way anymore. Can i scan the units in the game and find ones with certain variables? Thanks for any help.
02/19/2005 (10:43 pm)
Acually, I figured this out, and its late so i sorry for not telling about what the problem really was, or how i fixed it.Edit: Ok fine, i was shooting for a way to spawn a unit, save there id onto the server, load it back up with the server, I dont think i need it to work that way anymore. Can i scan the units in the game and find ones with certain variables? Thanks for any help.
#3
For example:
Certainly, but which units do you mean? Every single one in game? The ones visible to a particular client?
I assume you mean you want to find ones that have specific values for a particular variable(s), but what are the variables you mean--common datablocks? common hitpoints? common class types?
02/20/2005 (9:01 am)
It sounds like what you may be trying to do is some form of persistence for your units, but we really need a more detailed description of the exact functionality you want to have before we can give suggestions as to the way you want to being implementation.For example:
Quote:Can i scan the units in the game and find ones with certain variables?
Certainly, but which units do you mean? Every single one in game? The ones visible to a particular client?
I assume you mean you want to find ones that have specific values for a particular variable(s), but what are the variables you mean--common datablocks? common hitpoints? common class types?
#4
02/20/2005 (4:12 pm)
Common datablocks, i think. So when the player comes online it scans all the units in the game for one with %units.owner = %player.nameBase; Also while im here ill ask if there is a way to get the %client id from a function on the server, without having to put (%this or %client) for the functions variables. Thanks for the help btw.
#5
Now, if this is what you want to change, a possible solution would be:
--Instead of deleting the objects (which happens in server/scripts/core/gameConnection.cs--GameConnection::onClientLeaveGame(): units are marked as disabled, and buildings are deleted when %this.buildings.delete() is called), place them in a group, call it $UncontrolledRTSObjects or something like that, and for each of those units/buildings add a field like %unit.OldPlayerName.
--if/when the client reconnects, iterate over this group (server side), and reconnect each unit where the %unit.OldPlayerName is the same as the client's playername. You would need to set the controllingConnection, and probably the team again on the units as well.
NOTE: There are several issues with this type of "partial persistence" solution:
1) TGE doesn't protect player names with passwords. Say PlayerA with a player name of "Poser" has a bunch of units, and then disconnects. Now, PlayerB connects, and has the same name of "Poser"--PlayerB will get control of all the units PlayerA had created.
2) units with no controlling connection are not handled AFAIK in stock RTS-SK 1.0, so you'll need to handle them properly. This might be really easy, or it might be a -lot- of work, I really don't know.
02/20/2005 (4:37 pm)
By definition, when a player logs in to stock RTS-SK games, there are no units with an owner of that client--when the client leaves the game, all their units (building and troop) are removed from the game.Now, if this is what you want to change, a possible solution would be:
--Instead of deleting the objects (which happens in server/scripts/core/gameConnection.cs--GameConnection::onClientLeaveGame(): units are marked as disabled, and buildings are deleted when %this.buildings.delete() is called), place them in a group, call it $UncontrolledRTSObjects or something like that, and for each of those units/buildings add a field like %unit.OldPlayerName.
--if/when the client reconnects, iterate over this group (server side), and reconnect each unit where the %unit.OldPlayerName is the same as the client's playername. You would need to set the controllingConnection, and probably the team again on the units as well.
NOTE: There are several issues with this type of "partial persistence" solution:
1) TGE doesn't protect player names with passwords. Say PlayerA with a player name of "Poser" has a bunch of units, and then disconnects. Now, PlayerB connects, and has the same name of "Poser"--PlayerB will get control of all the units PlayerA had created.
2) units with no controlling connection are not handled AFAIK in stock RTS-SK 1.0, so you'll need to handle them properly. This might be really easy, or it might be a -lot- of work, I really don't know.
#6
02/20/2005 (8:00 pm)
I have this kinda working now, but i have another question, is there a way to get the %client id from a function on the server, without having to put (%this or %client) for the functions variables. Thanks.
#7
02/20/2005 (8:04 pm)
Not really. Why do you not want to have them as function parameters?
#8
02/20/2005 (8:08 pm)
Acually. Im sorry that i asked that so soon, i just figured out a way to fix it. Sorry again, and thanks for help.
#9
02/20/2005 (8:34 pm)
That's good, but it really sounds like you are backing yourself into a corner--%client and %this are passed as parameters for extremely good reasons, and "back-ending" things around putting them in as parameters suggests that you are doing things unconventionally...and most often, that limits your options extremely...
#10
function(%this)
{
%this.owner = "new";
}
Is that acually wrong?
02/20/2005 (9:11 pm)
This is what im doing with %this function(%this)
{
%this.owner = "new";
}
Is that acually wrong?
#11
That being said, the psuedo-code block you posted is exactly how parameters are supposed to be used--so I don't understand your question:
You put %this in the function's variables in the code block above...
02/20/2005 (9:15 pm)
It depends on what you are sending as the parameters. You've stripped it down entirely, so I don't really have a context of what is calling the function, or what "%this" is...That being said, the psuedo-code block you posted is exactly how parameters are supposed to be used--so I don't understand your question:
Quote:is there a way to get the %client id from a function on the server, without having to put (%this or %client) for the functions variables
You put %this in the function's variables in the code block above...
#12
02/20/2005 (9:38 pm)
Oh right, thats because at first i couldent get the %this to return any data, but i fixed that, so i was looking for another way to get the %client id. Sorry for the confusion.
Associate Kyle Carter
You can probably acheive your goal more easily in a different way - what are you shooting for here? :)