Sniper / Gun
#11
Oh, right, when you're creating real projectiles, you can use that hook.

And the proper way to create a projectile is to use cWorld:CreateProjectile() ( http://apidocs.cuberite.org/cWorld.html )
Reply
Thanks given by:
#12
Okay it seems the plugin will be finished this weekBig Grin
I know now how to spawn projectiles, but I don't know how to define the direction of the projectlie, where the cursor is looking at...
Reply
Thanks given by:
#13
Use this:
World:CreateProjectile(X, Y, Z, cProjectileEntity.pkArrow, CreatorPlayer, CreatorPlayer:GetEquippedItem(), CreatorPlayer:GetLookVector() * 10)
Reply
Thanks given by:
#14
The speed includes the vector Idea
It works nearly! The problem is, the hook HOOK_PLAYER_LEFT_CLICK is called only when the player hits a block, not in the air, and I don't want to shoot blocksBig Grin
Reply
Thanks given by:
#15
I used to have the same problem with WorldEdit's compass tool. Use the HOOK_PLAYER_ANIMATION for that. Here is an example:
function OnPlayerAnimation(a_Player, a_Animation)
	-- In 1.8.x the left click has a value of 0, while in 1.7.x it\'s 1
	local LeftClickAnimation = (a_Player:GetClientHandle():GetProtocolVersion() > 5) and 0 or 1
	if (a_Animation ~= LeftClickAnimation) then
		return false
	end
	DoStuff(a_Player)
end


function DoStuff(a_Player)
	--  Do the things
end
Here is my code from WorldEdit
Reply
Thanks given by:
#16
Awsome!Big Grin Thank you!
Reply
Thanks given by:
#17
I'm sorry for asking so much,Blush but how can I store if a player is aming at? The first right click means aim at and lay effects over the sniper, the scond rightclick should removing the effects... But how could that be stored in a variable? I tried to declare boolean variables with the name of the player or anything like that. It is possible to detect the effects, but it is impossible to detect if the effects are made by trunks... Any ides? Undecided
Reply
Thanks given by:
#18
Try cPawn:HasEntityEffect(EffectType) together with cPawn:RemoveEntityEffect(EffectType)
Example:
if (not Player:HasEntityEffect(cEntityEffect.Slowness)) then
   -- Does not have entity effect
   Player:AddEntit...
else
   -- Has entity effect
   Player:RemoveEntit....
end
Reply
Thanks given by:
#19
That's not a good solution, because the player could have the effect from some other cause. You should really be remembering your state in a player-map. For each player, have an entry in a global variable that points to a table describing whatever you want remembered for the player; don't forget to clear the entry when the player disconnects.
Reply
Thanks given by:
#20
Good catch, I didn't think of that.
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)