Jump to content

Map change and FPS weapon pack


BluHornet
 Share

Recommended Posts

I will start by saying I just started learning Lua and scripting in the last week when I got the steam indie edition. I have done the tutorials that are in the engine when I got it. I also read the tutoials on the Leadwerks site and the Project Saturn videos off YouTube.

 

Ok on to the topic. When I load the 09-changemap.map everything works fine. If I drop a pistol pickup from the FPS Weapon pack and walk around it everything is still good. If I pick up the weapon everything is ok until I collide with the change map block. That is when I get a Lua stack overflow and the game crashes back to the editor. I found this after about 2 hours of messing around when my project did the same thing. I have looked into the stack error and it has something to do with Lua passing info to C. I have no idea, can someone at least point me in the right direction?

 

Thanks!

Link to comment
Share on other sites

While continuing to work on this issue I have found one work around.

 

If I use the base autopistol by giving it to the player at the start of each map and creating a global value in the app.lua for the number of magazines remaining. I allow the game to clear the player weapon table and then changed the reload script to check then reduce the mag counter. this is cool for a survival game but I want to make a zombie survival shooter. I paid $20 for the fps pack. I am learning a lot along the way.

 

My most recent endeavor was to make the weapon table and curretweaponindex global instead of player.script. this works fine until the mapchange hits then it crashes and in the log it says

OpenAL: AL_INVALID_OPERATION

Link to comment
Share on other sites

this seems come from OpenAL (Open Audio Library)

did u try clean the table here in player?

Script:Cleanup()

  • Upvote 1

PC : Win 10 Pro 64 Bit , 4x cores ~2 GHz , 8 GB RAM , AMD R7 265

2D : Photoline , Zooner Photo Studio 13 , Art Rage Studio 3.5.4 , Ashampoo Snap 7 , ...

3D : Shade 15 Basic , Carrara 8.5 & DAZ Studio 4.8 , Cheetah 3D 6.3.2 , Via Cad 8

Music : Samplitude Music Studio , Music Creator 7

IDE : Leadwerks Engine 3.x , Unity 5.x , (Unreal 4.8.x) , AGK v2.x , Construct 2 , (Clickteam Fusion 2.5) , ShiVa 1.9 , Game Maker Studio , MS Visual Studio .Net , Android Studio , Monkey , ...

Link to comment
Share on other sites

Ok so I changed the weapons table, currentweaponindex variable, and weaponlowerangle variables into global In the APP instead of being in the FPSPlayer script. I changed all references in the FPSPlayer, FPSGun, and Pickup Weapon scripts. I have a small HUD I tweaked from the Project Saturn tutorial. It shows player health and I added clipammo and total ammo for the currently held weapon. When I pick up weapons everything works well now. When I change maps using the TriggerMapChange I can see that my HUD shows I have those weapons and their total and clip ammo is correct and I have a crosshair in the proper spot on the screen. there is no model drawn though. If I cycle weapons my HUD updates the values properly but the only other thing I can see changing is the pick up models visibility is cycling as if they are being confused for the currently equipped weapons. nothing appears in my hands. if I try to reload nothing happens and if I try to fire the game freezes and the windows "Program has stopped working" happens. the window closes back to the editor and the error, debug, and warnings are blank, while other than loading textures and the process complete line the log is uneventful. I think the required models, animations, sounds and such are not loading. how do I know if that is the problem? how do I get them to load properly?

Link to comment
Share on other sites

Today I worked on trying to copy the weapons table, currentweaponindex variable, and weaponlowerangle variables to global variables using the trigger change map script. I think this isn't working due to I am not coping the table correctly. Will a line

globalweapons = entity.script.weapons

copy one complete table with all it's contents to another or do I need to follow the "for in pairs"?

I am not sure how to use table iterations.

Link to comment
Share on other sites

For a good source of code using tables, refer to the GetEntityNeighbors.lua which can be found in Scripts Functions.

 

Its one of the more complex pieces of LUA code in leadwerks, but if you take your time to follow what it does you can make some useful functions.

 

