PDA

View Full Version : How to give the player an upgrade through actions? (plus random insights)



shiremct
8th Oct 06, 3:21 AM
In making a buildable bazooka team, I've run into a little problem. My bazooka team are given their bazookas through a global slot_item upgrade, but i don't want the player to have to research the upgrade, i want it to automatically start researched. Within the actions, there is a remove upgrade function, but nothing to add one, however, there is a call scar function, so it should be possible to give the player the upgrade through scar (which is just a scripting language, correct?), yes? I don't have any experience with scar or any of relic's other exclusive structures for that matter, so could perhaps someone direct me to a location with scar functions and descriptions? Thanks in advance.

This would be very helpful, as using upgrades to tweak and add to the game is likely something i will be using alot. Sometimes the same functionality can be achieved through other means (like on_constructed actions,etc) but using upgrades is a great way to keep things consistent. And actually, i have a question regarding my upgrade; as I am not all that familiar with .lua editing, I'm not sure if part of my code is actually valid or not, and its not exactly something that is easy to see.


GameData = Inherit([[]])
GameData["upgrade_bag"] = Reference([[bags\upgrade_bag.lua]])
GameData["upgrade_bag"]["actions"]["action_01"] = Reference([[action\upgrade_action\filter_action.lua]])
GameData["upgrade_bag"]["actions"]["action_01"]["action_table"]["upgrade_actions"]["action_01"] = Reference([[action\upgrade_action\slot_item_add.lua]])
GameData["upgrade_bag"]["actions"]["action_01"]["action_table"]["upgrade_actions"]["action_01"]["slot_item"] = [[slot_item\allies_m9bazooka.lua]]
GameData["upgrade_bag"]["actions"]["action_01"]["action_table"]["upgrade_actions"]["action_02"] = Reference([[action\upgrade_action\slot_item_add.lua]])
GameData["upgrade_bag"]["actions"]["action_01"]["action_table"]["upgrade_actions"]["action_02"]["slot_item"] = [[slot_item\allies_m9bazooka.lua]]
GameData["upgrade_bag"]["actions"]["action_01"]["apply_to_future_units"] = true
GameData["upgrade_bag"]["actions"]["action_01"]["squad_type"] = [[sbps\races\allies\soldiers\ranger_team.lua]]
GameData["upgrade_bag"]["actions"]["action_02"] = Reference([[action\ability_action\filter_action.lua]])
GameData["upgrade_bag"]["actions"]["action_02"]["action_table"]["ability_actions"]["action_01"] = Reference([[action\ability_action\apply_modifiers_action.lua]])
GameData["upgrade_bag"]["actions"]["action_02"]["action_table"]["ability_actions"]["action_01"]["modifiers"]["modifier_01"] = Reference([[modifiers\accuracy_weapon_modifier.lua]])
GameData["upgrade_bag"]["actions"]["action_02"]["action_table"]["ability_actions"]["action_01"]["modifiers"]["modifier_01"]["value"] = 1.20
GameData["upgrade_bag"]["actions"]["action_02"]["action_table"]["ability_actions"]["action_01"]["modifiers"]["modifier_02"] = Reference([[modifiers\damage_weapon_modifier.lua]])
GameData["upgrade_bag"]["actions"]["action_02"]["action_table"]["ability_actions"]["action_01"]["modifiers"]["modifier_02"]["value"]= 1.20
GameData["upgrade_bag"]["actions"]["action_02"]["apply_to_future_units"] = true
GameData["upgrade_bag"]["actions"]["action_02"]["entity_type"] = [[ebps\races\allies\soldiers\bazooka_team_gunner.lua]]
GameData["upgrade_bag"]["global_max_limit"] = 1
GameData["upgrade_bag"]["local_max_limit"] = 1
GameData["upgrade_bag"]["owner_type"] = [[player]]

This is the code, which i frankenstiened from a few abilities and veterency info. I know that action_01 works fine as I have used it many times and as you can see, my boys are packing :)

