Hello. Given is the Name of the Player as string and I need it as a cPlayer. I tried FindAndDoWithPlayer and ForEachPlayer but it doesn't work at all. I tried it for two hours and the most programmers here solve my problems in a minute so I decided to ask for help...
Get player by name
|
You can't get a player due to multi-threading reasons. Use callbacks instead:
cRoot:Get():FindAndDoWithPlayer(PlayerName, function(a_Player) if (a_Player:GetName() ~= PlayerName) then -- Callback is called for the player who matches the target playername the closest. return false end -- Do stuff with the player end ) Or if you already have the world object/know in which world the player is: World:DoWithPlayer(PlayerName, function(a_Player) -- Do stuff. No need to check username here end )
01-08-2016, 03:06 AM
Quote:function DetectcPlayerByName(GivenName) I've tried that to convert the string to a cPlayer, but the console says Quote:LUA: Plugins/Sniper/main.lua~:86: error in function 'TakeDamage'. Line 86 is Quote:Entity:TakeDamage(dtArrow, DetectcPlayerByName(ShooterName), 18, ProjectileEntity:GetPosition())
01-08-2016, 03:13 AM
Try this instead:
Entity:GetWorld():DoWithPlayer(ShooterName, function(a_Player) Entity:TakeDamage(dtArrow, a_Player, 18, ProjectileEntity:GetPosition() end )
I believe we are very near
function OnProjectileHitEntity(ProjectileEntity, Entity) ShooterName = ProjectileEntity:GetCreatorName() --Entity:TakeDamage(DamageType, AttackerEntity, RawDamage, KnockbackAmount) Entity:GetWorld():DoWithPlayer(ShooterName, function(a_Player) Entity:TakeDamage(dtArrow, a_Player, 18, ProjectileEntity:GetPosition()) end ) end but Quote:[18:23:02] LUA: Plugins/Sniper/main.lua~:88: error in function 'TakeDamage'. What do I wrong?
01-08-2016, 03:35 AM
Strange. I don't see a TakeDamage function that has a cEntity as first parameter. What I did notice though is that you're giving the position of the projectile entity. That should be a double.
Something like this: Entity:TakeDamage(dtArrow, a_Player, 18, 4) Also, please use Code: [shcode=lua][/shcode]
01-08-2016, 03:50 AM
Okay, thanks It works now You are just awsome!!! Thank you!!!
01-08-2016, 07:55 AM
@NiLSPACE: The cEntity:TakeDamage() function is overloaded, there are three overloads, one of them takes just a cEntity as its only parameter; tolua works by iterating over the overloads until the parameters match; if none of the overloads match, the last overload iterated is reported as the "wanted" signature, so that's what we're seeing. I'd like to change this behavior sometime by having (heavily templatized) manual bindings for all functions, somewhat like current cLuaState::GetStackValues(), but with extended error reporting.
The documentation for cEntity:TakeDamage() is somewhat flawed, there's no indication on what the datatypes are, the KnockbackAmount should be a single number (but I have no idea how that translates into knockback direction)
Yeah, I didn't notice the TakeDamage function with only an entity as parameter.
We need something that allows us to tell the types of parameters. With Cuberite classes it's easy, because we just redirect them to the proper API page, but with numbers and stuff it's harder. How about we add an anker tag with a title around them. We'll have to update allot of documentation though. Something like this (notice the title for the knockback amount):
01-08-2016, 11:44 PM
That's not good enough, mouse hover is not a good interface (especially if you have to hover over multiple things). On the other hand, most parameters don't need this kind of info, they are self-explanatory.
How about listing one parameter per line, and add an optional type after, say, a colon? Code: DamageType: [eDamageType] For this to work, we could extend the APIDesc format for the "Params" - if it's a simple string, use the current behavior, if it is an array, consider each item a separate parameter and each item should have up to three member strings: name, typename, typelink: TakeDamage = { { Params = "{{AttackerEntity|cEntity}}", Return = "", Notes = "Causes this entity to take damage that AttackerEntity would inflict. Includes their weapon and this entity's armor." }, { Params = { {"DamageType", "eDamageType", "Globals#eDamageType"}, {"AttackerEntity", "cEntity"}, {"RawDamage"}, {"KnockbackAmount", "number"}, }, Return = "", Notes = "Causes this entity to take damage of the specified type, from the specified attacker (may be nil). The final damage is calculated from RawDamage using the currently equipped armor." }, ... },We could even do the same for the return values - sometimes there's more of them and of various types. |
« Next Oldest | Next Newest »
|
Users browsing this thread: 5 Guest(s)