Cuberite Forum
Sniper / Gun - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Plugins (https://forum.cuberite.org/forum-1.html)
+--- Forum: Plugin Requests (https://forum.cuberite.org/forum-3.html)
+--- Thread: Sniper / Gun (/thread-2302.html)

Pages: 1 2 3


RE: Sniper / Gun - xoft - 01-07-2016

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 )


RE: Sniper / Gun - JuliB - 01-07-2016

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...


RE: Sniper / Gun - NiLSPACE - 01-07-2016

Use this:
World:CreateProjectile(X, Y, Z, cProjectileEntity.pkArrow, CreatorPlayer, CreatorPlayer:GetEquippedItem(), CreatorPlayer:GetLookVector() * 10)



RE: Sniper / Gun - JuliB - 01-07-2016

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


RE: Sniper / Gun - NiLSPACE - 01-07-2016

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


RE: Sniper / Gun - JuliB - 01-07-2016

Awsome!Big Grin Thank you!


RE: Sniper / Gun - JuliB - 01-07-2016

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


RE: Sniper / Gun - NiLSPACE - 01-07-2016

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



RE: Sniper / Gun - xoft - 01-08-2016

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.


RE: Sniper / Gun - NiLSPACE - 01-08-2016

Good catch, I didn't think of that.