http://www.freeimagehosting.net/%5D%5Bimg%5Dhttp://img2.freeimagehosting.net/uploads/93ffa5226f.jpg
(If pic doesnt show up = (http://img2.freeimagehosting.net/image.php?93ffa5226f.jpg))

However, I'm not sure about action_02. I think it [i]should work, but I find it hard to tell. I was hoping someone familiar with .lua editing could tell me yes, these are valid commands, but if not, i have a few ideas in mind to test it out, i just didnt want to mess with it if I didnt have too. I could tweak the code to replace the entity's weapon... that would be obvious, but that still doesnt gaurentee that I can alter accuracy and damage on the entity by entity basis, but it seems that I should be able to do so... If someone knows for sure one way or the other, please let me know.

The idea with the code in action_02 is that, honestly, bazookas are not an effective means of anti-tank support as they stand currently, not even against light armor like the puma, however, by tweaking the accuracy of the bazooka team gunners and not the bazooka, it makes it a better idea to leave the bazookas in the trained bazooka team, rather than picking them up with riflemen. If the code works as intended, it would be pretty easy to tack on a requirement that the bazooka slot_item must be equipped to recieve the bonuses.

Using methods like this, you could add a lot of depth and tactical/strategic value to the game with complex relationships, but have it all take place under the surface, where the player could ignore it if they chose and it not really penalize them but at the same time, a player who pays closer attention to what his troops equip and how he uses them would see extra benifits.

Speaking of slot_items, just a FYI for those who may not know it, but slot_items applied through upgrades, and possibly through pickups (not sure, but easily tested) are distributed in the order of the squad's loadout. Say you have a squad with 3 engineers and 4 Riflemen, but you want the engineers to equip the heavy weapons... you would add the engineers to the first entry on the squad loadout and the rifles in the second. Yes, it may be easier to simply place the engineer's heavy weapon as such&such in their ebps/.../hardpoint_01 but that is many times a much worse implementation then adding a slot_item to the squad. In most of the mods that people have released recently, I see their weapon changes largely being implemented by hardcoding it into their hardpoint table. I'm not trying to disrespect the modders or their work, I'm just trying to point out there is a better way. :) (Of coures, excellent work on all the mods you guys are releasing! I am having fun playing around with them and seeing what and how you all changed various things.)

I'm thinking there was something else I intended to include...but, well, no need to write a friggen book!
I'll be back if I forgot something :bigwave:

shiremct
8th Oct 06, 5:28 AM
Just a quick update: The modifiers on the individual entities within the squad worked as expected (I added another modifier that multiplied weapon range by 5 to test). Add to this using the required_slot_item and I think that a lot of possibilites are opened up.

Still looking for a way to give an upgrade automatically though:mag:

2ltben
8th Oct 06, 9:04 AM
http://forums.relicnews.com/showthread.php?t=111944

Couldn't you just make a new "Bazooka Gunner" unit in ebps and set his hardpoint to a Bazooka?

shiremct
8th Oct 06, 1:52 PM
http://forums.relicnews.com/showthread.php?t=111944 (http://showthread.php?t=111944)

Couldn't you just make a new "Bazooka Gunner" unit in ebps and set his hardpoint to a Bazooka?

*Sigh*
Yes, but that is exactly what I am talking about in my last main paragraph. That is an easy way of doing it, but you lose a lot of flexibility and functionality in doing so. This is the reason all the items in the game are added with upgrades or abilities, rather than just hardcoded on as the standard hardpoint. Because the upgrade adds slot_items, the squads can function without their upgrades, can drop the heavy weapons, can pass them onto another member when the carrier is killed, etc etc.

Take the airborne infantry squad for an example. The game could go the route of switching the soldier's weapons or altering its loadout when you purchase the recoilless rifle upgrade, but if it did things that way, the heavy weapon carriers would be static entities. When that soldier died, the gun would go with him. Reinforcing him back into the squad would bring him and his weapon back, but while he was dead, the weapon would be lost to the squad. He would also never drop the weapon for other squads to pickup (I know that the recoilless rifles dont drop anyway, but for the sake of the argument, most slot_item upgrades can be dropped when the carrier is killed and captured by another squad).
So all those cool little details, like being able to retrieve the weapons when a squad takes losses and the squads passing the heavy weapons on to surviving members in combat... when you go the ebps\...\hardpoint_01 route, you cut all of these little things out of your new unit. If that squad is killed, its weapons are lost with no chance to recapture... If the weapon carrier dies, the rest of the squad cant access the weapon until that member is reinforced... If the squad happens to pick up an existing slot_item on the ground or purchases one through an upgrade, you could find that that BAR is equiped by the bazooka gunner rather than the guy with the pistol...

Basically, that method is a cheap and easy path to what you want, but it negates many of the great little features that the game has to offer. Even in situations where the flexibility it would cut out would be minimal, I wouldn't take that path because its just bad procedure. Sure, its all fine to do it that way to mess around and learn the tool and code, but it is not really the best way to do it.

I have tried to stress the disadvantages of this method several times, but I don't think many people realize just what they are cutting out by taking this route and how little extra effort is required to do it right. I've been intending to put a HOW TO post up, but haven't gotten around to it yet. In the meantime, check the post linked below for a pretty good description of how to go about it:
http://forums.relicnews.com/showthread.php?t=110844

communist_bob
9th Oct 06, 12:01 AM
Damn you make long posts. Interesting though, that slot_item stuff is something new (to me)

naradaman
9th Oct 06, 12:07 AM
Mmmkya after some searching I've dug something up:

From data/scar/squad.scar.

--? @shortdesc Gives all slot items in a table to the squad. The table should come from Squad_GetSlotItemsTable
--? @args SquadID squadid, LuaTable itemTable
--? @result Void
function Squad_GiveSlotItemsFromTable(squadid, itemTable)

for i = 1, table.getn(itemTable) do

Squad_GiveSlotItem(squadid, itemTable)

end

endThe idea now is you can use the action scar_function_call</i> to call the function. Things get tricky from here, though.

Can someone confirm to me what form [i]scar_function_call will take? There's only one value, function name, so where do arguments go?

When we figure that out we have to find a way to reference the squad (probably something like self) and the weapon table.

I'll do some more digging when I can.

Edit: derrr, I'm an idiot. It says the required table should come from this function:
function Squad_GetSlotItemsTable(squadid)

local slotItems = {}
local itemcount = Squad_GetSlotItemCount(squadid)
for i = 1, itemcount do

local item = Squad_GetSlotItemAt(squadid, i)
table.insert(slotItems, item)

end

return slotItems

endThis makes it a little easier. Because the upgrade you want applied is already in the squad's slot, we can just use this.

The only thing left to find is a way to reference the squad.

shiremct
9th Oct 06, 6:53 AM
That will be useful in some situations, but I am doing a little more with upgrades that I would still like to be able to call automatically. I am working on a small showcase mod for the ammo box right now.

Delphy
9th Oct 06, 7:17 AM
shiremct, good ideas with the slot item stuff - I've been looking into stuff like that myself, but focusing more on the fact that you have to give a squad a position number for the UI for it to show up in a building, as opposed to the building itself saying what slot the squad to build shows up in (as the forward hq does). It's tricky work though, but I applaud you working with the game too :)

shiremct
9th Oct 06, 12:50 PM
Couple other updates:

I can't believe I didnt think about using abilities to do things i wanted initially researched... especially since I have used them for similar things in the past! So, an ability that has no requirements and runs a filter action to add weapons to a squad accomplishes one of my goals, and that makes me happy :D

Unfortuntely, my other goal has hit a brick wall. I need some help working with requirements. I need an ability to only work when a squad has a certain weapon (say, a bazooka). I tried required_slot_item and i tried required_entity. None of the other requirements options look usable for what I want to do.
So... does anyone know HOW these requirements are compared? For required_slot_item, WHERE does it look for the slot_item? Is required_slot_item one of the many remenants of things no longer usable or existing in the retail build of the game? I'm going nuts, i really want this to work! plz help!