Results 1 to 4 of 4

Thread: 3 Problems: GUI visual style, pathfinding, respawning entities

  1. #1

    Default 3 Problems: GUI visual style, pathfinding, respawning entities

    I've run into a few mental roadblocks with my game, and any help would be appreciated.

    1) My HUD is essentially a copy/paste of the interface script from Top Down RPG with the coin code from TreeWorld mixed in. I've added another icon based on the coin bits to the HUD which indicates the currently equipped magic. When the HUD is updated, it runs a function in my current_spell.lua script which should change the visual style to another icon. This function is running (can see it in my log), but no matter what I do, the style will not change.

    I've also tried changing the style directly from interface.lua, but that won't work either.

    So, yea, is it that my spell script can't access the interface after setup because it's running as a global or something?


    2) Is there a way to make brains temporarily ignore paths and walk directly towards a moving target? My bat creature should fly straight towards the player if the player is within range and in its line of sight. If the bat loses line of sight, it should return to its perch and idle.

    With no path nodes on the map, the bat chases the player perfectly, but gets lost on its way "home" and falls asleep in mid-air. With a network of path nodes, it goes home correctly, but that makes the chase awkward. As in, the angular movements along the path edges looks weird for a flying creature, and if the player is between nodes, the bat will often backtrack to the previous node just before and after attacking the player.

    3) Is there an easy-ish way to make entities which respawn every time you enter a map? I've made invisible entities which can spawn beasties on visible and on init/map insert. On visible is good for never ending zombies, to be sure, but on init and map insert only seem to work when you start a new game or continue.

  2. #2
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,343

    Default

    1) My HUD is essentially a copy/paste of the interface script from Top Down RPG with the coin code from TreeWorld mixed in. I've added another icon based on the coin bits to the HUD which indicates the currently equipped magic. When the HUD is updated, it runs a function in my current_spell.lua script which should change the visual style to another icon. This function is running (can see it in my log), but no matter what I do, the style will not change.

    I've also tried changing the style directly from interface.lua, but that won't work either.

    So, yea, is it that my spell script can't access the interface after setup because it's running as a global or something?
    Hmm, I can't think of any reason why this wouldn't work. Possible bug? If you can give me a copy of your world I'd be glad to check it out.

    2) Is there a way to make brains temporarily ignore paths and walk directly towards a moving target? My bat creature should fly straight towards the player if the player is within range and in its line of sight. If the bat loses line of sight, it should return to its perch and idle.
    I think I need to add a way to control pathfinding per entity. I'll add this and make sure there is a C_PATHFINDING_NONE flag available so your bat can ignore it.


    3) Is there an easy-ish way to make entities which respawn every time you enter a map? I've made invisible entities which can spawn beasties on visible and on init/map insert. On visible is good for never ending zombies, to be sure, but on init and map insert only seem to work when you start a new game or continue.
    So, after you go into the store and come back, all the entities are "reset"? one cheapish way would be to reload the entire map. (Make sure the map isn't set to persistent in the map properties in that case)

    The StrongAI example does this, everytime you start a game, it unloads (GetMapManager:UnloadMapByName) and then loads the map (GetMapManager:LoadMapByName) to refresh all the monsters and items.

    If you only want the monsters refreshed and not the items.. hmm.. maybe you could broadcast a message to every enemy on the map to kill itself, and they could in turn turn back on their parent spawner (they could remember who spawned them) or something like that.

    How could you broadcast to every entity on the map in the warp script?

    Well...

    Map:GetTilesByRect() could do it, for the rect to search, you could use Map:GetWorldRect() so everything on the map is included. Then you would cycle through and check for enemy entities and run their "OnPlayerLeftMap()" function or such.

    This seems a little bit slow/messy though, I have been thinking about adding a kind of BroadcastToEntityByCategory(category, vPos, vRange (0 could mean the whole map or something), "SomeFunctionToCall", parms..) thing that would make it easier, this would also be useful for having enemies within range "hear" things and get startled, or take radius damage from a bomb.
    Seth A. Robinson
    Robinson Technologies

  3. #3

    Default

    Hmm, I can't think of any reason why this wouldn't work. Possible bug? If you can give me a copy of your world I'd be glad to check it out.
    It might be a bug, or it's entirely possible I'm just doing something stupid. Just uploaded the current version of the world here, and stuck a sword and spell pickup beside the starting point so you don't have to go looking for them.

    I think I need to add a way to control pathfinding per entity. I'll add this and make sure there is a C_PATHFINDING_NONE flag available so your bat can ignore it.
    That would be great, thanks.

    So, after you go into the store and come back, all the entities are "reset"?
    Pretty much, yea. But only for the enemies. Most of my maps will eventually have other things on them that should be persistent. In the new version uploaded above, for instance, the main map has a castle gate which should remember whether it's open. Likewise, the castle itself will have more doors, secret passages, puzzles, etc.. Not to mention items strewn about.

    Broadcasting from the warp script sounds like a good idea. But perhaps instead of searching for entities, the spawn points could add themselves to a data table somewhere when placed on the map. Then the warp script could step through the table and tells them to run a spawn function.

  4. #4

    Default

    I solved the respawning problem!

    First, beast_habitat.lua is run from game_start.lua:

    Code:
    g_Enemies = {};
    
    function AddEnemy(spawnID, mapName)
    
    	table.insert(g_Enemies, 1, {spawner = spawnID, map = mapName});
    	--LogMsg("should have added"..spawnID.." to "..mapName..".");
    	
    end
    
    function RefreshEnemies(mapName)
    
    	for i, v in ipairs(g_Enemies) do
    		if (v.map == mapName)then
    			GetEntityByID(v.spawner):RunFunction("REspawn");
    			--LogMsg("should have refreshed "..v.spawner.." on "..v.map..".");
    		end
    	end
    
    end
    New bat-spawner.lua looks like this:

    Code:
    function OnInit()
    	this:SetVisualProfile("~/bat.xml", "baticon");
    	this:LoadCollisionInfo("~/baticon.col");
    	this:Data():SetIfNull("DeleteAfterRun", "false");
    	this:Data():SetIfNull("BatHasSpawned", "false");	
    	
    end
    
    function OnPostInit()
    
    	this:SetDensity(0);
    	this:SetCollisionListenCategory(C_CATEGORY_PLAYER, false);
    	this:SetCollisionCategories(C_CATEGORIES_NONE);	
    	
    end
    
    function OnMapInsert()
    
    	if (GameIsActive()) then
    		entBat = this:CreateEntity(this:GetMap(), this:GetPos(), "~/bat.lua");
    		entBat:RunFunction("SetParent", this);
    		AddEnemy(this:GetID(), this:GetMap():GetName());
    		this:Data():Set("BatHasSpawned", "true");
    	end	
    
    end
    
    function REspawn()
    
    	if (toboolean(this:Data():Get("BatHasSpawned")) == false and GameIsActive()) then
    		entBat = this:CreateEntity(this:GetMap(), this:GetPos(), "~/bat.lua");
    		entBat:RunFunction("SetParent", this);
    		this:Data():Set("BatHasSpawned", "true");
    		--LogMsg("bat"..this:GetID().." should have respawned.");
    	end
    
    end
    
    
    function OnKill()
    
    end
    (The bat itself sets BatHasSpawned in its parent back to false when it dies, so they will still be somewhat persistent.)

    Next, I made my own copy of warp.lua, added this to OnInit:

    Code:
    this:Data():SetIfNull("RespawnEnemies", "false");
    and stuck this in OnTriggerEnter between where it calls PreWarp and sets the entity map/position:

    Code:
    	if (toboolean(this:Data():Get("RespawnEnemies")) == true) then
    		RefreshEnemies(this:GetMap():GetName());
    	end
    This could get ugly after lots of entities and maps are added to the table, but one could always clear the table and unload maps in "buffer" areas between major levels. Perhaps with better/more generic names, something like this could be part of the default system palette?

Similar Threads

  1. Dumb Pathfinding (Ignores walls etc)
    By Pleng in forum Novashell Game Creation System
    Replies: 1
    Last Post: 01-15-2010, 05:20 PM
  2. Real bug to do with entities
    By Uhfgood in forum Novashell Game Creation System
    Replies: 9
    Last Post: 07-17-2008, 03:49 AM
  3. Help with attaching entities
    By Uhfgood in forum Novashell Game Creation System
    Replies: 1
    Last Post: 07-13-2008, 02:02 AM
  4. Interaction between two entities - Grabbing
    By Siris in forum Novashell Game Creation System
    Replies: 2
    Last Post: 03-22-2008, 05:14 AM
  5. Getting Entities to discover the Brain State of other entities
    By stellarvector in forum Novashell Game Creation System
    Replies: 1
    Last Post: 06-28-2007, 11:11 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •