Razish / japp

JA++ server and client modification for Jedi Academy
GNU General Public License v2.0
44 stars 30 forks source link

Add: Entity API #119

Open Exmirai opened 10 years ago

Exmirai commented 10 years ago

what about entity api?here are some functions: GetEntity() ent:GetType() (grenades, npc, etc...) ent:SetHealth() (if npc / breakable object) ent:GetHealth() ent:Teleport() ent:GetPosition ent:SetSpeed() / GetSpeed etc....

Razish commented 10 years ago

Yeah, it'll come eventually. Just wondering what issues it'll cause between entities/ and players, considering players are entities. Hopefully none.

Exmirai commented 10 years ago

plz add that in clientside :)

Exmirai commented 10 years ago

What about this thing?)

Exmirai commented 10 years ago

some working Entity API code and maker mod plugin :) https://www.dropbox.com/s/nvn6a7ke43kp7cq/game.zip Please, can you improve code ( if needed ) and add them to serverside

Exmirai commented 9 years ago

Particularly done in ac33e2856c01d30b4ad1f9088a2dc94ec565b5e9 But... i can't test refEntities and client side features et all...blow up my videocard

Exmirai commented 9 years ago

done localentities and refentities in ef7a2df1a0ce79bceaac2a18a50c913f7e604539

ghost commented 8 years ago

Can you give me examples how to use the entity api in server side lua script? Also I was trying to use the JPLUA_ENTITY_USE event with a listener but it didn't seem to work. How should I use it?

Exmirai commented 8 years ago

entity:SetUseFunction(function() print('hello world') end)

all listeners described here: https://github.com/Razish/japp/blob/master/game/bg_luaentity.cpp#L1076

ghost commented 8 years ago

So the setusefunction is executed when the entity is being used. Is this function has parameters like self, other, activator? And Is there a command to get a list of entities on the server to find and id for an entity?

Exmirai commented 8 years ago

https://github.com/Razish/japp/blob/master/game/bg_luaentity.cpp#L1115 ///listener behavior

https://github.com/Razish/japp/blob/master/game/bg_lua.cpp#L1507 https://github.com/Razish/japp/blob/master/game/bg_lua.cpp#L1493

ghost commented 8 years ago

I have no luck with entities..

I tried this but didn't work, when I use the command nothing happens.

AddClientCommand( 'test', function(player) local clientNum = player.id local entities = FindEntityByClassName("info_null") for k, v in pairs(entities) do SendReliableCommand( clientNum, 'print "'..k..'-'..v..'\n"' ) end end )

It would have been much easier if there was a command which simply list all entities on the map with their id. You also gave me link on the previous post for EntitiesInBox and CreateEntity but without saying what is the EntitiesInBox for or how to use the CreateEntitiy it's not much help man.

ensiform commented 8 years ago

info_null entities do not exist. They are removed 1 frame after game has loaded.

ghost commented 8 years ago

I tired it with other entity like func_door as well:

AddClientCommand( 'test', function(player)
local entities = FindEntityByClassName("func_door")
for k, v in pairs(entities) do
SendReliableCommand( player.id, 'print "id: '.. v.id ..' classname:'.. v.classname ..'\n"' )
end
end )

Still shows nothing. On the other hand I fixed this issue by adding a lua function which lists all the entities.

Now I'm stucked with the SetUseFunction. I have a trigger_multiple which target is a target_teleporter and that is linked to a misc_teleporter_dest. I would like to add some code when a player is using the trigger_multiple(like it could change the target on specific circumtances) and I just added a simple text print for this function but it doesn't show up when the player is using the trigger_multiple.

AddClientCommand( 'test2', function(player)
local ent = GetEntity(151)
ent:SetUseFunction(function()
SendReliableCommand( player.id, 'print "Entity 151 was used by player.\n"' )
end)
end )
Razish commented 8 years ago

use != touch, aren't triggers specifically entities that are touched?

ghost commented 8 years ago

Well you may be right. I just thought the player is using the use button when interacting with the trigger so that's why I went for the use function. I will try with the touch function then.

Razish commented 8 years ago

As for FindEntityByClassName maybe ipairs would work better