Cuberite Forum

Full Version: Sniper / Gun
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
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 )
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...
Use this:
World:CreateProjectile(X, Y, Z, cProjectileEntity.pkArrow, CreatorPlayer, CreatorPlayer:GetEquippedItem(), CreatorPlayer:GetLookVector() * 10)
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
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
Awsome!Big Grin Thank you!
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
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
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.
Good catch, I didn't think of that.
Pages: 1 2 3