Scripts / Script to load multiple weapons at the start of game/level

Author
Message
Methos
7
Years of Service
User Offline
Joined: 21st Sep 2016
Location:
Posted: 1st Jul 2017 15:27 Edited at: 1st Jul 2017 15:27
Looks like I figured a way to give your character specific weapons right from the start - pretty simple too so figured I'd share in case anyone else is interested. The project I'm working on calls for an external program "manager" of sorts where you will decide what weapons you want to carry on a mission and that will edit the scripts used in the map. That way one map can be used (the external manager will control other aspects of modifying the base map to customize your mission as well).

So, what I do is place every weapon that could be used into the level - location doesn't matter as there's no distance check. You don't pick up the weapons, they are just added automatically. Next, select, "myloadweapon.lua" as the script for each weapon. Script is as follows:



It's simple enough .. just check the name of the weapon and if it equals one that you want to use, add it to the player. It's easy enough to deselect weapons - just comment out the "AddPlayerWeapon(e)" line of the weapon(s) you don't want and they will be removed.

Only thing I'm not sure how to do yet is to set each weapon to a specific slot in the player's inventory. That WOULD be nice. And I'm not sure (haven't tested enough) if the order they are added is random or if it follows the order in which the weapons were added to the level. If the latter, that would make it easy to set what you want where.

Enjoy! Or don't - up to you. (lol)
PM
Corno_1
GameGuru Tool Maker
13
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 1st Jul 2017 15:38 Edited at: 1st Jul 2017 15:41
Just one thing, this should do the same thing:



also if you want to filter it is better to use a for loop in this case or at least use elseif. And for your slot problem use this
SetWeaponSlot: SetWeaponSlot ( index, got flag, preference flag ) -- Sets the weapon data directly, index is 1 through 10
(dont ask me what this flags mean)

Have a nice day
Ebe Editor Free - Build your own EBE structures with easy and without editing any text files
Thread and Download
PM
Methos
7
Years of Service
User Offline
Joined: 21st Sep 2016
Location:
Posted: 2nd Jul 2017 05:20 Edited at: 2nd Jul 2017 05:21
Ummmm, that's what's in my script already. And as far as a loop or using elseif, really doesn't matter as it gets the job done. These aren't the weapons I have, I just put the default in cause I know some people were talking about pre-loading specific weapons. But my game will have 6 weapons to choose from for every mission so I just need a check to see which ones were selected. The external program, "manager" basically rewrites the lua file each time to specify what's going to be active so that's how I will comment out the AddPlayerWeapon(e) lines that won't be active.

I will look into the SetWeaponSlot thing though. Looks good.
PM
Corno_1
GameGuru Tool Maker
13
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 2nd Jul 2017 12:33
Quote: "Ummmm, that's what's in my script already."

I know and what I mean to say that all your "if"s just filter the weapons and thats not clear to me. Because you give the weapons the script which should added to the player at start, but then you filter the weapons. Why you not filter the weapons when you add the script to them or what reason you have to exclude a weapon like "Sword"? The script will run all the time in the back and reduce performance for all weapons which are excluded.

Quote: "And as far as a loop or using elseif, really doesn't matter as it gets the job done. "

That is right, but for a game engine which has so many memory lacks, it is not well done and you should care about such extra performance decreases.
Ebe Editor Free - Build your own EBE structures with easy and without editing any text files
Thread and Download
PM
Methos
7
Years of Service
User Offline
Joined: 21st Sep 2016
Location:
Posted: 2nd Jul 2017 17:19
How will it continue to run in the back? Isn't it like weapon.lua? when conditions are right, addplayerweapon and destroy ends it, right? And since there will only be those initial weapons, shouldn't it run at the start, add the weapons and then end? There are no further weapons to pick up. Or am I missing something?
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 2nd Jul 2017 21:26
you are correct
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Login to post a reply

Server time is: 2024-04-24 00:31:32
Your offset time is: 2024-04-24 00:31:32