Here is one pair of additional functions that I used in LastOneStandingWins to get the number of zombies and crawlers still alive in the level. It uses a axis aligned bounding box 100m from the centre in all directions, and calls the call back for each entity found. In this simplifed callback fundtion the table processing has been removed, as its not required.

 

WorldGetEntitiesInAABBDoCallbackTable = nil

GetEntityNeighborsScriptedOnly=false

NumCrawlers=nil

NumZombies=nil

 

function WorldGetEntitiesInAABBDoCallbackTeamAlive(entity)

if entity~=nil then

if entity.script~=nil then

--team members

if (entity.script.teamid==1) then

if entity.script.health > 0 then

-- who are alive

NumCrawlers = NumCrawlers + 1

end

elseif (entity.script.teamid==2) then

if entity.script.health > 0 then

-- who are alive

NumZombies = NumZombies + 1

end

end

end

end

end

function GetTeamScore(entity)

-- How many members of the specified team are alive

local aabb = AABB()

local p = Vec3(0,0,0) -- centre of world

NumCrawlers=0

NumZombies=0

 

aabb.min = p - 100

aabb.max = p + 100

aabb:Update()

entity.world:ForEachEntityInAABBDo(aabb,"WorldGetEntitiesInAABBDoCallbackTeamAlive")

return NumCrawlers,NumZombies

end

 

its driven from MonsterAI.lua

 

in SetMode(mode) when the mode is "dead" and in Start() with this line of code.

 

App:SetScores(GetTeamScore(self.entity))

 

 

This Function is added in App.lua

 

function App:SetScores(numCrawlers,numZombies)

if numCrawlers == nil then

StartingCrawlers = 1000

else

StartingCrawlers = numCrawlers

end

if numZombies == nil then

StartingZombies = 1000

else

StartingZombies = numZombies

end

end

 

You can also tweak the way the AI works by updating GetEntityNeighbors, for instance only storing opposing team members in the table,and setting a much smaller distance, so the stored entities are localised. to the current entity. This means a smaller table and therefore processing faster and more efficiently. If this returns no entries scan again but with a much bigger distance that encompases the whole map, and this typically only gets called as the area empties. Doing this allowed me to have over 20 per team and keep up a reasonable frame rate early in each level, and use Lua script.

  • Upvote 1
Link to comment
Share on other sites

That is something I never even knew could be done. That is a very nifty piece of script. I would have tried to do mob counts with global variables and then having spawning add to the count and death subtract. I will have to look at the GetNeighbors and see if I can learn anything there. Thanks for your reply

Link to comment
Share on other sites

@Gonan

 

i hope you will not get angry and please only take this as an try to help. :)

 

I wouldn't do it this way to check how many are still alive.

I tried something similar (and a couple other approaches) with my RTS script to keep track of units.

 

First it might get slower as more entities get into the world. (at least if you call it every frame or so when running as you probably do when you want to keep track of alive enemies).

Since it goes over every entity. Even if it is only a scene entity.

 

Second it is limited to a specific map size depending on your set AABB Size.

 

 

I would use the map load hook once to get all enemies which are placed by the map creator.

http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/map/mapload-r510

 

and then only add or substract one when the according spawn or die function of the enemie is called.

 

That should solve the possible issues and would make your code easier.

Link to comment
Share on other sites

@beo6, thanks for the alternative.

 

In my case I only perform the check when an entity is dead.

 

The two approaches will ideally give the same results, subtracting 1 from a total, is obviously way faster than an entity scan and totalling up each side every time one dies.

 

The subtlety is one method catches all the ones that die and subtracts 1 from a total as part of that function, and the other counts all those that are alive and in play. As long as I remember to update the counter every time something dies or is born, or is resurrected, both methods will give the same answers.

 

The government have the same problems with population count, people arrive, leave, born, die, countries vote for independence so could leave taking all their population with them, but every 10 years they check the totals with a census.

 

Having both methods have their uses, just use them at the right time.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...