NONONONONONO, do not listen to the wolf!
That code is horrible!, here lemme fix it a bit. Edit soon.
EDIT (later than I thought):
Ok, so a problem with how keyAttack works made this become finished later than I thought, as I didn't think it was an error witht he function, so I had to debugg the whole fricking thing before resigning to the fact that the function must be odd on every server, even my listen server.
anywho, here's code:
Code:
@name Kinetic -ktccd-
@outputs [Own Object]:entity
@outputs [Weapon Mode]:string
@outputs [Said]:array
@outputs [Land HoldPlace]:vector
@outputs Collide
@outputs Key1 Key2
#Test: E:keyAttack1() changed value?
@outputs CKey1 CKey2
#Test result: Succes!
#Test conclusion: Some error in the code makes changed(keyAttack1/2 not work. Must be fixed.
#W00T, structure!
##start setup##
if (first()|duped())
{
runOnTick(1)
#interval(10), don't need both.
#Actually, you should NOT have both.
runOnChat(1)#or the chatcommand fails horribly.
Own=owner()
Mode="Grabbing"
Collide=20
#This is how much distance to the target counts as collision
#if it goes back and forth on target, make value higher.
print("Kinetic: COMMANDS ARE AS FOLLOWS")
print("Kinetic: MOUSE1 IS GRAB OBJECT")
print("Kinetic: MOUSE2 IS THROW OBJECT")
print("Kinetic: WARNING! SECURITY LEVEL1, DISALLOW MANIPULATION OF OTHER PLAYERS PROPS!")
print("****************")
timer("CHAT",5000)
}
if (clk("CHAT"))
{
print("Kinetic: CHAT COMMANDS ARE AS FOLLOWS")
print("Kinetic: -KINETIC MASS <NUMBER>")
print("Kinetic: -KINETIC DROP")
}
##Chat##
if (chatClk(Own))
{
Said=Own:lastSaid():lower():explode(" ")
}
##Weapon##
Weapon=(Own:weapon():type())
##After that, it's too messy to even bother cleaning. I'll just re-do to save time.
if (Weapon=="weapon_crowbar")
{
Key1=Own:keyAttack1()
Key2=Own:keyAttack2()
CKey1=changed(Key1)
CKey2=changed(Key2)
##Mouseclick left##
if (Key1 & CKey1)
{
##Grab object##
if (Mode=="Grabbing")
{
##This line is for not picking up others stuff##
Object=(Own:aimEntity():owner()==Own ? Own:aimEntity() : noentity())
hint("Kinetic: GRABBING " + toString(Object):upper(),5)
##Holding object##
if (Object)
{
Mode="Holding"
}
}
}
##Mouseclick right##
if (Key2 & CKey2)
{
##Throw object##
if (Mode=="Holding")
{
hint("Kinetic: THROWING!",5)
Land=Own:aimPos()
Mode="Throwing"
}
}
}
##Hold, I'm gonna make it fly a little above you too##
if (Mode=="Holding")
{
HoldPlace=Own:pos()+vec(0,0,Object:radius()+100)-Object:pos()
#Fly above owner
Object:applyForce((HoldPlace-Object:vel())*Object:mass())
##This part is if yuo have propcore. if you don't, don't worry, it won't break, I know my stuff.
#ifdef propSpawn(string,vector,number)
Object:propNotSolid(1)
#endif
##This should make it non-solid if it can use that command.
}
if (Mode=="Throwing")
{
##Throw##
Object:applyForce((Land-Object:pos()-Object:vel()/sqrt(Object:pos():distance(Land)))*Object:mass())
#ifdef propSpawn(string,vector,number)
Object:propNotSolid(0)
#endif
##makes solid again##
##Detect collision##
if (Object:pos():distance(Land)<Collide)
{
if (Object)
{
Mode="Grabbing"
Object=noentity()
Land=vec(0,0,0)
hint("Kinetic: TARGET REACHED!",5)
}
}
}
if (Mode=="Throwing" | Mode=="Holding")
{
if (!Object)
{
#ifdef propSpawn(string,vector,number)
Object:propNotSolid(0)
#endif
Object=noentity()
Land=vec(0,0,0)
Mode="Grabbing"
hint("Kinetic: ABORT!",5)
}
}
##chat commands##
if (chatClk(Own))
{
if (Said[1,string]=="-kinetic")
{
hideChat(1)
if (Said[2,string]=="mass")
{
Object:setMass(Said[3,string]:toNumber())
hint("Kinetic: INCREASE MASS!",5)
}
if (Said[2,string]=="drop")
{
#ifdef propSpawn(string,vector,number)
Object:propNotSolid(0)
#endif
Object=noentity()
Land=vec(0,0,0)
Mode="Grabbing"
hint("Kinetic: ABORT!",5)
}
}
} marvel at it's beauty!
XD
EDIT2: Fixed some stuff (like what happens if the object is gone when throwing?) and made print stuff to understand how to use it.
Bookmarks