LuaFunctions.cpp 422 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "LuaFunctions.h"
  17. #include "Spawn.h"
  18. #include "WorldDatabase.h"
  19. #include "LuaInterface.h"
  20. #include "../common/ConfigReader.h"
  21. #include "client.h"
  22. #include "World.h"
  23. #include "Commands/Commands.h"
  24. #include "races.h"
  25. #include "classes.h"
  26. #include "Variables.h"
  27. #include "SpellProcess.h"
  28. #include "Rules/Rules.h"
  29. #include "../common/Log.h"
  30. #include <math.h>
  31. #include "HeroicOp/HeroicOp.h"
  32. #include "RaceTypes/RaceTypes.h"
  33. #include "ClientPacketFunctions.h"
  34. #include "Transmute.h"
  35. #include "Titles.h"
  36. #include <boost/algorithm/string/predicate.hpp>
  37. #include <sstream>
  38. #include <boost/algorithm/string.hpp>
  39. extern MasterFactionList master_faction_list;
  40. extern WorldDatabase database;
  41. extern LuaInterface* lua_interface;
  42. extern ConfigReader configReader;
  43. extern MasterQuestList master_quest_list;
  44. extern MasterItemList master_item_list;
  45. extern MasterSpellList master_spell_list;
  46. extern World world;
  47. extern Commands commands;
  48. extern ZoneList zone_list;
  49. extern Races races;
  50. extern Classes classes;
  51. extern Variables variables;
  52. extern MasterSkillList master_skill_list;
  53. extern MasterHeroicOPList master_ho_list;
  54. extern MasterRaceTypeList race_types_list;
  55. extern MasterLanguagesList master_languages_list;
  56. extern MasterTitlesList master_titles_list;
  57. extern RuleManager rule_manager;
  58. vector<string> ParseString(string strVal, char delim) {
  59. stringstream ss(strVal);
  60. vector<string> ret;
  61. while (ss.good())
  62. {
  63. string substr;
  64. getline(ss, substr, delim);
  65. ret.push_back(substr);
  66. }
  67. return ret;
  68. }
  69. vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
  70. stringstream ss(strVal);
  71. vector<unsigned int> ret;
  72. while (ss.good())
  73. {
  74. string substr;
  75. getline(ss, substr, delim);
  76. stringstream valss(substr);
  77. unsigned int val = 0;
  78. valss >> val;
  79. ret.push_back(val);
  80. }
  81. return ret;
  82. }
  83. map<string, signed int> ParseStringMap(string strVal, char delim) {
  84. vector<string> pairs = ParseString(strVal, delim);
  85. vector<string>::iterator itr;
  86. map<string, signed int> ret;
  87. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  88. vector<string> keyvaluepair = ParseString(*itr, ':');
  89. if (keyvaluepair.size() == 2) {
  90. stringstream valss(keyvaluepair[1]);
  91. int32 val = 0;
  92. valss >> val;
  93. ret[keyvaluepair[0]] = val;
  94. }
  95. }
  96. return ret;
  97. }
  98. map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
  99. vector<string> pairs = ParseString(strVal, delim);
  100. vector<string>::iterator itr;
  101. map<unsigned int, unsigned short> ret;
  102. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  103. vector<string> keyvaluepair = ParseString(*itr, ':');
  104. int32 key = 0;
  105. if (keyvaluepair.size() > 0) {
  106. stringstream keyss(keyvaluepair[0]);
  107. keyss >> key;
  108. }
  109. if (keyvaluepair.size() == 1) {
  110. ret[key] = 1;
  111. }
  112. else if (keyvaluepair.size() == 2) {
  113. stringstream valss(keyvaluepair[1]);
  114. unsigned short val = 0;
  115. valss >> val;
  116. ret[key] = val;
  117. }
  118. }
  119. return ret;
  120. }
  121. map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
  122. vector<string> pairs = ParseString(strVal, delim);
  123. vector<string>::iterator itr;
  124. map<unsigned int, signed int> ret;
  125. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  126. vector<string> keyvaluepair = ParseString(*itr, ':');
  127. int32 key = 0;
  128. if (keyvaluepair.size() > 0) {
  129. stringstream keyss(keyvaluepair[0]);
  130. keyss >> key;
  131. }
  132. if (keyvaluepair.size() == 1) {
  133. ret[key] = 1;
  134. }
  135. else if (keyvaluepair.size() == 2) {
  136. stringstream valss(keyvaluepair[1]);
  137. signed int val = 0;
  138. valss >> val;
  139. ret[key] = val;
  140. }
  141. }
  142. return ret;
  143. }
  144. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  145. if (!lua_interface)
  146. return 0;
  147. Spawn* spawn = lua_interface->GetSpawn(state);
  148. string mp3_string = lua_interface->GetStringValue(state, 2);
  149. string text_string = lua_interface->GetStringValue(state, 3);
  150. string emote_string = lua_interface->GetStringValue(state, 4);
  151. int32 key1 = lua_interface->GetInt32Value(state, 5);
  152. int32 key2 = lua_interface->GetInt32Value(state, 6);
  153. Spawn* player = lua_interface->GetSpawn(state, 7);
  154. int8 language = lua_interface->GetInt8Value(state, 8);
  155. lua_interface->ResetFunctionStack(state);
  156. if (spawn) {
  157. const char* mp3 = 0;
  158. const char* text = 0;
  159. const char* emote = 0;
  160. if (mp3_string.length() > 0)
  161. mp3 = mp3_string.c_str();
  162. if (text_string.length() > 0)
  163. text = text_string.c_str();
  164. if (emote_string.length() > 0)
  165. emote = emote_string.c_str();
  166. Client* client = 0;
  167. if (player && player->IsPlayer())
  168. client = ((Player*)player)->GetClient();
  169. if (client) {
  170. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  171. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  172. }
  173. else
  174. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  175. }
  176. return 0;
  177. }
  178. int EQ2Emu_lua_PlayFlavorID(lua_State* state) {
  179. if (!lua_interface)
  180. return 0;
  181. Spawn* spawn = lua_interface->GetSpawn(state);
  182. int8 type = lua_interface->GetInt8Value(state, 2);
  183. int32 id = lua_interface->GetInt32Value(state, 3);
  184. int16 index = lua_interface->GetInt16Value(state, 4);
  185. Spawn* player = lua_interface->GetSpawn(state, 5);
  186. int8 language = lua_interface->GetInt8Value(state, 6);
  187. lua_interface->ResetFunctionStack(state);
  188. if (spawn) {
  189. Client* client = 0;
  190. if (player && player->IsPlayer())
  191. client = ((Player*)player)->GetClient();
  192. if (client) {
  193. VoiceOverStruct non_garble, garble;
  194. bool garble_success = false;
  195. bool success = world.FindVoiceOver(type, id, index, &non_garble, &garble_success, &garble);
  196. client->SendPlayFlavor(spawn, language, &non_garble, &garble, success, garble_success);
  197. }
  198. else
  199. spawn->GetZone()->PlayFlavorID(spawn, type, id, index, language);
  200. }
  201. return 0;
  202. }
  203. int EQ2Emu_lua_PlaySound(lua_State* state) {
  204. if (!lua_interface)
  205. return 0;
  206. Spawn* spawn = lua_interface->GetSpawn(state);
  207. string sound_string = lua_interface->GetStringValue(state, 2);
  208. float x = lua_interface->GetFloatValue(state, 3);
  209. float y = lua_interface->GetFloatValue(state, 4);
  210. float z = lua_interface->GetFloatValue(state, 5);
  211. Spawn* player = lua_interface->GetSpawn(state, 6);
  212. lua_interface->ResetFunctionStack(state);
  213. if (spawn && sound_string.length() > 0) {
  214. Client* client = 0;
  215. if (player && player->IsPlayer())
  216. client = ((Player*)player)->GetClient();
  217. if (client)
  218. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  219. else
  220. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  221. }
  222. return 0;
  223. }
  224. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  225. if (!lua_interface)
  226. return 0;
  227. Spawn* spawn = lua_interface->GetSpawn(state);
  228. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  229. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  230. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  231. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  232. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  233. lua_interface->ResetFunctionStack(state);
  234. if (!spawn) {
  235. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  236. return 0;
  237. }
  238. if (quest_id > 0) {
  239. //Add this quest to the list of required quests for this spawn
  240. spawn->SetQuestsRequired(quest_id, quest_step);
  241. //If private spawn value set
  242. if (private_spawn) {
  243. //Set the spawn to be private when not granted access through this quest
  244. spawn->AddAllowAccessSpawn(spawn);
  245. spawn->SetPrivateQuestSpawn(true);
  246. }
  247. //This value allows access after a quest step, or the whole quest has been completed
  248. if (continued_access)
  249. spawn->SetQuestsRequiredContinuedAccess(true);
  250. //This value will override vis_flags in the vis packet
  251. if (flag_override > 0)
  252. spawn->SetQuestsRequiredOverride(flag_override);
  253. }
  254. return 0;
  255. }
  256. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  257. if (!lua_interface)
  258. return 0;
  259. Spawn* spawn = lua_interface->GetSpawn(state);
  260. float max_distance = lua_interface->GetFloatValue(state, 2);
  261. string variable = lua_interface->GetStringValue(state, 3);
  262. string value = lua_interface->GetStringValue(state, 4);
  263. lua_interface->ResetFunctionStack(state);
  264. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  265. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  266. return 0;
  267. }
  268. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  269. if (!lua_interface)
  270. return 0;
  271. Client* client = 0;
  272. Spawn* player = lua_interface->GetSpawn(state);
  273. float intensity = lua_interface->GetFloatValue(state, 2);
  274. int8 direction = lua_interface->GetInt8Value(state, 3);
  275. lua_interface->ResetFunctionStack(state);
  276. if (!player) {
  277. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  278. return 0;
  279. }
  280. if (!player->IsPlayer()) {
  281. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  282. return 0;
  283. }
  284. if (player->GetZone())
  285. client = ((Player*)player)->GetClient();
  286. if (!client) {
  287. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  288. return 0;
  289. }
  290. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  291. if (packet) {
  292. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  293. v1 = *(float *)(a1 + 4);
  294. if ( v1 > 0.0 )
  295. v2 = fminf(v1, 1.0);
  296. else
  297. v2 = 0.1;
  298. */
  299. packet->setDataByName("intensity", intensity);
  300. if ( client->GetVersion() > 546 )
  301. packet->setDataByName("direction", direction);
  302. client->QueuePacket(packet->serialize());
  303. safe_delete(packet);
  304. }
  305. return 0;
  306. }
  307. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  308. if (!lua_interface)
  309. return 0;
  310. Spawn* dead = lua_interface->GetSpawn(state);
  311. Spawn* killer = lua_interface->GetSpawn(state, 2);
  312. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  313. lua_interface->ResetFunctionStack(state);
  314. if (dead && dead->Alive() && dead->GetZone())
  315. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  316. return 0;
  317. }
  318. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  319. if (!lua_interface)
  320. return 0;
  321. Spawn* spawn = lua_interface->GetSpawn(state);
  322. float max_distance = lua_interface->GetFloatValue(state, 2);
  323. bool include_players = lua_interface->GetInt8Value(state, 3);
  324. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  325. lua_interface->ResetFunctionStack(state);
  326. if (max_distance > 0 && spawn && spawn->GetZone())
  327. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  328. return 0;
  329. }
  330. int EQ2Emu_lua_Despawn(lua_State* state) {
  331. if (!lua_interface)
  332. return 0;
  333. Spawn* spawn = lua_interface->GetSpawn(state);
  334. int32 delay = lua_interface->GetInt32Value(state, 2);
  335. lua_interface->ResetFunctionStack(state);
  336. if (spawn && spawn->GetZone())
  337. spawn->GetZone()->Despawn(spawn, delay);
  338. return 0;
  339. }
  340. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  341. if (!lua_interface)
  342. return 0;
  343. Spawn* spawn = lua_interface->GetSpawn(state);
  344. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  345. lua_interface->ResetFunctionStack(state);
  346. if (spawn) {
  347. spawn->info_changed = true;
  348. spawn->SetShowHandIcon(displayHandIcon);
  349. }
  350. return 0;
  351. }
  352. //this function is used to force an update packet to be sent.
  353. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  354. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  355. if (!lua_interface)
  356. return 0;
  357. Spawn* spawn = lua_interface->GetSpawn(state);
  358. lua_interface->ResetFunctionStack(state);
  359. if (spawn) {
  360. spawn->vis_changed = true;
  361. spawn->GetZone()->AddChangedSpawn(spawn);
  362. }
  363. return 0;
  364. }
  365. //this function is used to force an update packet to be sent.
  366. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  367. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  368. if (!lua_interface)
  369. return 0;
  370. Spawn* spawn = lua_interface->GetSpawn(state);
  371. lua_interface->ResetFunctionStack(state);
  372. if (spawn) {
  373. spawn->info_changed = true;
  374. spawn->GetZone()->AddChangedSpawn(spawn);
  375. }
  376. return 0;
  377. }
  378. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  379. if (!lua_interface)
  380. return 0;
  381. Spawn* spawn = lua_interface->GetSpawn(state);
  382. int32 new_state = lua_interface->GetInt32Value(state, 2);
  383. Spawn* player = lua_interface->GetSpawn(state, 3);
  384. lua_interface->ResetFunctionStack(state);
  385. if (spawn) {
  386. if(player)
  387. {
  388. if(player->IsPlayer())
  389. {
  390. Client* client = ((Player*)player)->GetClient();
  391. if(client)
  392. {
  393. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  394. lua_interface->SetBooleanValue(state, true);
  395. return 1;
  396. }
  397. else
  398. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument does not have active client.", spawn->GetName());
  399. }
  400. else
  401. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument is NOT a player.", spawn->GetName());
  402. }
  403. else
  404. {
  405. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  406. lua_interface->SetBooleanValue(state, true);
  407. return 1;
  408. }
  409. }
  410. lua_interface->SetBooleanValue(state, false);
  411. return 1;
  412. }
  413. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  414. if (!lua_interface)
  415. return 0;
  416. Spawn* spawn = lua_interface->GetSpawn(state);
  417. string variable = lua_interface->GetStringValue(state, 2);
  418. string value = lua_interface->GetStringValue(state, 3);
  419. bool no_update = lua_interface->GetBooleanValue(state, 4); // send update is true by default in SetSpawnCommand, so allow user to specify 'true' to disable send update.
  420. bool temporary_flag = true;
  421. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  422. int8 index = 0;
  423. if(num_args >= 5)
  424. {
  425. temporary_flag = lua_interface->GetBooleanValue(state, 5); // this used to be false, but no one bothered to set it temporary, we don't need to update the DB
  426. index = lua_interface->GetInt8Value(state, 6);
  427. }
  428. lua_interface->ResetFunctionStack(state);
  429. int32 type = commands.GetSpawnSetType(variable);
  430. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  431. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag, nullptr, index);
  432. return 0;
  433. }
  434. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  435. if (!lua_interface)
  436. return 0;
  437. Spawn* spawn = lua_interface->GetSpawn(state);
  438. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  439. lua_interface->ResetFunctionStack(state);
  440. if (spawn && spawn_id > 0) {
  441. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  442. if (closest_spawn) {
  443. lua_interface->SetSpawnValue(state, closest_spawn);
  444. return 1;
  445. }
  446. }
  447. return 0;
  448. }
  449. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  450. if (!lua_interface)
  451. return 0;
  452. vector<Spawn*> spawns;
  453. int32 position = 0;
  454. if(lua_istable(state, 1)) {
  455. size_t len = lua_rawlen(state, 1);
  456. for(int i=1;i <= len; i++)
  457. {
  458. // get the entry to stack
  459. lua_rawgeti(state, 1, i);
  460. int Top = lua_gettop(state);
  461. if(lua_islightuserdata(state,Top)) {
  462. LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
  463. if(data->IsSpawn()) {
  464. spawns.push_back(data->spawn);
  465. }
  466. }
  467. // remove entry from stack
  468. lua_pop(state,1);
  469. }
  470. }
  471. position = lua_interface->GetInt32Value(state, 2);
  472. lua_interface->ResetFunctionStack(state);
  473. Spawn* spawn = 0;
  474. if(position < spawns.size()) {
  475. spawn = spawns.at(position);
  476. }
  477. if(spawn) {
  478. lua_interface->SetSpawnValue(state, spawn);
  479. return 1;
  480. }
  481. return 0;
  482. }
  483. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  484. if (!lua_interface)
  485. return 0;
  486. vector<Spawn*> spawns;
  487. if(lua_istable(state, 1)) {
  488. size_t len = lua_rawlen(state, 1);
  489. for(int i=1;i <= len; i++)
  490. {
  491. // get the entry to stack
  492. lua_rawgeti(state, 1, i);
  493. int Top = lua_gettop(state);
  494. if(lua_islightuserdata(state,Top)) {
  495. LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
  496. if(data->IsSpawn()) {
  497. spawns.push_back(data->spawn);
  498. }
  499. }
  500. // remove entry from stack
  501. lua_pop(state,1);
  502. }
  503. }
  504. lua_interface->ResetFunctionStack(state);
  505. lua_interface->SetInt32Value(state, spawns.size());
  506. return 1;
  507. }
  508. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  509. if (!lua_interface)
  510. return 0;
  511. Spawn* spawn = lua_interface->GetSpawn(state);
  512. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  513. lua_interface->ResetFunctionStack(state);
  514. if (spawn) {
  515. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  516. if (spawns.size() > 0) {
  517. lua_createtable(state, spawns.size(), 0);
  518. int newTable = lua_gettop(state);
  519. for (int32 i = 0; i < spawns.size(); i++) {
  520. lua_interface->SetSpawnValue(state, spawns.at(i));
  521. lua_rawseti(state, newTable, i + 1);
  522. }
  523. return 1;
  524. }
  525. }
  526. return 0;
  527. }
  528. int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
  529. if (!lua_interface)
  530. return 0;
  531. Spawn* spawn = lua_interface->GetSpawn(state);
  532. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  533. lua_interface->ResetFunctionStack(state);
  534. if (spawn) {
  535. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
  536. if (spawns.size() > 0) {
  537. lua_createtable(state, spawns.size(), 0);
  538. int newTable = lua_gettop(state);
  539. for (int32 i = 0; i < spawns.size(); i++) {
  540. lua_interface->SetSpawnValue(state, spawns.at(i));
  541. lua_rawseti(state, newTable, i + 1);
  542. }
  543. return 1;
  544. }
  545. }
  546. return 0;
  547. }
  548. int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
  549. if (!lua_interface)
  550. return 0;
  551. Spawn* spawn = lua_interface->GetSpawn(state);
  552. lua_interface->ResetFunctionStack(state);
  553. if (spawn) {
  554. vector<Spawn*> spawns = spawn->GetPassengersOnRail();
  555. if (spawns.size() > 0) {
  556. lua_createtable(state, spawns.size(), 0);
  557. int newTable = lua_gettop(state);
  558. for (int32 i = 0; i < spawns.size(); i++) {
  559. lua_interface->SetSpawnValue(state, spawns.at(i));
  560. lua_rawseti(state, newTable, i + 1);
  561. }
  562. return 1;
  563. }
  564. }
  565. return 0;
  566. }
  567. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  568. if (!lua_interface)
  569. return 0;
  570. string variable_name = lua_interface->GetStringValue(state);
  571. lua_interface->ResetFunctionStack(state);
  572. Variable* var = variables.FindVariable(variable_name);
  573. if (var) {
  574. lua_interface->SetStringValue(state, var->GetValue());
  575. return 1;
  576. }
  577. return 0;
  578. }
  579. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  580. if (!lua_interface)
  581. return 0;
  582. int32 total_coins = lua_interface->GetInt32Value(state);
  583. lua_interface->ResetFunctionStack(state);
  584. if (total_coins == 0) {
  585. lua_interface->SetStringValue(state, "0 copper");
  586. return 1;
  587. }
  588. char tmp[64] = { 0 };
  589. string message = "";
  590. int32 val = 0;
  591. if (total_coins >= 1000000) {
  592. val = total_coins / 1000000;
  593. total_coins -= 1000000 * val;
  594. sprintf(tmp, " %u Platinum", val);
  595. message.append(tmp);
  596. memset(tmp, 0, 64);
  597. }
  598. if (total_coins >= 10000) {
  599. val = total_coins / 10000;
  600. total_coins -= 10000 * val;
  601. sprintf(tmp, " %u Gold", val);
  602. message.append(tmp);
  603. memset(tmp, 0, 64);
  604. }
  605. if (total_coins >= 100) {
  606. val = total_coins / 100;
  607. total_coins -= 100 * val;
  608. sprintf(tmp, " %u Silver", val);
  609. message.append(tmp);
  610. memset(tmp, 0, 64);
  611. }
  612. if (total_coins > 0) {
  613. sprintf(tmp, " %u Copper", (int32)total_coins);
  614. message.append(tmp);
  615. }
  616. lua_interface->SetStringValue(state, message.c_str());
  617. return 1;
  618. }
  619. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  620. ZoneServer* zone = lua_interface->GetZone(state);
  621. int32 group_id = lua_interface->GetInt32Value(state, 2);
  622. lua_interface->ResetFunctionStack(state);
  623. if (zone) {
  624. Spawn* spawn = zone->GetSpawnGroup(group_id);
  625. if (spawn) {
  626. lua_interface->SetSpawnValue(state, spawn);
  627. return 1;
  628. }
  629. }
  630. return 0;
  631. }
  632. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  633. ZoneServer* zone = lua_interface->GetZone(state);
  634. int32 location_id = lua_interface->GetInt32Value(state, 2);
  635. lua_interface->ResetFunctionStack(state);
  636. if (zone) {
  637. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  638. if (spawn) {
  639. lua_interface->SetSpawnValue(state, spawn);
  640. return 1;
  641. }
  642. }
  643. return 0;
  644. }
  645. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  646. Spawn* spawn = lua_interface->GetSpawn(state);
  647. lua_interface->ResetFunctionStack(state);
  648. if (spawn) {
  649. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  650. return 1;
  651. }
  652. return 0;
  653. }
  654. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  655. Spawn* spawn = lua_interface->GetSpawn(state);
  656. lua_interface->ResetFunctionStack(state);
  657. if (spawn) {
  658. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  659. return 1;
  660. }
  661. return 0;
  662. }
  663. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  664. if (!lua_interface)
  665. return 0;
  666. Spawn* spawn = lua_interface->GetSpawn(state);
  667. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  668. lua_interface->ResetFunctionStack(state);
  669. if (spawn) {
  670. spawn->SetSpawnGroupID(new_group_id);
  671. lua_interface->SetBooleanValue(state, true);
  672. return 1;
  673. }
  674. lua_interface->SetBooleanValue(state, false);
  675. return 1;
  676. }
  677. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  678. if (!lua_interface)
  679. return 0;
  680. Spawn* spawn = lua_interface->GetSpawn(state);
  681. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  682. lua_interface->ResetFunctionStack(state);
  683. if (spawn) {
  684. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  685. lua_interface->SetBooleanValue(state, true);
  686. return 1;
  687. }
  688. lua_interface->SetBooleanValue(state, false);
  689. return 1;
  690. }
  691. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  692. Spawn* spawn = lua_interface->GetSpawn(state);
  693. lua_interface->ResetFunctionStack(state);
  694. if (spawn) {
  695. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  696. return 1;
  697. }
  698. return 0;
  699. }
  700. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  701. Spawn* spawn = lua_interface->GetSpawn(state);
  702. lua_interface->ResetFunctionStack(state);
  703. if (spawn) {
  704. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  705. return 1;
  706. }
  707. return 0;
  708. }
  709. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  710. Player* player = (Player*)lua_interface->GetSpawn(state);
  711. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  712. lua_interface->ResetFunctionStack(state);
  713. if (player && player->IsPlayer() && faction_id > 0) {
  714. lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  715. return 1;
  716. }
  717. return 0;
  718. }
  719. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  720. if (!lua_interface)
  721. return 0;
  722. Spawn* spawn = lua_interface->GetSpawn(state);
  723. int32 value = lua_interface->GetInt32Value(state, 2);
  724. lua_interface->ResetFunctionStack(state);
  725. if (spawn) {
  726. spawn->SetFactionID(value);
  727. }
  728. return 0;
  729. }
  730. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  731. Spawn* spawn = lua_interface->GetSpawn(state);
  732. lua_interface->ResetFunctionStack(state);
  733. if (spawn) {
  734. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  735. return 1;
  736. }
  737. return 0;
  738. }
  739. int EQ2Emu_lua_GetGender(lua_State* state) {
  740. Spawn* spawn = lua_interface->GetSpawn(state);
  741. lua_interface->ResetFunctionStack(state);
  742. if (spawn) {
  743. lua_interface->SetInt32Value(state, spawn->GetGender());
  744. return 1;
  745. }
  746. return 0;
  747. }
  748. int EQ2Emu_lua_GetTarget(lua_State* state) {
  749. Spawn* spawn = lua_interface->GetSpawn(state);
  750. lua_interface->ResetFunctionStack(state);
  751. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  752. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  753. return 1;
  754. }
  755. return 0;
  756. }
  757. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  758. if (!lua_interface)
  759. return 0;
  760. Spawn* spawn = lua_interface->GetSpawn(state);
  761. string mp3_string = lua_interface->GetStringValue(state, 2);
  762. int32 key1 = lua_interface->GetInt32Value(state, 3);
  763. int32 key2 = lua_interface->GetInt32Value(state, 4);
  764. Spawn* player = lua_interface->GetSpawn(state, 5);
  765. lua_interface->ResetFunctionStack(state);
  766. if (spawn && mp3_string.length() > 0) {
  767. Client* client = 0;
  768. if (player && player->IsPlayer())
  769. client = ((Player*)player)->GetClient();
  770. if (client) {
  771. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  772. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  773. }
  774. else
  775. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  776. }
  777. return 0;
  778. }
  779. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  780. if (!lua_interface)
  781. return 0;
  782. Spawn* spawn = lua_interface->GetSpawn(state);
  783. lua_interface->ResetFunctionStack(state);
  784. if (spawn) {
  785. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  786. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  787. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  788. return 3;
  789. }
  790. return 0;
  791. }
  792. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  793. if (!lua_interface)
  794. return 0;
  795. Spawn* spawn = lua_interface->GetSpawn(state);
  796. if (spawn) {
  797. int32 item_id = lua_interface->GetInt32Value(state, 2);
  798. lua_interface->ResetFunctionStack(state);
  799. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  800. return 1;
  801. }
  802. lua_interface->ResetFunctionStack(state);
  803. return 0;
  804. }
  805. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  806. if (!lua_interface)
  807. return 0;
  808. Spawn* spawn = lua_interface->GetSpawn(state);
  809. if (spawn && spawn->IsEntity()) {
  810. int32 item_id = lua_interface->GetInt32Value(state, 2);
  811. int16 charges = lua_interface->GetInt16Value(state, 3);
  812. if (charges == 0)
  813. charges = 1;
  814. ((Entity*)spawn)->AddLootItem(item_id, charges);
  815. }
  816. lua_interface->ResetFunctionStack(state);
  817. return 0;
  818. }
  819. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  820. if (!lua_interface)
  821. return 0;
  822. Spawn* spawn = lua_interface->GetSpawn(state);
  823. if (spawn && spawn->IsEntity()) {
  824. int32 item_id = lua_interface->GetInt32Value(state, 2);
  825. Item* item = spawn->LootItem(item_id);
  826. lua_interface->SetLuaUserDataStale(item);
  827. safe_delete(item);
  828. }
  829. lua_interface->ResetFunctionStack(state);
  830. return 0;
  831. }
  832. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  833. if (!lua_interface)
  834. return 0;
  835. Spawn* spawn = lua_interface->GetSpawn(state);
  836. if (spawn) {
  837. int32 val = lua_interface->GetInt32Value(state, 2);
  838. spawn->AddLootCoins(val);
  839. }
  840. lua_interface->ResetFunctionStack(state);
  841. return 0;
  842. }
  843. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  844. if (!lua_interface)
  845. return 0;
  846. Spawn* entity = lua_interface->GetSpawn(state);
  847. Spawn* player = lua_interface->GetSpawn(state, 2);
  848. if (entity && player && player->IsPlayer()) {
  849. int32 coins = lua_interface->GetInt32Value(state, 3);
  850. vector<Item*>* items = 0;
  851. int i = 0;
  852. int32 item_id = 0;
  853. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  854. if (items == 0)
  855. items = new vector<Item*>;
  856. if (master_item_list.GetItem(item_id))
  857. items->push_back(master_item_list.GetItem(item_id));
  858. i++;
  859. }
  860. Client* client = 0;
  861. client = ((Player*)player)->GetClient();
  862. if (client)
  863. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  864. if(coins > 0)
  865. entity->AddLootCoins(coins);
  866. safe_delete(items);
  867. }
  868. lua_interface->ResetFunctionStack(state);
  869. return 0;
  870. }
  871. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  872. if (!lua_interface)
  873. return 0;
  874. Spawn* entity = lua_interface->GetSpawn(state);
  875. Spawn* player = lua_interface->GetSpawn(state, 2);
  876. int32 item_id = lua_interface->GetInt32Value(state, 3);
  877. lua_interface->ResetFunctionStack(state);
  878. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  879. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  880. return 1;
  881. }
  882. return 0;
  883. }
  884. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  885. if (!lua_interface)
  886. return 0;
  887. Spawn* entity = lua_interface->GetSpawn(state);
  888. Spawn* player = lua_interface->GetSpawn(state, 2);
  889. lua_interface->ResetFunctionStack(state);
  890. if (entity && player && player->IsPlayer()) {
  891. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  892. return 1;
  893. }
  894. return 0;
  895. }
  896. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  897. if (!lua_interface)
  898. return 0;
  899. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  900. lua_interface->SetLuaUserDataStale(conversation);
  901. safe_delete(conversation);
  902. lua_interface->ResetFunctionStack(state);
  903. conversation = new vector<ConversationOption>();
  904. lua_interface->SetConversationValue(state, conversation);
  905. return 1;
  906. }
  907. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  908. if (!lua_interface)
  909. return 0;
  910. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  911. if (conversation) {
  912. ConversationOption conv_option;
  913. conv_option.option = lua_interface->GetStringValue(state, 2);
  914. conv_option.function = lua_interface->GetStringValue(state, 3);
  915. if (conv_option.option.length() > 0)
  916. conversation->push_back(conv_option);
  917. }
  918. lua_interface->ResetFunctionStack(state);
  919. return 0;
  920. }
  921. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  922. if (!lua_interface)
  923. return 0;
  924. Spawn* npc = lua_interface->GetSpawn(state);
  925. Spawn* player = lua_interface->GetSpawn(state, 2);
  926. lua_interface->ResetFunctionStack(state);
  927. if (npc && player && player->IsPlayer() && player->GetZone()) {
  928. Client* client = ((Player*)player)->GetClient();
  929. if (client) {
  930. int32 conversation_id = client->GetConversationID(npc, 0);
  931. client->CloseDialog(conversation_id);
  932. }
  933. }
  934. return 0;
  935. }
  936. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  937. if (!lua_interface)
  938. return 0;
  939. Item* item = lua_interface->GetItem(state);
  940. Spawn* player = lua_interface->GetSpawn(state, 2);
  941. lua_interface->ResetFunctionStack(state);
  942. if (item && player && player->IsPlayer() && player->GetZone()) {
  943. Client* client = ((Player*)player)->GetClient();
  944. if (client) {
  945. int32 conversation_id = client->GetConversationID(0, item);
  946. client->CloseDialog(conversation_id);
  947. }
  948. }
  949. return 0;
  950. }
  951. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  952. if (!lua_interface)
  953. return 0;
  954. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  955. Spawn* spawn = 0;
  956. Item* item = 0;
  957. int8 type = lua_interface->GetInt8Value(state, 2);
  958. if (type == 1 || type == 3)
  959. spawn = lua_interface->GetSpawn(state, 3);
  960. else if (type == 2 || type == 4)
  961. item = lua_interface->GetItem(state, 3);
  962. Spawn* player = lua_interface->GetSpawn(state, 4);
  963. string text = lua_interface->GetStringValue(state, 5);
  964. string mp3 = lua_interface->GetStringValue(state, 6);
  965. int32 key1 = lua_interface->GetInt32Value(state, 7);
  966. int32 key2 = lua_interface->GetInt32Value(state, 8);
  967. int8 language = lua_interface->GetInt8Value(state, 9);
  968. int numargs = lua_interface->GetNumberOfArgs(state);
  969. int8 can_close = 1;
  970. if(numargs > 9)
  971. can_close = lua_interface->GetInt32Value(state, 10);
  972. lua_interface->ResetFunctionStack(state);
  973. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  974. Client* client = ((Player*)player)->GetClient();
  975. if (client) {
  976. if (spawn) {
  977. // Need to do this so the function works the same as it did before
  978. if (type == 1)
  979. type++;
  980. if (mp3.length() > 0)
  981. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2, language, can_close);
  982. else
  983. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), nullptr, 0, 0, language, can_close);
  984. }
  985. else {
  986. if (mp3.length() > 0)
  987. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2, language, can_close);
  988. else
  989. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, nullptr, 0, 0, language, can_close);
  990. }
  991. }
  992. }
  993. lua_interface->SetLuaUserDataStale(conversation);
  994. safe_delete(conversation);
  995. return 0;
  996. }
  997. int EQ2Emu_lua_StartConversation(lua_State* state) {
  998. if (!lua_interface)
  999. return 0;
  1000. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  1001. Spawn* source = lua_interface->GetSpawn(state, 2);
  1002. Spawn* player = lua_interface->GetSpawn(state, 3);
  1003. string text = lua_interface->GetStringValue(state, 4);
  1004. string mp3 = lua_interface->GetStringValue(state, 5);
  1005. int32 key1 = lua_interface->GetInt32Value(state, 6);
  1006. int32 key2 = lua_interface->GetInt32Value(state, 7);
  1007. int8 language = lua_interface->GetInt32Value(state, 8);
  1008. int numargs = lua_interface->GetNumberOfArgs(state);
  1009. int8 can_close = 1;
  1010. if(numargs > 8)
  1011. can_close = lua_interface->GetInt32Value(state, 9);
  1012. lua_interface->ResetFunctionStack(state);
  1013. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  1014. Client* client = ((Player*)player)->GetClient();
  1015. if (mp3.length() > 0)
  1016. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2, language, can_close);
  1017. else
  1018. client->DisplayConversation(source, 1, conversation, text.c_str(), nullptr, 0, 0, language, can_close);
  1019. lua_interface->SetLuaUserDataStale(conversation);
  1020. safe_delete(conversation);
  1021. }
  1022. else
  1023. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in StartConversation, potentially AddConversationOption not yet called or the StartConversation arguments are incorrect, text: %s, conversationSize: %i.", source ? source->GetName() : "UNKNOWN", text.size() ? text.c_str() : "", conversation ? conversation->size() : -1);
  1024. return 0;
  1025. }
  1026. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  1027. if (!lua_interface)
  1028. return 0;
  1029. Spawn* spawn = lua_interface->GetSpawn(state);
  1030. float distance = lua_interface->GetFloatValue(state, 2);
  1031. string in_range_function = lua_interface->GetStringValue(state, 3);
  1032. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  1033. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  1034. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  1035. return 0;
  1036. }
  1037. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  1038. ZoneServer* zone = lua_interface->GetZone(state);
  1039. float x = lua_interface->GetFloatValue(state, 2);
  1040. float y = lua_interface->GetFloatValue(state, 3);
  1041. float z = lua_interface->GetFloatValue(state, 4);
  1042. float max_variation = lua_interface->GetFloatValue(state, 5);
  1043. string in_range_function = lua_interface->GetStringValue(state, 6);
  1044. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  1045. lua_interface->ResetFunctionStack(state);
  1046. if (zone && in_range_function.length() > 0)
  1047. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  1048. return 0;
  1049. }
  1050. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  1051. if (!lua_interface)
  1052. return 0;
  1053. Spawn* spawn = lua_interface->GetSpawn(state);
  1054. if (spawn && spawn->IsEntity()) {
  1055. int32 val = lua_interface->GetInt32Value(state, 2);
  1056. ((Entity*)spawn)->SetLootCoins(val);
  1057. }
  1058. lua_interface->ResetFunctionStack(state);
  1059. return 0;
  1060. }
  1061. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  1062. if (!lua_interface)
  1063. return 0;
  1064. Spawn* spawn = lua_interface->GetSpawn(state);
  1065. lua_interface->ResetFunctionStack(state);
  1066. if (spawn && spawn->IsEntity()) {
  1067. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1068. return 1;
  1069. }
  1070. return 0;
  1071. }
  1072. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1073. if (!lua_interface)
  1074. return 0;
  1075. Spawn* spawn = lua_interface->GetSpawn(state);
  1076. float x = lua_interface->GetFloatValue(state, 2);
  1077. float y = lua_interface->GetFloatValue(state, 3);
  1078. float z = lua_interface->GetFloatValue(state, 4);
  1079. float speed = lua_interface->GetFloatValue(state, 5);
  1080. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1081. string function = lua_interface->GetStringValue(state, 7);
  1082. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1083. float heading = lua_interface->GetFloatValue(state, 8);
  1084. if (spawn) {
  1085. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1086. spawn->GetZone()->AddMovementNPC(spawn);
  1087. }
  1088. lua_interface->ResetFunctionStack(state);
  1089. return 0;
  1090. }
  1091. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1092. if (!lua_interface)
  1093. return 0;
  1094. Spawn* spawn = lua_interface->GetSpawn(state);
  1095. lua_interface->ResetFunctionStack(state);
  1096. if (spawn) {
  1097. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1098. return 1;
  1099. }
  1100. return 0;
  1101. }
  1102. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1103. if (!lua_interface)
  1104. return 0;
  1105. Spawn* spawn = lua_interface->GetSpawn(state);
  1106. lua_interface->ResetFunctionStack(state);
  1107. if (spawn && spawn->IsPlayer()) {
  1108. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1109. return 1;
  1110. }
  1111. lua_interface->SetInt32Value(state, 0);
  1112. return 1;
  1113. }
  1114. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1115. if (!lua_interface)
  1116. return 0;
  1117. Spawn* spawn = lua_interface->GetSpawn(state);
  1118. Spawn* target = lua_interface->GetSpawn(state, 2);
  1119. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1120. bool reset_action_state = true;
  1121. if(num_args > 2)
  1122. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1123. if (spawn && target) {
  1124. if (spawn->IsEntity())
  1125. // ((Entity*)spawn)->FaceTarget(target);
  1126. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1127. }
  1128. lua_interface->ResetFunctionStack(state);
  1129. return 0;
  1130. }
  1131. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1132. if (!lua_interface)
  1133. return 0;
  1134. Spawn* spawn = lua_interface->GetSpawn(state);
  1135. float x = lua_interface->GetFloatValue(state, 2);
  1136. float y = lua_interface->GetFloatValue(state, 3);
  1137. float z = lua_interface->GetFloatValue(state, 4);
  1138. float speed = lua_interface->GetFloatValue(state, 5);
  1139. string lua_function = lua_interface->GetStringValue(state, 6);
  1140. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1141. if (spawn) {
  1142. if (speed == 0)
  1143. speed = spawn->GetSpeed();
  1144. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1145. }
  1146. lua_interface->ResetFunctionStack(state);
  1147. return 0;
  1148. }
  1149. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1150. if (!lua_interface)
  1151. return 0;
  1152. Spawn* spawn = lua_interface->GetSpawn(state);
  1153. lua_interface->ResetFunctionStack(state);
  1154. if (spawn) {
  1155. spawn->ClearRunningLocations();
  1156. }
  1157. return 0;
  1158. }
  1159. int EQ2Emu_lua_Say(lua_State* state) {
  1160. if (!lua_interface)
  1161. return 0;
  1162. Spawn* spawn = lua_interface->GetSpawn(state);
  1163. string message = lua_interface->GetStringValue(state, 2);
  1164. Spawn* player = lua_interface->GetSpawn(state, 3);
  1165. float dist = lua_interface->GetFloatValue(state, 4);
  1166. int32 language = lua_interface->GetInt32Value(state, 5);
  1167. if (spawn && message.length() > 0) {
  1168. Client* client = 0;
  1169. if (player && player->IsPlayer())
  1170. client = ((Player*)player)->GetClient();
  1171. if (client)
  1172. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1173. else
  1174. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1175. }
  1176. lua_interface->ResetFunctionStack(state);
  1177. return 0;
  1178. }
  1179. int EQ2Emu_lua_Shout(lua_State* state) {
  1180. if (!lua_interface)
  1181. return 0;
  1182. Spawn* spawn = lua_interface->GetSpawn(state);
  1183. string message = lua_interface->GetStringValue(state, 2);
  1184. Spawn* player = lua_interface->GetSpawn(state, 3);
  1185. float dist = lua_interface->GetFloatValue(state, 4);
  1186. int32 language = lua_interface->GetInt32Value(state, 5);
  1187. if (spawn && message.length() > 0) {
  1188. Client* client = 0;
  1189. if (player && player->IsPlayer())
  1190. client = ((Player*)player)->GetClient();
  1191. if (client)
  1192. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1193. else
  1194. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1195. }
  1196. lua_interface->ResetFunctionStack(state);
  1197. return 0;
  1198. }
  1199. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1200. if (!lua_interface)
  1201. return 0;
  1202. Spawn* spawn = lua_interface->GetSpawn(state);
  1203. string message = lua_interface->GetStringValue(state, 2);
  1204. Spawn* player = lua_interface->GetSpawn(state, 3);
  1205. float dist = lua_interface->GetFloatValue(state, 4);
  1206. int32 language = lua_interface->GetInt32Value(state, 5);
  1207. if (spawn && message.length() > 0) {
  1208. Client* client = 0;
  1209. if (player && player->IsPlayer())
  1210. client = ((Player*)player)->GetClient();
  1211. if (client)
  1212. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1213. else
  1214. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1215. }
  1216. lua_interface->ResetFunctionStack(state);
  1217. return 0;
  1218. }
  1219. int EQ2Emu_lua_Emote(lua_State* state) {
  1220. if (!lua_interface)
  1221. return 0;
  1222. Spawn* spawn = lua_interface->GetSpawn(state);
  1223. string message = lua_interface->GetStringValue(state, 2);
  1224. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1225. Spawn* player = lua_interface->GetSpawn(state, 4);
  1226. char* to = 0;
  1227. if (spawn2)
  1228. to = spawn2->GetName();
  1229. if (spawn && message.length() > 0) {
  1230. Client* client = 0;
  1231. if (player && player->IsPlayer())
  1232. client = ((Player*)player)->GetClient();
  1233. if (client)
  1234. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1235. else
  1236. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1237. }
  1238. lua_interface->ResetFunctionStack(state);
  1239. return 0;
  1240. }
  1241. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1242. if (!lua_interface)
  1243. return 0;
  1244. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1245. if(!luaspell || luaspell->resisted) {
  1246. lua_interface->ResetFunctionStack(state);
  1247. return 0;
  1248. }
  1249. Spawn* caster = luaspell->caster;
  1250. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1251. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1252. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1253. Spawn* target = lua_interface->GetSpawn(state, 4);
  1254. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1255. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1256. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1257. lua_interface->ResetFunctionStack(state);
  1258. boost::to_lower(heal_type);
  1259. if (caster && caster->IsEntity()) {
  1260. bool success = false;
  1261. luaspell->resisted = false;
  1262. if (target) {
  1263. float distance = caster->GetDistance(target, true);
  1264. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1265. success = true;
  1266. }
  1267. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1268. Spawn* target = 0;
  1269. ZoneServer* zone = luaspell->caster->GetZone();
  1270. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1271. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1272. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1273. float distance = caster->GetDistance(target, true);
  1274. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1275. }
  1276. }
  1277. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1278. success = true;
  1279. }
  1280. if (success) {
  1281. if (caster->GetZone())
  1282. caster->GetZone()->TriggerCharSheetTimer();
  1283. }
  1284. }
  1285. return 0;
  1286. }
  1287. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1288. if (!lua_interface)
  1289. return 0;
  1290. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1291. if(!luaspell || luaspell->resisted) {
  1292. lua_interface->ResetFunctionStack(state);
  1293. return 0;
  1294. }
  1295. Spawn* caster = luaspell->caster;
  1296. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1297. float percentage = lua_interface->GetFloatValue(state, 2);
  1298. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1299. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1300. Spawn* target = lua_interface->GetSpawn(state, 5);
  1301. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1302. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1303. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1304. lua_interface->ResetFunctionStack(state);
  1305. boost::to_lower(heal_type);
  1306. int32 min_heal = 0, max_heal = 0;
  1307. if (caster && caster->IsEntity() && target) {
  1308. if(percentage <= 0.0f)
  1309. {
  1310. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1311. return 0;
  1312. }
  1313. if(heal_type == "power")
  1314. {
  1315. if(current_value)
  1316. {
  1317. if(caster_value)
  1318. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1319. else
  1320. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1321. }
  1322. else
  1323. {
  1324. if(caster_value)
  1325. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1326. else
  1327. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1328. }
  1329. }
  1330. else
  1331. {
  1332. if(current_value)
  1333. {
  1334. if(caster_value)
  1335. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1336. else
  1337. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1338. }
  1339. else
  1340. {
  1341. if(caster_value)
  1342. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1343. else
  1344. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1345. }
  1346. }
  1347. bool success = false;
  1348. luaspell->resisted = false;
  1349. if (target) {
  1350. float distance = caster->GetDistance(target, true);
  1351. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1352. success = true;
  1353. }
  1354. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1355. Spawn* target = 0;
  1356. ZoneServer* zone = luaspell->caster->GetZone();
  1357. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1358. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1359. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1360. float distance = caster->GetDistance(target, true);
  1361. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1362. }
  1363. }
  1364. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1365. success = true;
  1366. }
  1367. if (success) {
  1368. if (caster->GetZone())
  1369. caster->GetZone()->TriggerCharSheetTimer();
  1370. }
  1371. }
  1372. return 0;
  1373. }
  1374. int EQ2Emu_lua_AddItem(lua_State* state) {
  1375. if (!lua_interface)
  1376. return 0;
  1377. Spawn* spawn = lua_interface->GetSpawn(state);
  1378. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1379. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1380. lua_interface->ResetFunctionStack(state);
  1381. // default of 1 quantity to add
  1382. if (quantity == 0)
  1383. quantity = 1;
  1384. if (spawn && spawn->IsPlayer()) {
  1385. Client* client = ((Player*)spawn)->GetClient();
  1386. if (client && item_id > 0) {
  1387. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1388. return 1;
  1389. }
  1390. }
  1391. lua_interface->SetBooleanValue(state, false);
  1392. return 1;
  1393. }
  1394. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1395. if (!lua_interface)
  1396. return 0;
  1397. Spawn* spawn = lua_interface->GetSpawn(state);
  1398. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1399. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1400. string location = lua_interface->GetStringValue(state, 4);
  1401. int16 item_count = lua_interface->GetInt16Value(state,5);
  1402. //devn00b: if we dont have a count, assume 1 item.
  1403. if(!item_count) {
  1404. item_count = 1;
  1405. }
  1406. lua_interface->ResetFunctionStack(state);
  1407. if (spawn && spawn->IsPlayer()) {
  1408. Client* client = ((Player*)spawn)->GetClient();
  1409. if (client && item_id > 0) {
  1410. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1411. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
  1412. else
  1413. lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
  1414. if (send_messages) {
  1415. Item* item = master_item_list.GetItem(item_id);
  1416. if (item) {
  1417. if(item_count > 1) {
  1418. client->Message(CHANNEL_COLOR_YELLOW, "You receive %i %s.", item_count, item->CreateItemLink(client->GetVersion()).c_str());
  1419. string popup_text1 = "You receive "+ item_count;
  1420. string popup_text2 = " " + item->name;
  1421. string popup_text = popup_text1 + popup_text2;
  1422. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1423. // return 1;
  1424. } else {
  1425. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1426. string popup_text = "You receive " + item->name;
  1427. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1428. }
  1429. }
  1430. }
  1431. return 1;
  1432. }
  1433. }
  1434. lua_interface->SetBooleanValue(state, false);
  1435. return 1;
  1436. }
  1437. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1438. Spawn* spawn = lua_interface->GetSpawn(state);
  1439. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1440. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1441. lua_interface->ResetFunctionStack(state);
  1442. // default of 1 to remove
  1443. if (quantity == 0)
  1444. quantity = 1;
  1445. Client* client;
  1446. Item* item;
  1447. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1448. if ((client = ((Player*)spawn)->GetClient())) {
  1449. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1450. if (client->RemoveItem(item, quantity)) {
  1451. lua_interface->SetBooleanValue(state, true);
  1452. return 1;
  1453. }
  1454. }
  1455. }
  1456. }
  1457. lua_interface->SetBooleanValue(state, false);
  1458. return 1;
  1459. }
  1460. int EQ2Emu_lua_HasItem(lua_State* state) {
  1461. Spawn* player = lua_interface->GetSpawn(state);
  1462. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1463. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1464. lua_interface->ResetFunctionStack(state);
  1465. if (player && player->IsPlayer()) {
  1466. bool hasItem = false;
  1467. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1468. if (!hasItem)
  1469. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1470. lua_interface->SetBooleanValue(state, hasItem);
  1471. return 1;
  1472. }
  1473. lua_interface->SetBooleanValue(state, false);
  1474. return 1;
  1475. }
  1476. int EQ2Emu_lua_Spawn(lua_State* state) {
  1477. if (!lua_interface)
  1478. return 0;
  1479. ZoneServer* zone = lua_interface->GetZone(state);
  1480. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1481. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1482. float x = lua_interface->GetFloatValue(state, 4);
  1483. float y = lua_interface->GetFloatValue(state, 5);
  1484. float z = lua_interface->GetFloatValue(state, 6);
  1485. float heading = lua_interface->GetFloatValue(state, 7);
  1486. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1487. Spawn* spawn = zone->GetSpawn(spawn_id);
  1488. if (!spawn)
  1489. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1490. else {
  1491. spawn->SetX(x);
  1492. spawn->SetZ(z);
  1493. spawn->SetY(y,true,true);
  1494. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1495. spawn->SetHeading(heading);
  1496. if (restricted_npc)
  1497. spawn->AddAllowAccessSpawn(spawn);
  1498. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1499. bool scriptActive = false;
  1500. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1501. scriptActive = true;
  1502. spawn->SetSpawnScript(string(spawn_script));
  1503. }
  1504. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1505. zone->AddSpawn(spawn);
  1506. if (scriptActive) {
  1507. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1508. }
  1509. lua_interface->ResetFunctionStack(state);
  1510. lua_interface->SetSpawnValue(state, spawn);
  1511. return 1;
  1512. }
  1513. }
  1514. else {
  1515. string output = "Invalid paramaters to LUA Spawn command: \n";
  1516. if (!zone)
  1517. output = output.append("\t").append("Missing zone reference. \n");
  1518. if (spawn_id == 0)
  1519. output = output.append("\t").append("Missing spawn_id.");
  1520. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1521. }
  1522. lua_interface->ResetFunctionStack(state);
  1523. return 0;
  1524. }
  1525. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1526. if (!lua_interface)
  1527. return 0;
  1528. ZoneServer* zone = lua_interface->GetZone(state);
  1529. lua_interface->ResetFunctionStack(state);
  1530. if (zone) {
  1531. lua_interface->SetStringValue(state, zone->GetZoneName());
  1532. return 1;
  1533. }
  1534. return 0;
  1535. }
  1536. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1537. if (!lua_interface)
  1538. return 0;
  1539. ZoneServer* zone = lua_interface->GetZone(state);
  1540. lua_interface->ResetFunctionStack(state);
  1541. if (zone) {
  1542. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1543. return 1;
  1544. }
  1545. return 0;
  1546. }
  1547. int EQ2Emu_lua_GetZone(lua_State* state) {
  1548. if (!lua_interface)
  1549. return 0;
  1550. int32 zone_id = lua_interface->GetInt32Value(state);
  1551. ZoneServer* zone = 0;
  1552. if (zone_id > 0)
  1553. zone = zone_list.Get(zone_id);
  1554. else {
  1555. string zone_name = lua_interface->GetStringValue(state);
  1556. if (zone_name.length() > 0) {
  1557. zone = zone_list.Get(zone_name.c_str());
  1558. }
  1559. else {
  1560. Spawn* spawn = lua_interface->GetSpawn(state);
  1561. if (spawn)
  1562. zone = spawn->GetZone();
  1563. }
  1564. }
  1565. lua_interface->ResetFunctionStack(state);
  1566. if (zone) {
  1567. lua_interface->SetZoneValue(state, zone);
  1568. return 1;
  1569. }
  1570. return 0;
  1571. }
  1572. int EQ2Emu_lua_AddHate(lua_State* state) {
  1573. Spawn* entity = lua_interface->GetSpawn(state);
  1574. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1575. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1576. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1577. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1578. if(luaspell && luaspell->resisted) {
  1579. lua_interface->ResetFunctionStack(state);
  1580. return 0;
  1581. }
  1582. if (entity && entity->IsEntity() && amount != 0) {
  1583. if (luaspell) {
  1584. ZoneServer* zone = luaspell->caster->GetZone();
  1585. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1586. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1587. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1588. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1589. entity->CheckEncounterState((Entity*)spawn);
  1590. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1591. if (send_packet)
  1592. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1593. }
  1594. }
  1595. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1596. }
  1597. else if (npc && npc->IsNPC() && npc->GetZone()) {
  1598. entity->CheckEncounterState((Entity*)npc);
  1599. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1600. }
  1601. }
  1602. lua_interface->ResetFunctionStack(state);
  1603. return 0;
  1604. }
  1605. int EQ2Emu_lua_Zone(lua_State* state) {
  1606. if (!lua_interface)
  1607. return 0;
  1608. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  1609. ZoneServer* zone = lua_interface->GetZone(state);
  1610. Spawn* player = lua_interface->GetSpawn(state, 2);
  1611. Client* client = 0;
  1612. if (player && player->IsPlayer())
  1613. client = ((Player*)player)->GetClient();
  1614. float x = lua_interface->GetFloatValue(state, 3);
  1615. float y = lua_interface->GetFloatValue(state, 4);
  1616. float z = lua_interface->GetFloatValue(state, 5);
  1617. float heading = lua_interface->GetFloatValue(state, 6);
  1618. if (zone && client) {
  1619. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1620. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1621. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1622. {
  1623. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1624. return 0;
  1625. }
  1626. if (x != 0 || y != 0 || z != 0) {
  1627. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1628. player->SetX(x);
  1629. player->SetY(y);
  1630. player->SetZ(z);
  1631. player->SetHeading(heading);
  1632. client->Zone(zone->GetZoneName(), false);
  1633. }
  1634. else
  1635. client->Zone(zone->GetZoneName());
  1636. }
  1637. else
  1638. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1639. lua_interface->ResetFunctionStack(state);
  1640. return 0;
  1641. }
  1642. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1643. if (!lua_interface)
  1644. return 0;
  1645. Spawn* spawn = lua_interface->GetSpawn(state);
  1646. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1647. if (spawn && spawn2)
  1648. spawn->AddAllowAccessSpawn(spawn2);
  1649. lua_interface->ResetFunctionStack(state);
  1650. return 0;
  1651. }
  1652. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1653. if (!lua_interface)
  1654. return 0;
  1655. Spawn* target = lua_interface->GetSpawn(state);
  1656. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1657. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1658. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1659. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1660. lua_interface->ResetFunctionStack(state);
  1661. if (!target) {
  1662. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1663. return 0;
  1664. }
  1665. if (!target->IsEntity()) {
  1666. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1667. return 0;
  1668. }
  1669. if (spell_id <= 0) {
  1670. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1671. return 0;
  1672. }
  1673. if (caster && !caster->IsEntity()) {
  1674. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1675. return 0;
  1676. }
  1677. if (spell_tier == 0)
  1678. spell_tier = 1;
  1679. if (!caster)
  1680. caster = target;
  1681. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1682. return 0;
  1683. }
  1684. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1685. if (!lua_interface)
  1686. return 0;
  1687. Spawn* target = lua_interface->GetSpawn(state);
  1688. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1689. if(!luaspell || luaspell->resisted) {
  1690. lua_interface->ResetFunctionStack(state);
  1691. return 0;
  1692. }
  1693. Spawn* caster = luaspell->caster;
  1694. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1695. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1696. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1697. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1698. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1699. //lua_interface->ResetFunctionStack(state);
  1700. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1701. vector<int16> faction_req;
  1702. vector<int16> race_req;
  1703. int32 class_req = 0;
  1704. int32 i = 0;
  1705. int8 f = 0;
  1706. int8 r = 0;
  1707. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1708. if (class_id < 100) {
  1709. class_req += pow(2.0, double(class_id - 1));
  1710. }
  1711. else if (class_id > 100 && class_id < 1000) {
  1712. race_req.push_back(class_id);
  1713. r++;
  1714. }
  1715. else {
  1716. faction_req.push_back(class_id);
  1717. f++;
  1718. }
  1719. i++;
  1720. }
  1721. lua_interface->ResetFunctionStack(state);
  1722. if (caster && caster->IsEntity()) {
  1723. bool race_match = false;
  1724. bool success = false;
  1725. luaspell->resisted = false;
  1726. if (luaspell->targets.size() > 0) {
  1727. ZoneServer* zone = luaspell->caster->GetZone();
  1728. Spawn* target = 0;
  1729. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1730. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1731. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1732. if (race_req.size() > 0) {
  1733. for (int8 i = 0; i < race_req.size(); i++) {
  1734. if(race_req[i] == target->GetRace() ||
  1735. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1736. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1737. race_match = true;
  1738. }
  1739. }
  1740. }
  1741. else
  1742. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1743. if (race_match == true) {
  1744. float distance = caster->GetDistance(target, true);
  1745. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1746. }
  1747. }
  1748. }
  1749. success = true;
  1750. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1751. }
  1752. else if (target) {
  1753. //check class and race/faction here
  1754. if (race_req.size() > 0) {
  1755. for (int8 i = 0; i < race_req.size(); i++) {
  1756. if(race_req[i] == target->GetRace() ||
  1757. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1758. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1759. race_match = true;
  1760. }
  1761. }
  1762. }
  1763. else
  1764. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1765. if (race_match == true) {
  1766. float distance = caster->GetDistance(target, true);
  1767. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1768. success = true;
  1769. }
  1770. }
  1771. if (success) {
  1772. Spell* spell = luaspell->spell;
  1773. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1774. ((Player*)caster)->InCombat(true);
  1775. if (caster->GetZone())
  1776. caster->GetZone()->TriggerCharSheetTimer();
  1777. }
  1778. }
  1779. }
  1780. return 0;
  1781. }
  1782. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1783. if (!lua_interface)
  1784. return 0;
  1785. Spawn* spawn = lua_interface->GetSpawn(state);
  1786. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1787. lua_interface->ResetFunctionStack(state);
  1788. if (spawn && value != 0) {
  1789. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1790. spawn->SetPower(spawn->GetTotalPower());
  1791. else
  1792. spawn->SetPower(spawn->GetPower() + value);
  1793. }
  1794. return 0;
  1795. }
  1796. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1797. if (!lua_interface)
  1798. return 0;
  1799. Spawn* spawn = lua_interface->GetSpawn(state);
  1800. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1801. lua_interface->ResetFunctionStack(state);
  1802. if (spawn && value != 0) {
  1803. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1804. spawn->SetHP(spawn->GetTotalHP());
  1805. else
  1806. spawn->SetHP(spawn->GetHP() + value);
  1807. }
  1808. return 0;
  1809. }
  1810. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1811. if (!lua_interface)
  1812. return 0;
  1813. Spawn* spawn = lua_interface->GetSpawn(state);
  1814. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1815. lua_interface->ResetFunctionStack(state);
  1816. if (spawn && value != 0) {
  1817. spawn->SetPower(spawn->GetPower() + value);
  1818. if (value > spawn->GetTotalHPBase())
  1819. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1820. }
  1821. return 0;
  1822. }
  1823. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1824. if (!lua_interface)
  1825. return 0;
  1826. Spawn* spawn = lua_interface->GetSpawn(state);
  1827. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1828. lua_interface->ResetFunctionStack(state);
  1829. if (spawn && value != 0) {
  1830. spawn->SetHP(spawn->GetHP() + value);
  1831. if (value > spawn->GetTotalHPBase())
  1832. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1833. }
  1834. return 0;
  1835. }
  1836. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1837. if (!lua_interface)
  1838. return 0;
  1839. Spawn* spawn = lua_interface->GetSpawn(state);
  1840. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1841. lua_interface->ResetFunctionStack(state);
  1842. if (spawn) {
  1843. spawn->SetHP(value);
  1844. if (value > spawn->GetTotalHPBase())
  1845. spawn->SetTotalHP(value);
  1846. }
  1847. return 0;
  1848. }
  1849. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1850. if (!lua_interface)
  1851. return 0;
  1852. Spawn* spawn = lua_interface->GetSpawn(state);
  1853. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1854. float value = lua_interface->GetFloatValue(state, 2);
  1855. lua_interface->ResetFunctionStack(state);
  1856. if (spawn && spawn->IsEntity() && value > 0)
  1857. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1858. if (spawn && spawn->IsPlayer())
  1859. ((Player*)spawn)->SetCharSheetChanged(true);
  1860. return 0;
  1861. }
  1862. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1863. if (!lua_interface)
  1864. return 0;
  1865. Spawn* spawn = lua_interface->GetSpawn(state);
  1866. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1867. lua_interface->ResetFunctionStack(state);
  1868. if (spawn && spawn->IsEntity() && value > 0)
  1869. ((Entity*)spawn)->SetTotalHPBase(value);
  1870. return 0;
  1871. }
  1872. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1873. if (!lua_interface)
  1874. return 0;
  1875. Spawn* spawn = lua_interface->GetSpawn(state);
  1876. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1877. lua_interface->ResetFunctionStack(state);
  1878. if (spawn && value > 0) {
  1879. spawn->SetPower(value);
  1880. if (value > spawn->GetTotalPowerBase())
  1881. spawn->SetTotalPower(value);
  1882. }
  1883. return 0;
  1884. }
  1885. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1886. if (!lua_interface)
  1887. return 0;
  1888. Spawn* spawn = lua_interface->GetSpawn(state);
  1889. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1890. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1891. lua_interface->ResetFunctionStack(state);
  1892. if (spawn && spawn->IsEntity() && value > 0)
  1893. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1894. return 0;
  1895. }
  1896. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1897. if (!lua_interface)
  1898. return 0;
  1899. Spawn* spawn = lua_interface->GetSpawn(state);
  1900. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1901. lua_interface->ResetFunctionStack(state);
  1902. if (spawn && spawn->IsEntity() && value > 0)
  1903. ((Entity*)spawn)->SetTotalPowerBase(value);
  1904. return 0;
  1905. }
  1906. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1907. if (!lua_interface)
  1908. return 0;
  1909. Spawn* spawn = lua_interface->GetSpawn(state);
  1910. float x = lua_interface->GetFloatValue(state, 2);
  1911. float y = lua_interface->GetFloatValue(state, 3);
  1912. float z = lua_interface->GetFloatValue(state, 4);
  1913. float heading = lua_interface->GetFloatValue(state, 5);
  1914. lua_interface->ResetFunctionStack(state);
  1915. if (spawn) {
  1916. spawn->SetX(x);
  1917. spawn->SetY(y);
  1918. spawn->SetZ(z);
  1919. if (heading != 0)
  1920. spawn->SetHeading(heading);
  1921. spawn->SetSpawnOrigX(spawn->GetX());
  1922. spawn->SetSpawnOrigY(spawn->GetY());
  1923. spawn->SetSpawnOrigZ(spawn->GetZ());
  1924. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1925. if (spawn->IsPlayer()) {
  1926. Client* client = ((Player*)spawn)->GetClient();
  1927. if (client) {
  1928. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1929. client->QueuePacket(packet);
  1930. }
  1931. }
  1932. }
  1933. return 0;
  1934. }
  1935. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1936. if (!lua_interface)
  1937. return 0;
  1938. Spawn* spawn = lua_interface->GetSpawn(state);
  1939. float value = lua_interface->GetFloatValue(state, 2);
  1940. lua_interface->ResetFunctionStack(state);
  1941. if (spawn) {
  1942. spawn->SetHeading(value);
  1943. if (spawn->IsPlayer()) {
  1944. Client* client = ((Player*)spawn)->GetClient();
  1945. if (client) {
  1946. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1947. client->QueuePacket(packet);
  1948. }
  1949. }
  1950. }
  1951. return 0;
  1952. }
  1953. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1954. if (!lua_interface)
  1955. return 0;
  1956. Spawn* spawn = lua_interface->GetSpawn(state);
  1957. int16 value = lua_interface->GetInt16Value(state, 2);
  1958. lua_interface->ResetFunctionStack(state);
  1959. if (spawn)
  1960. spawn->SetModelType(value);
  1961. return 0;
  1962. }
  1963. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1964. if (!lua_interface)
  1965. return 0;
  1966. Spawn* spawn = lua_interface->GetSpawn(state);
  1967. int8 value = lua_interface->GetInt8Value(state, 2);
  1968. lua_interface->ResetFunctionStack(state);
  1969. if (spawn) {
  1970. if (spawn->IsPlayer())
  1971. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1972. else
  1973. spawn->SetAdventureClass(value);
  1974. }
  1975. return 0;
  1976. }
  1977. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1978. if (!lua_interface)
  1979. return 0;
  1980. Spawn* spawn = lua_interface->GetSpawn(state);
  1981. int8 value = lua_interface->GetInt8Value(state, 2);
  1982. lua_interface->ResetFunctionStack(state);
  1983. if (spawn) {
  1984. spawn->SetTradeskillClass(value);
  1985. if (spawn->IsEntity()) {
  1986. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1987. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1988. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1989. }
  1990. if (spawn->IsPlayer())
  1991. ((Player*)spawn)->SetCharSheetChanged(true);
  1992. }
  1993. return 0;
  1994. }
  1995. int EQ2Emu_lua_SetMount(lua_State* state) {
  1996. if (!lua_interface)
  1997. return 0;
  1998. Spawn* spawn = lua_interface->GetSpawn(state);
  1999. int16 value = lua_interface->GetInt16Value(state, 2);
  2000. if (spawn && spawn->IsEntity()) {
  2001. ((Entity*)spawn)->SetMount(value);
  2002. EQ2_Color color;
  2003. color.red = 255;
  2004. color.green = 255;
  2005. color.blue = 255;
  2006. ((Entity*)spawn)->SetMountColor(&color);
  2007. ((Entity*)spawn)->SetMountSaddleColor(&color);
  2008. }
  2009. return 0;
  2010. }
  2011. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  2012. if (!lua_interface)
  2013. return 0;
  2014. Spawn* spawn = lua_interface->GetSpawn(state);
  2015. EQ2_Color mount_color;
  2016. EQ2_Color saddle_color;
  2017. mount_color.red = lua_interface->GetInt8Value(state, 2);
  2018. mount_color.green = lua_interface->GetInt8Value(state, 3);
  2019. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  2020. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  2021. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  2022. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  2023. if (spawn && spawn->IsEntity()) {
  2024. ((Entity*)spawn)->SetMountColor(&mount_color);
  2025. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  2026. }
  2027. return 0;
  2028. }
  2029. int EQ2Emu_lua_GetMount(lua_State* state) {
  2030. if (!lua_interface)
  2031. return 0;
  2032. Spawn* spawn = lua_interface->GetSpawn(state);
  2033. if (spawn && spawn->IsEntity()) {
  2034. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  2035. return 1;
  2036. }
  2037. return 0;
  2038. }
  2039. int EQ2Emu_lua_GetRace(lua_State* state) {
  2040. if (!lua_interface)
  2041. return 0;
  2042. Spawn* spawn = lua_interface->GetSpawn(state);
  2043. if (spawn)
  2044. {
  2045. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2046. lua_interface->SetInt32Value(state, spawn->GetRace());
  2047. return 1;
  2048. }
  2049. return 0;
  2050. }
  2051. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2052. if (!lua_interface)
  2053. return 0;
  2054. Spawn* spawn = lua_interface->GetSpawn(state);
  2055. if (spawn) {
  2056. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2057. return 1;
  2058. }
  2059. return 0;
  2060. }
  2061. int EQ2Emu_lua_GetClass(lua_State* state) {
  2062. Spawn* spawn = lua_interface->GetSpawn(state);
  2063. if (spawn) {
  2064. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2065. return 1;
  2066. }
  2067. return 0;
  2068. }
  2069. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2070. Spawn* spawn = lua_interface->GetSpawn(state);
  2071. if (spawn) {
  2072. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2073. return 1;
  2074. }
  2075. return 0;
  2076. }
  2077. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2078. if (!lua_interface)
  2079. return 0;
  2080. Spawn* spawn = lua_interface->GetSpawn(state);
  2081. float value = lua_interface->GetFloatValue(state, 2);
  2082. lua_interface->ResetFunctionStack(state);
  2083. if (spawn) {
  2084. spawn->SetSpeed(value);
  2085. if(spawn->IsEntity())
  2086. ((Entity*)spawn)->SetSpeed(value);
  2087. if (spawn->IsPlayer()) {
  2088. Client* client = ((Player*)spawn)->GetClient();
  2089. if (client) {
  2090. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2091. if (packet) {
  2092. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2093. packet->setDataByName("speed", value);
  2094. packet->setDataByName("size", 0.51);
  2095. EQ2Packet* app = packet->serialize();
  2096. client->QueuePacket(app);
  2097. safe_delete(packet);
  2098. }
  2099. }
  2100. }
  2101. }
  2102. return 0;
  2103. }
  2104. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2105. if (!lua_interface)
  2106. return 0;
  2107. Spawn* spawn = lua_interface->GetSpawn(state);
  2108. const int16 type = lua_interface->GetInt16Value(state, 2);
  2109. const float value = lua_interface->GetFloatValue(state, 3);
  2110. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2111. if(!luaspell || luaspell->resisted) {
  2112. lua_interface->ResetFunctionStack(state);
  2113. return 0;
  2114. }
  2115. int64 class_req = 0;
  2116. int32 class_id = 0;
  2117. vector<int16> faction_req;
  2118. vector<int16> race_req;
  2119. int32 i = 0;
  2120. int8 f = 0;
  2121. int8 r = 0;
  2122. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2123. if (class_id < 100) {
  2124. class_req += pow(2.0, double(class_id - 1));
  2125. }
  2126. else if (class_id > 100 && class_id < 1000) {
  2127. race_req.push_back(class_id);
  2128. r++;
  2129. }
  2130. else {
  2131. faction_req.push_back(class_id);
  2132. f++;
  2133. }
  2134. i++;
  2135. }
  2136. if (value != 0 && type >= 0) {
  2137. if (luaspell && luaspell->spell && luaspell->caster) {
  2138. ZoneServer* zone = luaspell->caster->GetZone();
  2139. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2140. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2141. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2142. if (target) {
  2143. if (target->IsPlayer()) {
  2144. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2145. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2146. if (((Player*)target)->GetGroupMemberInfo())
  2147. ((Player*)target)->UpdateGroupMemberInfo();
  2148. ((Player*)target)->SetCharSheetChanged(true);
  2149. }
  2150. else if (target->IsNPC())
  2151. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2152. else
  2153. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2154. }
  2155. }
  2156. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2157. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2158. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2159. }
  2160. else if (spawn && spawn->IsEntity()) {
  2161. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2162. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2163. if (spawn->IsPlayer())
  2164. ((Player*)spawn)->SetCharSheetChanged(true);
  2165. }
  2166. else
  2167. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2168. }
  2169. else
  2170. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2171. return 0;
  2172. }
  2173. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2174. if (!lua_interface)
  2175. return 0;
  2176. Spawn* spawn = lua_interface->GetSpawn(state);
  2177. int16 type = lua_interface->GetInt16Value(state, 2);
  2178. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2179. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2180. if (!spawn) {
  2181. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2182. return 0;
  2183. }
  2184. if (!spawn->IsEntity()) {
  2185. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2186. return 0;
  2187. }
  2188. if (value == 0) {
  2189. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2190. return 0;
  2191. }
  2192. if (!luaspell || !luaspell->spell) {
  2193. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2194. return 0;
  2195. }
  2196. if(luaspell->resisted) {
  2197. lua_interface->ResetFunctionStack(state);
  2198. return 0;
  2199. }
  2200. int32 class_req = 0;
  2201. vector<int16> faction_req;
  2202. vector<int16> race_req;
  2203. int32 class_id = 0;
  2204. int32 i = 0;
  2205. int8 f = 0;
  2206. int8 r = 0;
  2207. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2208. if (class_id < 100) {
  2209. class_req += pow(2.0, double(class_id - 1));
  2210. }
  2211. else if (class_id > 100 && class_id < 1000) {
  2212. race_req.push_back(class_id);
  2213. r++;
  2214. }
  2215. else {
  2216. faction_req.push_back(class_id);
  2217. f++;
  2218. }
  2219. i++;
  2220. }
  2221. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2222. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2223. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2224. if (spawn->IsPlayer())
  2225. ((Player*)spawn)->SetCharSheetChanged(true);
  2226. return 0;
  2227. }
  2228. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2229. if (!lua_interface)
  2230. return 0;
  2231. Spawn* spawn = lua_interface->GetSpawn(state);
  2232. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2233. if (!spawn) {
  2234. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2235. return 0;
  2236. }
  2237. if (!spawn->IsEntity()) {
  2238. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2239. return 0;
  2240. }
  2241. if (!luaspell || !luaspell->spell) {
  2242. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2243. return 0;
  2244. }
  2245. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2246. if (spawn->IsPlayer())
  2247. ((Player*)spawn)->SetCharSheetChanged(true);
  2248. return 0;
  2249. }
  2250. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2251. if (!lua_interface)
  2252. return 0;
  2253. Spawn* spawn = lua_interface->GetSpawn(state);
  2254. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2255. if (luaspell && luaspell->spell) {
  2256. ZoneServer* zone = luaspell->caster->GetZone();
  2257. if(!zone) {
  2258. zone = spawn->GetZone(); // workaround to try to establish a zone to find the targets and remove the spells
  2259. }
  2260. Spawn* target = 0;
  2261. if(zone) {
  2262. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2263. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2264. target = zone->GetSpawnByID(luaspell->targets[i]);
  2265. if (target && target->IsEntity()) {
  2266. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2267. if (target->IsPlayer())
  2268. ((Player*)target)->SetCharSheetChanged(true);
  2269. }
  2270. }
  2271. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2272. }
  2273. else {
  2274. LogWrite(LUA__ERROR, 0, "LUA", "Error removing spell bonus buff %s called by %s, zone is not available.", luaspell->spell ? luaspell->spell->GetName() : "NotSet", spawn->GetName());
  2275. }
  2276. }
  2277. else if (spawn && spawn->IsEntity()) {
  2278. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2279. if (spawn->IsPlayer())
  2280. ((Player*)spawn)->SetCharSheetChanged(true);
  2281. }
  2282. return 0;
  2283. }
  2284. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2285. if (!lua_interface)
  2286. return 0;
  2287. Spawn* spawn = lua_interface->GetSpawn(state);
  2288. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2289. float value = lua_interface->GetFloatValue(state, 3);
  2290. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2291. if (value != 0) {
  2292. int32 spell_id = 0;
  2293. if (luaspell && luaspell->spell && luaspell->caster) {
  2294. if(luaspell->resisted) {
  2295. lua_interface->ResetFunctionStack(state);
  2296. return 0;
  2297. }
  2298. spell_id = luaspell->spell->GetSpellID();
  2299. ZoneServer* zone = luaspell->caster->GetZone();
  2300. Spawn* target = 0;
  2301. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2302. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2303. target = zone->GetSpawnByID(luaspell->targets[i]);
  2304. if (target && target->Alive()) {
  2305. if (target->IsPlayer()) {
  2306. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2307. Client* client = ((Player*)target)->GetClient();
  2308. if (client) {
  2309. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2310. if (packet)
  2311. client->QueuePacket(packet);
  2312. }
  2313. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2314. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2315. }
  2316. else if (target->IsNPC()) {
  2317. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2318. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2319. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2320. }
  2321. else
  2322. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2323. }
  2324. }
  2325. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2326. }
  2327. else if (spawn) {
  2328. if (spawn->IsPlayer()) {
  2329. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2330. Client* client = ((Player*)spawn)->GetClient();
  2331. if (client) {
  2332. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2333. if (packet)
  2334. client->QueuePacket(packet);
  2335. }
  2336. }
  2337. else if (spawn->IsNPC())
  2338. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2339. else
  2340. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2341. }
  2342. }
  2343. else
  2344. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2345. return 0;
  2346. }
  2347. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2348. if (!lua_interface)
  2349. return 0;
  2350. Spawn* spawn = lua_interface->GetSpawn(state);
  2351. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2352. if (spawn && spawn->IsPlayer()) {
  2353. int32 spell_id = 0;
  2354. if (luaspell && luaspell->spell) {
  2355. if(luaspell->resisted) {
  2356. lua_interface->ResetFunctionStack(state);
  2357. return 0;
  2358. }
  2359. spell_id = luaspell->spell->GetSpellID();
  2360. ZoneServer* zone = luaspell->caster->GetZone();
  2361. Spawn* target = 0;
  2362. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2363. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2364. target = zone->GetSpawnByID(luaspell->targets[i]);
  2365. if (target) {
  2366. if (target->IsPlayer()) {
  2367. ((Player*)target)->RemoveSkillBonus(spell_id);
  2368. Client* client = ((Player*)target)->GetClient();
  2369. if (client) {
  2370. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2371. if (packet)
  2372. client->QueuePacket(packet);
  2373. }
  2374. }
  2375. else if (target->IsNPC())
  2376. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2377. else
  2378. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2379. }
  2380. }
  2381. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2382. }
  2383. else if (spawn) {
  2384. if (spawn->IsPlayer()) {
  2385. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2386. Client* client = ((Player*)spawn)->GetClient();
  2387. if (client) {
  2388. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2389. if (packet)
  2390. client->QueuePacket(packet);
  2391. }
  2392. }
  2393. else if (spawn->IsNPC())
  2394. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2395. else
  2396. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2397. }
  2398. }
  2399. return 0;
  2400. }
  2401. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2402. if (!lua_interface)
  2403. return 0;
  2404. Spawn* spawn = lua_interface->GetSpawn(state);
  2405. int8 type = lua_interface->GetInt32Value(state, 2);
  2406. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2407. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2408. if(luaspell && luaspell->resisted) {
  2409. lua_interface->ResetFunctionStack(state);
  2410. return 0;
  2411. }
  2412. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2413. ZoneServer* zone = luaspell->caster->GetZone();
  2414. Spawn* target = 0;
  2415. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2416. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2417. target = zone->GetSpawnByID(luaspell->targets[i]);
  2418. if (target && target->IsEntity()) {
  2419. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2420. ((Entity*)target)->AddMezSpell(luaspell);
  2421. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2422. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2423. if (target->IsNPC())
  2424. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2425. }
  2426. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2427. ((Entity*)target)->AddStifleSpell(luaspell);
  2428. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2429. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2430. if (target->IsNPC())
  2431. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2432. }
  2433. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2434. ((Entity*)target)->AddDazeSpell(luaspell);
  2435. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2436. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2437. if (target->IsNPC())
  2438. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2439. }
  2440. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2441. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2442. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2443. ((Entity*)target)->AddStunSpell(luaspell);
  2444. if (target->IsNPC())
  2445. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2446. }
  2447. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2448. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2449. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2450. ((Entity*)target)->AddRootSpell(luaspell);
  2451. if (target->IsNPC())
  2452. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2453. }
  2454. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2455. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2456. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2457. ((Entity*)target)->AddFearSpell(luaspell);
  2458. if (target->IsNPC())
  2459. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2460. }
  2461. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2462. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2463. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2464. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2465. }
  2466. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2467. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2468. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2469. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2470. }
  2471. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2472. ((Entity*)target)->AddSnareSpell(luaspell);
  2473. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2474. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2475. if (target->IsNPC())
  2476. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2477. }
  2478. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2479. ((Entity*)target)->AddFlightSpell(luaspell);
  2480. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2481. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2482. }
  2483. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2484. ((Entity*)target)->AddGlideSpell(luaspell);
  2485. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2486. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2487. }
  2488. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2489. ((Entity*)target)->AddSafefallSpell(luaspell);
  2490. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2491. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2492. }
  2493. else
  2494. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2495. }
  2496. else
  2497. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (target != nullptr) ? target->GetName() : "NO_TARGET");
  2498. }
  2499. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2500. }
  2501. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2502. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2503. ((Entity*)spawn)->AddMezSpell(luaspell);
  2504. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2505. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2506. }
  2507. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2508. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2509. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2510. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2511. }
  2512. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2513. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2514. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2515. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2516. }
  2517. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2518. ((Entity*)spawn)->AddStunSpell(luaspell);
  2519. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2520. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2521. }
  2522. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2523. ((Entity*)spawn)->AddRootSpell(luaspell);
  2524. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2525. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2526. }
  2527. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2528. ((Entity*)spawn)->AddFearSpell(luaspell);
  2529. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2530. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2531. }
  2532. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2533. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2534. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2535. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2536. }
  2537. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2538. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2539. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2540. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2541. }
  2542. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2543. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2544. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2545. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2546. }
  2547. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2548. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2549. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2550. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2551. }
  2552. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2553. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2554. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2555. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2556. }
  2557. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2558. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2559. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2560. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2561. }
  2562. else
  2563. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2564. }
  2565. else
  2566. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (spawn != nullptr) ? spawn->GetName() : "NO_SPAWN");
  2567. return 0;
  2568. }
  2569. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2570. if (!lua_interface)
  2571. return 0;
  2572. Spawn* spawn = lua_interface->GetSpawn(state);
  2573. int8 type = lua_interface->GetInt8Value(state, 2);
  2574. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2575. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2576. if (spawn && spawn->IsEntity()) {
  2577. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2578. ZoneServer* zone = luaspell->caster->GetZone();
  2579. Spawn* target = 0;
  2580. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2581. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2582. target = zone->GetSpawnByID(luaspell->targets[i]);
  2583. if (target) {
  2584. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2585. ((Entity*)target)->RemoveMezSpell(luaspell);
  2586. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2587. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2588. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2589. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2590. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2591. ((Entity*)target)->RemoveStunSpell(luaspell);
  2592. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2593. ((Entity*)target)->RemoveRootSpell(luaspell);
  2594. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2595. ((Entity*)target)->RemoveFearSpell(luaspell);
  2596. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2597. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2598. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2599. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2600. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2601. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2602. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2603. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2604. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2605. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2606. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2607. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2608. else
  2609. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2610. }
  2611. }
  2612. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2613. }
  2614. else if (only_remove_spawn) {
  2615. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2616. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2617. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2618. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2619. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2620. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2621. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2622. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2623. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2624. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2625. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2626. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2627. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2628. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2629. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2630. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2631. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2632. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2633. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2634. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2635. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2636. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2637. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2638. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2639. else
  2640. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2641. }
  2642. }
  2643. return 0;
  2644. }
  2645. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2646. if (!lua_interface)
  2647. return 0;
  2648. Spawn* spawn = lua_interface->GetSpawn(state);
  2649. int8 type = lua_interface->GetInt8Value(state, 2);
  2650. bool hasEffect = false;
  2651. if (!spawn)
  2652. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2653. else if (!spawn->IsEntity())
  2654. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2655. else if (type < CONTROL_MAX_EFFECTS)
  2656. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2657. else
  2658. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2659. lua_interface->SetBooleanValue(state, hasEffect);
  2660. return 1;
  2661. }
  2662. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2663. if (!lua_interface)
  2664. return 0;
  2665. Spawn* spawn = lua_interface->GetSpawn(state);
  2666. float distance = 0.0f;
  2667. if (!spawn)
  2668. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2669. else if (!spawn->IsNPC())
  2670. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2671. else
  2672. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2673. lua_interface->SetFloatValue(state, distance);
  2674. return 1;
  2675. }
  2676. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2677. if (!lua_interface)
  2678. return 0;
  2679. Spawn* spawn = lua_interface->GetSpawn(state);
  2680. float distance = 0.0f;
  2681. if (!spawn)
  2682. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2683. else if (!spawn->IsNPC())
  2684. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2685. else
  2686. distance = ((NPC*)spawn)->GetAggroRadius();
  2687. lua_interface->SetFloatValue(state, distance);
  2688. return 1;
  2689. }
  2690. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2691. if (!lua_interface)
  2692. return 0;
  2693. Spawn* spawn = lua_interface->GetSpawn(state);
  2694. float distance = lua_interface->GetFloatValue(state, 2);
  2695. bool override = lua_interface->GetBooleanValue(state, 3);
  2696. bool result = false;
  2697. lua_interface->ResetFunctionStack(state);
  2698. if (!spawn)
  2699. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2700. else if (!spawn->IsNPC())
  2701. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2702. else
  2703. {
  2704. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2705. result = true;
  2706. }
  2707. lua_interface->SetBooleanValue(state, result);
  2708. return 1;
  2709. }
  2710. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2711. if (!lua_interface)
  2712. return 0;
  2713. Spawn* spawn = lua_interface->GetSpawn(state);
  2714. int16 value = lua_interface->GetInt16Value(state, 2);
  2715. if (spawn && spawn->IsEntity()) {
  2716. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2717. if (spawn->IsPlayer())
  2718. ((Player*)spawn)->SetCharSheetChanged(true);
  2719. }
  2720. return 0;
  2721. }
  2722. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2723. if (!lua_interface)
  2724. return 0;
  2725. Spawn* spawn = lua_interface->GetSpawn(state);
  2726. int16 value = lua_interface->GetInt16Value(state, 2);
  2727. if (spawn && spawn->IsEntity()) {
  2728. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2729. if (spawn->IsPlayer())
  2730. ((Player*)spawn)->SetCharSheetChanged(true);
  2731. }
  2732. return 0;
  2733. }
  2734. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2735. if (!lua_interface)
  2736. return 0;
  2737. Spawn* spawn = lua_interface->GetSpawn(state);
  2738. int16 value = lua_interface->GetInt16Value(state, 2);
  2739. if (spawn && spawn->IsEntity()) {
  2740. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2741. if (spawn->IsPlayer())
  2742. ((Player*)spawn)->SetCharSheetChanged(true);
  2743. }
  2744. return 0;
  2745. }
  2746. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2747. if (!lua_interface)
  2748. return 0;
  2749. Spawn* spawn = lua_interface->GetSpawn(state);
  2750. int16 value = lua_interface->GetInt16Value(state, 2);
  2751. if (spawn && spawn->IsEntity()) {
  2752. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2753. if (spawn->IsPlayer())
  2754. ((Player*)spawn)->SetCharSheetChanged(true);
  2755. }
  2756. return 0;
  2757. }
  2758. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2759. if (!lua_interface)
  2760. return 0;
  2761. Spawn* spawn = lua_interface->GetSpawn(state);
  2762. int16 value = lua_interface->GetInt16Value(state, 2);
  2763. if (spawn && spawn->IsEntity()) {
  2764. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2765. if (spawn->IsPlayer())
  2766. ((Player*)spawn)->SetCharSheetChanged(true);
  2767. }
  2768. return 0;
  2769. }
  2770. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2771. if (!lua_interface)
  2772. return 0;
  2773. Spawn* spawn = lua_interface->GetSpawn(state);
  2774. int8 value = lua_interface->GetInt8Value(state, 2);
  2775. if (spawn && spawn->IsEntity()) {
  2776. ((Entity*)spawn)->SetDeity(value);
  2777. if (spawn->IsPlayer())
  2778. ((Player*)spawn)->SetCharSheetChanged(true);
  2779. }
  2780. lua_interface->ResetFunctionStack(state);
  2781. return 0;
  2782. }
  2783. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2784. if (!lua_interface)
  2785. return 0;
  2786. Spawn* spawn = lua_interface->GetSpawn(state);
  2787. if (spawn && spawn->IsEntity()) {
  2788. int8 deity = ((Entity*)spawn)->GetDeity();
  2789. lua_interface->SetInt32Value(state, deity);
  2790. return 1;
  2791. }
  2792. return 0;
  2793. }
  2794. int EQ2Emu_lua_SetInt(lua_State* state) {
  2795. if (!lua_interface)
  2796. return 0;
  2797. Spawn* spawn = lua_interface->GetSpawn(state);
  2798. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2799. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2800. if (spawn && spawn->IsEntity()) {
  2801. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_INT, value);
  2802. if (spawn->IsPlayer())
  2803. ((Player*)spawn)->SetCharSheetChanged(true);
  2804. }
  2805. return 0;
  2806. }
  2807. int EQ2Emu_lua_SetWis(lua_State* state) {
  2808. if (!lua_interface)
  2809. return 0;
  2810. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2811. Spawn* spawn = lua_interface->GetSpawn(state);
  2812. float value = lua_interface->GetFloatValue(state, 2);
  2813. if (spawn && spawn->IsEntity()) {
  2814. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_WIS, value);
  2815. if (spawn->IsPlayer())
  2816. ((Player*)spawn)->SetCharSheetChanged(true);
  2817. }
  2818. return 0;
  2819. }
  2820. int EQ2Emu_lua_SetSta(lua_State* state) {
  2821. if (!lua_interface)
  2822. return 0;
  2823. Spawn* spawn = lua_interface->GetSpawn(state);
  2824. float value = lua_interface->GetFloatValue(state, 2);
  2825. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2826. if (spawn && spawn->IsEntity()) {
  2827. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STA, value);
  2828. if (spawn->IsPlayer())
  2829. ((Player*)spawn)->SetCharSheetChanged(true);
  2830. }
  2831. return 0;
  2832. }
  2833. int EQ2Emu_lua_SetStr(lua_State* state) {
  2834. if (!lua_interface)
  2835. return 0;
  2836. Spawn* spawn = lua_interface->GetSpawn(state);
  2837. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2838. float value = lua_interface->GetFloatValue(state, 2);
  2839. if (spawn && spawn->IsEntity()) {
  2840. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STR, value);
  2841. if (spawn->IsPlayer())
  2842. ((Player*)spawn)->SetCharSheetChanged(true);
  2843. }
  2844. return 0;
  2845. }
  2846. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2847. if (!lua_interface)
  2848. return 0;
  2849. Spawn* spawn = lua_interface->GetSpawn(state);
  2850. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2851. float value = lua_interface->GetFloatValue(state, 2);
  2852. if (spawn && spawn->IsEntity()) {
  2853. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_AGI, value);
  2854. if (spawn->IsPlayer())
  2855. ((Player*)spawn)->SetCharSheetChanged(true);
  2856. }
  2857. return 0;
  2858. }
  2859. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2860. if (!lua_interface)
  2861. return 0;
  2862. Spawn* spawn = lua_interface->GetSpawn(state);
  2863. if (spawn) {
  2864. lua_interface->SetInt32Value(state, spawn->GetHP());
  2865. return 1;
  2866. }
  2867. return 0;
  2868. }
  2869. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2870. if (!lua_interface)
  2871. return 0;
  2872. Spawn* spawn = lua_interface->GetSpawn(state);
  2873. if (spawn) {
  2874. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2875. return 1;
  2876. }
  2877. return 0;
  2878. }
  2879. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2880. if (!lua_interface)
  2881. return 0;
  2882. Spawn* spawn = lua_interface->GetSpawn(state);
  2883. if (spawn) {
  2884. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2885. return 1;
  2886. }
  2887. return 0;
  2888. }
  2889. int EQ2Emu_lua_GetName(lua_State* state) {
  2890. if (!lua_interface)
  2891. return 0;
  2892. Spawn* spawn = lua_interface->GetSpawn(state);
  2893. if (spawn) {
  2894. lua_interface->SetStringValue(state, spawn->GetName());
  2895. return 1;
  2896. }
  2897. return 0;
  2898. }
  2899. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2900. Spawn* spawn = lua_interface->GetSpawn(state);
  2901. if (spawn) {
  2902. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2903. return 1;
  2904. }
  2905. return 0;
  2906. }
  2907. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2908. if (!lua_interface)
  2909. return 0;
  2910. Spawn* spawn = lua_interface->GetSpawn(state);
  2911. if (spawn) {
  2912. lua_interface->SetInt32Value(state, spawn->GetPower());
  2913. return 1;
  2914. }
  2915. return 0;
  2916. }
  2917. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2918. if (!lua_interface)
  2919. return 0;
  2920. Spawn* spawn = lua_interface->GetSpawn(state);
  2921. if (spawn) {
  2922. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2923. return 1;
  2924. }
  2925. return 0;
  2926. }
  2927. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2928. if (!lua_interface)
  2929. return 0;
  2930. Spawn* spawn = lua_interface->GetSpawn(state);
  2931. if (spawn) {
  2932. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2933. return 1;
  2934. }
  2935. return 0;
  2936. }
  2937. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2938. if (!lua_interface)
  2939. return 0;
  2940. Spawn* spawn = lua_interface->GetSpawn(state);
  2941. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2942. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2943. if (spawn && spawn2) {
  2944. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2945. lua_interface->SetFloatValue(state, distance);
  2946. return 1;
  2947. }
  2948. return 0;
  2949. }
  2950. int EQ2Emu_lua_GetX(lua_State* state) {
  2951. if (!lua_interface)
  2952. return 0;
  2953. Spawn* spawn = lua_interface->GetSpawn(state);
  2954. if (spawn) {
  2955. lua_interface->SetFloatValue(state, spawn->GetX());
  2956. return 1;
  2957. }
  2958. return 0;
  2959. }
  2960. int EQ2Emu_lua_GetY(lua_State* state) {
  2961. if (!lua_interface)
  2962. return 0;
  2963. Spawn* spawn = lua_interface->GetSpawn(state);
  2964. if (spawn) {
  2965. lua_interface->SetFloatValue(state, spawn->GetY());
  2966. return 1;
  2967. }
  2968. return 0;
  2969. }
  2970. int EQ2Emu_lua_GetZ(lua_State* state) {
  2971. if (!lua_interface)
  2972. return 0;
  2973. Spawn* spawn = lua_interface->GetSpawn(state);
  2974. if (spawn) {
  2975. lua_interface->SetFloatValue(state, spawn->GetZ());
  2976. return 1;
  2977. }
  2978. return 0;
  2979. }
  2980. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2981. if (!lua_interface)
  2982. return 0;
  2983. Spawn* spawn = lua_interface->GetSpawn(state);
  2984. if (spawn) {
  2985. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2986. return 1;
  2987. }
  2988. return 0;
  2989. }
  2990. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2991. if (!lua_interface)
  2992. return 0;
  2993. Spawn* spawn = lua_interface->GetSpawn(state);
  2994. if (spawn) {
  2995. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2996. return 1;
  2997. }
  2998. return 0;
  2999. }
  3000. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  3001. if (!lua_interface)
  3002. return 0;
  3003. Spawn* spawn = lua_interface->GetSpawn(state);
  3004. if (spawn) {
  3005. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  3006. return 1;
  3007. }
  3008. return 0;
  3009. }
  3010. int EQ2Emu_lua_HasMoved(lua_State* state) {
  3011. if (!lua_interface)
  3012. return 0;
  3013. Spawn* spawn = lua_interface->GetSpawn(state);
  3014. if (spawn && spawn->IsEntity()) {
  3015. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  3016. return 1;
  3017. }
  3018. return 0;
  3019. }
  3020. int EQ2Emu_lua_GetInt(lua_State* state) {
  3021. if (!lua_interface)
  3022. return 0;
  3023. Spawn* spawn = lua_interface->GetSpawn(state);
  3024. if (spawn && spawn->IsEntity()) {
  3025. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  3026. return 1;
  3027. }
  3028. return 0;
  3029. }
  3030. int EQ2Emu_lua_GetWis(lua_State* state) {
  3031. if (!lua_interface)
  3032. return 0;
  3033. Spawn* spawn = lua_interface->GetSpawn(state);
  3034. if (spawn && spawn->IsEntity()) {
  3035. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  3036. return 1;
  3037. }
  3038. return 0;
  3039. }
  3040. int EQ2Emu_lua_GetSta(lua_State* state) {
  3041. if (!lua_interface)
  3042. return 0;
  3043. Spawn* spawn = lua_interface->GetSpawn(state);
  3044. if (spawn && spawn->IsEntity()) {
  3045. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  3046. return 1;
  3047. }
  3048. return 0;
  3049. }
  3050. int EQ2Emu_lua_GetStr(lua_State* state) {
  3051. if (!lua_interface)
  3052. return 0;
  3053. Spawn* spawn = lua_interface->GetSpawn(state);
  3054. if (spawn && spawn->IsEntity()) {
  3055. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  3056. return 1;
  3057. }
  3058. return 0;
  3059. }
  3060. int EQ2Emu_lua_GetAgi(lua_State* state) {
  3061. if (!lua_interface)
  3062. return 0;
  3063. Spawn* spawn = lua_interface->GetSpawn(state);
  3064. if (spawn && spawn->IsEntity()) {
  3065. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  3066. return 1;
  3067. }
  3068. return 0;
  3069. }
  3070. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3071. if (!lua_interface)
  3072. return 0;
  3073. Spawn* spawn = lua_interface->GetSpawn(state);
  3074. if (spawn && spawn->IsEntity()) {
  3075. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3076. return 1;
  3077. }
  3078. return 0;
  3079. }
  3080. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3081. if (!lua_interface)
  3082. return 0;
  3083. Spawn* spawn = lua_interface->GetSpawn(state);
  3084. if (spawn && spawn->IsEntity()) {
  3085. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3086. return 1;
  3087. }
  3088. return 0;
  3089. }
  3090. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3091. if (!lua_interface)
  3092. return 0;
  3093. Spawn* spawn = lua_interface->GetSpawn(state);
  3094. if (spawn && spawn->IsEntity()) {
  3095. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3096. return 1;
  3097. }
  3098. return 0;
  3099. }
  3100. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3101. if (!lua_interface)
  3102. return 0;
  3103. Spawn* spawn = lua_interface->GetSpawn(state);
  3104. if (spawn && spawn->IsEntity()) {
  3105. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3106. return 1;
  3107. }
  3108. return 0;
  3109. }
  3110. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3111. if (!lua_interface)
  3112. return 0;
  3113. Spawn* spawn = lua_interface->GetSpawn(state);
  3114. if (spawn && spawn->IsEntity()) {
  3115. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3116. return 1;
  3117. }
  3118. return 0;
  3119. }
  3120. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3121. if (!lua_interface)
  3122. return 0;
  3123. Spawn* player = lua_interface->GetSpawn(state);
  3124. if (!player || !player->IsPlayer()) {
  3125. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3126. return 0;
  3127. }
  3128. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3129. if (quest_id <= 0) {
  3130. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3131. return 0;
  3132. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3133. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3134. return 0;
  3135. }
  3136. int32 step = lua_interface->GetInt32Value(state, 3);
  3137. if (step > 0) {
  3138. Client* client = ((Player*)player)->GetClient();
  3139. if (client)
  3140. client->AddPendingQuestUpdate(quest_id, step);
  3141. } else {
  3142. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3143. }
  3144. return 0;
  3145. }
  3146. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3147. Spawn* player = lua_interface->GetSpawn(state);
  3148. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3149. int32 step = lua_interface->GetInt32Value(state, 3);
  3150. int32 progress = lua_interface->GetInt32Value(state, 4);
  3151. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3152. Client* client = ((Player*)player)->GetClient();
  3153. if (client)
  3154. client->AddPendingQuestUpdate(quest_id, step, progress);
  3155. }
  3156. return 0;
  3157. }
  3158. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3159. if (!lua_interface)
  3160. return 0;
  3161. Spawn* player = lua_interface->GetSpawn(state);
  3162. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3163. if (player && player->IsPlayer() && quest_id > 0) {
  3164. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3165. return 1;
  3166. }
  3167. return 0;
  3168. }
  3169. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3170. if (!lua_interface)
  3171. return 0;
  3172. Spawn* player = lua_interface->GetSpawn(state);
  3173. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3174. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3175. if (player && player->IsPlayer() && quest_id > 0) {
  3176. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3177. return 1;
  3178. }
  3179. return 0;
  3180. }
  3181. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3182. if (!lua_interface)
  3183. return 0;
  3184. Spawn* player = lua_interface->GetSpawn(state);
  3185. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3186. if (player && player->IsPlayer() && quest_id > 0) {
  3187. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3188. return 1;
  3189. }
  3190. return 0;
  3191. }
  3192. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3193. if (!lua_interface)
  3194. return 0;
  3195. Quest* quest = lua_interface->GetQuest(state);
  3196. string name = lua_interface->GetStringValue(state, 2);
  3197. string type = lua_interface->GetStringValue(state, 3);
  3198. string zone = lua_interface->GetStringValue(state, 4);
  3199. int16 level = lua_interface->GetInt16Value(state, 5);
  3200. string description = lua_interface->GetStringValue(state, 6);
  3201. bool load = true;
  3202. if (!quest) {
  3203. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3204. load = false;
  3205. }
  3206. if (load && name.length() == 0) {
  3207. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3208. load = false;
  3209. }
  3210. if (load && type.length() == 0) {
  3211. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3212. load = false;
  3213. }
  3214. if (load && zone.length() == 0) {
  3215. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3216. load = false;
  3217. }
  3218. if (load && description.length() == 0) {
  3219. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3220. load = false;
  3221. }
  3222. if (load && level == 0) {
  3223. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3224. load = false;
  3225. }
  3226. if (load)
  3227. quest->RegisterQuest(name, type, zone, level, description);
  3228. return 0;
  3229. }
  3230. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3231. if (!lua_interface)
  3232. return 0;
  3233. Quest* quest = lua_interface->GetQuest(state);
  3234. if (quest) {
  3235. int8 level = lua_interface->GetInt16Value(state, 2);
  3236. quest->SetPrereqLevel(level);
  3237. }
  3238. return 0;
  3239. }
  3240. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3241. if (!lua_interface)
  3242. return 0;
  3243. Quest* quest = lua_interface->GetQuest(state);
  3244. if (quest) {
  3245. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3246. quest->AddPrereqQuest(quest_id);
  3247. }
  3248. return 0;
  3249. }
  3250. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3251. if (!lua_interface)
  3252. return 0;
  3253. Quest* quest = lua_interface->GetQuest(state);
  3254. if (quest) {
  3255. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3256. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3257. if (quantity == 0)
  3258. quantity = 1;
  3259. Item* master_item = master_item_list.GetItem(item_id);
  3260. if (master_item) {
  3261. Item* item = new Item(master_item);
  3262. item->details.count = quantity;
  3263. quest->AddPrereqItem(item);
  3264. }
  3265. }
  3266. return 0;
  3267. }
  3268. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3269. if (!lua_interface)
  3270. return 0;
  3271. Spawn* player = lua_interface->GetSpawn(state);
  3272. if(!player || !player->IsPlayer()) {
  3273. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3274. return 0;
  3275. }
  3276. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3277. if (quest_id > 0) {
  3278. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3279. return 1;
  3280. } else {
  3281. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3282. }
  3283. return 0;
  3284. }
  3285. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3286. if (!lua_interface)
  3287. return 0;
  3288. Quest* quest = lua_interface->GetQuest(state);
  3289. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3290. lua_interface->ResetFunctionStack(state);
  3291. if (quest && spawn_id > 0)
  3292. quest->SetQuestReturnNPC(spawn_id);
  3293. return 0;
  3294. }
  3295. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3296. if (!lua_interface)
  3297. return 0;
  3298. Spawn* spawn = lua_interface->GetSpawn(state);
  3299. int32 time = lua_interface->GetInt32Value(state, 2);
  3300. string function = lua_interface->GetStringValue(state, 3);
  3301. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3302. Spawn* player = lua_interface->GetSpawn(state, 5);
  3303. lua_interface->ResetFunctionStack(state);
  3304. if (!spawn) {
  3305. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3306. return 0;
  3307. }
  3308. if (time <= 0) {
  3309. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3310. return 0;
  3311. }
  3312. if (function.length() == 0) {
  3313. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3314. return 0;
  3315. }
  3316. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3317. if ( time < 10)
  3318. time = 10;
  3319. timer->timer = Timer::GetCurrentTime2() + time;
  3320. timer->function = function;
  3321. timer->spawn = spawn->GetID();
  3322. timer->player = player ? player->GetID() : 0;
  3323. if (max_count == 0)
  3324. max_count = 1;
  3325. timer->max_count = max_count;
  3326. timer->current_count = 0;
  3327. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3328. return 0;
  3329. }
  3330. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3331. if (!lua_interface)
  3332. return 0;
  3333. Spawn* spawn = lua_interface->GetSpawn(state);
  3334. string function = lua_interface->GetStringValue(state, 2);
  3335. lua_interface->ResetFunctionStack(state);
  3336. if (!spawn) {
  3337. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3338. return 0;
  3339. }
  3340. if(!spawn->GetZone()) {
  3341. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3342. return 0;
  3343. }
  3344. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3345. return 0;
  3346. }
  3347. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3348. if (!lua_interface)
  3349. return 0;
  3350. Spawn* player = lua_interface->GetSpawn(state);
  3351. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3352. lua_interface->ResetFunctionStack(state);
  3353. if (player && player->IsPlayer() && quest_id > 0) {
  3354. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3355. return 1;
  3356. }
  3357. return 0;
  3358. }
  3359. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3360. if (!lua_interface)
  3361. return 0;
  3362. Spawn* player = lua_interface->GetSpawn(state);
  3363. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3364. lua_interface->ResetFunctionStack(state);
  3365. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3366. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3367. if (quest)
  3368. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3369. return 1;
  3370. }
  3371. return 0;
  3372. }
  3373. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3374. if (!lua_interface)
  3375. return 0;
  3376. Spawn* player = lua_interface->GetSpawn(state);
  3377. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3378. lua_interface->ResetFunctionStack(state);
  3379. if (player && player->IsPlayer() && quest_id > 0) {
  3380. lua_interface->SetBooleanValue(state, (((Player*)player)->HasQuestBeenCompleted(quest_id) != 0));
  3381. return 1;
  3382. }
  3383. return 0;
  3384. }
  3385. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3386. if (!lua_interface)
  3387. return 0;
  3388. Spawn* npc = lua_interface->GetSpawn(state);
  3389. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3390. lua_interface->ResetFunctionStack(state);
  3391. if (npc && !npc->IsPlayer() && quest_id > 0)
  3392. npc->AddProvidedQuest(quest_id);
  3393. return 0;
  3394. }
  3395. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3396. if (!lua_interface)
  3397. return 0;
  3398. Spawn* npc = lua_interface->GetSpawn(state);
  3399. Spawn* player = lua_interface->GetSpawn(state, 2);
  3400. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3401. bool forced = lua_interface->GetBooleanValue(state, 4);
  3402. lua_interface->ResetFunctionStack(state);
  3403. /* NPC is allowed to be null */
  3404. if (player && player->IsPlayer() && quest_id > 0) {
  3405. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3406. if (master_quest) {
  3407. Client* client = ((Player*)player)->GetClient();
  3408. if (!client) {
  3409. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3410. }
  3411. Quest* quest = new Quest(master_quest);
  3412. if (!quest) {
  3413. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3414. }
  3415. if (client && quest) {
  3416. if (npc)
  3417. quest->SetQuestGiver(npc->GetDatabaseID());
  3418. else
  3419. quest->SetQuestGiver(0);
  3420. client->AddPendingQuest(quest, forced);
  3421. }
  3422. }
  3423. else {
  3424. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3425. }
  3426. }
  3427. else {
  3428. lua_interface->LogError("%s: LUA OfferQuest command error: player is not set or bad quest id %p %d", lua_interface->GetScriptName(state), player, quest_id);
  3429. }
  3430. return 0;
  3431. }
  3432. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3433. if (!lua_interface)
  3434. return 0;
  3435. Quest* quest = lua_interface->GetQuest(state);
  3436. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3437. lua_interface->ResetFunctionStack(state);
  3438. if (quest) {
  3439. quest->AddPrereqClass(class_id);
  3440. }
  3441. return 0;
  3442. }
  3443. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3444. if (!lua_interface)
  3445. return 0;
  3446. Quest* quest = lua_interface->GetQuest(state);
  3447. int8 race = lua_interface->GetInt8Value(state, 2);
  3448. lua_interface->ResetFunctionStack(state);
  3449. if (quest) {
  3450. quest->AddPrereqRace(race);
  3451. }
  3452. return 0;
  3453. }
  3454. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3455. if (!lua_interface)
  3456. return 0;
  3457. Quest* quest = lua_interface->GetQuest(state);
  3458. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3459. lua_interface->ResetFunctionStack(state);
  3460. if (quest) {
  3461. quest->AddPrereqModelType(model_type);
  3462. }
  3463. return 0;
  3464. }
  3465. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3466. if (!lua_interface)
  3467. return 0;
  3468. Quest* quest = lua_interface->GetQuest(state);
  3469. int8 level = lua_interface->GetInt8Value(state, 2);
  3470. lua_interface->ResetFunctionStack(state);
  3471. if (!quest) {
  3472. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3473. return 0;
  3474. }
  3475. quest->SetPrereqTSLevel(level);
  3476. return 0;
  3477. }
  3478. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3479. if (!lua_interface)
  3480. return 0;
  3481. Quest* quest = lua_interface->GetQuest(state);
  3482. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3483. lua_interface->ResetFunctionStack(state);
  3484. if (!quest) {
  3485. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3486. return 0;
  3487. }
  3488. quest->AddPrereqTradeskillClass(class_id);
  3489. return 0;
  3490. }
  3491. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3492. if (!lua_interface)
  3493. return 0;
  3494. Quest* quest = lua_interface->GetQuest(state);
  3495. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3496. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3497. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3498. lua_interface->ResetFunctionStack(state);
  3499. if (quest) {
  3500. quest->AddPrereqFaction(faction_id, min, max);
  3501. }
  3502. return 0;
  3503. }
  3504. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3505. if (!lua_interface)
  3506. return 0;
  3507. Quest* quest = lua_interface->GetQuest(state);
  3508. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3509. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3510. lua_interface->ResetFunctionStack(state);
  3511. if (quest) {
  3512. if (quantity == 0)
  3513. quantity = 1;
  3514. Item* master_item = master_item_list.GetItem(item_id);
  3515. if (master_item) {
  3516. Item* item = new Item(master_item);
  3517. item->details.count = quantity;
  3518. quest->AddSelectableRewardItem(item);
  3519. }
  3520. }
  3521. return 0;
  3522. }
  3523. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3524. if (!lua_interface)
  3525. return 0;
  3526. Quest* quest = lua_interface->GetQuest(state);
  3527. if (quest) {
  3528. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3529. vector<Item*>* items = quest->GetRewardItems();
  3530. if (items) {
  3531. vector<Item*>::iterator itr;
  3532. for (itr = items->begin(); itr != items->end(); itr++) {
  3533. if (*itr && (*itr)->details.item_id == item_id) {
  3534. lua_interface->SetBooleanValue(state, true);
  3535. return 1;
  3536. }
  3537. }
  3538. }
  3539. }
  3540. lua_interface->SetBooleanValue(state, false);
  3541. return 1;
  3542. }
  3543. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3544. if (!lua_interface)
  3545. return 0;
  3546. Quest* quest = lua_interface->GetQuest(state);
  3547. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3548. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3549. lua_interface->ResetFunctionStack(state);
  3550. if (quest) {
  3551. if (quantity == 0)
  3552. quantity = 1;
  3553. Item* master_item = master_item_list.GetItem(item_id);
  3554. if (master_item) {
  3555. Item* item = new Item(master_item);
  3556. item->details.count = quantity;
  3557. quest->AddRewardItem(item);
  3558. }
  3559. }
  3560. return 0;
  3561. }
  3562. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3563. if (!lua_interface)
  3564. return 0;
  3565. Quest* quest = lua_interface->GetQuest(state);
  3566. int32 copper = lua_interface->GetInt32Value(state, 2);
  3567. int32 silver = lua_interface->GetInt32Value(state, 3);
  3568. int32 gold = lua_interface->GetInt32Value(state, 4);
  3569. int32 plat = lua_interface->GetInt32Value(state, 5);
  3570. lua_interface->ResetFunctionStack(state);
  3571. if (quest) {
  3572. quest->AddRewardCoins(copper, silver, gold, plat);
  3573. }
  3574. return 0;
  3575. }
  3576. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3577. if (!lua_interface)
  3578. return 0;
  3579. Quest* quest = lua_interface->GetQuest(state);
  3580. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3581. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3582. lua_interface->ResetFunctionStack(state);
  3583. if (quest && faction_id > 0 && amount != 0)
  3584. quest->AddRewardFaction(faction_id, amount);
  3585. return 0;
  3586. }
  3587. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3588. if (!lua_interface)
  3589. return 0;
  3590. Quest* quest = lua_interface->GetQuest(state);
  3591. int32 status = lua_interface->GetInt32Value(state, 2);
  3592. lua_interface->ResetFunctionStack(state);
  3593. if (quest) {
  3594. quest->SetRewardStatus(status);
  3595. }
  3596. return 0;
  3597. }
  3598. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3599. if (!lua_interface)
  3600. return 0;
  3601. Quest* quest = lua_interface->GetQuest(state);
  3602. int32 status = lua_interface->GetInt32Value(state, 2);
  3603. lua_interface->ResetFunctionStack(state);
  3604. if (quest) {
  3605. quest->SetStatusTmpReward(status);
  3606. }
  3607. return 0;
  3608. }
  3609. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3610. if (!lua_interface)
  3611. return 0;
  3612. Quest* quest = lua_interface->GetQuest(state);
  3613. int64 coins = lua_interface->GetInt64Value(state, 2);
  3614. lua_interface->ResetFunctionStack(state);
  3615. if (quest) {
  3616. quest->SetCoinTmpReward(coins);
  3617. }
  3618. return 0;
  3619. }
  3620. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3621. if (!lua_interface)
  3622. return 0;
  3623. Quest* quest = lua_interface->GetQuest(state);
  3624. string comment = lua_interface->GetStringValue(state, 2);
  3625. lua_interface->ResetFunctionStack(state);
  3626. if (quest) {
  3627. quest->SetRewardComment(comment);
  3628. }
  3629. return 0;
  3630. }
  3631. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3632. if (!lua_interface)
  3633. return 0;
  3634. Quest* quest = lua_interface->GetQuest(state);
  3635. int32 exp = lua_interface->GetInt32Value(state, 2);
  3636. lua_interface->ResetFunctionStack(state);
  3637. if (quest) {
  3638. quest->SetRewardXP(exp);
  3639. }
  3640. return 0;
  3641. }
  3642. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3643. Quest* quest = lua_interface->GetQuest(state);
  3644. int32 step = lua_interface->GetInt32Value(state, 2);
  3645. string description = lua_interface->GetStringValue(state, 3);
  3646. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3647. float percentage = lua_interface->GetFloatValue(state, 5);
  3648. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3649. int16 icon = lua_interface->GetInt16Value(state, 7);
  3650. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3651. if (quest) {
  3652. const char* taskgroup = 0;
  3653. if (str_taskgroup.length() > 0)
  3654. taskgroup = str_taskgroup.c_str();
  3655. int32 id = 0;
  3656. vector<int32>* ids = 0;
  3657. int i = 0;
  3658. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3659. if (ids == 0)
  3660. ids = new vector<int32>;
  3661. ids->push_back(id);
  3662. i++;
  3663. }
  3664. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3665. if (quest_step && icon && quantity > 0)
  3666. quest_step->SetIcon(icon);
  3667. if (quest->GetPlayer()) {
  3668. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3669. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3670. }
  3671. }
  3672. lua_interface->ResetFunctionStack(state);
  3673. return 0;
  3674. }
  3675. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3676. {
  3677. if (!lua_interface)
  3678. return 0;
  3679. Quest* quest = lua_interface->GetQuest(state);
  3680. int32 step = lua_interface->GetInt32Value(state, 2);
  3681. string description = lua_interface->GetStringValue(state, 3);
  3682. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3683. float percentage = lua_interface->GetFloatValue(state, 5);
  3684. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3685. int16 icon = lua_interface->GetInt16Value(state, 7);
  3686. if (quest) {
  3687. const char* taskgroup = 0;
  3688. if (str_taskgroup.length() > 0)
  3689. taskgroup = str_taskgroup.c_str();
  3690. int32 id = 0;
  3691. vector<int32>* ids = 0;
  3692. int i = 0;
  3693. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3694. if (ids == 0)
  3695. ids = new vector<int32>;
  3696. ids->push_back(id);
  3697. i++;
  3698. }
  3699. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3700. if (quest_step && icon > 0 && quantity > 0)
  3701. quest_step->SetIcon(icon);
  3702. if (quest->GetPlayer()) {
  3703. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3704. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3705. }
  3706. safe_delete(ids);
  3707. }
  3708. lua_interface->ResetFunctionStack(state);
  3709. return 0;
  3710. }
  3711. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3712. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3713. }
  3714. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3715. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3716. }
  3717. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3718. if (!lua_interface)
  3719. return 0;
  3720. Quest* quest = lua_interface->GetQuest(state);
  3721. int32 step = lua_interface->GetInt32Value(state, 2);
  3722. string description = lua_interface->GetStringValue(state, 3);
  3723. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3724. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3725. int16 icon = lua_interface->GetInt16Value(state, 6);
  3726. if (quest) {
  3727. const char* taskgroup = 0;
  3728. if (str_taskgroup.length() > 0)
  3729. taskgroup = str_taskgroup.c_str();
  3730. int32 npc_id = 0;
  3731. vector<int32>* ids = 0;
  3732. int i = 0;
  3733. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3734. if (ids == 0)
  3735. ids = new vector<int32>;
  3736. ids->push_back(npc_id);
  3737. i++;
  3738. }
  3739. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3740. if (quest_step && icon > 0)
  3741. quest_step->SetIcon(icon);
  3742. if (quest->GetPlayer()) {
  3743. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3744. if(client)
  3745. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3746. }
  3747. safe_delete(ids);
  3748. }
  3749. lua_interface->ResetFunctionStack(state);
  3750. return 0;
  3751. }
  3752. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3753. if (!lua_interface)
  3754. return 0;
  3755. Quest* quest = lua_interface->GetQuest(state);
  3756. int32 step = lua_interface->GetInt32Value(state, 2);
  3757. string description = lua_interface->GetStringValue(state, 3);
  3758. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3759. float percentage = lua_interface->GetFloatValue(state, 5);
  3760. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3761. int16 icon = lua_interface->GetInt16Value(state, 7);
  3762. if (quest) {
  3763. const char* taskgroup = 0;
  3764. if (str_taskgroup.length() > 0)
  3765. taskgroup = str_taskgroup.c_str();
  3766. int32 item_id = 0;
  3767. vector<int32>* ids = 0;
  3768. int i = 0;
  3769. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3770. if (ids == 0)
  3771. ids = new vector<int32>;
  3772. ids->push_back(item_id);
  3773. i++;
  3774. }
  3775. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3776. if (quest_step && icon > 0 && quantity > 0)
  3777. quest_step->SetIcon(icon);
  3778. if (quest->GetPlayer()) {
  3779. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3780. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3781. }
  3782. safe_delete(ids);
  3783. }
  3784. lua_interface->ResetFunctionStack(state);
  3785. return 0;
  3786. }
  3787. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3788. if (!lua_interface)
  3789. return 0;
  3790. Quest* quest = lua_interface->GetQuest(state);
  3791. int32 step = lua_interface->GetInt32Value(state, 2);
  3792. string description = lua_interface->GetStringValue(state, 3);
  3793. float max_variation = lua_interface->GetFloatValue(state, 4);
  3794. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3795. int16 icon = lua_interface->GetInt16Value(state, 6);
  3796. if (quest) {
  3797. const char* taskgroup = 0;
  3798. if (str_taskgroup.length() > 0)
  3799. taskgroup = str_taskgroup.c_str();
  3800. vector<Location>* locations = 0;
  3801. int8 i = 7;
  3802. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3803. while (true) {
  3804. Location loc;
  3805. loc.x = lua_interface->GetFloatValue(state, i);
  3806. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3807. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3808. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3809. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3810. break;
  3811. if (locations == 0)
  3812. locations = new vector<Location>;
  3813. locations->push_back(loc);
  3814. i += 4;
  3815. }
  3816. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3817. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3818. if (quest_step && icon > 0)
  3819. quest_step->SetIcon(icon);
  3820. if (quest->GetPlayer()) {
  3821. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3822. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3823. }
  3824. }
  3825. lua_interface->ResetFunctionStack(state);
  3826. return 0;
  3827. }
  3828. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3829. if (!lua_interface)
  3830. return 0;
  3831. Quest* quest = lua_interface->GetQuest(state);
  3832. int32 step = lua_interface->GetInt32Value(state, 2);
  3833. string description = lua_interface->GetStringValue(state, 3);
  3834. float max_variation = lua_interface->GetFloatValue(state, 4);
  3835. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3836. int16 icon = lua_interface->GetInt16Value(state, 6);
  3837. if (quest) {
  3838. const char* taskgroup = 0;
  3839. if (str_taskgroup.length() > 0)
  3840. taskgroup = str_taskgroup.c_str();
  3841. vector<Location>* locations = 0;
  3842. int8 i = 7;
  3843. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3844. while (true) {
  3845. Location loc;
  3846. loc.x = lua_interface->GetFloatValue(state, i);
  3847. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3848. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3849. loc.zone_id = 0;
  3850. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3851. break;
  3852. if (locations == 0)
  3853. locations = new vector<Location>;
  3854. locations->push_back(loc);
  3855. i += 3;
  3856. }
  3857. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3858. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3859. if (quest_step && icon > 0)
  3860. quest_step->SetIcon(icon);
  3861. if (quest->GetPlayer()) {
  3862. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3863. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3864. }
  3865. }
  3866. lua_interface->ResetFunctionStack(state);
  3867. return 0;
  3868. }
  3869. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3870. if (!lua_interface)
  3871. return 0;
  3872. Quest* quest = lua_interface->GetQuest(state);
  3873. int32 step = lua_interface->GetInt32Value(state, 2);
  3874. string description = lua_interface->GetStringValue(state, 3);
  3875. float max_variation = lua_interface->GetFloatValue(state, 4);
  3876. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3877. int16 icon = lua_interface->GetInt16Value(state, 6);
  3878. if (quest) {
  3879. const char* taskgroup = 0;
  3880. if (str_taskgroup.length() > 0)
  3881. taskgroup = str_taskgroup.c_str();
  3882. vector<Location>* locations = 0;
  3883. int i = 7;
  3884. while (true) {
  3885. Location loc;
  3886. loc.x = lua_interface->GetFloatValue(state, i);
  3887. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3888. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3889. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3890. break;
  3891. if (locations == 0)
  3892. locations = new vector<Location>;
  3893. locations->push_back(loc);
  3894. i += 3;
  3895. }
  3896. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3897. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3898. if (quest_step && icon > 0)
  3899. quest_step->SetIcon(icon);
  3900. if (quest->GetPlayer()) {
  3901. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3902. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3903. }
  3904. }
  3905. lua_interface->ResetFunctionStack(state);
  3906. return 0;
  3907. }
  3908. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3909. Quest* quest = lua_interface->GetQuest(state);
  3910. int32 step = lua_interface->GetInt32Value(state, 2);
  3911. string description = lua_interface->GetStringValue(state, 3);
  3912. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3913. float percentage = lua_interface->GetFloatValue(state, 5);
  3914. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3915. int16 icon = lua_interface->GetInt16Value(state, 7);
  3916. if (quest) {
  3917. const char* taskgroup = 0;
  3918. if (str_taskgroup.length() > 0)
  3919. taskgroup = str_taskgroup.c_str();
  3920. int32 spell_id = 0;
  3921. vector<int32>* ids = 0;
  3922. int i = 0;
  3923. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3924. if (ids == 0)
  3925. ids = new vector<int32>;
  3926. ids->push_back(spell_id);
  3927. i++;
  3928. }
  3929. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3930. if (quest_step && icon > 0 && quantity > 0)
  3931. quest_step->SetIcon(icon);
  3932. if (quest->GetPlayer()) {
  3933. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3934. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3935. }
  3936. safe_delete(ids);
  3937. }
  3938. lua_interface->ResetFunctionStack(state);
  3939. return 0;
  3940. }
  3941. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3942. if (!lua_interface)
  3943. return 0;
  3944. Quest* quest = lua_interface->GetQuest(state);
  3945. int32 step = lua_interface->GetInt32Value(state, 2);
  3946. string description = lua_interface->GetStringValue(state, 3);
  3947. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3948. float percentage = lua_interface->GetFloatValue(state, 5);
  3949. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3950. int16 icon = lua_interface->GetInt16Value(state, 7);
  3951. if (quest) {
  3952. const char* taskgroup = 0;
  3953. if (str_taskgroup.length() > 0)
  3954. taskgroup = str_taskgroup.c_str();
  3955. int32 item_id = 0;
  3956. vector<int32>* ids = 0;
  3957. int i = 0;
  3958. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3959. if (ids == 0)
  3960. ids = new vector<int32>;
  3961. ids->push_back(item_id);
  3962. i++;
  3963. }
  3964. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3965. if (quest_step && icon > 0 && quantity > 0)
  3966. quest_step->SetIcon(icon);
  3967. if (quest->GetPlayer()) {
  3968. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3969. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3970. }
  3971. safe_delete(ids);
  3972. }
  3973. lua_interface->ResetFunctionStack(state);
  3974. return 0;
  3975. }
  3976. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3977. if (!lua_interface)
  3978. return 0;
  3979. Quest* quest = lua_interface->GetQuest(state);
  3980. int32 step = lua_interface->GetInt32Value(state, 2);
  3981. string description = lua_interface->GetStringValue(state, 3);
  3982. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3983. float percentage = lua_interface->GetFloatValue(state, 5);
  3984. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3985. int16 icon = lua_interface->GetInt16Value(state, 7);
  3986. if (quest) {
  3987. const char* taskgroup = 0;
  3988. if (str_taskgroup.length() > 0)
  3989. taskgroup = str_taskgroup.c_str();
  3990. int32 item_id = 0;
  3991. vector<int32>* ids = 0;
  3992. int i = 0;
  3993. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3994. if (ids == 0)
  3995. ids = new vector<int32>;
  3996. ids->push_back(item_id);
  3997. i++;
  3998. }
  3999. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4000. if (quest_step && icon > 0 && quantity > 0)
  4001. quest_step->SetIcon(icon);
  4002. if (quest->GetPlayer()) {
  4003. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4004. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4005. }
  4006. safe_delete(ids);
  4007. }
  4008. lua_interface->ResetFunctionStack(state);
  4009. return 0;
  4010. }
  4011. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  4012. if (!lua_interface)
  4013. return 0;
  4014. Quest* quest = lua_interface->GetQuest(state);
  4015. string action = lua_interface->GetStringValue(state, 2);
  4016. lua_interface->ResetFunctionStack(state);
  4017. if (quest) {
  4018. if (action.length() > 0)
  4019. quest->SetCompleteAction(action);
  4020. }
  4021. return 0;
  4022. }
  4023. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  4024. if (!lua_interface)
  4025. return 0;
  4026. Quest* quest = lua_interface->GetQuest(state);
  4027. int32 step = lua_interface->GetInt32Value(state, 2);
  4028. string action = lua_interface->GetStringValue(state, 3);
  4029. lua_interface->ResetFunctionStack(state);
  4030. if (quest) {
  4031. if (step > 0 && action.length() > 0)
  4032. quest->AddCompleteAction(step, action);
  4033. }
  4034. return 0;
  4035. }
  4036. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  4037. if (!lua_interface)
  4038. return 0;
  4039. Quest* quest = lua_interface->GetQuest(state);
  4040. int32 step = lua_interface->GetInt32Value(state, 2);
  4041. string action = lua_interface->GetStringValue(state, 3);
  4042. lua_interface->ResetFunctionStack(state);
  4043. if (quest) {
  4044. if (step > 0 && action.length() > 0)
  4045. quest->AddProgressAction(step, action);
  4046. }
  4047. return 0;
  4048. }
  4049. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  4050. if (!lua_interface)
  4051. return 0;
  4052. Quest* quest = lua_interface->GetQuest(state);
  4053. string description = lua_interface->GetStringValue(state, 2);
  4054. lua_interface->ResetFunctionStack(state);
  4055. if (quest && description.length() > 0)
  4056. quest->SetDescription(description);
  4057. return 0;
  4058. }
  4059. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  4060. if (!lua_interface)
  4061. return 0;
  4062. Quest* quest = lua_interface->GetQuest(state);
  4063. string description = lua_interface->GetStringValue(state, 2);
  4064. lua_interface->ResetFunctionStack(state);
  4065. if (quest && description.length() > 0)
  4066. quest->SetCompletedDescription(description);
  4067. return 0;
  4068. }
  4069. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  4070. if (!lua_interface)
  4071. return 0;
  4072. Quest* quest = lua_interface->GetQuest(state);
  4073. int32 step = lua_interface->GetInt32Value(state, 2);
  4074. string description = lua_interface->GetStringValue(state, 3);
  4075. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4076. lua_interface->ResetFunctionStack(state);
  4077. if (quest && step > 0 && description.length() > 0) {
  4078. quest->SetTaskGroupDescription(step, description, display_bullets);
  4079. /* if (quest->GetPlayer()) {
  4080. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4081. if (client)
  4082. client->SendQuestUpdateStep(quest, step, false);
  4083. }*/
  4084. }
  4085. return 0;
  4086. }
  4087. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4088. if (!lua_interface)
  4089. return 0;
  4090. Quest* quest = lua_interface->GetQuest(state);
  4091. int32 step = lua_interface->GetInt32Value(state, 2);
  4092. string description = lua_interface->GetStringValue(state, 3);
  4093. lua_interface->ResetFunctionStack(state);
  4094. if (quest && step > 0 && description.length() > 0) {
  4095. quest->SetStepDescription(step, description);
  4096. /*if (quest->GetPlayer()) {
  4097. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4098. if (client)
  4099. client->SendQuestUpdateStepImmediately(quest, step);
  4100. }*/
  4101. }
  4102. return 0;
  4103. }
  4104. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4105. Quest* quest = lua_interface->GetQuest(state);
  4106. string zone = lua_interface->GetStringValue(state, 2);
  4107. lua_interface->ResetFunctionStack(state);
  4108. if (quest && zone.length() > 0)
  4109. quest->SetZone(zone);
  4110. return 0;
  4111. }
  4112. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4113. if (!lua_interface)
  4114. return 0;
  4115. Quest* quest = lua_interface->GetQuest(state);
  4116. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4117. lua_interface->ResetFunctionStack(state);
  4118. if (quest && spawn) {
  4119. if (spawn->IsPlayer()) {
  4120. Client* client = ((Player*)spawn)->GetClient();
  4121. if (client) {
  4122. client->AddPendingQuestReward(quest);
  4123. }
  4124. }
  4125. }
  4126. return 0;
  4127. }
  4128. int EQ2Emu_lua_Harvest(lua_State* state) {
  4129. if (!lua_interface)
  4130. return 0;
  4131. Spawn* player = lua_interface->GetSpawn(state);
  4132. Spawn* node = lua_interface->GetSpawn(state, 2);
  4133. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4134. Client* client = ((Player*)player)->GetClient();
  4135. if (client) {
  4136. ((GroundSpawn*)node)->ProcessHarvest(client);
  4137. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4138. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4139. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4140. }
  4141. }
  4142. }
  4143. else if (player && player->IsPlayer()) {
  4144. Client* client = ((Player*)player)->GetClient();
  4145. if (client)
  4146. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4147. }
  4148. lua_interface->ResetFunctionStack(state);
  4149. return 0;
  4150. }
  4151. int EQ2Emu_lua_Bind(lua_State* state) {
  4152. if (!lua_interface)
  4153. return 0;
  4154. Spawn* spawn = lua_interface->GetSpawn(state);
  4155. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4156. float x = lua_interface->GetFloatValue(state, 3);
  4157. float y = lua_interface->GetFloatValue(state, 4);
  4158. float z = lua_interface->GetFloatValue(state, 5);
  4159. float h = lua_interface->GetFloatValue(state, 6);
  4160. lua_interface->ResetFunctionStack(state);
  4161. if (!spawn) {
  4162. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4163. return 0;
  4164. }
  4165. if (!spawn->IsPlayer()) {
  4166. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4167. return 0;
  4168. }
  4169. if (zone_id == 0) {
  4170. Client* client = ((Player*)spawn)->GetClient();
  4171. if (!client) {
  4172. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4173. return 0;
  4174. }
  4175. if (!client->Bind())
  4176. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4177. }
  4178. else {
  4179. Player* player = (Player*)spawn;
  4180. player->GetPlayerInfo()->SetBindZone(zone_id);
  4181. player->GetPlayerInfo()->SetBindX(x);
  4182. player->GetPlayerInfo()->SetBindY(y);
  4183. player->GetPlayerInfo()->SetBindZ(z);
  4184. player->GetPlayerInfo()->SetBindHeading(h);
  4185. }
  4186. return 0;
  4187. }
  4188. int EQ2Emu_lua_Gate(lua_State* state) {
  4189. if (!lua_interface)
  4190. return 0;
  4191. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4192. Spawn* spawn = lua_interface->GetSpawn(state);
  4193. lua_interface->ResetFunctionStack(state);
  4194. if (spawn) {
  4195. if (spawn->IsPlayer()) {
  4196. Client* client = ((Player*)spawn)->GetClient();
  4197. if (client) {
  4198. if (!client->Gate((spell != nullptr) ? true : false))
  4199. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4200. }
  4201. }
  4202. }
  4203. return 0;
  4204. }
  4205. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4206. if (!lua_interface)
  4207. return 0;
  4208. bool ret = false;
  4209. Spawn* spawn = lua_interface->GetSpawn(state);
  4210. lua_interface->ResetFunctionStack(state);
  4211. if (spawn) {
  4212. if (spawn->IsPlayer()) {
  4213. Client* client = ((Player*)spawn)->GetClient();
  4214. if (client)
  4215. ret = client->BindAllowed();
  4216. }
  4217. }
  4218. lua_interface->SetBooleanValue(state, ret);
  4219. return 1;
  4220. }
  4221. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4222. if (!lua_interface)
  4223. return 0;
  4224. bool ret = false;
  4225. Spawn* spawn = lua_interface->GetSpawn(state);
  4226. lua_interface->ResetFunctionStack(state);
  4227. if (spawn) {
  4228. if (spawn->IsPlayer()) {
  4229. Client* client = ((Player*)spawn)->GetClient();
  4230. ZoneServer* zone = lua_interface->GetZone(state);
  4231. if (client && zone){
  4232. ret = zone->GetCanGate();
  4233. }
  4234. }
  4235. }
  4236. lua_interface->SetBooleanValue(state, ret);
  4237. return 1;
  4238. }
  4239. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4240. Spawn* spawn = lua_interface->GetSpawn(state);
  4241. lua_interface->ResetFunctionStack(state);
  4242. if (spawn) {
  4243. lua_interface->SetBooleanValue(state, spawn->Alive());
  4244. return 1;
  4245. }
  4246. return 0;
  4247. }
  4248. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4249. if (!lua_interface)
  4250. return 0;
  4251. Spawn* spawn = lua_interface->GetSpawn(state);
  4252. lua_interface->ResetFunctionStack(state);
  4253. if (spawn && spawn->IsEntity()) {
  4254. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4255. return 1;
  4256. }
  4257. return 0;
  4258. }
  4259. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4260. Spawn* spawn = lua_interface->GetSpawn(state);
  4261. string message = lua_interface->GetStringValue(state, 2);
  4262. string color_str = lua_interface->GetStringValue(state, 3);
  4263. lua_interface->ResetFunctionStack(state);
  4264. int8 color = CHANNEL_NARRATIVE;
  4265. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4266. Client* client = ((Player*)spawn)->GetClient();
  4267. if (client) {
  4268. if (color_str.length() > 0) {
  4269. // leave for backwards compat, but all future should just use the number
  4270. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4271. color = CHANNEL_COLOR_RED;
  4272. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4273. color = CHANNEL_COLOR_YELLOW;
  4274. else
  4275. {
  4276. // use a number to specify the channel as per Commands/Commands.h defines
  4277. color = (int8)atoul(color_str.c_str());
  4278. }
  4279. }
  4280. client->SimpleMessage(color, message.c_str());
  4281. }
  4282. }
  4283. return 0;
  4284. }
  4285. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4286. Spawn* spawn = lua_interface->GetSpawn(state);
  4287. string message = lua_interface->GetStringValue(state, 2);
  4288. int8 red = lua_interface->GetInt8Value(state, 3);
  4289. int8 green = lua_interface->GetInt8Value(state, 4);
  4290. int8 blue = lua_interface->GetInt8Value(state, 5);
  4291. lua_interface->ResetFunctionStack(state);
  4292. if (!spawn) {
  4293. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4294. return 0;
  4295. }
  4296. if (!spawn->IsPlayer()) {
  4297. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not a player.", lua_interface->GetScriptName(state));
  4298. return 0;
  4299. }
  4300. int32 words = ::CountWordsInString(message.c_str());
  4301. if (words < 5)
  4302. words = 5;
  4303. Client* client = ((Player*)spawn)->GetClient();
  4304. if (client)
  4305. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4306. return 0;
  4307. }
  4308. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4309. Spawn* spawn = lua_interface->GetSpawn(state);
  4310. int8 param = lua_interface->GetInt8Value(state, 2);
  4311. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4312. int8 value = lua_interface->GetInt8Value(state, 4);
  4313. lua_interface->ResetFunctionStack(state);
  4314. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4315. Client* client = ((Player*)spawn)->GetClient();
  4316. if (client) {
  4317. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4318. switch (param) {
  4319. case 1: {
  4320. packet->setDataByName("parameter1", param_value);
  4321. break;
  4322. }
  4323. case 2: {
  4324. packet->setDataByName("parameter2", param_value);
  4325. break;
  4326. }
  4327. case 3: {
  4328. packet->setDataByName("parameter3", param_value);
  4329. break;
  4330. }
  4331. case 4: {
  4332. packet->setDataByName("parameter4", param_value);
  4333. break;
  4334. }
  4335. case 5: {
  4336. packet->setDataByName("parameter5", param_value);
  4337. break;
  4338. }
  4339. }
  4340. packet->setDataByName("value", value);
  4341. client->QueuePacket(packet->serialize());
  4342. safe_delete(packet);
  4343. }
  4344. }
  4345. return 0;
  4346. }
  4347. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4348. Spawn* spawn = lua_interface->GetSpawn(state);
  4349. lua_interface->ResetFunctionStack(state);
  4350. if (spawn && spawn->IsPlayer()) {
  4351. if (((Player*)spawn)->GetIsTracking())
  4352. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4353. else
  4354. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4355. }
  4356. return 0;
  4357. }
  4358. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4359. Spawn* player = lua_interface->GetSpawn(state);
  4360. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4361. string name = lua_interface->GetStringValue(state, 3);
  4362. float distance = lua_interface->GetFloatValue(state, 4);
  4363. string command = lua_interface->GetStringValue(state, 5);
  4364. string error_text = lua_interface->GetStringValue(state, 6);
  4365. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4366. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4367. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4368. lua_interface->ResetFunctionStack(state);
  4369. if (spawn) {
  4370. if (distance == 0)
  4371. distance = 10.0f;
  4372. if (command.length() == 0)
  4373. command = name;
  4374. if (command.length() < 1 && name.length() < 1)
  4375. {
  4376. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4377. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4378. spawn->RemovePrimaryCommands();
  4379. }
  4380. else
  4381. {
  4382. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4383. }
  4384. }
  4385. return 0;
  4386. }
  4387. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4388. if (!lua_interface)
  4389. return 0;
  4390. Spawn* player = lua_interface->GetSpawn(state);
  4391. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4392. int16 tier = lua_interface->GetInt16Value(state, 3);
  4393. lua_interface->ResetFunctionStack(state);
  4394. if (player && player->IsPlayer()) {
  4395. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4396. return 1;
  4397. }
  4398. return 0;
  4399. }
  4400. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4401. if (!lua_interface)
  4402. return 0;
  4403. Spawn* player = lua_interface->GetSpawn(state);
  4404. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4405. int16 tier = lua_interface->GetInt16Value(state, 3);
  4406. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4407. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4408. bool add_to_hotbar = true;
  4409. if (num_args > 4) {
  4410. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4411. }
  4412. lua_interface->ResetFunctionStack(state);
  4413. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4414. if (player && spell && player->IsPlayer()) {
  4415. Client* client = player->GetClient();
  4416. if (client) {
  4417. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4418. {
  4419. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4420. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4421. client->GetPlayer()->UnlockSpell(spell);
  4422. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4423. }
  4424. else
  4425. {
  4426. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4427. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4428. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4429. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4430. client->GetPlayer()->UnlockSpell(spell);
  4431. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4432. }
  4433. //if (client ) {
  4434. // ((Player*)player)->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), ((Player*)player)->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4435. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4436. if (outapp)
  4437. client->QueuePacket(outapp);
  4438. }
  4439. }
  4440. return 0;
  4441. }
  4442. int EQ2Emu_lua_DeleteSpellBook(lua_State* state) {
  4443. if (!lua_interface)
  4444. return 0;
  4445. Spawn* player = lua_interface->GetSpawn(state);
  4446. int8 type_selection = lua_interface->GetInt8Value(state, 2);
  4447. lua_interface->ResetFunctionStack(state);
  4448. if (player && player->IsPlayer()) {
  4449. Client* client = player->GetClient();
  4450. if (client) {
  4451. ((Player*)player)->DeleteSpellBook(type_selection);
  4452. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4453. if (outapp)
  4454. client->QueuePacket(outapp);
  4455. }
  4456. }
  4457. return 0;
  4458. }
  4459. int EQ2Emu_lua_SendNewAdventureSpells(lua_State* state) {
  4460. if (!lua_interface)
  4461. return 0;
  4462. Spawn* player = lua_interface->GetSpawn(state);
  4463. lua_interface->ResetFunctionStack(state);
  4464. if (player && player->IsPlayer()) {
  4465. Client* client = player->GetClient();
  4466. if (client) {
  4467. client->SendNewAdventureSpells();
  4468. }
  4469. }
  4470. return 0;
  4471. }
  4472. int EQ2Emu_lua_SendNewTradeskillSpells(lua_State* state) {
  4473. if (!lua_interface)
  4474. return 0;
  4475. Spawn* player = lua_interface->GetSpawn(state);
  4476. lua_interface->ResetFunctionStack(state);
  4477. if (player && player->IsPlayer()) {
  4478. Client* client = player->GetClient();
  4479. if (client) {
  4480. client->SendNewTradeskillSpells();
  4481. }
  4482. }
  4483. return 0;
  4484. }
  4485. int EQ2Emu_lua_RemoveSpellBookEntry(lua_State* state) {
  4486. if (!lua_interface)
  4487. return 0;
  4488. Spawn* player = lua_interface->GetSpawn(state);
  4489. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4490. lua_interface->ResetFunctionStack(state);
  4491. if (player && player->IsPlayer()) {
  4492. SpellBookEntry* sbe = ((Player*)player)->GetSpellBookSpell(spellid);
  4493. Client* client = player->GetClient();
  4494. if (sbe && client) {
  4495. ((Player*)player)->RemoveSpellBookEntry(spellid);
  4496. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4497. if (outapp)
  4498. client->QueuePacket(outapp);
  4499. }
  4500. }
  4501. return 0;
  4502. }
  4503. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4504. if (!lua_interface)
  4505. return 0;
  4506. Spawn* player = lua_interface->GetSpawn(state);
  4507. lua_interface->ResetFunctionStack(state);
  4508. if (player && player->IsPlayer()) {
  4509. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4510. return 1;
  4511. }
  4512. return 0;
  4513. }
  4514. int EQ2Emu_lua_Attack(lua_State* state) {
  4515. if (lua_interface) {
  4516. Spawn* npc = lua_interface->GetSpawn(state);
  4517. Spawn* player = lua_interface->GetSpawn(state, 2);
  4518. lua_interface->ResetFunctionStack(state);
  4519. if (npc && player && npc->IsNPC() && player->IsEntity())
  4520. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4521. }
  4522. return 0;
  4523. }
  4524. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4525. if (lua_interface) {
  4526. Spawn* target = lua_interface->GetSpawn(state);
  4527. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4528. lua_interface->ResetFunctionStack(state);
  4529. if (target && target->GetZone())
  4530. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4531. }
  4532. return 0;
  4533. }
  4534. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4535. Spawn* player;
  4536. if (lua_interface) {
  4537. player = lua_interface->GetSpawn(state);
  4538. lua_interface->ResetFunctionStack(state);
  4539. if (player && player->IsPlayer()) {
  4540. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4541. return 1;
  4542. }
  4543. }
  4544. return 0;
  4545. }
  4546. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4547. Spawn* player;
  4548. Client* client;
  4549. if (lua_interface) {
  4550. player = lua_interface->GetSpawn(state);
  4551. lua_interface->ResetFunctionStack(state);
  4552. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4553. if ((client = ((Player*)player)->GetClient()))
  4554. client->HandInCollections();
  4555. }
  4556. return 0;
  4557. }
  4558. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4559. Spawn* widget;
  4560. if (lua_interface) {
  4561. widget = lua_interface->GetSpawn(state);
  4562. lua_interface->ResetFunctionStack(state);
  4563. if (widget && widget->IsWidget())
  4564. ((Widget*)widget)->HandleUse(nullptr, "");
  4565. }
  4566. return 0;
  4567. }
  4568. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4569. Spawn* spawn = 0;
  4570. int32 primary_list = 0;
  4571. int32 secondary_list = 0;
  4572. if (lua_interface) {
  4573. spawn = lua_interface->GetSpawn(state);
  4574. primary_list = lua_interface->GetInt32Value(state, 2);
  4575. secondary_list = lua_interface->GetInt32Value(state, 3);
  4576. lua_interface->ResetFunctionStack(state);
  4577. if (!spawn->IsNPC()) {
  4578. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4579. return 0;
  4580. }
  4581. NPC* npc = (NPC*)spawn;
  4582. npc->SetPrimarySpellList(primary_list);
  4583. npc->SetSecondarySpellList(secondary_list);
  4584. npc->SetSpells(world.GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4585. }
  4586. return 0;
  4587. }
  4588. int EQ2Emu_lua_GetPet(lua_State* state) {
  4589. if (!lua_interface)
  4590. return 0;
  4591. Spawn* spawn = lua_interface->GetSpawn(state);
  4592. lua_interface->ResetFunctionStack(state);
  4593. if (spawn) {
  4594. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4595. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4596. return 1;
  4597. }
  4598. }
  4599. return 0;
  4600. }
  4601. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4602. if (!lua_interface)
  4603. return 0;
  4604. Spawn* spawn = lua_interface->GetSpawn(state);
  4605. lua_interface->ResetFunctionStack(state);
  4606. if (spawn) {
  4607. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4608. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4609. return 1;
  4610. }
  4611. }
  4612. return 0;
  4613. }
  4614. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4615. if (!lua_interface)
  4616. return 0;
  4617. Spawn* spawn = lua_interface->GetSpawn(state);
  4618. lua_interface->ResetFunctionStack(state);
  4619. if (spawn) {
  4620. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4621. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4622. return 1;
  4623. }
  4624. }
  4625. return 0;
  4626. }
  4627. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4628. if (!lua_interface)
  4629. return 0;
  4630. Spawn* spawn = lua_interface->GetSpawn(state);
  4631. lua_interface->ResetFunctionStack(state);
  4632. if (spawn) {
  4633. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4634. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4635. return 1;
  4636. }
  4637. }
  4638. return 0;
  4639. }
  4640. int EQ2Emu_lua_Charm(lua_State* state) {
  4641. if (!lua_interface)
  4642. return 0;
  4643. Spawn* owner = lua_interface->GetSpawn(state);
  4644. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4645. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4646. lua_interface->ResetFunctionStack(state);
  4647. if (!luaspell) {
  4648. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4649. return 0;
  4650. }
  4651. if(luaspell->resisted) {
  4652. return 0;
  4653. }
  4654. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4655. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4656. pet->SetPet(true);
  4657. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4658. ((NPC*)pet)->SetOwner((Entity*)owner);
  4659. // If owner is player and player does not have a summoned pet set the players charsheet
  4660. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4661. Player* player = (Player*)owner;
  4662. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4663. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4664. player->GetInfoStruct()->set_pet_movement(2);
  4665. player->GetInfoStruct()->set_pet_behavior(3);
  4666. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4667. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4668. // Make sure the values get sent to the client
  4669. player->SetCharSheetChanged(true);
  4670. }
  4671. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4672. pet->SetSpawnScript("");
  4673. // Set faction to the same as the owner
  4674. pet->SetFactionID(owner->GetFactionID());
  4675. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4676. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4677. // Clear hate list
  4678. ((NPC*)pet)->Brain()->ClearHate();
  4679. // Set the brain to a pet brain
  4680. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4681. }
  4682. return 0;
  4683. }
  4684. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4685. if (!lua_interface)
  4686. return 0;
  4687. Spawn* spawn = lua_interface->GetSpawn(state);
  4688. lua_interface->ResetFunctionStack(state);
  4689. if (!spawn) {
  4690. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4691. return 0;
  4692. }
  4693. vector<Spawn*> groupMembers;
  4694. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4695. groupMembers = *spawn->GetSpawnGroup();
  4696. }
  4697. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4698. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4699. deque<GroupMemberInfo*>::iterator itr;
  4700. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4701. if (group)
  4702. {
  4703. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4704. deque<GroupMemberInfo*>* members = group->GetMembers();
  4705. GroupMemberInfo* info = 0;
  4706. for (itr = members->begin(); itr != members->end(); itr++) {
  4707. info = *itr;
  4708. if (info->client)
  4709. groupMembers.push_back(info->client->GetPlayer());
  4710. }
  4711. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4712. }
  4713. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4714. }
  4715. else
  4716. return 0;
  4717. lua_createtable(state, groupMembers.size(), 0);
  4718. int newTable = lua_gettop(state);
  4719. for (int32 i = 0; i < groupMembers.size(); i++) {
  4720. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4721. lua_rawseti(state, newTable, i + 1);
  4722. }
  4723. return 1;
  4724. }
  4725. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4726. if (!lua_interface)
  4727. return 0;
  4728. lua_interface->ResetFunctionStack(state);
  4729. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4730. lua_interface->SetOptionWindowValue(state, option_window);
  4731. return 1;
  4732. }
  4733. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4734. if (!lua_interface)
  4735. return 0;
  4736. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4737. if (option_window) {
  4738. OptionWindowOption option_window_option;
  4739. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4740. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4741. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4742. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4743. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4744. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4745. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4746. option_window->push_back(option_window_option);
  4747. }
  4748. lua_interface->ResetFunctionStack(state);
  4749. return 0;
  4750. }
  4751. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4752. if (!lua_interface)
  4753. return 0;
  4754. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4755. Spawn* player = lua_interface->GetSpawn(state, 2);
  4756. string window_title = lua_interface->GetStringValue(state, 3);
  4757. string cancel_command = lua_interface->GetStringValue(state, 4);
  4758. lua_interface->ResetFunctionStack(state);
  4759. if (!player->IsPlayer()) {
  4760. lua_interface->LogError("%s: LUA SendOptionWindow command error: spawn is not a player", lua_interface->GetScriptName(state));
  4761. return 0;
  4762. }
  4763. Client* client = ((Player*)player)->GetClient();
  4764. if (option_window && window_title.length() > 0 && client) {
  4765. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4766. if (!packet)
  4767. return 0;
  4768. packet->setDataByName("title_text", window_title.c_str());
  4769. if (cancel_command.length() > 0)
  4770. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4771. packet->setArrayLengthByName("num_selections", option_window->size());
  4772. vector<OptionWindowOption>::iterator itr;
  4773. int8 i = 0;
  4774. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4775. OptionWindowOption opt = *itr;
  4776. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4777. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4778. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4779. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4780. if (opt.optionCommand.length() > 0)
  4781. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4782. if (opt.optionConfirmTitle.length() > 0)
  4783. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4784. i++;
  4785. }
  4786. client->QueuePacket(packet->serialize());
  4787. lua_interface->SetLuaUserDataStale(option_window);
  4788. safe_delete(option_window);
  4789. safe_delete(packet);
  4790. }
  4791. return 0;
  4792. }
  4793. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4794. if (!lua_interface)
  4795. return 0;
  4796. Spawn* spawn = lua_interface->GetSpawn(state);
  4797. lua_interface->ResetFunctionStack(state);
  4798. if (spawn) {
  4799. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4800. return 1;
  4801. }
  4802. else
  4803. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4804. return 0;
  4805. }
  4806. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4807. if (!lua_interface)
  4808. return 0;
  4809. Spawn* spawn = lua_interface->GetSpawn(state);
  4810. lua_interface->ResetFunctionStack(state);
  4811. if (spawn) {
  4812. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4813. return 1;
  4814. }
  4815. else
  4816. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4817. return 0;
  4818. }
  4819. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4820. if (!lua_interface)
  4821. return 0;
  4822. Spawn* spawn = lua_interface->GetSpawn(state);
  4823. lua_interface->ResetFunctionStack(state);
  4824. if (spawn) {
  4825. int8 class_id = spawn->GetTradeskillClass();
  4826. // Need to add 42 for the offset in the array
  4827. class_id += 44;
  4828. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4829. return 1;
  4830. }
  4831. else
  4832. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4833. return 0;
  4834. }
  4835. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4836. if (!lua_interface)
  4837. return 0;
  4838. Spawn* spawn = lua_interface->GetSpawn(state);
  4839. int16 level = lua_interface->GetInt8Value(state, 2);
  4840. lua_interface->ResetFunctionStack(state);
  4841. if (spawn) {
  4842. if (spawn->IsPlayer() && ((Player*)spawn)->GetClient())
  4843. ((Player*)spawn)->GetClient()->ChangeTSLevel(spawn->GetTSLevel(), level);
  4844. else
  4845. spawn->SetTSLevel(level);
  4846. }
  4847. else
  4848. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4849. return 0;
  4850. }
  4851. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4852. if (!lua_interface)
  4853. return 0;
  4854. Spawn* spawn = lua_interface->GetSpawn(state);
  4855. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4856. lua_interface->ResetFunctionStack(state);
  4857. if (spawn) {
  4858. spawn->SetAttackable(attackable);
  4859. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4860. }
  4861. return 0;
  4862. }
  4863. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4864. // Check to see if we have a valid lua_interface
  4865. if (!lua_interface)
  4866. return 0;
  4867. // Get the spawn that is getting the pet
  4868. Spawn* spawn = lua_interface->GetSpawn(state);
  4869. // Get the DB ID of the pet
  4870. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4871. // The max level the pet can gain
  4872. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4873. // Get the spell that this command was called from
  4874. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4875. lua_interface->ResetFunctionStack(state);
  4876. // Check to make sure the spawn pointer is valid
  4877. if (!spawn) {
  4878. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4879. return 0;
  4880. }
  4881. // Check to make sure the spawn is an entity
  4882. if (!spawn->IsEntity()) {
  4883. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4884. return 0;
  4885. }
  4886. // Check to make sure the spawn doesn't already have a pet of this type
  4887. if (((Entity*)spawn)->GetPet()) {
  4888. if (spawn->IsPlayer()) {
  4889. Client* client = ((Player*)spawn)->GetClient();
  4890. if (client)
  4891. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4892. }
  4893. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4894. return 0;
  4895. }
  4896. // Check to see if the DB ID for the pet is set
  4897. if (pet_id == 0) {
  4898. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4899. return 0;
  4900. }
  4901. // Check to see if the pointer to the spell is valid
  4902. if (!luaspell) {
  4903. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4904. return 0;
  4905. }
  4906. if(luaspell->resisted) {
  4907. return 0;
  4908. }
  4909. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4910. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4911. if (!pet) {
  4912. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4913. return 0;
  4914. }
  4915. // Check to make sure the pet is an npc
  4916. if (!pet->IsNPC()) {
  4917. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4918. return 0;
  4919. }
  4920. // Spawn the pet at the same location as the owner
  4921. pet->SetX(spawn->GetX());
  4922. pet->SetY(spawn->GetY());
  4923. pet->SetZ(spawn->GetZ());
  4924. pet->SetLocation(spawn->GetLocation());
  4925. pet->SetHeading(spawn->GetHeading());
  4926. std::string petName = std::string("");
  4927. if(spawn->IsEntity()) {
  4928. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  4929. }
  4930. if(petName.size() < 1) {
  4931. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4932. petName = spawn->GetZone()->pet_names.at(rand_index);
  4933. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  4934. }
  4935. // If player set various values for the char sheet (pet window)
  4936. if (spawn->IsPlayer()) {
  4937. Player* player = (Player*)spawn;
  4938. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4939. player->GetInfoStruct()->set_pet_name(petName);
  4940. player->GetInfoStruct()->set_pet_movement(2);
  4941. player->GetInfoStruct()->set_pet_behavior(3);
  4942. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4943. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4944. // Make sure the values get sent to the client
  4945. player->SetCharSheetChanged(true);
  4946. }
  4947. // Set the pets name
  4948. pet->SetName(petName.c_str());
  4949. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4950. if (max_level > 0)
  4951. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4952. else
  4953. pet->SetLevel(spawn->GetLevel());
  4954. // Set the max level this pet can reach
  4955. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4956. ((NPC*)pet)->UpdateWeapons();
  4957. // Set the faction of the pet to the same faction as the owner
  4958. pet->SetFactionID(spawn->GetFactionID());
  4959. // Set the spawn as a pet
  4960. pet->SetPet(true);
  4961. // Give a pointer of the owner to the pet
  4962. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4963. // Give a pointer of the pet to the owner
  4964. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4965. // Set the pet type
  4966. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4967. // Set the spell id used to create this pet
  4968. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4969. // Set the spell tier used to create this pet
  4970. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4971. // Set the pets spawn type to 6
  4972. pet->SetSpawnType(6);
  4973. // Set the pets brain
  4974. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4975. // Check to see if the pet has a subtitle
  4976. if (strlen(pet->GetSubTitle()) > 0) {
  4977. // Add the players name to the front of the sub title
  4978. string pet_subtitle;
  4979. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4980. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4981. // Set the pets subtitle to the new one
  4982. pet->SetSubTitle(pet_subtitle.c_str());
  4983. }
  4984. // Add the "Pet Options" entity command to the pet
  4985. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4986. const char* spawn_script = world.GetSpawnScript(pet_id);
  4987. bool runScript = false;
  4988. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4989. runScript = true;
  4990. pet->SetSpawnScript(string(spawn_script));
  4991. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_PRESPAWN);
  4992. }
  4993. spawn->GetZone()->AddSpawn(pet);
  4994. if(runScript){
  4995. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_SPAWN);
  4996. }
  4997. // Set the pet as the return value for this function
  4998. lua_interface->SetSpawnValue(state, pet);
  4999. return 1;
  5000. }
  5001. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  5002. if (!lua_interface)
  5003. return 0;
  5004. Spawn* spawn = lua_interface->GetSpawn(state);
  5005. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5006. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5007. lua_interface->ResetFunctionStack(state);
  5008. if (!spawn) {
  5009. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5010. return 0;
  5011. }
  5012. if (!spawn->IsEntity()) {
  5013. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5014. return 0;
  5015. }
  5016. if (((Entity*)spawn)->GetDeityPet()) {
  5017. if (spawn->IsPlayer()) {
  5018. Client* client = ((Player*)spawn)->GetClient();
  5019. if (client)
  5020. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  5021. }
  5022. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5023. return 0;
  5024. }
  5025. if (pet_id == 0) {
  5026. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5027. return 0;
  5028. }
  5029. if (!luaspell) {
  5030. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5031. return 0;
  5032. }
  5033. if(luaspell->resisted) {
  5034. return 0;
  5035. }
  5036. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5037. if (!pet) {
  5038. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5039. return 0;
  5040. }
  5041. if (!pet->IsNPC()) {
  5042. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5043. return 0;
  5044. }
  5045. pet->SetX(spawn->GetX());
  5046. pet->SetY(spawn->GetY());
  5047. pet->SetZ(spawn->GetZ());
  5048. pet->SetLocation(spawn->GetLocation());
  5049. pet->SetHeading(spawn->GetHeading());
  5050. spawn->GetZone()->AddSpawn(pet);
  5051. string random_pet_name;
  5052. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5053. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5054. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5055. pet->SetName(random_pet_name.c_str());
  5056. pet->SetLevel(spawn->GetLevel());
  5057. pet->SetFactionID(spawn->GetFactionID());
  5058. pet->SetPet(true);
  5059. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  5060. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5061. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  5062. pet->SetSpawnType(6);
  5063. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5064. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5065. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5066. if (strlen(pet->GetSubTitle()) > 0) {
  5067. string pet_subtitle;
  5068. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5069. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5070. pet->SetSubTitle(pet_subtitle.c_str());
  5071. }
  5072. // deity and cosmetic pets are not attackable
  5073. pet->SetAttackable(false);
  5074. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5075. lua_interface->SetSpawnValue(state, pet);
  5076. return 1;
  5077. }
  5078. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  5079. if (!lua_interface)
  5080. return 0;
  5081. Spawn* spawn = lua_interface->GetSpawn(state);
  5082. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5083. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5084. lua_interface->ResetFunctionStack(state);
  5085. if (!spawn) {
  5086. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5087. return 0;
  5088. }
  5089. if (!spawn->IsEntity()) {
  5090. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5091. return 0;
  5092. }
  5093. if (((Entity*)spawn)->GetCosmeticPet()) {
  5094. if (spawn->IsPlayer()) {
  5095. Client* client = ((Player*)spawn)->GetClient();
  5096. if (client)
  5097. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  5098. }
  5099. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5100. return 0;
  5101. }
  5102. if (pet_id == 0) {
  5103. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5104. return 0;
  5105. }
  5106. if (!luaspell) {
  5107. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5108. return 0;
  5109. }
  5110. if(luaspell->resisted) {
  5111. return 0;
  5112. }
  5113. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5114. if (!pet) {
  5115. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5116. return 0;
  5117. }
  5118. if (!pet->IsNPC()) {
  5119. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5120. return 0;
  5121. }
  5122. pet->SetX(spawn->GetX());
  5123. pet->SetY(spawn->GetY());
  5124. pet->SetZ(spawn->GetZ());
  5125. pet->SetLocation(spawn->GetLocation());
  5126. pet->SetHeading(spawn->GetHeading());
  5127. spawn->GetZone()->AddSpawn(pet);
  5128. string random_pet_name;
  5129. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5130. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5131. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5132. pet->SetName(random_pet_name.c_str());
  5133. pet->SetLevel(spawn->GetLevel());
  5134. pet->SetFactionID(spawn->GetFactionID());
  5135. pet->SetPet(true);
  5136. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  5137. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5138. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  5139. pet->SetSpawnType(6);
  5140. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5141. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5142. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5143. if (strlen(pet->GetSubTitle()) > 0) {
  5144. string pet_subtitle;
  5145. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5146. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5147. pet->SetSubTitle(pet_subtitle.c_str());
  5148. }
  5149. pet->SetAttackable(false);
  5150. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5151. lua_interface->SetSpawnValue(state, pet);
  5152. return 1;
  5153. }
  5154. int EQ2Emu_lua_DismissPet(lua_State* state) {
  5155. if (!lua_interface)
  5156. return 0;
  5157. Spawn* spawn = lua_interface->GetSpawn(state);
  5158. lua_interface->ResetFunctionStack(state);
  5159. if (!spawn) {
  5160. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5161. return 0;
  5162. }
  5163. if (!spawn->IsPet()) {
  5164. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  5165. return 0;
  5166. }
  5167. if (!((NPC*)spawn)->IsDismissing() && ((NPC*)spawn)->GetOwner())
  5168. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  5169. return 0;
  5170. }
  5171. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  5172. if (!lua_interface)
  5173. return 0;
  5174. Quest* quest = lua_interface->GetQuest(state);
  5175. if (!quest) {
  5176. lua_interface->LogError("%s: LUA SetQuestFeatherColor command error: valid quest not found, SetQuestFeatherColor can only be called from a quest script", lua_interface->GetScriptName(state));
  5177. lua_interface->ResetFunctionStack(state);
  5178. return 0;
  5179. }
  5180. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5181. lua_interface->ResetFunctionStack(state);
  5182. if (feather_color > 0)
  5183. quest->SetFeatherColor(feather_color);
  5184. return 0;
  5185. }
  5186. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5187. if (!lua_interface)
  5188. return 0;
  5189. Spawn* spawn = lua_interface->GetSpawn(state);
  5190. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5191. lua_interface->ResetFunctionStack(state);
  5192. if (!spawn) {
  5193. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5194. return 0;
  5195. }
  5196. if (!spawn2) {
  5197. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5198. return 0;
  5199. }
  5200. spawn->RemoveSpawnAccess(spawn2);
  5201. return 0;
  5202. }
  5203. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5204. if (!lua_interface)
  5205. return 0;
  5206. ZoneServer* zone = lua_interface->GetZone(state);
  5207. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5208. lua_interface->ResetFunctionStack(state);
  5209. if (!zone) {
  5210. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5211. return 0;
  5212. }
  5213. if (location_id == 0) {
  5214. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5215. return 0;
  5216. }
  5217. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5218. if (!location) {
  5219. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5220. return 0;
  5221. }
  5222. Spawn* spawn = 0;
  5223. if (location->entities[0]) {
  5224. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5225. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  5226. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5227. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  5228. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5229. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  5230. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5231. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  5232. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5233. spawn = zone->AddSignSpawn(location, location->entities[0]);
  5234. if(spawn && spawn->IsOmittedByDBFlag())
  5235. {
  5236. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5237. safe_delete(spawn);
  5238. spawn = 0;
  5239. return 0;
  5240. }
  5241. if (spawn) {
  5242. const char* script = 0;
  5243. for (int x = 0; x < 3; x++) {
  5244. switch (x) {
  5245. case 0:
  5246. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5247. break;
  5248. case 1:
  5249. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5250. break;
  5251. case 2:
  5252. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5253. break;
  5254. }
  5255. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5256. spawn->SetSpawnScript(string(script));
  5257. break;
  5258. }
  5259. }
  5260. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5261. lua_interface->SetSpawnValue(state, spawn);
  5262. return 1;
  5263. }
  5264. else {
  5265. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5266. safe_delete(spawn);
  5267. }
  5268. }
  5269. return 0;
  5270. }
  5271. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5272. if (!lua_interface)
  5273. return 0;
  5274. Spawn* caster = lua_interface->GetSpawn(state);
  5275. Spawn* target = lua_interface->GetSpawn(state, 2);
  5276. int32 id = lua_interface->GetInt32Value(state, 3);
  5277. string command = lua_interface->GetStringValue(state, 4);
  5278. lua_interface->ResetFunctionStack(state);
  5279. if (!caster) {
  5280. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5281. return 0;
  5282. }
  5283. if (!target) {
  5284. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5285. return 0;
  5286. }
  5287. if (!caster->IsPlayer()) {
  5288. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5289. return 0;
  5290. }
  5291. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5292. if (!entity_command) {
  5293. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid EntityCommand with the given ID (%u) and name (%s)", lua_interface->GetScriptName(state), id, command.c_str());
  5294. return 0;
  5295. }
  5296. Client* client = ((Player*)caster)->GetClient();
  5297. if (!client) {
  5298. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5299. return 0;
  5300. }
  5301. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5302. return 0;
  5303. }
  5304. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5305. if (!lua_interface)
  5306. return 0;
  5307. Spawn* spawn = lua_interface->GetSpawn(state);
  5308. lua_interface->ResetFunctionStack(state);
  5309. if (!spawn) {
  5310. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5311. return 0;
  5312. }
  5313. if (!spawn->IsNPC()) {
  5314. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5315. return 0;
  5316. }
  5317. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5318. return 0;
  5319. }
  5320. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5321. if (!lua_interface)
  5322. return 0;
  5323. Spawn* spawn = lua_interface->GetSpawn(state);
  5324. int16 tick = lua_interface->GetInt16Value(state, 2);
  5325. lua_interface->ResetFunctionStack(state);
  5326. if (!spawn) {
  5327. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5328. return 0;
  5329. }
  5330. if (!spawn->IsNPC()) {
  5331. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5332. return 0;
  5333. }
  5334. if (tick < 20) {
  5335. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5336. return 0;
  5337. }
  5338. ((NPC*)spawn)->Brain()->SetTick(tick);
  5339. return 0;
  5340. }
  5341. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5342. if (!lua_interface)
  5343. return 0;
  5344. Spawn* spawn = lua_interface->GetSpawn(state);
  5345. Spawn* target = lua_interface->GetSpawn(state, 2);
  5346. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5347. lua_interface->ResetFunctionStack(state);
  5348. if (!spawn) {
  5349. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5350. return 0;
  5351. }
  5352. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5353. spawn->SetFollowTarget(target, follow_distance);
  5354. return 0;
  5355. }
  5356. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5357. if (!lua_interface)
  5358. return 0;
  5359. Spawn* spawn = lua_interface->GetSpawn(state);
  5360. lua_interface->ResetFunctionStack(state);
  5361. if (!spawn) {
  5362. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5363. return 0;
  5364. }
  5365. Spawn* target = spawn->GetFollowTarget();
  5366. if (target) {
  5367. lua_interface->SetSpawnValue(state, target);
  5368. return 1;
  5369. }
  5370. return 0;
  5371. }
  5372. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5373. if (!lua_interface)
  5374. return 0;
  5375. Spawn* spawn = lua_interface->GetSpawn(state);
  5376. lua_interface->ResetFunctionStack(state);
  5377. if (!spawn) {
  5378. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5379. return 0;
  5380. }
  5381. if (spawn->following)
  5382. spawn->following = false;
  5383. else
  5384. spawn->following = true;
  5385. return 0;
  5386. }
  5387. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5388. if (!lua_interface)
  5389. return 0;
  5390. Spawn* spawn = lua_interface->GetSpawn(state);
  5391. lua_interface->ResetFunctionStack(state);
  5392. if (!spawn) {
  5393. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5394. return 0;
  5395. }
  5396. lua_interface->SetBooleanValue(state, spawn->following);
  5397. return 1;
  5398. }
  5399. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5400. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5401. // I will attempt to explain how this function works for future refrence
  5402. // Fist lets make sure lua_interface is valid, if not return out
  5403. if (!lua_interface)
  5404. return 0;
  5405. // Next we grab the first 2 params same as we usually would
  5406. Spawn* spawn = lua_interface->GetSpawn(state);
  5407. string var = lua_interface->GetStringValue(state, 2);
  5408. // DataType will let us know the value type so we can handle it correctly, we set these ourself so the values I used are made up
  5409. // 1 = Spawn
  5410. // 2 = Zone
  5411. // 3 = Item
  5412. // 4 = Quest
  5413. // 5 = String
  5414. // 6 = nil (null)
  5415. int8 dataType = 0;
  5416. // Define pointers for each potential type
  5417. Spawn* spawnVal = 0;
  5418. ZoneServer* zone = 0;
  5419. Item* item = 0;
  5420. Quest* quest = 0;
  5421. string val;
  5422. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5423. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5424. // options window are also light user data be we do not handle those.
  5425. // We check with lua_islightuserdata(lua_State*, index)
  5426. if (lua_islightuserdata(state, 3)) {
  5427. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5428. // and convert it to LUAUserData*
  5429. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5430. // Check to make sure the data we got is valid, if not give an error
  5431. if (!data || !data->IsCorrectlyInitialized()) {
  5432. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5433. }
  5434. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5435. else if (data->IsSpawn()) {
  5436. spawnVal = data->spawn;
  5437. dataType = 1;
  5438. }
  5439. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5440. else if (data->IsZone()) {
  5441. zone = data->zone;
  5442. dataType = 2;
  5443. }
  5444. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5445. else if (data->IsItem()) {
  5446. item = data->item;
  5447. dataType = 3;
  5448. }
  5449. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5450. else if (data->IsQuest()) {
  5451. quest = data->quest;
  5452. dataType = 4;
  5453. }
  5454. }
  5455. // Wasn't light user data, check if it is nil(null)
  5456. else if (lua_isnil(state, 3)) {
  5457. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5458. dataType = 6;
  5459. }
  5460. // Wasn't light user data or nil (null), must be a string
  5461. else {
  5462. // Set the string and dataType variable
  5463. val = lua_interface->GetStringValue(state, 3);
  5464. dataType = 5;
  5465. }
  5466. lua_interface->ResetFunctionStack(state);
  5467. // We now have all the params, lets check to make sure they are valid
  5468. if (!spawn) {
  5469. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5470. return 0;
  5471. }
  5472. if (var.length() == 0) {
  5473. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5474. return 0;
  5475. }
  5476. if (dataType == 0) {
  5477. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5478. return 0;
  5479. }
  5480. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5481. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5482. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5483. switch (dataType) {
  5484. case 1:
  5485. // 1 = Spawn
  5486. spawn->AddTempVariable(var, spawnVal);
  5487. break;
  5488. case 2:
  5489. // 2 = Zone
  5490. spawn->AddTempVariable(var, zone);
  5491. break;
  5492. case 3:
  5493. // 3 = Item
  5494. spawn->AddTempVariable(var, item);
  5495. break;
  5496. case 4:
  5497. // 4 = Quest
  5498. spawn->AddTempVariable(var, quest);
  5499. break;
  5500. case 5:
  5501. // 5 = String
  5502. spawn->AddTempVariable(var, val);
  5503. break;
  5504. case 6:
  5505. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5506. spawn->DeleteTempVariable(var);
  5507. break;
  5508. }
  5509. // And we are done so return out
  5510. return 0;
  5511. }
  5512. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5513. if (!lua_interface)
  5514. return 0;
  5515. Spawn* spawn = lua_interface->GetSpawn(state);
  5516. string var = lua_interface->GetStringValue(state, 2);
  5517. lua_interface->ResetFunctionStack(state);
  5518. if (!spawn) {
  5519. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5520. return 0;
  5521. }
  5522. if (var.length() == 0) {
  5523. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5524. return 0;
  5525. }
  5526. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5527. int8 type = spawn->GetTempVariableType(var);
  5528. Spawn* spawn2 = 0;
  5529. ZoneServer* zone = 0;
  5530. Item* item = 0;
  5531. Quest* quest = 0;
  5532. // Set the lua function return value based on the type of data the variable contains
  5533. switch (type) {
  5534. case 1:
  5535. spawn2 = spawn->GetTempVariableSpawn(var);
  5536. if (!spawn2)
  5537. return 0;
  5538. lua_interface->SetSpawnValue(state, spawn2);
  5539. break;
  5540. case 2:
  5541. zone = spawn->GetTempVariableZone(var);
  5542. if (!zone)
  5543. return 0;
  5544. lua_interface->SetZoneValue(state, zone);
  5545. break;
  5546. case 3:
  5547. item = spawn->GetTempVariableItem(var);
  5548. if (!item)
  5549. return 0;
  5550. lua_interface->SetItemValue(state, item);
  5551. break;
  5552. case 4:
  5553. quest = spawn->GetTempVariableQuest(var);
  5554. if (!quest)
  5555. return 0;
  5556. lua_interface->SetQuestValue(state, quest);
  5557. break;
  5558. case 5:
  5559. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5560. break;
  5561. default:
  5562. // Not a valid type then the variable was not set so return out
  5563. return 0;
  5564. }
  5565. // Return value was set so return out
  5566. return 1;
  5567. }
  5568. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5569. {
  5570. if (!lua_interface)
  5571. return 0;
  5572. Quest* quest = lua_interface->GetQuest(state);
  5573. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5574. string description = lua_interface->GetStringValue(state, 3);
  5575. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5576. if (!quest) {
  5577. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5578. lua_interface->ResetFunctionStack(state);
  5579. lua_interface->SetBooleanValue(state, false);
  5580. return 1;
  5581. }
  5582. if (!spawn) {
  5583. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5584. lua_interface->ResetFunctionStack(state);
  5585. lua_interface->SetBooleanValue(state, false);
  5586. return 1;
  5587. }
  5588. if (!spawn->IsPlayer()) {
  5589. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5590. lua_interface->ResetFunctionStack(state);
  5591. lua_interface->SetBooleanValue(state, false);
  5592. return 1;
  5593. }
  5594. if (item_id == 0) {
  5595. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5596. lua_interface->ResetFunctionStack(state);
  5597. lua_interface->SetBooleanValue(state, false);
  5598. return 1;
  5599. }
  5600. Client* client = ((Player*)spawn)->GetClient();
  5601. if (!client) {
  5602. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given player spawn", lua_interface->GetScriptName(state));
  5603. lua_interface->ResetFunctionStack(state);
  5604. lua_interface->SetBooleanValue(state, false);
  5605. return 1;
  5606. }
  5607. Item* item = master_item_list.GetItem(item_id);
  5608. if (!item) {
  5609. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5610. lua_interface->ResetFunctionStack(state);
  5611. lua_interface->SetBooleanValue(state, false);
  5612. return 1;
  5613. }
  5614. Item* firstItem = new Item(item);
  5615. quest->AddTmpRewardItem(firstItem);
  5616. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5617. bool itemsAddedSuccessfully = true;
  5618. if(num_args > 4)
  5619. {
  5620. for(int8 n=5;n<num_args+1;n++)
  5621. {
  5622. int32 new_item = lua_interface->GetInt32Value(state, n);
  5623. Item* tmpItem = master_item_list.GetItem(new_item);
  5624. if(tmpItem)
  5625. {
  5626. Item* newTmpItem = new Item(tmpItem);
  5627. quest->AddTmpRewardItem(newTmpItem);
  5628. }
  5629. else
  5630. itemsAddedSuccessfully = false;
  5631. }
  5632. }
  5633. client->AddPendingQuestReward(quest, true, true, description); // queue for display
  5634. lua_interface->ResetFunctionStack(state);
  5635. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5636. return 1;
  5637. }
  5638. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5639. if (!lua_interface)
  5640. return 0;
  5641. Quest* quest = lua_interface->GetQuest(state);
  5642. lua_interface->ResetFunctionStack(state);
  5643. if (!quest) {
  5644. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5645. return 0;
  5646. }
  5647. quest->SetRepeatable(true);
  5648. return 0;
  5649. }
  5650. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5651. if (!lua_interface)
  5652. return 0;
  5653. Spawn* spawn = lua_interface->GetSpawn(state);
  5654. lua_interface->ResetFunctionStack(state);
  5655. if (!spawn) {
  5656. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5657. return 0;
  5658. }
  5659. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5660. string ret = classes.GetClassNameCase(base_class);
  5661. if (ret.length() > 0) {
  5662. lua_interface->SetStringValue(state, ret.c_str());
  5663. return 1;
  5664. }
  5665. return 0;
  5666. }
  5667. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5668. if (!lua_interface)
  5669. return 0;
  5670. Spawn* player = lua_interface->GetSpawn(state);
  5671. lua_interface->ResetFunctionStack(state);
  5672. if (player && player->IsPlayer()) {
  5673. Client* client = player->GetClient();
  5674. if (client)
  5675. client->SendWaypoints();
  5676. }
  5677. return 0;
  5678. }
  5679. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5680. if (!lua_interface)
  5681. return 0;
  5682. Spawn* player = lua_interface->GetSpawn(state);
  5683. string name = lua_interface->GetStringValue(state, 2);
  5684. int32 type = lua_interface->GetInt32Value(state, 3);
  5685. lua_interface->ResetFunctionStack(state);
  5686. if (type == 0)
  5687. type = 2;
  5688. if (name.length() > 0) {
  5689. if (player && player->IsPlayer()) {
  5690. Client* client = player->GetClient();
  5691. if (client)
  5692. client->AddWaypoint(name, type);
  5693. }
  5694. }
  5695. return 0;
  5696. }
  5697. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5698. if (!lua_interface)
  5699. return 0;
  5700. Spawn* player = lua_interface->GetSpawn(state);
  5701. string name = lua_interface->GetStringValue(state, 2);
  5702. lua_interface->ResetFunctionStack(state);
  5703. if (name.length() > 0) {
  5704. if (player && player->IsPlayer()) {
  5705. Client* client = player->GetClient();
  5706. if (client)
  5707. client->RemoveWaypoint(name);
  5708. }
  5709. }
  5710. return 0;
  5711. }
  5712. int EQ2Emu_lua_AddWard(lua_State* state) {
  5713. if (!lua_interface)
  5714. return 0;
  5715. int32 damage = lua_interface->GetInt32Value(state);
  5716. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5717. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5718. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5719. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5720. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5721. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5722. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5723. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5724. lua_interface->ResetFunctionStack(state);
  5725. if(!spell || spell->resisted) {
  5726. return 0;
  5727. }
  5728. bool ward_was_added = false;
  5729. ZoneServer* zone = spell->caster->GetZone();
  5730. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5731. for (int32 i = 0; i < spell->targets.size(); i++) {
  5732. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5733. if (!target)
  5734. continue;
  5735. if (target->IsEntity()) {
  5736. // If the ward is already active remove it
  5737. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5738. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5739. // Create new ward info
  5740. WardInfo* ward = new WardInfo;
  5741. ward->Spell = spell;
  5742. ward->BaseDamage = damage;
  5743. ward->DamageLeft = damage;
  5744. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5745. ward->keepWard = keepWard;
  5746. ward->WardType = wardType;
  5747. if (damageAbsorptionPercent > 100)
  5748. damageAbsorptionPercent = 100;
  5749. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5750. if (damageAbsorptionMaxHealthPercent > 100)
  5751. damageAbsorptionMaxHealthPercent = 100;
  5752. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5753. ward->RedirectDamagePercent = redirectDamagePercent;
  5754. ward->LastRedirectDamage = 0;
  5755. ward->LastAbsorbedDamage = 0;
  5756. ward->HitCount = 0;
  5757. spell->num_triggers = maxHitCount;
  5758. spell->had_triggers = true;
  5759. spell->cancel_after_all_triggers = false;
  5760. ward->MaxHitCount = maxHitCount;
  5761. ward->RoundTriggered = false;
  5762. if (wardType == WARD_TYPE_MAGICAL)
  5763. ward->DamageType = damageTypes;
  5764. // Add the ward to the entity
  5765. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5766. ward_was_added = true;
  5767. }
  5768. }
  5769. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5770. if (ward_was_added && spell->caster->IsPlayer()) {
  5771. spell->had_dmg_remaining = true;
  5772. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, damage, 1);
  5773. }
  5774. return 0;
  5775. }
  5776. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5777. if (!lua_interface)
  5778. return 0;
  5779. int32 amount = lua_interface->GetInt32Value(state);
  5780. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5781. lua_interface->ResetFunctionStack(state);
  5782. WardInfo* ward = 0;
  5783. if(!spell || spell->resisted) {
  5784. return 0;
  5785. }
  5786. ZoneServer* zone = spell->caster->GetZone();
  5787. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5788. if (spell->targets.size() > 0 && zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5789. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5790. ward = target->GetWard(spell->spell->GetSpellID());
  5791. if (target && ward) {
  5792. ward->DamageLeft += amount;
  5793. if (ward->DamageLeft > ward->BaseDamage)
  5794. ward->DamageLeft = ward->BaseDamage;
  5795. for (int32 i = 0; i < spell->targets.size(); i++) {
  5796. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5797. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5798. }
  5799. }
  5800. }
  5801. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5802. if (ward && spell->caster->IsPlayer())
  5803. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, ward->DamageLeft, 1);
  5804. return 0;
  5805. }
  5806. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5807. if (!lua_interface)
  5808. return 0;
  5809. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5810. lua_interface->ResetFunctionStack(state);
  5811. if (!spell) {
  5812. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5813. return 0;
  5814. }
  5815. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5816. if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5817. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5818. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5819. if (ward) {
  5820. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5821. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5822. return 1;
  5823. }
  5824. }
  5825. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5826. return 0;
  5827. }
  5828. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5829. if (!lua_interface)
  5830. return 0;
  5831. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5832. if (!spell) {
  5833. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5834. lua_interface->ResetFunctionStack(state);
  5835. return 0;
  5836. }
  5837. string type = lua_interface->GetStringValue(state, 2);
  5838. lua_interface->ResetFunctionStack(state);
  5839. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5840. if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5841. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5842. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5843. if (ward) {
  5844. if (boost::iequals(type, "damageleft"))
  5845. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5846. else if (boost::iequals(type, "basedamage"))
  5847. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5848. else if (boost::iequals(type, "keepward"))
  5849. lua_interface->SetBooleanValue(state, ward->keepWard);
  5850. else if (boost::iequals(type, "wardtype"))
  5851. lua_interface->SetInt32Value(state, ward->WardType);
  5852. else if (boost::iequals(type, "dmgabsorptionpct"))
  5853. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5854. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5855. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5856. else if (boost::iequals(type, "redirectdamagepercent"))
  5857. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5858. else if (boost::iequals(type, "lastredirectdamage"))
  5859. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5860. else if (boost::iequals(type, "lastabsorbeddamage"))
  5861. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5862. else if (boost::iequals(type, "hitcount"))
  5863. lua_interface->SetInt32Value(state, ward->HitCount);
  5864. else if (boost::iequals(type, "maxhitcount"))
  5865. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5866. else
  5867. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5868. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5869. return 1;
  5870. }
  5871. }
  5872. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5873. return 0;
  5874. }
  5875. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5876. if (!lua_interface)
  5877. return 0;
  5878. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5879. lua_interface->ResetFunctionStack(state);
  5880. if(!spell) {
  5881. return 0;
  5882. }
  5883. ZoneServer* zone = spell->caster->GetZone();
  5884. Spawn* target = 0;
  5885. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5886. for (int32 i = 0; i < spell->targets.size(); i++) {
  5887. target = zone->GetSpawnByID(spell->targets.at(i));
  5888. if (target && target->IsEntity()) {
  5889. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5890. }
  5891. }
  5892. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5893. return 0;
  5894. }
  5895. int EQ2Emu_lua_Interrupt(lua_State* state)
  5896. {
  5897. if (!lua_interface)
  5898. return 0;
  5899. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5900. Spawn* target = lua_interface->GetSpawn(state, 2);
  5901. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5902. lua_interface->ResetFunctionStack(state);
  5903. if (!caster)
  5904. {
  5905. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5906. return 0;
  5907. }
  5908. if (!target)
  5909. {
  5910. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5911. return 0;
  5912. }
  5913. if (!spell) {
  5914. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5915. return 0;
  5916. }
  5917. if (!target->IsEntity() && !spell)
  5918. {
  5919. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5920. return 0;
  5921. }
  5922. if (!target && spell) {
  5923. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5924. for (int8 i = 0; i < spell->targets.size(); i++) {
  5925. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5926. if (!target || !target->IsEntity())
  5927. continue;
  5928. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5929. }
  5930. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5931. }
  5932. else
  5933. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5934. return 0;
  5935. }
  5936. int EQ2Emu_lua_Stealth(lua_State* state) {
  5937. if (!lua_interface)
  5938. return 0;
  5939. int8 type = lua_interface->GetInt8Value(state);
  5940. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5941. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5942. lua_interface->ResetFunctionStack(state);
  5943. if (!spell) {
  5944. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5945. return 0;
  5946. }
  5947. ZoneServer* zone = spell->caster->GetZone();
  5948. if (spawn) {
  5949. if (spawn->IsEntity()) {
  5950. if (type == 1) {
  5951. ((Entity*)spawn)->AddStealthSpell(spell);
  5952. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5953. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5954. }
  5955. else if (type == 2) {
  5956. ((Entity*)spawn)->AddInvisSpell(spell);
  5957. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5958. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5959. }
  5960. return 0;
  5961. }
  5962. else {
  5963. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5964. return 0;
  5965. }
  5966. }
  5967. else {
  5968. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5969. for (int32 i = 0; i < spell->targets.size(); i++) {
  5970. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5971. if (!spawn || !spawn->IsEntity())
  5972. continue;
  5973. if (type == 1) {
  5974. ((Entity*)spawn)->AddStealthSpell(spell);
  5975. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5976. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5977. }
  5978. else if (type == 2) {
  5979. ((Entity*)spawn)->AddInvisSpell(spell);
  5980. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5981. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5982. }
  5983. else {
  5984. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5985. break;
  5986. }
  5987. }
  5988. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5989. }
  5990. return 0;
  5991. }
  5992. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5993. if (!lua_interface)
  5994. return 0;
  5995. Spawn* spawn = lua_interface->GetSpawn(state);
  5996. lua_interface->ResetFunctionStack(state);
  5997. if (!spawn) {
  5998. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5999. return 0;
  6000. }
  6001. if (spawn->IsEntity()) {
  6002. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  6003. return 1;
  6004. }
  6005. else
  6006. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  6007. return 0;
  6008. }
  6009. int EQ2Emu_lua_IsInvis(lua_State* state) {
  6010. if (!lua_interface)
  6011. return 0;
  6012. Spawn* spawn = lua_interface->GetSpawn(state);
  6013. lua_interface->ResetFunctionStack(state);
  6014. if (!spawn) {
  6015. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  6016. return 0;
  6017. }
  6018. if (spawn->IsEntity()) {
  6019. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  6020. return 1;
  6021. }
  6022. else
  6023. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  6024. return 0;
  6025. }
  6026. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  6027. if (!lua_interface)
  6028. return 0;
  6029. Spawn* player = lua_interface->GetSpawn(state);
  6030. int32 item_id = lua_interface->GetInt32Value(state, 2);
  6031. lua_interface->ResetFunctionStack(state);
  6032. if (!player->IsPlayer()) {
  6033. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  6034. return 0;
  6035. }
  6036. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  6037. return 1;
  6038. }
  6039. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  6040. if (!lua_interface)
  6041. return 0;
  6042. Spawn* spawn = lua_interface->GetSpawn(state);
  6043. int8 slot = lua_interface->GetInt8Value(state, 2);
  6044. lua_interface->ResetFunctionStack(state);
  6045. if (!spawn) {
  6046. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6047. return 0;
  6048. }
  6049. if (!spawn->IsEntity()) {
  6050. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6051. return 0;
  6052. }
  6053. Item* item = ((Entity*)spawn)->GetEquipmentList()->GetItem(slot);
  6054. if (!item) {
  6055. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  6056. return 0;
  6057. }
  6058. lua_interface->SetItemValue(state, item);
  6059. return 1;
  6060. }
  6061. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  6062. if (!lua_interface)
  6063. return 0;
  6064. Spawn* player = lua_interface->GetSpawn(state);
  6065. int32 id = lua_interface->GetInt32Value(state, 2);
  6066. lua_interface->ResetFunctionStack(state);
  6067. if (!player) {
  6068. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6069. return 0;
  6070. }
  6071. if (!player->IsPlayer()) {
  6072. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6073. return 0;
  6074. }
  6075. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  6076. if (!item) {
  6077. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  6078. return 0;
  6079. }
  6080. lua_interface->SetItemValue(state, item);
  6081. return 1;
  6082. }
  6083. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  6084. if (!lua_interface)
  6085. return 0;
  6086. Spawn* spawn = lua_interface->GetSpawn(state);
  6087. int8 slot = lua_interface->GetInt8Value(state, 2);
  6088. int32 item_id = lua_interface->GetInt32Value(state, 3);
  6089. lua_interface->ResetFunctionStack(state);
  6090. if (!spawn) {
  6091. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6092. return 0;
  6093. }
  6094. if (!spawn->IsEntity()) {
  6095. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6096. return 0;
  6097. }
  6098. Item* item = master_item_list.GetItem(item_id);
  6099. if (!item) {
  6100. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  6101. return 0;
  6102. }
  6103. Item* copy = new Item(item);
  6104. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  6105. if(result)
  6106. {
  6107. ((Entity*)spawn)->SetEquipment(copy, slot);
  6108. spawn->vis_changed = true;
  6109. if(spawn->IsPlayer())
  6110. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6111. }
  6112. else
  6113. {
  6114. safe_delete(copy);
  6115. }
  6116. lua_interface->SetBooleanValue(state, result);
  6117. return 1;
  6118. }
  6119. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  6120. if (!lua_interface)
  6121. return 0;
  6122. Spawn* spawn = lua_interface->GetSpawn(state);
  6123. int8 slot = lua_interface->GetInt8Value(state, 2);
  6124. Item* item = lua_interface->GetItem(state, 3);
  6125. lua_interface->ResetFunctionStack(state);
  6126. if (!spawn) {
  6127. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  6128. return 0;
  6129. }
  6130. if (!spawn->IsEntity()) {
  6131. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6132. return 0;
  6133. }
  6134. if (!item) {
  6135. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  6136. return 0;
  6137. }
  6138. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  6139. if(result)
  6140. {
  6141. ((Entity*)spawn)->SetEquipment(item, slot);
  6142. spawn->vis_changed = true;
  6143. if(spawn->IsPlayer())
  6144. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6145. }
  6146. lua_interface->SetBooleanValue(state, result);
  6147. return 1;
  6148. }
  6149. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  6150. if (!lua_interface)
  6151. return 0;
  6152. Spawn* spawn = lua_interface->GetSpawn(state);
  6153. int8 slot = lua_interface->GetInt8Value(state, 2);
  6154. bool no_delete_item = (lua_interface->GetBooleanValue(state, 3) == false); // if not set then we default to deleting it, otherwise if set to true we don't delete
  6155. lua_interface->ResetFunctionStack(state);
  6156. if (!spawn) {
  6157. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6158. return 0;
  6159. }
  6160. if (!spawn->IsEntity()) {
  6161. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6162. return 0;
  6163. }
  6164. if(slot >= NUM_SLOTS) {
  6165. lua_interface->LogError("%s: LUA UnequipSlot command error: wrong slot id given %u, max %u", lua_interface->GetScriptName(state), slot, NUM_SLOTS);
  6166. return 0;
  6167. }
  6168. if(spawn->IsPlayer() && ((Player*)spawn)->GetClient()) {
  6169. Item* item = ((Player*)spawn)->GetEquipmentList()->GetItem(slot);
  6170. if(item) {
  6171. item->save_needed = true;
  6172. if(no_delete_item) {
  6173. database.DeleteItem(((Player*)spawn)->GetClient()->GetCharacterID(), item, 0);
  6174. ((Player*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6175. }
  6176. else{
  6177. Client* client = ((Player*)spawn)->GetClient();
  6178. client->UnequipItem(item->details.index);
  6179. }
  6180. }
  6181. }
  6182. else
  6183. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6184. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  6185. spawn->vis_changed = true;
  6186. if(spawn->IsPlayer())
  6187. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6188. lua_interface->SetBooleanValue(state, true);
  6189. return 1;
  6190. }
  6191. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  6192. if (!lua_interface)
  6193. return 0;
  6194. Spawn* spawn = lua_interface->GetSpawn(state);
  6195. int8 slot = lua_interface->GetInt8Value(state, 2);
  6196. int16 type = lua_interface->GetInt16Value(state, 3);
  6197. int8 r = lua_interface->GetInt8Value(state, 4);
  6198. int8 g = lua_interface->GetInt8Value(state, 5);
  6199. int8 b = lua_interface->GetInt8Value(state, 6);
  6200. int8 h_r = lua_interface->GetInt8Value(state, 7);
  6201. int8 h_g = lua_interface->GetInt8Value(state, 8);
  6202. int8 h_b = lua_interface->GetInt8Value(state, 9);
  6203. lua_interface->ResetFunctionStack(state);
  6204. if (!spawn) {
  6205. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  6206. return 0;
  6207. }
  6208. if (!spawn->IsEntity()) {
  6209. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6210. return 0;
  6211. }
  6212. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  6213. spawn->vis_changed = true;
  6214. lua_interface->SetBooleanValue(state, true);
  6215. return 1;
  6216. }
  6217. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  6218. if (!lua_interface)
  6219. return 0;
  6220. Spawn* player = lua_interface->GetSpawn(state);
  6221. int32 id = lua_interface->GetInt32Value(state, 2);
  6222. int8 count = lua_interface->GetInt8Value(state, 3);
  6223. bool include_bank = lua_interface->GetInt8Value(state, 4);
  6224. lua_interface->ResetFunctionStack(state);
  6225. if (!player) {
  6226. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6227. return 0;
  6228. }
  6229. if (!player->IsPlayer()) {
  6230. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6231. return 0;
  6232. }
  6233. if (!count)
  6234. count = 1;
  6235. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  6236. if (!item) {
  6237. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  6238. return 0;
  6239. }
  6240. lua_interface->SetItemValue(state, item);
  6241. return 1;
  6242. }
  6243. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6244. if (!lua_interface)
  6245. return 0;
  6246. Spawn* spawn = lua_interface->GetSpawn(state);
  6247. int32 anim = lua_interface->GetInt32Value(state, 2);
  6248. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6249. int8 type = lua_interface->GetInt8Value(state, 4);
  6250. lua_interface->ResetFunctionStack(state);
  6251. if (!spawn) {
  6252. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6253. return 0;
  6254. }
  6255. if (spawn2) {
  6256. if (spawn2->IsPlayer()) {
  6257. if (type != 1 && type != 2)
  6258. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6259. else
  6260. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6261. return 0;
  6262. }
  6263. else {
  6264. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6265. return 0;
  6266. }
  6267. }
  6268. else
  6269. spawn->GetZone()->PlayAnimation(spawn, anim);
  6270. return 0;
  6271. }
  6272. int EQ2Emu_lua_IsPet(lua_State* state) {
  6273. if (!lua_interface)
  6274. return 0;
  6275. Spawn* spawn = lua_interface->GetSpawn(state);
  6276. lua_interface->ResetFunctionStack(state);
  6277. if (!spawn) {
  6278. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6279. return 0;
  6280. }
  6281. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6282. return 1;
  6283. }
  6284. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6285. if (!lua_interface)
  6286. return 0;
  6287. Spawn* spawn = lua_interface->GetSpawn(state);
  6288. lua_interface->ResetFunctionStack(state);
  6289. if (!spawn) {
  6290. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6291. return 0;
  6292. }
  6293. if (!spawn->IsNPC()) {
  6294. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6295. return 0;
  6296. }
  6297. if (((NPC*)spawn)->GetOwner()) {
  6298. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6299. return 1;
  6300. }
  6301. return 0;
  6302. }
  6303. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6304. if (!lua_interface)
  6305. return 0;
  6306. Spawn* spawn = lua_interface->GetSpawn(state);
  6307. Spawn* target = lua_interface->GetSpawn(state, 2);
  6308. lua_interface->ResetFunctionStack(state);
  6309. if (!spawn) {
  6310. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6311. return 0;
  6312. }
  6313. if (!spawn) {
  6314. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6315. return 0;
  6316. }
  6317. spawn->SetTarget(target);
  6318. return 0;
  6319. }
  6320. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6321. if (!lua_interface)
  6322. return 0;
  6323. Spawn* spawn = lua_interface->GetSpawn(state);
  6324. bool val = lua_interface->GetBooleanValue(state, 2);
  6325. lua_interface->ResetFunctionStack(state);
  6326. if (!spawn) {
  6327. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6328. return 0;
  6329. }
  6330. if (!spawn->IsEntity()) {
  6331. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6332. return 0;
  6333. }
  6334. ((Entity*)spawn)->InCombat(val);
  6335. if (val) {
  6336. spawn->ClearRunningLocations();
  6337. spawn->CalculateRunningLocation(true);
  6338. }
  6339. return 0;
  6340. }
  6341. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6342. if (!lua_interface)
  6343. return 0;
  6344. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6345. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6346. lua_interface->ResetFunctionStack(state);
  6347. if (!spawn1) {
  6348. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6349. return 0;
  6350. }
  6351. if (!spawn2) {
  6352. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6353. return 0;
  6354. }
  6355. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6356. return 1;
  6357. }
  6358. int EQ2Emu_lua_ClearRunback(lua_State* state){
  6359. if (!lua_interface)
  6360. return 0;
  6361. Spawn* spawn = lua_interface->GetSpawn(state);
  6362. lua_interface->ResetFunctionStack(state);
  6363. if (!spawn) {
  6364. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6365. return 0;
  6366. }
  6367. if (!spawn->IsNPC()) {
  6368. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6369. return 0;
  6370. }
  6371. ((NPC*)spawn)->ClearRunback();
  6372. return 0;
  6373. }
  6374. int EQ2Emu_lua_Runback(lua_State* state) {
  6375. if (!lua_interface)
  6376. return 0;
  6377. Spawn* spawn = lua_interface->GetSpawn(state);
  6378. lua_interface->ResetFunctionStack(state);
  6379. if (!spawn) {
  6380. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6381. return 0;
  6382. }
  6383. if (!spawn->IsNPC()) {
  6384. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6385. return 0;
  6386. }
  6387. ((NPC*)spawn)->Runback();
  6388. return 0;
  6389. }
  6390. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6391. if (!lua_interface)
  6392. return 0;
  6393. Spawn* spawn = lua_interface->GetSpawn(state);
  6394. lua_interface->ResetFunctionStack(state);
  6395. if (!spawn) {
  6396. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6397. return 0;
  6398. }
  6399. if (!spawn->IsNPC()) {
  6400. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6401. return 0;
  6402. }
  6403. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6404. return 1;
  6405. }
  6406. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6407. if (!lua_interface)
  6408. return 0;
  6409. Spawn* spawn = lua_interface->GetSpawn(state);
  6410. lua_interface->ResetFunctionStack(state);
  6411. if (!spawn) {
  6412. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6413. return 0;
  6414. }
  6415. if (!spawn->IsEntity()) {
  6416. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6417. return 0;
  6418. }
  6419. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6420. return 1;
  6421. }
  6422. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6423. if (!lua_interface)
  6424. return 0;
  6425. Spawn* spawn = lua_interface->GetSpawn(state);
  6426. lua_interface->ResetFunctionStack(state);
  6427. if (!spawn) {
  6428. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6429. return 0;
  6430. }
  6431. if (!spawn->IsEntity()) {
  6432. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6433. return 0;
  6434. }
  6435. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6436. return 1;
  6437. }
  6438. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6439. if (!lua_interface)
  6440. return 0;
  6441. Spawn* spawn = lua_interface->GetSpawn(state);
  6442. lua_interface->ResetFunctionStack(state);
  6443. if (!spawn) {
  6444. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6445. return 0;
  6446. }
  6447. if (!spawn->IsEntity()) {
  6448. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6449. return 0;
  6450. }
  6451. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6452. return 1;
  6453. }
  6454. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6455. if (!lua_interface)
  6456. return 0;
  6457. Spawn* spawn = lua_interface->GetSpawn(state);
  6458. lua_interface->ResetFunctionStack(state);
  6459. if (!spawn) {
  6460. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6461. return 0;
  6462. }
  6463. if (!spawn->IsEntity()) {
  6464. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6465. return 0;
  6466. }
  6467. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6468. return 1;
  6469. }
  6470. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6471. if (!lua_interface)
  6472. return 0;
  6473. Spawn* spawn = lua_interface->GetSpawn(state);
  6474. Spawn* target = lua_interface->GetSpawn(state, 2);
  6475. float distance = lua_interface->GetFloatValue(state, 3);
  6476. lua_interface->ResetFunctionStack(state);
  6477. if (!spawn) {
  6478. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6479. return 0;
  6480. }
  6481. if (!target) {
  6482. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6483. return 0;
  6484. }
  6485. if (!spawn->IsNPC()) {
  6486. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6487. return 0;
  6488. }
  6489. if (!target->IsEntity()) {
  6490. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6491. return 0;
  6492. }
  6493. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6494. return 1;
  6495. }
  6496. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6497. if (!lua_interface)
  6498. return 0;
  6499. Spawn* spawn = lua_interface->GetSpawn(state);
  6500. Spawn* target = lua_interface->GetSpawn(state, 2);
  6501. float distance = lua_interface->GetFloatValue(state, 3);
  6502. lua_interface->ResetFunctionStack(state);
  6503. if (!spawn) {
  6504. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6505. return 0;
  6506. }
  6507. if (!target) {
  6508. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6509. return 0;
  6510. }
  6511. if (!spawn->IsNPC()) {
  6512. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6513. return 0;
  6514. }
  6515. if (!target->IsEntity()) {
  6516. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6517. return 0;
  6518. }
  6519. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6520. return 0;
  6521. }
  6522. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6523. if (!lua_interface)
  6524. return 0;
  6525. Spawn* spawn = lua_interface->GetSpawn(state);
  6526. lua_interface->ResetFunctionStack(state);
  6527. if (!spawn) {
  6528. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6529. return 0;
  6530. }
  6531. if (!spawn->IsNPC()) {
  6532. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6533. return 0;
  6534. }
  6535. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6536. return 1;
  6537. }
  6538. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6539. if (!lua_interface)
  6540. return 0;
  6541. Spawn* spawn = lua_interface->GetSpawn(state);
  6542. lua_interface->ResetFunctionStack(state);
  6543. if (!spawn) {
  6544. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6545. return 0;
  6546. }
  6547. if (!spawn->IsNPC()) {
  6548. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6549. return 0;
  6550. }
  6551. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6552. return 1;
  6553. }
  6554. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6555. if (!lua_interface)
  6556. return 0;
  6557. Spawn* spawn = lua_interface->GetSpawn(state);
  6558. lua_interface->ResetFunctionStack(state);
  6559. if (!spawn) {
  6560. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6561. return 0;
  6562. }
  6563. if (!spawn->IsNPC()) {
  6564. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6565. return 0;
  6566. }
  6567. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6568. if (hated) {
  6569. lua_interface->SetSpawnValue(state, hated);
  6570. return 1;
  6571. }
  6572. return 0;
  6573. }
  6574. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6575. if (!lua_interface)
  6576. return 0;
  6577. Spawn* spawn = lua_interface->GetSpawn(state);
  6578. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6579. lua_interface->ResetFunctionStack(state);
  6580. if (!spawn) {
  6581. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6582. return 0;
  6583. }
  6584. if (!spawn->IsNPC()) {
  6585. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6586. return 0;
  6587. }
  6588. if (!hated) {
  6589. ((NPC*)spawn)->Brain()->ClearHate();
  6590. return 0;
  6591. }
  6592. else
  6593. {
  6594. if (!hated->IsEntity()) {
  6595. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6596. return 0;
  6597. }
  6598. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6599. return 0;
  6600. }
  6601. return 0;
  6602. }
  6603. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6604. if (!lua_interface)
  6605. return 0;
  6606. Spawn* spawn = lua_interface->GetSpawn(state);
  6607. lua_interface->ResetFunctionStack(state);
  6608. if (!spawn) {
  6609. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6610. return 0;
  6611. }
  6612. if (!spawn->IsNPC()) {
  6613. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6614. return 0;
  6615. }
  6616. ((NPC*)spawn)->Brain()->ClearEncounter();
  6617. return 0;
  6618. }
  6619. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6620. if (!lua_interface)
  6621. return 0;
  6622. Spawn* spawn = lua_interface->GetSpawn(state);
  6623. lua_interface->ResetFunctionStack(state);
  6624. if (!spawn) {
  6625. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6626. return 0;
  6627. }
  6628. if (!spawn->IsNPC()) {
  6629. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6630. return 0;
  6631. }
  6632. // Temp list to store hate list
  6633. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6634. if (encounterList->size() == 0) {
  6635. safe_delete(encounterList);
  6636. return 0;
  6637. }
  6638. lua_createtable(state, encounterList->size(), 0);
  6639. int newTable = lua_gettop(state);
  6640. for (int32 i = 0; i < encounterList->size(); i++) {
  6641. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6642. if (temp)
  6643. lua_interface->SetSpawnValue(state, temp);
  6644. lua_rawseti(state, newTable, i + 1);
  6645. }
  6646. safe_delete(encounterList);
  6647. return 1;
  6648. }
  6649. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6650. if (!lua_interface)
  6651. return 0;
  6652. Spawn* spawn = lua_interface->GetSpawn(state);
  6653. lua_interface->ResetFunctionStack(state);
  6654. if (!spawn) {
  6655. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6656. return 0;
  6657. }
  6658. if (!spawn->IsNPC()) {
  6659. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6660. return 0;
  6661. }
  6662. // Temp list to store hate list
  6663. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6664. if (hateList->size() == 0) {
  6665. safe_delete(hateList);
  6666. return 0;
  6667. }
  6668. lua_createtable(state, hateList->size(), 0);
  6669. int newTable = lua_gettop(state);
  6670. for (int32 i = 0; i < hateList->size(); i++) {
  6671. lua_interface->SetSpawnValue(state, hateList->at(i));
  6672. lua_rawseti(state, newTable, i + 1);
  6673. }
  6674. safe_delete(hateList);
  6675. return 1;
  6676. }
  6677. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6678. if (!lua_interface)
  6679. return 0;
  6680. Spawn* spawn = lua_interface->GetSpawn(state);
  6681. lua_interface->ResetFunctionStack(state);
  6682. if (!spawn) {
  6683. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6684. return 0;
  6685. }
  6686. if (spawn->IsPlayer()) {
  6687. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6688. lua_interface->SetBooleanValue(state, true);
  6689. else
  6690. lua_interface->SetBooleanValue(state, false);
  6691. return 1;
  6692. }
  6693. else {
  6694. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6695. return 1;
  6696. }
  6697. }
  6698. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6699. if (!lua_interface)
  6700. return 0;
  6701. Quest* quest = lua_interface->GetQuest(state);
  6702. lua_interface->ResetFunctionStack(state);
  6703. if (!quest) {
  6704. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6705. return 0;
  6706. }
  6707. quest->SetCompletedFlag(true);
  6708. return 0;
  6709. }
  6710. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6711. if (!lua_interface)
  6712. return 0;
  6713. Spawn* spawn = lua_interface->GetSpawn(state);
  6714. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6715. int8 tier = lua_interface->GetInt8Value(state, 3);
  6716. lua_interface->ResetFunctionStack(state);
  6717. if (!spawn) {
  6718. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6719. return 0;
  6720. }
  6721. if (!spawn->IsEntity()) {
  6722. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6723. return 0;
  6724. }
  6725. if (spellID == 0) {
  6726. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6727. return 0;
  6728. }
  6729. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6730. if (effect) {
  6731. if (tier > 0) {
  6732. // If a tier was passed chec to see if it is the same as the effect
  6733. if (tier == effect->tier)
  6734. lua_interface->SetBooleanValue(state, true);
  6735. else
  6736. lua_interface->SetBooleanValue(state, false);
  6737. return 1;
  6738. }
  6739. else {
  6740. // Have an effect but no tier was passed so return true
  6741. lua_interface->SetBooleanValue(state, true);
  6742. }
  6743. return 1;
  6744. }
  6745. // no effect so return false
  6746. lua_interface->SetBooleanValue(state, false);
  6747. return 1;
  6748. }
  6749. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6750. if (!lua_interface)
  6751. return 0;
  6752. Spawn* spawn = lua_interface->GetSpawn(state);
  6753. int32 id = lua_interface->GetInt32Value(state, 2);
  6754. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6755. lua_interface->ResetFunctionStack(state);
  6756. Spawn* spawn2 = 0;
  6757. vector<Spawn*> list;
  6758. if (!spawn) {
  6759. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6760. return 0;
  6761. }
  6762. //If zone not provided, use spawn's zone
  6763. if (!zone)
  6764. zone = spawn->GetZone();
  6765. list = zone->GetSpawnsByID(id);
  6766. if (list.size() == 0) {
  6767. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6768. return 0;
  6769. }
  6770. vector<Spawn*>::iterator itr = list.begin();
  6771. for (int8 i = 0; i < list.size(); i++) {
  6772. spawn2 = itr[i];
  6773. if (spawn2)
  6774. spawn2->AddAllowAccessSpawn(spawn);
  6775. }
  6776. return 0;
  6777. }
  6778. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6779. if (!lua_interface)
  6780. return 0;
  6781. Spawn* spawn = lua_interface->GetSpawn(state);
  6782. int32 id = lua_interface->GetInt32Value(state, 2);
  6783. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6784. lua_interface->ResetFunctionStack(state);
  6785. Spawn* spawn2 = 0;
  6786. if (!spawn) {
  6787. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6788. return 0;
  6789. }
  6790. //If zone not provided, use spawn's zone
  6791. if (!zone)
  6792. zone = spawn->GetZone();
  6793. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6794. vector<Spawn*>::iterator itr = list.begin();
  6795. if (list.size() == 0) {
  6796. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6797. return 0;
  6798. }
  6799. for (int8 i = 0; i < list.size(); i++) {
  6800. spawn2 = itr[i];
  6801. if (spawn2)
  6802. spawn2->RemoveSpawnAccess(spawn);
  6803. }
  6804. return 0;
  6805. }
  6806. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6807. if (!lua_interface)
  6808. return 0;
  6809. Quest* quest = lua_interface->GetQuest(state);
  6810. lua_interface->ResetFunctionStack(state);
  6811. if (!quest) {
  6812. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6813. return 0;
  6814. }
  6815. quest->SetYellowName(true);
  6816. return 0;
  6817. }
  6818. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6819. if (!lua_interface)
  6820. return 0;
  6821. Spawn* spawn = lua_interface->GetSpawn(state);
  6822. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6823. lua_interface->ResetFunctionStack(state);
  6824. if (!spawn) {
  6825. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6826. return 0;
  6827. }
  6828. if (!spawn->IsPlayer()) {
  6829. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6830. return 0;
  6831. }
  6832. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6833. return 1;
  6834. }
  6835. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6836. if (!lua_interface)
  6837. return 0;
  6838. Spawn* spawn = lua_interface->GetSpawn(state);
  6839. lua_interface->ResetFunctionStack(state);
  6840. if (!spawn) {
  6841. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6842. return 0;
  6843. }
  6844. if (!spawn->IsPlayer()) {
  6845. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6846. return 0;
  6847. }
  6848. ZoneServer* zone = spawn->GetZone();
  6849. if (!zone) {
  6850. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6851. return 0;
  6852. }
  6853. Instance_Type iType = zone->GetInstanceType();
  6854. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6855. iType == GROUP_LOCKOUT_INSTANCE ||
  6856. iType == RAID_LOCKOUT_INSTANCE ||
  6857. iType == SOLO_PERSIST_INSTANCE ||
  6858. iType == GROUP_PERSIST_INSTANCE ||
  6859. iType == RAID_PERSIST_INSTANCE) {
  6860. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6861. if (data) {
  6862. // Check to see if the timer has already been set, if it has return out.
  6863. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6864. return 0;
  6865. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6866. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6867. if(spawn->IsPlayer()) {
  6868. Client* client = ((Player*)spawn)->GetClient();
  6869. if (client) {
  6870. string time_msg = "";
  6871. int32 time = data->success_lockout_time;
  6872. int16 hour;
  6873. int8 min;
  6874. int8 sec;
  6875. hour = time / 3600;
  6876. time = time % 3600;
  6877. min = time / 60;
  6878. time = time % 60;
  6879. sec = time;
  6880. if (hour > 0) {
  6881. char temp[10];
  6882. sprintf(temp, " %i", hour);
  6883. time_msg.append(temp);
  6884. time_msg.append(" hour");
  6885. time_msg.append((hour > 1) ? "s" : "");
  6886. }
  6887. if (min > 0) {
  6888. char temp[5];
  6889. sprintf(temp, " %i", min);
  6890. time_msg.append(temp);
  6891. time_msg.append(" minute");
  6892. time_msg.append((min > 1) ? "s" : "");
  6893. }
  6894. // Only add seconds if minutes and hours are 0
  6895. if (hour == 0 && min == 0 && sec > 0) {
  6896. char temp[5];
  6897. sprintf(temp, " %i", sec);
  6898. time_msg.append(temp);
  6899. time_msg.append(" second");
  6900. time_msg.append((sec > 1) ? "s" : "");
  6901. }
  6902. client->Message(CHANNEL_COLOR_YELLOW, "The success zone reuse timer for %s has been set. You can return in%s.", data->zone_name.c_str(), time_msg.c_str());
  6903. }
  6904. else {
  6905. lua_interface->LogError("LUA SetSuccessTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6906. }
  6907. }
  6908. }
  6909. else
  6910. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6911. }
  6912. else
  6913. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6914. return 0;
  6915. }
  6916. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6917. if (!lua_interface)
  6918. return 0;
  6919. Spawn* spawn = lua_interface->GetSpawn(state);
  6920. lua_interface->ResetFunctionStack(state);
  6921. if (!spawn) {
  6922. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6923. return 0;
  6924. }
  6925. if (!spawn->IsPlayer()) {
  6926. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6927. return 0;
  6928. }
  6929. ZoneServer* zone = spawn->GetZone();
  6930. if (!zone) {
  6931. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6932. return 0;
  6933. }
  6934. Instance_Type iType = zone->GetInstanceType();
  6935. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6936. iType == GROUP_LOCKOUT_INSTANCE ||
  6937. iType == RAID_LOCKOUT_INSTANCE ||
  6938. iType == SOLO_PERSIST_INSTANCE ||
  6939. iType == GROUP_PERSIST_INSTANCE ||
  6940. iType == RAID_PERSIST_INSTANCE) {
  6941. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6942. if (data) {
  6943. // Check to see if the timer has already been set, if it has return out.
  6944. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6945. return 0;
  6946. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6947. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6948. if(spawn->IsPlayer()) {
  6949. Client* client = ((Player*)spawn)->GetClient();
  6950. if (client) {
  6951. string time_msg = "";
  6952. int32 time = data->failure_lockout_time;
  6953. int16 hour;
  6954. int8 min;
  6955. int8 sec;
  6956. hour = time / 3600;
  6957. time = time % 3600;
  6958. min = time / 60;
  6959. time = time % 60;
  6960. sec = time;
  6961. if (hour > 0) {
  6962. char temp[10];
  6963. sprintf(temp, " %i", hour);
  6964. time_msg.append(temp);
  6965. time_msg.append(" hour");
  6966. time_msg.append((hour > 1) ? "s" : "");
  6967. }
  6968. if (min > 0) {
  6969. char temp[5];
  6970. sprintf(temp, " %i", min);
  6971. time_msg.append(temp);
  6972. time_msg.append(" minute");
  6973. time_msg.append((min > 1) ? "s" : "");
  6974. }
  6975. // Only add seconds if minutes and hours are 0
  6976. if (hour == 0 && min == 0 && sec > 0) {
  6977. char temp[5];
  6978. sprintf(temp, " %i", sec);
  6979. time_msg.append(temp);
  6980. time_msg.append(" second");
  6981. time_msg.append((sec > 1) ? "s" : "");
  6982. }
  6983. client->Message(CHANNEL_COLOR_YELLOW, "The failure zone reuse timer for %s has been set. You can return in%s", data->zone_name.c_str(), time_msg.c_str());
  6984. }
  6985. }
  6986. else {
  6987. lua_interface->LogError("LUA SetFailureTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6988. }
  6989. }
  6990. else
  6991. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6992. }
  6993. else
  6994. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6995. return 0;
  6996. }
  6997. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6998. if (!lua_interface)
  6999. return 0;
  7000. Spawn* spawn = lua_interface->GetSpawn(state);
  7001. lua_interface->ResetFunctionStack(state);
  7002. if (!spawn) {
  7003. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  7004. return 0;
  7005. }
  7006. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  7007. return 1;
  7008. }
  7009. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  7010. if (!lua_interface)
  7011. return 0;
  7012. Spawn* player = lua_interface->GetSpawn(state);
  7013. Spawn* ground = lua_interface->GetSpawn(state, 2);
  7014. if (!player) {
  7015. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7016. lua_interface->ResetFunctionStack(state);
  7017. return 0;
  7018. }
  7019. if (!player->IsPlayer()) {
  7020. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  7021. lua_interface->ResetFunctionStack(state);
  7022. return 0;
  7023. }
  7024. if (!ground) {
  7025. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7026. lua_interface->ResetFunctionStack(state);
  7027. return 0;
  7028. }
  7029. if (!ground->IsGroundSpawn()) {
  7030. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  7031. lua_interface->ResetFunctionStack(state);
  7032. return 0;
  7033. }
  7034. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7035. if (!groundspawn_entries) {
  7036. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7037. lua_interface->ResetFunctionStack(state);
  7038. return 0;
  7039. }
  7040. Skill* skill = 0;
  7041. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  7042. if (collection_skill == "Collecting")
  7043. skill = ((Player*)player)->GetSkillByName("Gathering");
  7044. else
  7045. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  7046. if (!skill) {
  7047. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  7048. lua_interface->ResetFunctionStack(state);
  7049. return 0;
  7050. }
  7051. vector<GroundSpawnEntry*>::iterator itr;
  7052. GroundSpawnEntry* entry = 0;
  7053. bool can_harvest = false;
  7054. sint32 min_skill = -1;
  7055. int16 totalSkill = skill->current_val;
  7056. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  7057. if(skillID != 0xFFFFFFFF)
  7058. {
  7059. ((Entity*)player)->MStats.lock();
  7060. totalSkill += ((Entity*)player)->stats[skillID];
  7061. ((Entity*)player)->MStats.unlock();
  7062. }
  7063. // first, iterate through groundspawn_entries, discard tables player cannot use
  7064. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  7065. {
  7066. entry = *itr;
  7067. if (min_skill == -1 || entry->min_skill_level < min_skill)
  7068. min_skill = entry->min_skill_level;
  7069. // if player lacks skill, skip table
  7070. if (entry->min_skill_level > totalSkill)
  7071. continue;
  7072. // if bonus, but player lacks level, skip table
  7073. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  7074. continue;
  7075. can_harvest = true;
  7076. break;
  7077. }
  7078. lua_interface->SetBooleanValue(state, can_harvest);
  7079. // If false, send the message to the client
  7080. if (!can_harvest) {
  7081. Client* client = ((Player*)player)->GetClient();
  7082. if (client) {
  7083. string msg = "You do not have enough skill to ";
  7084. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  7085. msg.append("gather");
  7086. else if (collection_skill == "Mining")
  7087. msg.append("mine");
  7088. else if (collection_skill == "Trapping")
  7089. msg.append("trap");
  7090. else if (collection_skill == "Foresting")
  7091. msg.append("forest");
  7092. else if (collection_skill == "Fishing")
  7093. msg.append("catch");
  7094. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  7095. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  7096. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  7097. }
  7098. }
  7099. lua_interface->ResetFunctionStack(state);
  7100. return 1;
  7101. }
  7102. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  7103. if (!lua_interface)
  7104. return 0;
  7105. Spawn* player = lua_interface->GetSpawn(state);
  7106. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  7107. lua_interface->ResetFunctionStack(state);
  7108. if (!player) {
  7109. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  7110. return 0;
  7111. }
  7112. if (!player->IsPlayer()) {
  7113. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  7114. return 0;
  7115. }
  7116. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  7117. lua_interface->SetBooleanValue(state, ret);
  7118. return 1;
  7119. }
  7120. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  7121. // Check to see if we have a valid lua_interface
  7122. if (!lua_interface)
  7123. return 0;
  7124. // Get the spawn that is getting the pet
  7125. Spawn* spawn = lua_interface->GetSpawn(state);
  7126. Spawn* target = lua_interface->GetSpawn(state, 2);
  7127. // Get the DB ID of the pet
  7128. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  7129. float x = lua_interface->GetFloatValue(state, 4);
  7130. float y = lua_interface->GetFloatValue(state, 5);
  7131. float z = lua_interface->GetFloatValue(state, 6);
  7132. // Get the spell that this command was called from
  7133. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7134. lua_interface->ResetFunctionStack(state);
  7135. // Check to make sure the spawn pointer is valid
  7136. if (!spawn) {
  7137. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  7138. return 0;
  7139. }
  7140. // Check to make sure the spawn is an entity
  7141. if (!spawn->IsEntity()) {
  7142. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  7143. return 0;
  7144. }
  7145. if (!target) {
  7146. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  7147. return 0;
  7148. }
  7149. if (!target->IsEntity()) {
  7150. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  7151. return 0;
  7152. }
  7153. // Check to see if the DB ID for the pet is set
  7154. if (pet_id == 0) {
  7155. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  7156. return 0;
  7157. }
  7158. // Check to see if the pointer to the spell is valid
  7159. if (!luaspell) {
  7160. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  7161. return 0;
  7162. }
  7163. if(luaspell->resisted) {
  7164. return 0;
  7165. }
  7166. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  7167. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  7168. if (!pet) {
  7169. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  7170. return 0;
  7171. }
  7172. // Check to make sure the pet is an npc
  7173. if (!pet->IsNPC()) {
  7174. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  7175. return 0;
  7176. }
  7177. if (x == 0)
  7178. x = spawn->GetX();
  7179. if (y == 0)
  7180. y = spawn->GetY();
  7181. if (z == 0)
  7182. z = spawn->GetZ();
  7183. // Spawn the pet at the same location as the owner
  7184. pet->SetX(x);
  7185. pet->SetY(y);
  7186. pet->SetZ(z);
  7187. pet->SetLocation(spawn->GetLocation());
  7188. pet->SetHeading(spawn->GetHeading());
  7189. spawn->GetZone()->AddSpawn(pet);
  7190. const char* spawn_script = world.GetSpawnScript(pet_id);
  7191. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  7192. spawn->SetSpawnScript(string(spawn_script));
  7193. spawn->GetZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  7194. }
  7195. std::string petName = std::string("");
  7196. if(spawn->IsEntity()) {
  7197. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  7198. }
  7199. if(petName.size() < 1) {
  7200. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  7201. petName = spawn->GetZone()->pet_names.at(rand_index);
  7202. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  7203. }
  7204. // Set the pets name
  7205. pet->SetName(petName.c_str());
  7206. // Set the level of the pet to the owners level
  7207. pet->SetLevel(spawn->GetLevel());
  7208. // Set the faction of the pet to the same faction as the owner
  7209. pet->SetFactionID(spawn->GetFactionID());
  7210. // Set the spawn as a pet
  7211. pet->SetPet(true);
  7212. // Give a pointer of the owner to the pet
  7213. ((NPC*)pet)->SetOwner((Entity*)spawn);
  7214. // Set the pet type
  7215. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  7216. // Set the spell id used to create this pet
  7217. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  7218. // Set the spell tier used to create this pet
  7219. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  7220. // Set the pets spawn type to 6
  7221. pet->SetSpawnType(6);
  7222. // Set the pets brain
  7223. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  7224. // Check to see if the pet has a subtitle
  7225. if (strlen(pet->GetSubTitle()) > 0) {
  7226. // Add the players name to the front of the sub title
  7227. string pet_subtitle;
  7228. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  7229. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  7230. // Set the pets subtitle to the new one
  7231. pet->SetSubTitle(pet_subtitle.c_str());
  7232. }
  7233. // Set the pet as the return value for this function
  7234. lua_interface->SetSpawnValue(state, pet);
  7235. return 1;
  7236. }
  7237. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  7238. if (!lua_interface)
  7239. return 0;
  7240. Spawn* spawn = lua_interface->GetSpawn(state);
  7241. Spawn* player = lua_interface->GetSpawn(state, 2);
  7242. float max_distance = lua_interface->GetFloatValue(state, 3);
  7243. string type = lua_interface->GetStringValue(state, 4);
  7244. lua_interface->ResetFunctionStack(state);
  7245. if (!spawn || (spawn && spawn->IsPlayer())) {
  7246. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  7247. return 0;
  7248. }
  7249. if (!player || !player->IsPlayer()) {
  7250. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  7251. return 0;
  7252. }
  7253. Client* client = ((Player*)player)->GetClient();
  7254. if (!client) {
  7255. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  7256. return 0;
  7257. }
  7258. //Set max_distance to default if not set or not proper value
  7259. if (max_distance <= 0)
  7260. max_distance = 500;
  7261. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  7262. if (packet) {
  7263. float unknown2_3 = 0;
  7264. int8 placement_mode = 0;
  7265. if (type == "wall") {
  7266. placement_mode = 2;
  7267. unknown2_3 = 150;
  7268. }
  7269. else if (type == "ceiling")
  7270. placement_mode = 1;
  7271. packet->setDataByName("placement_mode", placement_mode);
  7272. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  7273. packet->setDataByName("model_type", spawn->GetModelType());
  7274. packet->setDataByName("unknown", 1); //size
  7275. packet->setDataByName("unknown2", 1); //size 2
  7276. packet->setDataByName("unknown2", .5, 1); //size 3
  7277. packet->setDataByName("unknown2", 3, 2);
  7278. packet->setDataByName("unknown2", unknown2_3, 3);
  7279. packet->setDataByName("max_distance", max_distance);
  7280. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  7281. client->QueuePacket(packet->serialize());
  7282. safe_delete(packet);
  7283. }
  7284. return 0;
  7285. }
  7286. int EQ2Emu_lua_GetItemType(lua_State* state) {
  7287. if (!lua_interface)
  7288. return 0;
  7289. Item* item = lua_interface->GetItem(state);
  7290. lua_interface->ResetFunctionStack(state);
  7291. if (!item) {
  7292. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7293. return 0;
  7294. }
  7295. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  7296. return 1;
  7297. }
  7298. int EQ2Emu_lua_GetItemEffectType(lua_State* state) {
  7299. if (!lua_interface)
  7300. return 0;
  7301. Item* item = lua_interface->GetItem(state);
  7302. lua_interface->ResetFunctionStack(state);
  7303. if (!item) {
  7304. lua_interface->LogError("%s: LUA GetItemEffectType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7305. return 0;
  7306. }
  7307. lua_interface->SetInt32Value(state, item->effect_type);
  7308. return 1;
  7309. }
  7310. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  7311. if (!lua_interface)
  7312. return 0;
  7313. Spawn* spawn = lua_interface->GetSpawn(state);
  7314. lua_interface->ResetFunctionStack(state);
  7315. if (!spawn) {
  7316. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7317. return 0;
  7318. }
  7319. if (spawn->GetZone())
  7320. spawn->GetZone()->AddTransportSpawn(spawn);
  7321. return 0;
  7322. }
  7323. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  7324. if (!lua_interface)
  7325. return 0;
  7326. Spawn* spawn = lua_interface->GetSpawn(state);
  7327. lua_interface->ResetFunctionStack(state);
  7328. if (!spawn) {
  7329. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7330. return 0;
  7331. }
  7332. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7333. return 1;
  7334. }
  7335. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7336. if (!lua_interface)
  7337. return 0;
  7338. Skill* skill = lua_interface->GetSkill(state);
  7339. lua_interface->ResetFunctionStack(state);
  7340. if (!skill) {
  7341. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7342. return 0;
  7343. }
  7344. lua_interface->SetInt32Value(state, skill->current_val);
  7345. return 1;
  7346. }
  7347. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7348. if (!lua_interface)
  7349. return 0;
  7350. Skill* skill = lua_interface->GetSkill(state);
  7351. lua_interface->ResetFunctionStack(state);
  7352. if (!skill) {
  7353. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7354. return 0;
  7355. }
  7356. lua_interface->SetInt32Value(state, skill->max_val);
  7357. return 1;
  7358. }
  7359. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7360. if (!lua_interface)
  7361. return 0;
  7362. Skill* skill = lua_interface->GetSkill(state);
  7363. lua_interface->ResetFunctionStack(state);
  7364. if (!skill) {
  7365. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7366. return 0;
  7367. }
  7368. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7369. return 1;
  7370. }
  7371. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7372. if (!lua_interface)
  7373. return 0;
  7374. Skill* skill = lua_interface->GetSkill(state);
  7375. int16 value = lua_interface->GetInt16Value(state, 2);
  7376. lua_interface->ResetFunctionStack(state);
  7377. if (!skill) {
  7378. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7379. return 0;
  7380. }
  7381. skill->max_val = value;
  7382. if (skill->max_val < skill->current_val)
  7383. skill->current_val = skill->max_val;
  7384. return 0;
  7385. }
  7386. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7387. if (!lua_interface)
  7388. return 0;
  7389. Skill* skill = lua_interface->GetSkill(state);
  7390. int16 value = lua_interface->GetInt16Value(state, 2);
  7391. lua_interface->ResetFunctionStack(state);
  7392. if (!skill) {
  7393. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7394. return 0;
  7395. }
  7396. if (value > skill->max_val)
  7397. skill->current_val = skill->max_val;
  7398. else
  7399. skill->current_val = value;
  7400. return 0;
  7401. }
  7402. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7403. if (!lua_interface)
  7404. return 0;
  7405. Spawn* player = lua_interface->GetSpawn(state);
  7406. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7407. lua_interface->ResetFunctionStack(state);
  7408. if (skill_id > 0 && player && player->IsPlayer()) {
  7409. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7410. return 1;
  7411. }
  7412. return 0;
  7413. }
  7414. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7415. if (!lua_interface)
  7416. return 0;
  7417. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7418. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7419. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7420. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7421. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7422. lua_interface->ResetFunctionStack(state);
  7423. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7424. if (player_spawn && player_spawn->IsPlayer()) {
  7425. Player* player = (Player*)player_spawn;
  7426. bool added = false;
  7427. if (!player->skill_list.HasSkill(skill_id)) {
  7428. player->AddSkill(skill_id, current_val, max_val, true);
  7429. added = true;
  7430. }
  7431. if (!more_to_add) { //need to send update regardless, even if THIS skill wasn't added, otherwise if you have a list and the last item wasn't added but the previous ones were, it wouldn't send the update
  7432. Client* client = player->GetClient();
  7433. if (client) {
  7434. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7435. if (packet)
  7436. client->QueuePacket(packet);
  7437. }
  7438. }
  7439. if (added) {
  7440. lua_interface->SetBooleanValue(state, true);
  7441. return 1;
  7442. }
  7443. }
  7444. else {
  7445. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7446. }
  7447. }
  7448. else {
  7449. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7450. }
  7451. lua_interface->SetBooleanValue(state, false);
  7452. return 1;
  7453. }
  7454. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7455. if (!lua_interface)
  7456. return 0;
  7457. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7458. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7459. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7460. lua_interface->ResetFunctionStack(state);
  7461. if (skill_id > 0) {
  7462. if (player_spawn && player_spawn->IsPlayer()) {
  7463. Player* player = (Player*)player_spawn;
  7464. if (player->skill_list.HasSkill(skill_id)) {
  7465. player->RemovePlayerSkill(skill_id, true);
  7466. if (!more_to_remove) {
  7467. Client* client = player->GetClient();
  7468. if (client) {
  7469. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7470. if (packet)
  7471. client->QueuePacket(packet);
  7472. }
  7473. }
  7474. }
  7475. }
  7476. else {
  7477. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7478. }
  7479. }
  7480. else {
  7481. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7482. }
  7483. return 0;
  7484. }
  7485. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7486. if (!lua_interface)
  7487. return 0;
  7488. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7489. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7490. int16 amount = lua_interface->GetInt8Value(state, 3);
  7491. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7492. lua_interface->ResetFunctionStack(state);
  7493. if (amount > 0 && skill_type < 100) {
  7494. if (player_spawn && player_spawn->IsPlayer()) {
  7495. Player* player = (Player*)player_spawn;
  7496. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7497. if (!more_to_increase) {
  7498. Client* client = player->GetClient();
  7499. if (client) {
  7500. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7501. if (packet)
  7502. client->QueuePacket(packet);
  7503. }
  7504. }
  7505. }
  7506. else {
  7507. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7508. }
  7509. }
  7510. else {
  7511. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7512. }
  7513. return 0;
  7514. }
  7515. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7516. if (!lua_interface)
  7517. return 0;
  7518. Spawn* spawn = lua_interface->GetSpawn(state);
  7519. string name = lua_interface->GetStringValue(state, 2);
  7520. lua_interface->ResetFunctionStack(state);
  7521. if (!spawn) {
  7522. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7523. return 0;
  7524. }
  7525. if (!spawn->IsEntity()) {
  7526. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7527. return 0;
  7528. }
  7529. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7530. if (skill) {
  7531. lua_interface->SetSkillValue(state, skill);
  7532. return 1;
  7533. }
  7534. return 0;
  7535. }
  7536. int EQ2Emu_lua_AddProc(lua_State* state) {
  7537. if (!lua_interface)
  7538. return 0;
  7539. Spawn* spawn = lua_interface->GetSpawn(state);
  7540. int8 type = lua_interface->GetInt8Value(state, 2);
  7541. float chance = lua_interface->GetFloatValue(state, 3);
  7542. Item* item = lua_interface->GetItem(state, 4);
  7543. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7544. LuaSpell* spell = 0;
  7545. if (!spawn && (!spell || !use_all_spelltargets)) {
  7546. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7547. return 0;
  7548. }
  7549. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7550. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7551. return 0;
  7552. }
  7553. if (!item)
  7554. spell = lua_interface->GetCurrentSpell(state);
  7555. if (!item && !spell) {
  7556. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7557. return 0;
  7558. }
  7559. if(spell && spell->resisted) {
  7560. return 0;
  7561. }
  7562. if (spell && spell->caster && spell->caster->GetZone() && use_all_spelltargets) {
  7563. Spawn* target;
  7564. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7565. for (int8 i = 0; i < spell->targets.size(); i++) {
  7566. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7567. if (!target || !target->IsEntity())
  7568. continue;
  7569. ((Entity*)target)->AddProc(type, chance, item, spell);
  7570. }
  7571. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7572. }
  7573. else
  7574. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7575. return 0;
  7576. }
  7577. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7578. if (!lua_interface)
  7579. return 0;
  7580. Spawn* spawn = lua_interface->GetSpawn(state);
  7581. Item* item = lua_interface->GetItem(state, 2);
  7582. LuaSpell* spell = 0;
  7583. if (!spawn) {
  7584. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7585. lua_interface->ResetFunctionStack(state);
  7586. return 0;
  7587. }
  7588. if (!spawn->IsEntity()) {
  7589. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7590. lua_interface->ResetFunctionStack(state);
  7591. return 0;
  7592. }
  7593. if (!item)
  7594. spell = lua_interface->GetCurrentSpell(state);
  7595. lua_interface->ResetFunctionStack(state);
  7596. if (!item && !spell) {
  7597. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7598. return 0;
  7599. }
  7600. if (spell && spell->caster && spell->caster->GetZone()) {
  7601. Spawn* target;
  7602. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7603. for (int8 i = 0; i < spell->targets.size(); i++) {
  7604. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7605. if (!target || !target->IsEntity())
  7606. continue;
  7607. ((Entity*)target)->RemoveProc(item, spell);
  7608. }
  7609. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7610. spell->caster->RemoveProc(item, spell);
  7611. }
  7612. else
  7613. ((Entity*)spawn)->RemoveProc(item, spell);
  7614. return 0;
  7615. }
  7616. int EQ2Emu_lua_Knockback(lua_State* state) {
  7617. if (!lua_interface)
  7618. return 0;
  7619. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7620. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7621. int32 duration = lua_interface->GetInt32Value(state, 3);
  7622. float vertical = lua_interface->GetFloatValue(state, 4);
  7623. float horizontal = lua_interface->GetFloatValue(state, 5);
  7624. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7625. lua_interface->ResetFunctionStack(state);
  7626. if (!target_spawn) {
  7627. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7628. return 0;
  7629. }
  7630. if (!spawn) {
  7631. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7632. return 0;
  7633. }
  7634. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7635. Client* client = ((Player*)spawn)->GetClient();
  7636. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7637. if (packet) {
  7638. packet->setDataByName("target_x", target_spawn->GetX());
  7639. packet->setDataByName("target_y", target_spawn->GetY());
  7640. packet->setDataByName("target_z", target_spawn->GetZ());
  7641. packet->setDataByName("vertical_movement", vertical);
  7642. packet->setDataByName("horizontal_movement", horizontal);
  7643. if (use_heading)
  7644. packet->setDataByName("use_player_heading", 1);
  7645. client->QueuePacket(packet->serialize());
  7646. }
  7647. safe_delete(packet);
  7648. }
  7649. return 0;
  7650. }
  7651. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7652. if (!lua_interface)
  7653. return 0;
  7654. Spawn* spawn = lua_interface->GetSpawn(state);
  7655. lua_interface->ResetFunctionStack(state);
  7656. if (!spawn) {
  7657. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7658. return 0;
  7659. }
  7660. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7661. return 1;
  7662. }
  7663. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7664. if (!lua_interface)
  7665. return 0;
  7666. Spawn* caster = lua_interface->GetSpawn(state);
  7667. Spawn* target = lua_interface->GetSpawn(state, 2);
  7668. string name = lua_interface->GetStringValue(state, 3);
  7669. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7670. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7671. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7672. string success_msg = lua_interface->GetStringValue(state, 7);
  7673. string effect_msg = lua_interface->GetStringValue(state, 8);
  7674. lua_interface->ResetFunctionStack(state);
  7675. if (!caster) {
  7676. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7677. return 0;
  7678. }
  7679. if (!caster->IsEntity()) {
  7680. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7681. return 0;
  7682. }
  7683. if (!target) {
  7684. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7685. return 0;
  7686. }
  7687. if (!target->IsEntity()) {
  7688. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7689. return 0;
  7690. }
  7691. if (name.length() == 0) {
  7692. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7693. return 0;
  7694. }
  7695. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7696. return 0;
  7697. }
  7698. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7699. if (!lua_interface)
  7700. return 0;
  7701. string name = lua_interface->GetStringValue(state);
  7702. lua_interface->ResetFunctionStack(state);
  7703. if (name.length() == 0) {
  7704. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7705. return 0;
  7706. }
  7707. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7708. if (!skill) {
  7709. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7710. return 0;
  7711. }
  7712. lua_interface->SetInt32Value(state, skill->skill_id);
  7713. return 1;
  7714. }
  7715. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7716. if (!lua_interface)
  7717. return 0;
  7718. Spawn* spawn = lua_interface->GetSpawn(state);
  7719. lua_interface->ResetFunctionStack(state);
  7720. if (!spawn) {
  7721. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7722. return 0;
  7723. }
  7724. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7725. return 1;
  7726. }
  7727. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7728. if (!lua_interface)
  7729. return 0;
  7730. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7731. lua_interface->ResetFunctionStack(state);
  7732. if (!luaspell) {
  7733. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7734. return 0;
  7735. }
  7736. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7737. return 1;
  7738. }
  7739. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7740. if (!lua_interface)
  7741. return 0;
  7742. Spawn* spawn = lua_interface->GetSpawn(state);
  7743. Spawn* target = lua_interface->GetSpawn(state, 2);
  7744. lua_interface->ResetFunctionStack(state);
  7745. if (!spawn) {
  7746. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7747. return 0;
  7748. }
  7749. if (!spawn->IsEntity()) {
  7750. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7751. return 0;
  7752. }
  7753. if (!target) {
  7754. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7755. return 0;
  7756. }
  7757. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7758. return 1;
  7759. }
  7760. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7761. if (!lua_interface)
  7762. return 0;
  7763. Spawn* spawn = lua_interface->GetSpawn(state);
  7764. Spawn* target = lua_interface->GetSpawn(state, 2);
  7765. lua_interface->ResetFunctionStack(state);
  7766. if (!spawn) {
  7767. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7768. return 0;
  7769. }
  7770. if (!spawn->IsEntity()) {
  7771. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7772. return 0;
  7773. }
  7774. if (!target) {
  7775. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7776. return 0;
  7777. }
  7778. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7779. return 1;
  7780. }
  7781. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7782. if (!lua_interface)
  7783. return 0;
  7784. Item* item = lua_interface->GetItem(state);
  7785. lua_interface->ResetFunctionStack(state);
  7786. if (!item) {
  7787. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7788. return 0;
  7789. }
  7790. lua_interface->SetInt32Value(state, item->details.count);
  7791. return 1;
  7792. }
  7793. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7794. if (!lua_interface)
  7795. return 0;
  7796. Item* item = lua_interface->GetItem(state);
  7797. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7798. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7799. lua_interface->ResetFunctionStack(state);
  7800. if (!item) {
  7801. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7802. return 0;
  7803. }
  7804. if (!owner) {
  7805. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7806. return 0;
  7807. }
  7808. if (!owner->IsPlayer()) {
  7809. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7810. return 0;
  7811. }
  7812. if (item->stack_count < new_count) {
  7813. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7814. return 0;
  7815. }
  7816. if (new_count > 0) {
  7817. item->details.count = new_count;
  7818. item->save_needed = true;
  7819. }
  7820. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7821. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7822. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7823. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7824. else
  7825. {
  7826. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7827. return 0;
  7828. }
  7829. Client* client = ((Player*)owner)->GetClient();
  7830. if (!client)
  7831. return 0;
  7832. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7833. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7834. if (app)
  7835. client->QueuePacket(app);
  7836. return 0;
  7837. }
  7838. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7839. if (!lua_interface)
  7840. return 0;
  7841. int32 time = lua_interface->GetInt32Value(state);
  7842. string function = lua_interface->GetStringValue(state, 2);
  7843. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7844. Spawn* target = lua_interface->GetSpawn(state, 4);
  7845. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7846. lua_interface->ResetFunctionStack(state);
  7847. if (time == 0) {
  7848. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7849. return 0;
  7850. }
  7851. if (function.length() == 0) {
  7852. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7853. return 0;
  7854. }
  7855. if (!spell || (!spell->caster || !spell->caster->GetZone())) {
  7856. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7857. return 0;
  7858. }
  7859. SpellScriptTimer* timer = new SpellScriptTimer;
  7860. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7861. #ifdef WIN32
  7862. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7863. #else
  7864. bzero(timer, sizeof(SpellScriptTimer));
  7865. #endif*/
  7866. timer->caster = 0;
  7867. timer->deleteWhenDone = false;
  7868. timer->target = 0;
  7869. timer->time = Timer::GetCurrentTime2() + time;
  7870. timer->customFunction = function;
  7871. timer->spell = spell;
  7872. if (caster)
  7873. timer->caster = caster->GetID();
  7874. if (target)
  7875. timer->target = target->GetID();
  7876. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7877. return 0;
  7878. }
  7879. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7880. if (!lua_interface)
  7881. return 0;
  7882. float hp_perc = lua_interface->GetFloatValue(state);
  7883. float power_perc = lua_interface->GetFloatValue(state, 2);
  7884. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7885. Spawn* target = lua_interface->GetSpawn(state, 4);
  7886. string heal_name = lua_interface->GetStringValue(state, 5);
  7887. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7888. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7889. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7890. lua_interface->ResetFunctionStack(state);
  7891. if (!spell) {
  7892. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7893. return 0;
  7894. }
  7895. Entity* caster = spell->caster;
  7896. if (!caster) {
  7897. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7898. return 0;
  7899. }
  7900. Client* client = 0;
  7901. PendingResurrection* rez = 0;
  7902. ZoneServer* zone = spell->caster->GetZone();
  7903. if (!target) {
  7904. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7905. if (spell->targets.size() > 0) {
  7906. vector<int32> spell_targets = spell->targets;
  7907. for (int8 i = 0; i < spell_targets.size(); i++) {
  7908. target = zone->GetSpawnByID(spell_targets.at(i));
  7909. if (!target)
  7910. continue;
  7911. if (!target->IsPlayer())
  7912. continue;
  7913. client = ((Player*)target)->GetClient();
  7914. if (!client)
  7915. continue;
  7916. rez = client->GetCurrentRez();
  7917. if (rez->active)
  7918. continue;
  7919. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7920. rez->active = true;
  7921. rez->caster = caster;
  7922. rez->expire_timer = new Timer;
  7923. int32 duration = spell->spell->GetSpellDuration();
  7924. rez->expire_timer->Start(duration * 100);
  7925. rez->hp_perc = hp_perc;
  7926. rez->mp_perc = power_perc;
  7927. rez->range = spell->spell->GetSpellData()->range;
  7928. rez->spell_name = spell->spell->GetName();
  7929. if (heal_name.length() > 0)
  7930. rez->heal_name = heal_name;
  7931. else
  7932. rez->heal_name = rez->spell_name;
  7933. rez->no_calcs = no_calcs;
  7934. rez->crit_mod = crit_mod;
  7935. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7936. if (send_window)
  7937. client->SendResurrectionWindow();
  7938. else {
  7939. target->GetZone()->ResurrectSpawn(target, client);
  7940. rez->should_delete = true;
  7941. }
  7942. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7943. }
  7944. }
  7945. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7946. }
  7947. else {
  7948. if(!target->IsPlayer())
  7949. return 0;
  7950. client = ((Player*)target)->GetClient();
  7951. if (!client)
  7952. return 0;
  7953. rez = client->GetCurrentRez();
  7954. if (rez->active)
  7955. return 0;
  7956. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7957. rez->active = true;
  7958. rez->caster = caster;
  7959. rez->expire_timer = new Timer;
  7960. int32 duration = spell->spell->GetSpellDuration();
  7961. rez->expire_timer->Start(duration * 100);
  7962. rez->hp_perc = hp_perc;
  7963. rez->mp_perc = power_perc;
  7964. rez->range = spell->spell->GetSpellData()->range;
  7965. rez->spell_name = spell->spell->GetName();
  7966. if (heal_name.length() > 0)
  7967. rez->heal_name = heal_name;
  7968. else
  7969. rez->heal_name = rez->spell_name;
  7970. rez->no_calcs = no_calcs;
  7971. rez->crit_mod = crit_mod;
  7972. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7973. if (send_window)
  7974. client->SendResurrectionWindow();
  7975. else {
  7976. target->GetZone()->ResurrectSpawn(target, client);
  7977. rez->should_delete = true;
  7978. }
  7979. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7980. }
  7981. return 0;
  7982. }
  7983. int EQ2Emu_lua_SetVision(lua_State* state) {
  7984. if (!lua_interface)
  7985. return 0;
  7986. Spawn* spawn = lua_interface->GetSpawn(state);
  7987. int32 vision = lua_interface->GetInt32Value(state, 2);
  7988. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7989. lua_interface->ResetFunctionStack(state);
  7990. if (!spawn) {
  7991. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7992. return 0;
  7993. }
  7994. if (!spawn->IsEntity()) {
  7995. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7996. return 0;
  7997. }
  7998. if (spell && spell->targets.size() > 0) {
  7999. ZoneServer* zone = spell->caster->GetZone();
  8000. for (int8 i = 0; i < spell->targets.size(); i++) {
  8001. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8002. if (target && target->IsEntity()) {
  8003. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  8004. if (target->IsPlayer())
  8005. ((Player*)target)->SetCharSheetChanged(true);
  8006. }
  8007. }
  8008. }
  8009. else {
  8010. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  8011. if (spawn->IsPlayer())
  8012. ((Player*)spawn)->SetCharSheetChanged(true);
  8013. }
  8014. return 0;
  8015. }
  8016. int EQ2Emu_lua_BlurVision(lua_State* state) {
  8017. if (!lua_interface)
  8018. return 0;
  8019. Spawn* spawn = lua_interface->GetSpawn(state);
  8020. float intensity = lua_interface->GetFloatValue(state, 2);
  8021. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8022. lua_interface->ResetFunctionStack(state);
  8023. if (!spawn) {
  8024. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8025. return 0;
  8026. }
  8027. if (!spawn->IsEntity()) {
  8028. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8029. return 0;
  8030. }
  8031. if (spell && spell->targets.size() > 0) {
  8032. ZoneServer* zone = spell->caster->GetZone();
  8033. for (int8 i = 0; i < spell->targets.size(); i++) {
  8034. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8035. if (target && target->IsEntity()) {
  8036. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  8037. if (target->IsPlayer())
  8038. ((Player*)target)->SetCharSheetChanged(true);
  8039. }
  8040. }
  8041. }
  8042. else {
  8043. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  8044. if (spawn->IsPlayer())
  8045. ((Player*)spawn)->SetCharSheetChanged(true);
  8046. }
  8047. return 0;
  8048. }
  8049. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  8050. if (!lua_interface)
  8051. return 0;
  8052. Spawn* spawn = lua_interface->GetSpawn(state);
  8053. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  8054. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8055. lua_interface->ResetFunctionStack(state);
  8056. if (!spawn) {
  8057. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  8058. return 0;
  8059. }
  8060. if (!spawn->IsEntity()) {
  8061. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  8062. return 0;
  8063. }
  8064. if (spell && spell->targets.size() > 0) {
  8065. ZoneServer* zone = spell->caster->GetZone();
  8066. for (int8 i = 0; i < spell->targets.size(); i++) {
  8067. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8068. if (target && target->IsEntity()) {
  8069. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8070. if (target->IsPlayer())
  8071. ((Player*)target)->SetCharSheetChanged(true);
  8072. }
  8073. }
  8074. }
  8075. else {
  8076. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8077. if (spawn->IsPlayer())
  8078. ((Player*)spawn)->SetCharSheetChanged(true);
  8079. }
  8080. return 0;
  8081. }
  8082. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  8083. if (!lua_interface)
  8084. return 0;
  8085. Item* item = lua_interface->GetItem(state);
  8086. int8 type = lua_interface->GetInt32Value(state, 2);
  8087. lua_interface->ResetFunctionStack(state);
  8088. if (!item) {
  8089. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  8090. return 0;
  8091. }
  8092. if (type == 1)
  8093. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  8094. else if (type == 2)
  8095. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  8096. return 1;
  8097. }
  8098. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  8099. if (!lua_interface)
  8100. return 0;
  8101. Spawn* target = lua_interface->GetSpawn(state);
  8102. float val = lua_interface->GetFloatValue(state, 2);
  8103. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8104. lua_interface->ResetFunctionStack(state);
  8105. // Added from Gangrenous post
  8106. if (spell && spell->resisted)
  8107. return 0;
  8108. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  8109. if (val > 1.0f)
  8110. val = 1.0f - (val / 100.0f);
  8111. if (spell && spell->spell && spell->targets.size() > 0) {
  8112. ZoneServer* zone = spell->caster->GetZone();
  8113. for (int32 i = 0; i != spell->targets.size(); i++) {
  8114. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  8115. if (spawn && spawn->IsEntity()) {
  8116. ((Entity*)spawn)->SetSpeedMultiplier(val);
  8117. if (spawn->IsPlayer())
  8118. ((Player*)spawn)->SetCharSheetChanged(true);
  8119. }
  8120. }
  8121. }
  8122. else {
  8123. if (target && target->IsEntity()) {
  8124. ((Entity*)target)->SetSpeedMultiplier(val);
  8125. if (target->IsPlayer())
  8126. ((Player*)target)->SetCharSheetChanged(true);
  8127. }
  8128. }
  8129. return 0;
  8130. }
  8131. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  8132. if (!lua_interface)
  8133. return 0;
  8134. Spawn* spawn = lua_interface->GetSpawn(state);
  8135. int16 model = lua_interface->GetInt16Value(state, 2);
  8136. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8137. lua_interface->ResetFunctionStack(state);
  8138. if (spell && spell->spell && spell->targets.size() > 0) {
  8139. ZoneServer* zone = spell->caster->GetZone();
  8140. for (int32 i = 0; i < spell->targets.size(); i++) {
  8141. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8142. if (target)
  8143. target->SetIllusionModel(model);
  8144. }
  8145. }
  8146. else {
  8147. if (!spawn) {
  8148. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8149. return 0;
  8150. }
  8151. spawn->SetIllusionModel(model);
  8152. }
  8153. return 0;
  8154. }
  8155. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  8156. if (!lua_interface)
  8157. return 0;
  8158. Spawn* spawn = lua_interface->GetSpawn(state);
  8159. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8160. lua_interface->ResetFunctionStack(state);
  8161. if (spell && spell->spell && spell->targets.size() > 0) {
  8162. ZoneServer* zone = spell->caster->GetZone();
  8163. for (int32 i = 0; i < spell->targets.size(); i++) {
  8164. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8165. if (target)
  8166. target->SetIllusionModel(0);
  8167. }
  8168. }
  8169. else {
  8170. if (!spawn) {
  8171. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8172. return 0;
  8173. }
  8174. spawn->SetIllusionModel(0);
  8175. }
  8176. return 0;
  8177. }
  8178. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  8179. if (!lua_interface)
  8180. return 0;
  8181. Spawn* caster = lua_interface->GetSpawn(state);
  8182. Spawn* target = lua_interface->GetSpawn(state, 2);
  8183. float chance = lua_interface->GetFloatValue(state, 3);
  8184. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8185. lua_interface->ResetFunctionStack(state);
  8186. if (!caster) {
  8187. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8188. return 0;
  8189. }
  8190. if (!caster->IsEntity()) {
  8191. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  8192. return 0;
  8193. }
  8194. if (!target) {
  8195. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8196. return 0;
  8197. }
  8198. if (!target->IsEntity()) {
  8199. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  8200. return 0;
  8201. }
  8202. if (chance <= 0) {
  8203. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  8204. return 0;
  8205. }
  8206. if (!spell) {
  8207. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8208. return 0;
  8209. }
  8210. if(spell->resisted) {
  8211. return 0;
  8212. }
  8213. if (((Entity*)caster)->GetThreatTransfer()) {
  8214. return 0;
  8215. }
  8216. ThreatTransfer* transfer = new ThreatTransfer;
  8217. transfer->Target = target->GetID();
  8218. transfer->Amount = chance;
  8219. transfer->Spell = spell;
  8220. ((Entity*)caster)->SetThreatTransfer(transfer);
  8221. return 0;
  8222. }
  8223. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  8224. if (!lua_interface)
  8225. return 0;
  8226. Spawn* spawn = lua_interface->GetSpawn(state);
  8227. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8228. lua_interface->ResetFunctionStack(state);
  8229. if (!spawn) {
  8230. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  8231. return 0;
  8232. }
  8233. if (!spell) {
  8234. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8235. return 0;
  8236. }
  8237. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  8238. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  8239. if(transfer && transfer->Spell != spell) {
  8240. lua_interface->LogError("%s: LUA RemoveThreatTransfer called, but there was a different spell set for the threat transfer.", lua_interface->GetScriptName(state));
  8241. return 0;
  8242. }
  8243. ((Entity*)spawn)->SetThreatTransfer(nullptr);
  8244. }
  8245. return 0;
  8246. }
  8247. int EQ2Emu_lua_CureByType(lua_State* state) {
  8248. if (!lua_interface)
  8249. return 0;
  8250. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8251. int8 cure_count = lua_interface->GetInt8Value(state);
  8252. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8253. string cure_name = lua_interface->GetStringValue(state, 3);
  8254. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8255. Spawn* target = lua_interface->GetSpawn(state, 5);
  8256. Spawn* caster = lua_interface->GetSpawn(state, 6); // optional
  8257. lua_interface->ResetFunctionStack(state);
  8258. if(spell && spell->resisted) {
  8259. return 0;
  8260. }
  8261. if (target) {
  8262. if (!target->IsEntity()) {
  8263. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8264. return 0;
  8265. }
  8266. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8267. std::string alternate_name = "item";
  8268. if(spell)
  8269. alternate_name = std::string(spell->spell->GetName());
  8270. if(!caster && spell)
  8271. caster = (Spawn*)spell->caster;
  8272. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : alternate_name, (Entity*)caster, cure_level);
  8273. }
  8274. }
  8275. else {
  8276. ZoneServer* zone = spell->caster->GetZone();
  8277. vector<int32> targets = spell->targets;
  8278. vector<Entity*> targets_to_cure;
  8279. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8280. for (int8 i = 0; i < targets.size(); i++) {
  8281. target = zone->GetSpawnByID(targets.at(i));
  8282. if (!target || !target->IsEntity())
  8283. continue;
  8284. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8285. targets_to_cure.push_back((Entity*)target);
  8286. }
  8287. }
  8288. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8289. vector<Entity*>::iterator itr;
  8290. for(itr = targets_to_cure.begin(); itr != targets_to_cure.end(); itr++) {
  8291. ((Entity*)*itr)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8292. }
  8293. }
  8294. return 0;
  8295. }
  8296. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  8297. if (!lua_interface)
  8298. return 0;
  8299. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8300. if (!spell) {
  8301. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8302. lua_interface->ResetFunctionStack(state);
  8303. return 0;
  8304. }
  8305. if(spell->resisted) {
  8306. lua_interface->ResetFunctionStack(state);
  8307. return 0;
  8308. }
  8309. int8 cure_count = lua_interface->GetInt8Value(state);
  8310. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8311. string cure_name = lua_interface->GetStringValue(state, 3);
  8312. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8313. Spawn* target = lua_interface->GetSpawn(state, 5);
  8314. lua_interface->ResetFunctionStack(state);
  8315. if (target) {
  8316. if (!target->IsEntity()) {
  8317. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8318. return 0;
  8319. }
  8320. if (((Entity*)target)->GetDetCount() > 0)
  8321. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8322. }
  8323. else {
  8324. ZoneServer* zone = spell->caster->GetZone();
  8325. vector<int32> targets = spell->targets;
  8326. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8327. for (int8 i = 0; i < targets.size(); i++) {
  8328. target = zone->GetSpawnByID(targets.at(i));
  8329. if (!target || !target->IsEntity())
  8330. continue;
  8331. if (((Entity*)target)->GetDetCount() > 0)
  8332. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8333. }
  8334. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8335. }
  8336. return 0;
  8337. }
  8338. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  8339. if (!lua_interface)
  8340. return 0;
  8341. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8342. lua_interface->ResetFunctionStack(state);
  8343. if (!spell) {
  8344. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  8345. return 0;
  8346. }
  8347. if (!spell->caster) {
  8348. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  8349. return 0;
  8350. }
  8351. if (!spell->caster->GetZone()) {
  8352. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  8353. return 0;
  8354. }
  8355. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8356. return 0;
  8357. }
  8358. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  8359. if (!lua_interface)
  8360. return 0;
  8361. Spawn* spawn = lua_interface->GetSpawn(state);
  8362. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8363. lua_interface->ResetFunctionStack(state);
  8364. if (!spell) {
  8365. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  8366. return 0;
  8367. }
  8368. if (spawn && spawn->IsEntity())
  8369. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8370. else {
  8371. ZoneServer* zone = spell->caster->GetZone();
  8372. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8373. for (int32 i = 0; i < spell->targets.size(); i++) {
  8374. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8375. if (!spawn || !spawn->IsEntity())
  8376. continue;
  8377. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8378. }
  8379. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8380. }
  8381. return 0;
  8382. }
  8383. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  8384. if (!lua_interface)
  8385. return 0;
  8386. Spawn* spawn = lua_interface->GetSpawn(state);
  8387. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8388. lua_interface->ResetFunctionStack(state);
  8389. if (!spell) {
  8390. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  8391. return 0;
  8392. }
  8393. if (spawn && spawn->IsEntity())
  8394. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8395. else {
  8396. ZoneServer* zone = spell->caster->GetZone();
  8397. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8398. for (int32 i = 0; i < spell->targets.size(); i++) {
  8399. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8400. if (!spawn || !spawn->IsEntity())
  8401. continue;
  8402. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8403. }
  8404. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8405. }
  8406. return 0;
  8407. }
  8408. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8409. if (!lua_interface)
  8410. return 0;
  8411. Spawn* caster = lua_interface->GetSpawn(state);
  8412. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8413. lua_interface->ResetFunctionStack(state);
  8414. if (!caster) {
  8415. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8416. return 0;
  8417. }
  8418. if (!caster->IsPlayer()) {
  8419. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8420. return 0;
  8421. }
  8422. Spawn* target = caster->GetTarget();
  8423. if (!target) {
  8424. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8425. return 0;
  8426. }
  8427. Client* client = ((Player*)caster)->GetClient();
  8428. if (!client) {
  8429. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8430. return 0;
  8431. }
  8432. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8433. if (ho) {
  8434. ho->SetTarget(target->GetID());
  8435. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8436. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8437. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8438. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8439. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8440. deque<GroupMemberInfo*>::iterator itr;
  8441. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8442. if (group)
  8443. {
  8444. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8445. deque<GroupMemberInfo*>* members = group->GetMembers();
  8446. for (itr = members->begin(); itr != members->end(); itr++) {
  8447. if ((*itr)->client)
  8448. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8449. }
  8450. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8451. }
  8452. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8453. }
  8454. else
  8455. safe_delete(ho);
  8456. }
  8457. else {
  8458. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8459. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8460. }
  8461. else
  8462. safe_delete(ho);
  8463. }
  8464. }
  8465. return 0;
  8466. }
  8467. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8468. if (!lua_interface)
  8469. return 0;
  8470. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8471. if (!spell) {
  8472. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8473. return 0;
  8474. }
  8475. int16 triggerCount = lua_interface->GetInt16Value(state);
  8476. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8477. if (!triggerCount) {
  8478. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8479. return 0;
  8480. }
  8481. spell->num_triggers = triggerCount;
  8482. spell->had_triggers = true;
  8483. spell->cancel_after_all_triggers = cancel_after_triggers;
  8484. return 0;
  8485. }
  8486. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8487. if (!lua_interface)
  8488. return 0;
  8489. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8490. lua_interface->ResetFunctionStack(state);
  8491. if (!spell) {
  8492. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8493. return 0;
  8494. }
  8495. lua_interface->SetInt32Value(state, spell->num_triggers);
  8496. return 1;
  8497. }
  8498. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8499. if (!lua_interface)
  8500. return 0;
  8501. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8502. if (!spell) {
  8503. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8504. lua_interface->ResetFunctionStack(state);
  8505. return 0;
  8506. }
  8507. if (!spell->caster || !spell->caster->GetZone()) {
  8508. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: caster / caster zone must be set!", lua_interface->GetScriptName(state));
  8509. lua_interface->ResetFunctionStack(state);
  8510. return 0;
  8511. }
  8512. int16 remove_count = lua_interface->GetInt16Value(state);
  8513. lua_interface->ResetFunctionStack(state);
  8514. if (!remove_count)
  8515. remove_count = 1;
  8516. if (remove_count >= spell->num_triggers) {
  8517. spell->num_triggers = 0;
  8518. if (spell->cancel_after_all_triggers)
  8519. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8520. }
  8521. else {
  8522. spell->num_triggers -= remove_count;
  8523. Client* client = spell->caster->IsPlayer() ? ((Player*)spell->caster)->GetClient() : nullptr;
  8524. ClientPacketFunctions::SendMaintainedExamineUpdate(client, spell->slot_pos, spell->num_triggers, 0);
  8525. }
  8526. return 0;
  8527. }
  8528. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8529. if (!lua_interface)
  8530. return 0;
  8531. Spawn* spawn = lua_interface->GetSpawn(state);
  8532. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8533. lua_interface->ResetFunctionStack(state);
  8534. if (!spawn) {
  8535. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8536. return 0;
  8537. }
  8538. if (!copy_spawn) {
  8539. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8540. return 0;
  8541. }
  8542. spawn->CopySpawnAppearance(copy_spawn);
  8543. return 0;
  8544. }
  8545. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8546. Spawn* spawn = lua_interface->GetSpawn(state);
  8547. int8 type = lua_interface->GetInt8Value(state, 2);
  8548. lua_interface->ResetFunctionStack(state);
  8549. if (!spawn) {
  8550. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8551. return 0;
  8552. }
  8553. else if (!spawn->IsEntity()) {
  8554. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8555. return 0;
  8556. }
  8557. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8558. return 1;
  8559. }
  8560. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8561. if (!lua_interface)
  8562. return 0;
  8563. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8564. int8 type = lua_interface->GetInt8Value(state);
  8565. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8566. lua_interface->ResetFunctionStack(state);
  8567. if (!spell) {
  8568. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8569. return 0;
  8570. }
  8571. if(spell->resisted) {
  8572. return 0;
  8573. }
  8574. if (spawn) {
  8575. if (!spawn->IsEntity()) {
  8576. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8577. return 0;
  8578. }
  8579. Entity* entity = ((Entity*)spawn);
  8580. entity->AddImmunity(spell, type);
  8581. }
  8582. else if(spell->caster && spell->caster->GetZone()) {
  8583. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8584. for (int8 i = 0; i < spell->targets.size(); i++) {
  8585. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8586. if (!spawn || !spawn->IsEntity())
  8587. continue;
  8588. Entity* entity = ((Entity*)spawn);
  8589. entity->AddImmunity(spell, type);
  8590. }
  8591. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8592. }
  8593. return 0;
  8594. }
  8595. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8596. if (!lua_interface)
  8597. return 0;
  8598. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8599. int8 type = lua_interface->GetInt8Value(state);
  8600. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8601. lua_interface->ResetFunctionStack(state);
  8602. if (!spell) {
  8603. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8604. return 0;
  8605. }
  8606. if (spawn) {
  8607. if (!spawn->IsEntity()) {
  8608. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8609. return 0;
  8610. }
  8611. Entity* entity = ((Entity*)spawn);
  8612. entity->RemoveImmunity(spell, type);
  8613. }
  8614. else if(spell->caster && spell->caster->GetZone()) {
  8615. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8616. for (int8 i = 0; i < spell->targets.size(); i++) {
  8617. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8618. if (!spawn || !spawn->IsEntity())
  8619. continue;
  8620. Entity* entity = ((Entity*)spawn);
  8621. entity->RemoveImmunity(spell, type);
  8622. }
  8623. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8624. }
  8625. return 0;
  8626. }
  8627. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8628. if (!lua_interface)
  8629. return 0;
  8630. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8631. if (!spell) {
  8632. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8633. lua_interface->ResetFunctionStack(state);
  8634. return 0;
  8635. }
  8636. if(spell->resisted) {
  8637. lua_interface->ResetFunctionStack(state);
  8638. return 0;
  8639. }
  8640. float snare = lua_interface->GetFloatValue(state);
  8641. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8642. lua_interface->ResetFunctionStack(state);
  8643. // convert the val to the speed multipler value (100 - val)
  8644. float val = 100.0 - snare;
  8645. val /= 100.0;
  8646. if (spawn) {
  8647. if (!spawn->IsEntity()) {
  8648. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8649. return 0;
  8650. }
  8651. ((Entity*)spawn)->SetSnareValue(spell, val);
  8652. }
  8653. else if(spell->caster && spell->caster->GetZone()) {
  8654. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8655. for (int8 i = 0; i < spell->targets.size(); i++) {
  8656. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8657. if (!spawn || !spawn->IsEntity())
  8658. continue;
  8659. ((Entity*)spawn)->SetSnareValue(spell, val);
  8660. }
  8661. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8662. }
  8663. return 0;
  8664. }
  8665. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8666. if (!lua_interface)
  8667. return 0;
  8668. Spawn* spawn = lua_interface->GetSpawn(state);
  8669. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8670. lua_interface->ResetFunctionStack(state);
  8671. if (!spawn) {
  8672. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8673. return 0;
  8674. }
  8675. if (race_id == 0) {
  8676. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8677. return 0;
  8678. }
  8679. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8680. return 1;
  8681. }
  8682. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8683. if (!lua_interface)
  8684. return 0;
  8685. Spawn* spawn = lua_interface->GetSpawn(state);
  8686. lua_interface->ResetFunctionStack(state);
  8687. if (!spawn) {
  8688. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8689. return 0;
  8690. }
  8691. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8692. return 1;
  8693. }
  8694. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8695. if (!lua_interface)
  8696. return 0;
  8697. Spawn* spawn = lua_interface->GetSpawn(state);
  8698. lua_interface->ResetFunctionStack(state);
  8699. if (!spawn) {
  8700. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8701. return 0;
  8702. }
  8703. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8704. return 1;
  8705. }
  8706. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8707. if (!lua_interface)
  8708. return 0;
  8709. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8710. lua_interface->ResetFunctionStack(state);
  8711. if (!spell) {
  8712. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8713. return 0;
  8714. }
  8715. lua_interface->SetStringValue(state, spell->spell->GetName());
  8716. return 1;
  8717. }
  8718. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8719. if (!lua_interface)
  8720. return 0;
  8721. Quest* quest = lua_interface->GetQuest(state);
  8722. lua_interface->ResetFunctionStack(state);
  8723. if (!quest) {
  8724. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8725. return 0;
  8726. }
  8727. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8728. return 1;
  8729. }
  8730. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8731. if (!lua_interface)
  8732. return 0;
  8733. Quest* quest = lua_interface->GetQuest(state);
  8734. int32 flags = lua_interface->GetInt32Value(state, 2);
  8735. lua_interface->ResetFunctionStack(state);
  8736. if (!quest) {
  8737. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8738. return 0;
  8739. }
  8740. quest->SetQuestFlags(flags);
  8741. return 0;
  8742. }
  8743. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8744. if (!lua_interface)
  8745. return 0;
  8746. Quest* quest = lua_interface->GetQuest(state);
  8747. Spawn* player = lua_interface->GetSpawn(state, 2);
  8748. int32 step = lua_interface->GetInt32Value(state, 3);
  8749. int32 duration = lua_interface->GetInt32Value(state, 4);
  8750. string action = lua_interface->GetStringValue(state, 5);
  8751. lua_interface->ResetFunctionStack(state);
  8752. if (!quest) {
  8753. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8754. return 0;
  8755. }
  8756. if (!player) {
  8757. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8758. return 0;
  8759. }
  8760. if (!player->IsPlayer()) {
  8761. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8762. return 0;
  8763. }
  8764. if (step == 0) {
  8765. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8766. return 0;
  8767. }
  8768. if (duration == 0) {
  8769. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8770. return 0;
  8771. }
  8772. if (action.length() == 0) {
  8773. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8774. return 0;
  8775. }
  8776. Client* client = ((Player*)player)->GetClient();
  8777. if (!client) {
  8778. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8779. return 0;
  8780. }
  8781. quest->SetTimerStep(step);
  8782. quest->AddFailedAction(step, action);
  8783. quest->SetStepTimer(duration);
  8784. client->AddQuestTimer(quest->GetQuestID());
  8785. return 0;
  8786. }
  8787. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8788. if (!lua_interface)
  8789. return 0;
  8790. Quest* quest = lua_interface->GetQuest(state);
  8791. Spawn* player = lua_interface->GetSpawn(state, 2);
  8792. lua_interface->ResetFunctionStack(state);
  8793. if (!quest) {
  8794. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8795. return 0;
  8796. }
  8797. if (!player) {
  8798. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8799. return 0;
  8800. }
  8801. if (!player->IsPlayer()) {
  8802. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8803. return 0;
  8804. }
  8805. Client* client = ((Player*)player)->GetClient();
  8806. if (!client) {
  8807. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8808. return 0;
  8809. }
  8810. quest->SetTimerStep(0);
  8811. quest->SetStepTimer(0);
  8812. client->RemoveQuestTimer(quest->GetQuestID());
  8813. return 0;
  8814. }
  8815. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8816. if (!lua_interface)
  8817. return 0;
  8818. Spawn* player = lua_interface->GetSpawn(state);
  8819. Quest* quest = lua_interface->GetQuest(state, 2);
  8820. int32 step = lua_interface->GetInt32Value(state, 3);
  8821. lua_interface->ResetFunctionStack(state);
  8822. if (!player) {
  8823. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8824. return 0;
  8825. }
  8826. if (!player->IsPlayer()) {
  8827. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8828. return 0;
  8829. }
  8830. if (!quest) {
  8831. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8832. return 0;
  8833. }
  8834. if (step == 0) {
  8835. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8836. return 0;
  8837. }
  8838. Client* client = ((Player*)player)->GetClient();
  8839. if (!client) {
  8840. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8841. return 0;
  8842. }
  8843. if (quest->RemoveQuestStep(step, client)) {
  8844. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8845. client->GetCurrentZone()->SendQuestUpdates(client);
  8846. }
  8847. else
  8848. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8849. return 0;
  8850. }
  8851. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8852. if (!lua_interface)
  8853. return 0;
  8854. Quest* quest = lua_interface->GetQuest(state, 1);
  8855. int32 step = lua_interface->GetInt32Value(state, 2);
  8856. string desc = lua_interface->GetStringValue(state, 3);
  8857. string task_group = lua_interface->GetStringValue(state, 4);
  8858. lua_interface->ResetFunctionStack(state);
  8859. if (!quest) {
  8860. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8861. return 0;
  8862. }
  8863. if (step == 0) {
  8864. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8865. return 0;
  8866. }
  8867. QuestStep* quest_step = quest->GetQuestStep(step);
  8868. if (!quest_step) {
  8869. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8870. return 0;
  8871. }
  8872. quest_step->SetStepProgress(0);
  8873. quest_step->SetTaskGroup(task_group);
  8874. quest_step->SetDescription(desc);
  8875. return 0;
  8876. }
  8877. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8878. if (!lua_interface)
  8879. return 0;
  8880. Quest* quest = lua_interface->GetQuest(state);
  8881. int32 step = lua_interface->GetInt32Value(state, 2);
  8882. string action = lua_interface->GetStringValue(state, 3);
  8883. lua_interface->ResetFunctionStack(state);
  8884. if (!quest) {
  8885. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8886. return 0;
  8887. }
  8888. if (step == 0) {
  8889. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8890. return 0;
  8891. }
  8892. if (action.length() == 0) {
  8893. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8894. return 0;
  8895. }
  8896. quest->AddFailedAction(step, action);
  8897. return 0;
  8898. }
  8899. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8900. if (!lua_interface)
  8901. return 0;
  8902. Spawn* player = lua_interface->GetSpawn(state);
  8903. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8904. int32 step = lua_interface->GetInt32Value(state, 3);
  8905. lua_interface->ResetFunctionStack(state);
  8906. if (!player) {
  8907. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8908. return 0;
  8909. }
  8910. if (!player->IsPlayer()) {
  8911. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8912. return 0;
  8913. }
  8914. if (quest_id == 0) {
  8915. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8916. return 0;
  8917. }
  8918. if (step == 0) {
  8919. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8920. return 0;
  8921. }
  8922. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8923. if (!quest) {
  8924. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8925. return 0;
  8926. }
  8927. quest->StepFailed(step);
  8928. return 0;
  8929. }
  8930. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8931. if (!lua_interface)
  8932. return 0;
  8933. Spawn* player = lua_interface->GetSpawn(state);
  8934. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8935. lua_interface->ResetFunctionStack(state);
  8936. if (!player) {
  8937. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8938. return 0;
  8939. }
  8940. if (!player->IsPlayer()) {
  8941. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8942. return 0;
  8943. }
  8944. if (quest_id == 0) {
  8945. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8946. return 0;
  8947. }
  8948. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestCompletedCount(quest_id));
  8949. return 1;
  8950. }
  8951. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8952. if (!lua_interface)
  8953. return 0;
  8954. string name = lua_interface->GetStringValue(state);
  8955. string value = lua_interface->GetStringValue(state, 2);
  8956. string comment = lua_interface->GetStringValue(state, 3);
  8957. lua_interface->ResetFunctionStack(state);
  8958. if (name.length() == 0) {
  8959. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8960. return 0;
  8961. }
  8962. if (value.length() == 0) {
  8963. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8964. return 0;
  8965. }
  8966. string varname = string("lua_").append(name);
  8967. Variable* var = variables.FindVariable(varname);
  8968. if (var)
  8969. var->SetValue(value.c_str());
  8970. else {
  8971. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8972. variables.AddVariable(var);
  8973. }
  8974. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8975. return 0;
  8976. }
  8977. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8978. if (!lua_interface)
  8979. return 0;
  8980. string name = lua_interface->GetStringValue(state);
  8981. lua_interface->ResetFunctionStack(state);
  8982. if (name.length() == 0) {
  8983. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8984. return 0;
  8985. }
  8986. string varname = string("lua_").append(name);
  8987. Variable* var = variables.FindVariable(varname);
  8988. if (var)
  8989. lua_interface->SetStringValue(state, var->GetValue());
  8990. else
  8991. lua_interface->SetStringValue(state, "NULL");
  8992. return 1;
  8993. }
  8994. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8995. if (!lua_interface)
  8996. return 0;
  8997. Spawn* player = lua_interface->GetSpawn(state);
  8998. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8999. lua_interface->ResetFunctionStack(state);
  9000. if (!player) {
  9001. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9002. return 0;
  9003. }
  9004. if (!player->IsPlayer()) {
  9005. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9006. return 0;
  9007. }
  9008. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  9009. return 1;
  9010. }
  9011. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  9012. if (!lua_interface)
  9013. return 0;
  9014. Spawn* player = lua_interface->GetSpawn(state);
  9015. int32 language_id = lua_interface->GetInt32Value(state, 2);
  9016. lua_interface->ResetFunctionStack(state);
  9017. if (!player) {
  9018. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9019. return 0;
  9020. }
  9021. if (!player->IsPlayer()) {
  9022. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9023. return 0;
  9024. }
  9025. Language* language = master_languages_list.GetLanguage(language_id);
  9026. if (language)
  9027. {
  9028. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  9029. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID(), 0);
  9030. }
  9031. return 0;
  9032. }
  9033. int EQ2Emu_lua_IsNight(lua_State* state) {
  9034. if (!lua_interface)
  9035. return 0;
  9036. ZoneServer* zone = lua_interface->GetZone(state);
  9037. lua_interface->ResetFunctionStack(state);
  9038. if (!zone) {
  9039. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  9040. return 0;
  9041. }
  9042. lua_interface->SetBooleanValue(state, zone->IsDusk());
  9043. return 1;
  9044. }
  9045. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  9046. if (!lua_interface)
  9047. return 0;
  9048. Spawn* spawn = lua_interface->GetSpawn(state);
  9049. lua_interface->ResetFunctionStack(state);
  9050. if (!spawn) {
  9051. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  9052. return 0;
  9053. }
  9054. if (!spawn->IsWidget()) {
  9055. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  9056. return 0;
  9057. }
  9058. ((Widget*)spawn)->SetMultiFloorLift(true);
  9059. if (spawn->GetZone())
  9060. spawn->GetZone()->AddTransportSpawn(spawn);
  9061. return 0;
  9062. }
  9063. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  9064. if (!lua_interface)
  9065. return 0;
  9066. Spawn* player = lua_interface->GetSpawn(state);
  9067. int32 path = lua_interface->GetInt32Value(state, 2);
  9068. lua_interface->ResetFunctionStack(state);
  9069. if (!player) {
  9070. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9071. return 0;
  9072. }
  9073. if (!player->IsPlayer()) {
  9074. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9075. return 0;
  9076. }
  9077. if (path == 0) {
  9078. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  9079. return 0;
  9080. }
  9081. Client* client = ((Player*)player)->GetClient();
  9082. if (!client) {
  9083. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9084. return 0;
  9085. }
  9086. client->SendFlightAutoMount(path);
  9087. return 0;
  9088. }
  9089. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  9090. if (!lua_interface)
  9091. return 0;
  9092. Spawn* player = lua_interface->GetSpawn(state);
  9093. if (!player) {
  9094. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9095. return 0;
  9096. }
  9097. if (!player->IsPlayer()) {
  9098. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9099. return 0;
  9100. }
  9101. Client* client = ((Player*)player)->GetClient();
  9102. if (!client) {
  9103. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9104. return 0;
  9105. }
  9106. client->EndAutoMount();
  9107. return 0;
  9108. }
  9109. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  9110. if (!lua_interface)
  9111. return 0;
  9112. Spawn* player = lua_interface->GetSpawn(state);
  9113. lua_interface->ResetFunctionStack(state);
  9114. if (!player) {
  9115. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  9116. return 0;
  9117. }
  9118. if (!player->IsPlayer()) {
  9119. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9120. return 0;
  9121. }
  9122. Client* client = ((Player*)player)->GetClient();
  9123. if (!client) {
  9124. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9125. return 0;
  9126. }
  9127. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  9128. return 1;
  9129. }
  9130. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  9131. if (!lua_interface)
  9132. return 0;
  9133. Spawn* player = lua_interface->GetSpawn(state);
  9134. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9135. int32 value = lua_interface->GetInt32Value(state, 3);
  9136. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9137. lua_interface->ResetFunctionStack(state);
  9138. if (!player) {
  9139. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9140. return 0;
  9141. }
  9142. if (!player->IsPlayer()) {
  9143. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9144. return 0;
  9145. }
  9146. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  9147. return 0;
  9148. }
  9149. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  9150. if (!lua_interface)
  9151. return 0;
  9152. Spawn* player = lua_interface->GetSpawn(state);
  9153. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9154. lua_interface->ResetFunctionStack(state);
  9155. if (!player) {
  9156. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9157. return 0;
  9158. }
  9159. if (!player->IsPlayer()) {
  9160. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9161. return 0;
  9162. }
  9163. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  9164. if (!hd)
  9165. return 0;
  9166. lua_interface->SetInt32Value(state, hd->Value);
  9167. lua_interface->SetInt32Value(state, hd->Value2);
  9168. return 2;
  9169. }
  9170. int EQ2Emu_lua_SetGridID(lua_State* state) {
  9171. if (!lua_interface)
  9172. return 0;
  9173. Spawn* spawn = lua_interface->GetSpawn(state);
  9174. int32 grid = lua_interface->GetInt32Value(state, 2);
  9175. lua_interface->ResetFunctionStack(state);
  9176. if (!spawn) {
  9177. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9178. return 0;
  9179. }
  9180. if (grid == 0) {
  9181. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  9182. return 0;
  9183. }
  9184. spawn->SetLocation(grid);
  9185. return 0;
  9186. }
  9187. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  9188. if (!lua_interface)
  9189. return 0;
  9190. Spawn* spawn = lua_interface->GetSpawn(state);
  9191. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9192. int32 value1 = lua_interface->GetInt32Value(state, 3);
  9193. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9194. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  9195. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  9196. lua_interface->ResetFunctionStack(state);
  9197. if (!spawn) {
  9198. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9199. return 0;
  9200. }
  9201. //Add this quest to the list of required quests for this spawn
  9202. spawn->SetRequiredHistory(event_id, value1, value2);
  9203. //If private spawn value set
  9204. if (private_spawn) {
  9205. //Set the spawn to be private when not granted access via history
  9206. spawn->AddAllowAccessSpawn(spawn);
  9207. spawn->SetPrivateQuestSpawn(true);
  9208. }
  9209. //This value will override vis_flags in the vis packet
  9210. if (flag_override > 0)
  9211. spawn->SetQuestsRequiredOverride(flag_override);
  9212. return 0;
  9213. }
  9214. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  9215. if (!lua_interface)
  9216. return 0;
  9217. Spawn* player = lua_interface->GetSpawn(state);
  9218. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9219. int32 step_id = lua_interface->GetInt32Value(state, 3);
  9220. lua_interface->ResetFunctionStack(state);
  9221. if (!player) {
  9222. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  9223. return 0;
  9224. }
  9225. if (!player->IsPlayer()) {
  9226. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  9227. return 0;
  9228. }
  9229. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  9230. return 1;
  9231. }
  9232. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  9233. if (!lua_interface)
  9234. return 0;
  9235. Spawn* player = lua_interface->GetSpawn(state);
  9236. int8 level = lua_interface->GetInt8Value(state, 2);
  9237. lua_interface->ResetFunctionStack(state);
  9238. if (!player) {
  9239. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  9240. return 0;
  9241. }
  9242. if (!player->IsPlayer()) {
  9243. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  9244. return 0;
  9245. }
  9246. if (level == 0) {
  9247. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  9248. return 0;
  9249. }
  9250. Client* client = ((Player*)player)->GetClient();
  9251. if (!client) {
  9252. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  9253. return 0;
  9254. }
  9255. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  9256. return 0;
  9257. }
  9258. int EQ2Emu_lua_AddCoin(lua_State* state) {
  9259. if (!lua_interface)
  9260. return 0;
  9261. Spawn* player = lua_interface->GetSpawn(state);
  9262. int32 amount = lua_interface->GetInt32Value(state, 2);
  9263. lua_interface->ResetFunctionStack(state);
  9264. if (!player) {
  9265. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9266. return 0;
  9267. }
  9268. if (!player->IsPlayer()) {
  9269. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9270. return 0;
  9271. }
  9272. if (amount == 0) {
  9273. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9274. return 0;
  9275. }
  9276. ((Player*)player)->AddCoins(amount);
  9277. return 0;
  9278. }
  9279. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  9280. if (!lua_interface)
  9281. return 0;
  9282. Spawn* player = lua_interface->GetSpawn(state);
  9283. int32 amount = lua_interface->GetInt32Value(state, 2);
  9284. lua_interface->ResetFunctionStack(state);
  9285. if (!player) {
  9286. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9287. return 0;
  9288. }
  9289. if (!player->IsPlayer()) {
  9290. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9291. return 0;
  9292. }
  9293. if (amount == 0) {
  9294. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9295. return 0;
  9296. }
  9297. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  9298. return 1;
  9299. }
  9300. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  9301. if (!lua_interface)
  9302. return 0;
  9303. ZoneServer* zone = lua_interface->GetZone(state);
  9304. lua_interface->ResetFunctionStack(state);
  9305. if (!zone) {
  9306. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9307. return 0;
  9308. }
  9309. vector<Entity*> players = zone->GetPlayers();
  9310. if (players.size() == 0)
  9311. return 0;
  9312. lua_createtable(state, players.size(), 0);
  9313. int newTable = lua_gettop(state);
  9314. for (int32 i = 0; i < players.size(); i++) {
  9315. lua_interface->SetSpawnValue(state, players.at(i));
  9316. lua_rawseti(state, newTable, i + 1);
  9317. }
  9318. return 1;
  9319. }
  9320. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  9321. if (!lua_interface)
  9322. return 0;
  9323. ZoneServer* zone = lua_interface->GetZone(state, 1);
  9324. if (!zone) {
  9325. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9326. return 0;
  9327. }
  9328. int32 group_id = lua_interface->GetInt32Value(state, 2);
  9329. lua_interface->ResetFunctionStack(state);
  9330. //Map of <placement_id, location_id>
  9331. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  9332. map<int32, int32>::iterator itr;
  9333. vector<Spawn*> group;
  9334. for (itr = locs->begin(); itr != locs->end(); itr++) {
  9335. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  9336. if (!location) {
  9337. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  9338. return 0;
  9339. }
  9340. Spawn* spawn = 0;
  9341. if (location->entities[0]) {
  9342. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  9343. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  9344. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  9345. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  9346. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  9347. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  9348. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  9349. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  9350. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  9351. spawn = zone->AddSignSpawn(location, location->entities[0]);
  9352. if(spawn && spawn->IsOmittedByDBFlag())
  9353. {
  9354. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met (LUA SpawnGroupByID).", location->entities[0]->spawn_id);
  9355. safe_delete(spawn);
  9356. continue;
  9357. }
  9358. if (spawn) {
  9359. const char* script = 0;
  9360. for (int x = 0; x < 3; x++) {
  9361. switch (x) {
  9362. case 0:
  9363. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  9364. break;
  9365. case 1:
  9366. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  9367. break;
  9368. case 2:
  9369. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  9370. break;
  9371. }
  9372. if (script && lua_interface->GetSpawnScript(script) != 0) {
  9373. spawn->SetSpawnScript(string(script));
  9374. break;
  9375. }
  9376. }
  9377. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  9378. lua_interface->SetSpawnValue(state, spawn);
  9379. group.push_back(spawn);
  9380. }
  9381. else {
  9382. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  9383. safe_delete(spawn);
  9384. }
  9385. }
  9386. }
  9387. if (!group.empty()) {
  9388. lua_createtable(state, group.size(), 0);
  9389. int newTable = lua_gettop(state);
  9390. for (int32 i = 0; i < group.size(); i++) {
  9391. lua_interface->SetSpawnValue(state, group[i]);
  9392. lua_rawseti(state, newTable, i + 1);
  9393. }
  9394. }
  9395. else
  9396. lua_pushnil(state);
  9397. return 1;
  9398. }
  9399. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  9400. if (!lua_interface)
  9401. return 0;
  9402. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9403. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  9404. int16 leeway = lua_interface->GetInt16Value(state, 3);
  9405. lua_interface->ResetFunctionStack(state);
  9406. if (!spawn) {
  9407. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  9408. return 0;
  9409. }
  9410. if (anim_id == 0) {
  9411. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  9412. return 0;
  9413. }
  9414. if (leeway == 0)
  9415. leeway = 5000;
  9416. spawn->SetSpawnAnim(anim_id);
  9417. spawn->SetSpawnAnimLeeway(leeway);
  9418. return 0;
  9419. }
  9420. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  9421. if (!lua_interface)
  9422. return 0;
  9423. Spawn* player = lua_interface->GetSpawn(state);
  9424. lua_interface->ResetFunctionStack(state);
  9425. if (!player || !player->IsPlayer()) {
  9426. return 0;
  9427. }
  9428. Client* client = ((Player*)player)->GetClient();
  9429. if (!client) {
  9430. return 0;
  9431. }
  9432. lua_interface->SetInt32Value(state, client->GetVersion());
  9433. return 1;
  9434. }
  9435. int EQ2Emu_lua_GetItemID(lua_State* state) {
  9436. if (!lua_interface)
  9437. return 0;
  9438. Item* item = lua_interface->GetItem(state);
  9439. lua_interface->ResetFunctionStack(state);
  9440. if (!item) {
  9441. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  9442. return 0;
  9443. }
  9444. lua_interface->SetInt32Value(state, item->details.item_id);
  9445. return 1;
  9446. }
  9447. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9448. if (!lua_interface)
  9449. return 0;
  9450. Spawn* spawn = lua_interface->GetSpawn(state);
  9451. lua_interface->ResetFunctionStack(state);
  9452. if (!spawn) {
  9453. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9454. return 0;
  9455. }
  9456. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9457. return 1;
  9458. }
  9459. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9460. if (!lua_interface)
  9461. return 0;
  9462. Spawn* spawn = lua_interface->GetSpawn(state);
  9463. lua_interface->ResetFunctionStack(state);
  9464. if (!spawn) {
  9465. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9466. return 0;
  9467. }
  9468. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9469. return 1;
  9470. }
  9471. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9472. if (!lua_interface)
  9473. return 0;
  9474. Spawn* spawn = lua_interface->GetSpawn(state);
  9475. lua_interface->ResetFunctionStack(state);
  9476. if (!spawn) {
  9477. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9478. return 0;
  9479. }
  9480. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9481. return 1;
  9482. }
  9483. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9484. if (!lua_interface)
  9485. return 0;
  9486. Spawn* spawn = lua_interface->GetSpawn(state);
  9487. lua_interface->ResetFunctionStack(state);
  9488. if (!spawn) {
  9489. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9490. return 0;
  9491. }
  9492. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9493. return 1;
  9494. }
  9495. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9496. if (!lua_interface)
  9497. return 0;
  9498. Spawn* spawn = lua_interface->GetSpawn(state);
  9499. float pct = lua_interface->GetFloatValue(state, 2);
  9500. lua_interface->ResetFunctionStack(state);
  9501. if (!spawn) {
  9502. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9503. return 0;
  9504. }
  9505. if (pct == 0) {
  9506. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9507. return 0;
  9508. }
  9509. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9510. lua_interface->SetInt32Value(state, amount);
  9511. return 1;
  9512. }
  9513. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9514. if (!lua_interface)
  9515. return 0;
  9516. Spawn* spawn = lua_interface->GetSpawn(state);
  9517. float pct = lua_interface->GetFloatValue(state, 2);
  9518. lua_interface->ResetFunctionStack(state);
  9519. if (!spawn) {
  9520. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9521. return 0;
  9522. }
  9523. if (pct == 0) {
  9524. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9525. return 0;
  9526. }
  9527. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9528. lua_interface->SetInt32Value(state, amount);
  9529. return 1;
  9530. }
  9531. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9532. if (!lua_interface)
  9533. return 0;
  9534. Spawn* spawn = lua_interface->GetSpawn(state);
  9535. lua_interface->ResetFunctionStack(state);
  9536. if (!spawn) {
  9537. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9538. return 0;
  9539. }
  9540. if (!spawn->IsPlayer()) {
  9541. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9542. return 0;
  9543. }
  9544. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9545. return 1;
  9546. }
  9547. int EQ2Emu_lua_Evac(lua_State* state) {
  9548. if (!lua_interface)
  9549. return 0;
  9550. Spawn* target = lua_interface->GetSpawn(state);
  9551. if (target) {
  9552. float x = target->GetZone()->GetSafeX();
  9553. float y = target->GetZone()->GetSafeY();
  9554. float z = target->GetZone()->GetSafeZ();
  9555. float h = target->GetZone()->GetSafeHeading();
  9556. target->SetX(x);
  9557. target->SetY(y);
  9558. target->SetZ(z);
  9559. target->SetHeading(h);
  9560. target->SetSpawnOrigX(x);
  9561. target->SetSpawnOrigY(y);
  9562. target->SetSpawnOrigZ(z);
  9563. target->SetSpawnOrigHeading(h);
  9564. if (target->IsPlayer()) {
  9565. Client* client = ((Player*)target)->GetClient();
  9566. if (client) {
  9567. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9568. int numargs = lua_interface->GetNumberOfArgs(state);
  9569. if(numargs == 4) {
  9570. x = lua_interface->GetFloatValue(state,1);
  9571. y = lua_interface->GetFloatValue(state,2);
  9572. z = lua_interface->GetFloatValue(state,3);
  9573. h = lua_interface->GetFloatValue(state,4);
  9574. }
  9575. client->SetReloadingZone(true);
  9576. target->SetX(x);
  9577. target->SetY(y);
  9578. target->SetZ(z);
  9579. target->SetHeading(h);
  9580. target->SetSpawnOrigX(x);
  9581. target->SetSpawnOrigY(y);
  9582. target->SetSpawnOrigZ(z);
  9583. target->SetSpawnOrigHeading(h);
  9584. target->SetAppearancePosition(x,y,z);
  9585. client->SetZoningCoords(x,y,z,h);
  9586. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9587. if (packet)
  9588. {
  9589. packet->setDataByName("x", x);
  9590. packet->setDataByName("y", y);
  9591. packet->setDataByName("z", z);
  9592. client->QueuePacket(packet->serialize());
  9593. safe_delete(packet);
  9594. }
  9595. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9596. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9597. }
  9598. }
  9599. lua_interface->ResetFunctionStack(state);
  9600. }
  9601. else {
  9602. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9603. if(!spell || !spell->caster || !spell->caster->GetZone()) {
  9604. lua_interface->ResetFunctionStack(state);
  9605. return 0;
  9606. }
  9607. ZoneServer* zone = spell->caster->GetZone();
  9608. float x = spell->caster->GetZone()->GetSafeX();
  9609. float y = spell->caster->GetZone()->GetSafeY();
  9610. float z = spell->caster->GetZone()->GetSafeZ();
  9611. float h = spell->caster->GetZone()->GetSafeHeading();
  9612. int numargs = lua_interface->GetNumberOfArgs(state);
  9613. if(numargs == 4) {
  9614. x = lua_interface->GetFloatValue(state,1);
  9615. y = lua_interface->GetFloatValue(state,2);
  9616. z = lua_interface->GetFloatValue(state,3);
  9617. h = lua_interface->GetFloatValue(state,4);
  9618. }
  9619. lua_interface->ResetFunctionStack(state);
  9620. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9621. for (int32 i = 0; i < spell->targets.size(); i++) {
  9622. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9623. if (!target2)
  9624. continue;
  9625. if (target2->IsPlayer()) {
  9626. Client* client = ((Player*)target2)->GetClient();
  9627. if (client) {
  9628. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9629. client->SetReloadingZone(true);
  9630. target2->SetX(x);
  9631. target2->SetY(y);
  9632. target2->SetZ(z);
  9633. target2->SetHeading(h);
  9634. target2->SetSpawnOrigX(x);
  9635. target2->SetSpawnOrigY(y);
  9636. target2->SetSpawnOrigZ(z);
  9637. target2->SetSpawnOrigHeading(h);
  9638. target2->SetAppearancePosition(x,y,z);
  9639. client->SetZoningCoords(x,y,z,h);
  9640. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9641. if (packet)
  9642. {
  9643. packet->setDataByName("x", x);
  9644. packet->setDataByName("y", y);
  9645. packet->setDataByName("z", z);
  9646. client->QueuePacket(packet->serialize());
  9647. safe_delete(packet);
  9648. }
  9649. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9650. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9651. }
  9652. }
  9653. }
  9654. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9655. }
  9656. return 0;
  9657. }
  9658. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9659. if (!lua_interface)
  9660. return 0;
  9661. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9662. lua_interface->ResetFunctionStack(state);
  9663. if (!luaspell) {
  9664. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9665. return 0;
  9666. }
  9667. int8 tier = luaspell->spell->GetSpellTier();
  9668. lua_interface->SetInt32Value(state, tier);
  9669. return 1;
  9670. }
  9671. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9672. if (!lua_interface)
  9673. return 0;
  9674. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9675. lua_interface->ResetFunctionStack(state);
  9676. if (!luaspell) {
  9677. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9678. return 0;
  9679. }
  9680. int32 spell_id = luaspell->spell->GetSpellID();
  9681. lua_interface->SetInt32Value(state, spell_id);
  9682. return 1;
  9683. }
  9684. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9685. if (!lua_interface)
  9686. return 0;
  9687. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9688. lua_interface->ResetFunctionStack(state);
  9689. if (!spawn) {
  9690. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9691. return 0;
  9692. }
  9693. if (!spawn->IsPlayer()) {
  9694. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9695. return 0;
  9696. }
  9697. ZoneServer* zone = spawn->GetZone();
  9698. if (!zone) {
  9699. return 0;
  9700. }
  9701. Client* client = ((Player*)spawn)->GetClient();
  9702. if (!client) {
  9703. return 0;
  9704. }
  9705. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9706. return 0;
  9707. }
  9708. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9709. if (!lua_interface)
  9710. return 0;
  9711. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9712. lua_interface->ResetFunctionStack(state);
  9713. if (!spawn) {
  9714. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9715. return 0;
  9716. }
  9717. if (!spawn->IsPlayer()) {
  9718. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9719. return 0;
  9720. }
  9721. ZoneServer* zone = spawn->GetZone();
  9722. if (!zone) {
  9723. return 0;
  9724. }
  9725. Client* client = ((Player*)spawn)->GetClient();
  9726. if (!client) {
  9727. return 0;
  9728. }
  9729. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9730. return 0;
  9731. }
  9732. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9733. if (!lua_interface)
  9734. return 0;
  9735. Spawn* caster = lua_interface->GetSpawn(state);
  9736. Spawn* target = lua_interface->GetSpawn(state, 2);
  9737. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9738. string spell_name = lua_interface->GetStringValue(state, 4);
  9739. lua_interface->ResetFunctionStack(state);
  9740. if (!caster) {
  9741. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9742. return 0;
  9743. }
  9744. if (!caster->IsEntity()) {
  9745. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9746. return 0;
  9747. }
  9748. if (!target) {
  9749. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9750. return 0;
  9751. }
  9752. if (!target->IsEntity()) {
  9753. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9754. return 0;
  9755. }
  9756. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9757. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9758. return 0;
  9759. }
  9760. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9761. if (!lua_interface)
  9762. return 0;
  9763. Spawn* player = lua_interface->GetSpawn(state);
  9764. int32 amount = lua_interface->GetInt32Value(state, 2);
  9765. lua_interface->ResetFunctionStack(state);
  9766. if (player && player->IsPlayer() && amount > 0) {
  9767. ((Player*)player)->AddXP(amount);
  9768. }
  9769. return 0;
  9770. }
  9771. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9772. if (!lua_interface)
  9773. return 0;
  9774. Spawn* player = lua_interface->GetSpawn(state);
  9775. int8 type = lua_interface->GetInt8Value(state, 2);
  9776. string text = lua_interface->GetStringValue(state, 3);
  9777. lua_interface->ResetFunctionStack(state);
  9778. Client* client = 0;
  9779. if (player && player->IsPlayer())
  9780. client = ((Player*)player)->GetClient();
  9781. if (!client || text.length() == 0) {
  9782. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9783. return 0;
  9784. }
  9785. client->SimpleMessage(type, text.c_str());
  9786. return 0;
  9787. }
  9788. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9789. if (!lua_interface)
  9790. return 0;
  9791. Spawn* player = lua_interface->GetSpawn(state);
  9792. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9793. lua_interface->ResetFunctionStack(state);
  9794. Client* client = 0;
  9795. if (player && player->IsPlayer())
  9796. client = ((Player*)player)->GetClient();
  9797. if (!client || !spawn) {
  9798. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9799. return 0;
  9800. }
  9801. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9802. if (!items) {
  9803. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9804. return 0;
  9805. }
  9806. client->Loot(spawn->GetLootCoins(), items, spawn);
  9807. return 0;
  9808. }
  9809. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9810. if (!lua_interface)
  9811. return 0;
  9812. Spawn* spawnref = lua_interface->GetSpawn(state);
  9813. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9814. lua_interface->ResetFunctionStack(state);
  9815. if (spawn_id > 0 && spawnref) {
  9816. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9817. if (spawns.size() == 0) {
  9818. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9819. return 0;
  9820. }
  9821. Spawn* spawn = 0;
  9822. int16 index = MakeRandomInt(0, spawns.size());
  9823. if (index >= spawns.size() || index < 0)
  9824. index = 0;
  9825. spawn = spawns[index];
  9826. lua_interface->SetSpawnValue(state, spawn);
  9827. return 1;
  9828. }
  9829. else {
  9830. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9831. }
  9832. return 0;
  9833. }
  9834. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9835. Spawn* player = lua_interface->GetSpawn(state);
  9836. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9837. string name = lua_interface->GetStringValue(state, 3);
  9838. float distance = lua_interface->GetFloatValue(state, 4);
  9839. string command = lua_interface->GetStringValue(state, 5);
  9840. string error_text = lua_interface->GetStringValue(state, 6);
  9841. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9842. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9843. lua_interface->ResetFunctionStack(state);
  9844. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9845. if (distance == 0)
  9846. distance = 10.0f;
  9847. if (command.length() == 0)
  9848. command = name;
  9849. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9850. if (spawns.size() == 0) {
  9851. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9852. return 0;
  9853. }
  9854. Spawn* spawn = 0;
  9855. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9856. spawn = *itr;
  9857. if (spawn) {
  9858. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9859. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9860. }
  9861. }
  9862. }
  9863. return 0;
  9864. }
  9865. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9866. if (!lua_interface)
  9867. return 0;
  9868. Client* client = 0;
  9869. Spawn* player = lua_interface->GetSpawn(state);
  9870. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9871. lua_interface->ResetFunctionStack(state);
  9872. if (player && player->IsPlayer() && player->GetZone())
  9873. client = ((Player*)player)->GetClient();
  9874. else{
  9875. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9876. return 0;
  9877. }
  9878. if (client) {
  9879. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9880. if (packet) {
  9881. packet->setDataByName("goal_num", goal_num);
  9882. client->QueuePacket(packet->serialize());
  9883. safe_delete(packet);
  9884. }
  9885. }
  9886. return 0;
  9887. }
  9888. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9889. if (!lua_interface)
  9890. return 0;
  9891. Client* client = 0;
  9892. Spawn* player = lua_interface->GetSpawn(state);
  9893. lua_interface->ResetFunctionStack(state);
  9894. if (player && player->IsPlayer() && player->GetZone())
  9895. client = ((Player*)player)->GetClient();
  9896. else {
  9897. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9898. return 0;
  9899. }
  9900. if (client) {
  9901. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9902. }
  9903. return 0;
  9904. }
  9905. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9906. if (!lua_interface)
  9907. return 0;
  9908. Client* client = 0;
  9909. Spawn* player = lua_interface->GetSpawn(state);
  9910. float duration = lua_interface->GetFloatValue(state, 2);
  9911. string text = lua_interface->GetStringValue(state, 3);
  9912. string voice = lua_interface->GetStringValue(state, 4);
  9913. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9914. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9915. string signal = lua_interface->GetStringValue(state, 7);
  9916. string goal1 = lua_interface->GetStringValue(state, 8);
  9917. string task1 = lua_interface->GetStringValue(state, 9);
  9918. string goal2 = lua_interface->GetStringValue(state, 10);
  9919. string task2 = lua_interface->GetStringValue(state, 11);
  9920. string goal3 = lua_interface->GetStringValue(state, 12);
  9921. string task3 = lua_interface->GetStringValue(state, 13);
  9922. string goal4 = lua_interface->GetStringValue(state, 14);
  9923. string task4 = lua_interface->GetStringValue(state, 15);
  9924. lua_interface->ResetFunctionStack(state);
  9925. if (!player) {
  9926. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9927. return 0;
  9928. }
  9929. if (!player->IsPlayer()) {
  9930. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9931. return 0;
  9932. }
  9933. else
  9934. client = ((Player*)player)->GetClient();
  9935. if (!client) {
  9936. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9937. return 0;
  9938. }
  9939. if (text.length() == 0) {
  9940. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9941. return 0;
  9942. }
  9943. if (duration >= 0 && duration < 2)
  9944. duration = 2;
  9945. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9946. if (packet) {
  9947. packet->setDataByName("open_seconds_max", duration);
  9948. packet->setDataByName("text", text.c_str());
  9949. packet->setDataByName("voice", voice.c_str());
  9950. int8 num_goals = 1;
  9951. if (task2.length() > 0)
  9952. num_goals++;
  9953. if (task3.length() > 0)
  9954. num_goals++;
  9955. if (task4.length() > 0)
  9956. num_goals++;
  9957. packet->setArrayLengthByName("num_goals", num_goals);
  9958. for (int8 i = 0; i < num_goals; i++) {
  9959. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9960. }
  9961. if (goal1.length() > 0)
  9962. packet->setArrayDataByName("goal_text", goal1.c_str());
  9963. if (goal2.length() > 0)
  9964. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9965. if (goal3.length() > 0)
  9966. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9967. if (goal4.length() > 0)
  9968. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9969. packet->setSubArrayDataByName("task_text", task1.c_str());
  9970. if (task2.length() > 0)
  9971. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9972. if (task3.length() > 0)
  9973. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9974. if (task4.length() > 0)
  9975. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9976. packet->setDataByName("complete_sound", "click");
  9977. packet->setDataByName("signal", signal.c_str());
  9978. packet->setDataByName("voice_key1", voice_key1);
  9979. packet->setDataByName("voice_key2", voice_key2);
  9980. client->QueuePacket(packet->serialize());
  9981. safe_delete(packet);
  9982. }
  9983. return 0;
  9984. }
  9985. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9986. if (!lua_interface)
  9987. return 0;
  9988. Client* client = 0;
  9989. Spawn* player = lua_interface->GetSpawn(state);
  9990. string window = lua_interface->GetStringValue(state, 2);
  9991. int8 show = lua_interface->GetInt8Value(state, 3);
  9992. lua_interface->ResetFunctionStack(state);
  9993. if (!player) {
  9994. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9995. return 0;
  9996. }
  9997. if (!player->IsPlayer()) {
  9998. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9999. return 0;
  10000. }
  10001. else
  10002. client = ((Player*)player)->GetClient();
  10003. if (!client) {
  10004. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  10005. return 0;
  10006. }
  10007. if (window.length() == 0) {
  10008. lua_interface->LogError("LUA ShowWindow required parameters not given");
  10009. return 0;
  10010. }
  10011. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  10012. if (packet) {
  10013. packet->setDataByName("window", window.c_str());
  10014. packet->setDataByName("show", show);
  10015. client->QueuePacket(packet->serialize());
  10016. safe_delete(packet);
  10017. }
  10018. return 0;
  10019. }
  10020. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  10021. //See GameEvents.txt for options that can be used for this function
  10022. if (!lua_interface)
  10023. return 0;
  10024. Client* client = 0;
  10025. Spawn* player = lua_interface->GetSpawn(state);
  10026. string event_name = lua_interface->GetStringValue(state, 2);
  10027. int8 enabled = lua_interface->GetInt8Value(state, 3);
  10028. lua_interface->ResetFunctionStack(state);
  10029. if (!player || !player->IsPlayer()) {
  10030. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  10031. return 0;
  10032. }
  10033. client = ((Player*)player)->GetClient();
  10034. if (!client) {
  10035. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  10036. return 0;
  10037. }
  10038. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  10039. if (packet) {
  10040. packet->setDataByName("event_name", event_name.c_str());
  10041. packet->setDataByName("enabled", enabled);
  10042. client->QueuePacket(packet->serialize());
  10043. safe_delete(packet);
  10044. }
  10045. return 0;
  10046. }
  10047. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  10048. if (!lua_interface)
  10049. return 0;
  10050. Spawn* player = lua_interface->GetSpawn(state);
  10051. lua_interface->ResetFunctionStack(state);
  10052. if (player && player->IsPlayer()) {
  10053. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  10054. return 1;
  10055. }
  10056. return 0;
  10057. }
  10058. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  10059. if (!lua_interface)
  10060. return 0;
  10061. Spawn* player = lua_interface->GetSpawn(state);
  10062. int8 step = lua_interface->GetInt8Value(state, 2);
  10063. lua_interface->ResetFunctionStack(state);
  10064. if (player && player->IsPlayer() && step > 0) {
  10065. ((Player*)player)->SetTutorialStep(step);
  10066. }
  10067. return 0;
  10068. }
  10069. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  10070. if (!lua_interface)
  10071. return 0;
  10072. Client* client = 0;
  10073. Spawn* player = lua_interface->GetSpawn(state);
  10074. string window = lua_interface->GetStringValue(state, 2);
  10075. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  10076. lua_interface->ResetFunctionStack(state);
  10077. if (!player) {
  10078. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  10079. return 0;
  10080. }
  10081. if (!player->IsPlayer()) {
  10082. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  10083. return 0;
  10084. }
  10085. else
  10086. client = ((Player*)player)->GetClient();
  10087. if (!client) {
  10088. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  10089. return 0;
  10090. }
  10091. if (window.length() == 0) {
  10092. lua_interface->LogError("LUA FlashWindow required parameters not given");
  10093. return 0;
  10094. }
  10095. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  10096. if (packet) {
  10097. packet->setDataByName("window", window.c_str());
  10098. packet->setDataByName("flash_seconds", flash_seconds);
  10099. client->QueuePacket(packet->serialize());
  10100. safe_delete(packet);
  10101. }
  10102. return 0;
  10103. }
  10104. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  10105. if (!lua_interface)
  10106. return 0;
  10107. Spawn* spawn = lua_interface->GetSpawn(state);
  10108. Spawn* target = lua_interface->GetSpawn(state, 2);
  10109. lua_interface->ResetFunctionStack(state);
  10110. if (spawn && target)
  10111. return spawn->CheckLoS(target);
  10112. return 0;
  10113. }
  10114. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  10115. if (!lua_interface)
  10116. return 0;
  10117. Spawn* spawn = lua_interface->GetSpawn(state);
  10118. float x = lua_interface->GetFloatValue(state, 2);
  10119. float y = lua_interface->GetFloatValue(state, 3);
  10120. float z = lua_interface->GetFloatValue(state, 4);
  10121. lua_interface->ResetFunctionStack(state);
  10122. if (spawn)
  10123. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  10124. return 0;
  10125. }
  10126. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  10127. if (!lua_interface)
  10128. return 0;
  10129. ZoneServer* zone = lua_interface->GetZone(state);
  10130. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  10131. lua_interface->ResetFunctionStack(state);
  10132. if (zone)
  10133. zone->SetExpansionFlag(xpackFlag);
  10134. return 0;
  10135. }
  10136. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  10137. if (!lua_interface)
  10138. return 0;
  10139. ZoneServer* zone = lua_interface->GetZone(state);
  10140. lua_interface->ResetFunctionStack(state);
  10141. if (zone) {
  10142. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  10143. return 1;
  10144. }
  10145. return 0;
  10146. }
  10147. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  10148. if (!lua_interface)
  10149. return 0;
  10150. ZoneServer* zone = lua_interface->GetZone(state);
  10151. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  10152. lua_interface->ResetFunctionStack(state);
  10153. if (zone)
  10154. zone->SetHolidayFlag(holidayFlag);
  10155. return 0;
  10156. }
  10157. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  10158. if (!lua_interface)
  10159. return 0;
  10160. ZoneServer* zone = lua_interface->GetZone(state);
  10161. lua_interface->ResetFunctionStack(state);
  10162. if (zone) {
  10163. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  10164. return 1;
  10165. }
  10166. return 0;
  10167. }
  10168. int EQ2Emu_lua_SetCanBind(lua_State* state) {
  10169. if (!lua_interface)
  10170. return 0;
  10171. Spawn* player = lua_interface->GetSpawn(state);
  10172. ZoneServer* zone = player->GetZone();
  10173. bool canbind = lua_interface->GetInt32Value(state, 2);
  10174. lua_interface->ResetFunctionStack(state);
  10175. if (zone)
  10176. zone->SetCanBind(canbind);
  10177. return 0;
  10178. }
  10179. int EQ2Emu_lua_GetCanBind(lua_State* state) {
  10180. if (!lua_interface)
  10181. return 0;
  10182. Spawn* player = lua_interface->GetSpawn(state);
  10183. ZoneServer* zone = player->GetZone();
  10184. lua_interface->ResetFunctionStack(state);
  10185. if (zone) {
  10186. lua_interface->SetInt32Value(state, zone->GetCanBind());
  10187. return 1;
  10188. }
  10189. return 0;
  10190. }
  10191. int EQ2Emu_lua_SetCanGate(lua_State* state) {
  10192. if (!lua_interface)
  10193. return 0;
  10194. Spawn* player = lua_interface->GetSpawn(state);
  10195. ZoneServer* zone = player->GetZone();
  10196. bool cangate = lua_interface->GetInt32Value(state, 2);
  10197. lua_interface->ResetFunctionStack(state);
  10198. if (zone)
  10199. zone->SetCanGate(cangate);
  10200. return 0;
  10201. }
  10202. int EQ2Emu_lua_GetCanGate(lua_State* state) {
  10203. if (!lua_interface)
  10204. return 0;
  10205. Spawn* player = lua_interface->GetSpawn(state);
  10206. ZoneServer* zone = player->GetZone();
  10207. lua_interface->ResetFunctionStack(state);
  10208. if (zone) {
  10209. lua_interface->SetInt32Value(state, zone->GetCanGate());
  10210. return 1;
  10211. }
  10212. return 0;
  10213. }
  10214. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  10215. if (!lua_interface)
  10216. return 0;
  10217. Spawn* spawn = lua_interface->GetSpawn(state);
  10218. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  10219. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  10220. float distance = lua_interface->GetFloatValue(state, 4);
  10221. string in_range_function = lua_interface->GetStringValue(state, 5);
  10222. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  10223. lua_interface->ResetFunctionStack(state);
  10224. if (spawn && distance > 0 && in_range_function.length() > 0)
  10225. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  10226. return 0;
  10227. }
  10228. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  10229. if (!lua_interface)
  10230. return 0;
  10231. Spawn* spawn = lua_interface->GetSpawn(state);
  10232. Spawn* target = lua_interface->GetSpawn(state, 2);
  10233. lua_interface->ResetFunctionStack(state);
  10234. if (spawn && target)
  10235. {
  10236. if (spawn->IsPlayer() && target->IsEntity())
  10237. {
  10238. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  10239. return 1;
  10240. }
  10241. else if (spawn->IsEntity() && target->IsEntity())
  10242. {
  10243. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  10244. return 1;
  10245. }
  10246. }
  10247. return 0;
  10248. }
  10249. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  10250. if (!lua_interface)
  10251. return 0;
  10252. Spawn* spawn = lua_interface->GetSpawn(state);
  10253. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10254. lua_interface->ResetFunctionStack(state);
  10255. if (spawn && spawn->IsEntity())
  10256. {
  10257. ((Entity*)spawn)->SetSeeInvisSpell(val);
  10258. if (spawn->IsPlayer())
  10259. {
  10260. Client* client = ((Player*)spawn)->GetClient();
  10261. if (client)
  10262. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  10263. }
  10264. }
  10265. return 0;
  10266. }
  10267. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  10268. if (!lua_interface)
  10269. return 0;
  10270. Spawn* spawn = lua_interface->GetSpawn(state);
  10271. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10272. lua_interface->ResetFunctionStack(state);
  10273. if (spawn && spawn->IsEntity())
  10274. {
  10275. ((Entity*)spawn)->SetSeeHideSpell(val);
  10276. if (spawn->IsPlayer())
  10277. {
  10278. Client* client = ((Player*)spawn)->GetClient();
  10279. if (client)
  10280. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  10281. }
  10282. }
  10283. return 0;
  10284. }
  10285. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  10286. {
  10287. if (!lua_interface)
  10288. return 0;
  10289. Spawn* player = lua_interface->GetSpawn(state);
  10290. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  10291. string command = lua_interface->GetStringValue(state, 3);
  10292. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10293. lua_interface->ResetFunctionStack(state);
  10294. if (spawn && player && player->IsPlayer())
  10295. {
  10296. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10297. bool res = false;
  10298. if (cmd)
  10299. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  10300. lua_interface->SetBooleanValue(state, res);
  10301. return 1;
  10302. }
  10303. return 0;
  10304. }
  10305. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  10306. {
  10307. if (!lua_interface)
  10308. return 0;
  10309. Spawn* spawn = lua_interface->GetSpawn(state);
  10310. int32 charID = lua_interface->GetInt32Value(state, 2);
  10311. string command = lua_interface->GetStringValue(state, 3);
  10312. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10313. lua_interface->ResetFunctionStack(state);
  10314. if (spawn && charID)
  10315. {
  10316. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10317. bool res = false;
  10318. if (cmd)
  10319. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  10320. lua_interface->SetBooleanValue(state, res);
  10321. return 1;
  10322. }
  10323. return 0;
  10324. }
  10325. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  10326. {
  10327. if (!lua_interface)
  10328. return 0;
  10329. Spawn* spawn = lua_interface->GetSpawn(state);
  10330. string command = lua_interface->GetStringValue(state, 2);
  10331. lua_interface->ResetFunctionStack(state);
  10332. if (spawn && command.length() > 0)
  10333. spawn->RemovePrimaryEntityCommand(command.c_str());
  10334. return 0;
  10335. }
  10336. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  10337. if (!lua_interface)
  10338. return 0;
  10339. Spawn* spawn = lua_interface->GetSpawn(state);
  10340. float distance = lua_interface->GetFloatValue(state, 2);
  10341. string command = lua_interface->GetStringValue(state, 3);
  10342. Spawn* player = lua_interface->GetSpawn(state, 4);
  10343. lua_interface->ResetFunctionStack(state);
  10344. if (spawn) {
  10345. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  10346. }
  10347. return 0;
  10348. }
  10349. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  10350. if (!lua_interface)
  10351. return 0;
  10352. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10353. Spawn* spawn = lua_interface->GetSpawn(state);
  10354. Spawn* player = lua_interface->GetSpawn(state, 2);
  10355. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  10356. lua_interface->ResetFunctionStack(state);
  10357. if (spawn && player && transport_id && player->IsPlayer()) {
  10358. Client* client = 0;
  10359. if (player && player->IsPlayer())
  10360. client = ((Player*)player)->GetClient();
  10361. if (!client)
  10362. return 0;
  10363. vector<TransportDestination*> destinations;
  10364. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  10365. if (destinations.size())
  10366. {
  10367. client->SetTemporaryTransportID(transport_id);
  10368. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  10369. }
  10370. else
  10371. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  10372. }
  10373. return 0;
  10374. }
  10375. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  10376. if (!lua_interface)
  10377. return 0;
  10378. Spawn* player = lua_interface->GetSpawn(state);
  10379. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  10380. lua_interface->ResetFunctionStack(state);
  10381. if (player && player->IsPlayer()) {
  10382. Client* client = 0;
  10383. if (player && player->IsPlayer())
  10384. client = ((Player*)player)->GetClient();
  10385. if (!client)
  10386. return 0;
  10387. client->SetTemporaryTransportID(transport_id);
  10388. }
  10389. return 0;
  10390. }
  10391. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  10392. if (!lua_interface)
  10393. return 0;
  10394. Spawn* player = lua_interface->GetSpawn(state);
  10395. lua_interface->ResetFunctionStack(state);
  10396. if (player && player->IsPlayer()) {
  10397. Client* client = 0;
  10398. if (player && player->IsPlayer())
  10399. client = ((Player*)player)->GetClient();
  10400. if (!client)
  10401. return 0;
  10402. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  10403. return 1;
  10404. }
  10405. return 0;
  10406. }
  10407. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  10408. if (!lua_interface)
  10409. return 0;
  10410. Spawn* spawn = lua_interface->GetSpawn(state);
  10411. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  10412. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10413. if (!spawn) {
  10414. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10415. return 0;
  10416. }
  10417. if (!spawn->IsEntity()) {
  10418. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10419. return 0;
  10420. }
  10421. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  10422. {
  10423. lua_interface->LogError("%s: LUA SetAlignment command error: alignment value beyond supported min: %i and max: %i", lua_interface->GetScriptName(state), SCHAR_MIN, SCHAR_MAX);
  10424. return 0;
  10425. }
  10426. lua_interface->ResetFunctionStack(state);
  10427. if (spell && spell->targets.size() > 0) {
  10428. ZoneServer* zone = spell->caster->GetZone();
  10429. for (int8 i = 0; i < spell->targets.size(); i++) {
  10430. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  10431. if (target && target->IsEntity()) {
  10432. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  10433. if (target->IsPlayer())
  10434. ((Player*)target)->SetCharSheetChanged(true);
  10435. }
  10436. }
  10437. }
  10438. else {
  10439. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  10440. if (spawn->IsPlayer())
  10441. ((Player*)spawn)->SetCharSheetChanged(true);
  10442. }
  10443. return 0;
  10444. }
  10445. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  10446. if (!lua_interface)
  10447. return 0;
  10448. Spawn* spawn = lua_interface->GetSpawn(state);
  10449. lua_interface->ResetFunctionStack(state);
  10450. if (!spawn) {
  10451. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10452. return 0;
  10453. }
  10454. if (!spawn->IsEntity()) {
  10455. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10456. return 0;
  10457. }
  10458. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  10459. return 1;
  10460. }
  10461. int EQ2Emu_lua_GetSpell(lua_State* state) {
  10462. if (!lua_interface)
  10463. return 0;
  10464. int32 spell_id = lua_interface->GetInt32Value(state);
  10465. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  10466. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  10467. if (spell_id > 0) {
  10468. if (spell_tier == 0)
  10469. spell_tier = 1;
  10470. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  10471. if(!spell) {
  10472. lua_interface->LogError("%s: GetSpell: Failed, spell id %u spell tier %u does not exist.", lua_interface->GetScriptName(state), spell_id, spell_tier);
  10473. lua_interface->ResetFunctionStack(state);
  10474. return 0;
  10475. }
  10476. LuaSpell* lua_spell = 0;
  10477. if(custom_lua_script.size() > 0)
  10478. {
  10479. // attempt to load the custom script since it isn't already loaded
  10480. // we will re-obtain the lua_spell further below
  10481. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  10482. {
  10483. LogWrite(LUA__WARNING, 0, "LUA", "GetSpell(%u, %u, '%s'), custom lua script not loaded, attempting to load.", spell_id, spell_tier, custom_lua_script.c_str());
  10484. lua_interface->LoadLuaSpell(custom_lua_script);
  10485. }
  10486. }
  10487. else
  10488. custom_lua_script = spell->GetSpellData()->lua_script;
  10489. if (!lua_spell && lua_interface)
  10490. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  10491. lua_interface->ResetFunctionStack(state);
  10492. if (!lua_spell)
  10493. {
  10494. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  10495. return 0;
  10496. }
  10497. lua_spell->spell = new Spell(spell);
  10498. lua_interface->AddCustomSpell(lua_spell);
  10499. lua_interface->SetSpellValue(state, lua_spell);
  10500. return 1;
  10501. }
  10502. return 0;
  10503. }
  10504. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  10505. if (!lua_interface)
  10506. return 0;
  10507. LuaSpell* spell = lua_interface->GetSpell(state);
  10508. string field = lua_interface->GetStringValue(state, 2);
  10509. lua_interface->ResetFunctionStack(state);
  10510. if (!spell) {
  10511. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  10512. return 0;
  10513. }
  10514. if (!spell->spell || !spell->spell->GetSpellData()) {
  10515. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  10516. return 0;
  10517. }
  10518. boost::to_lower(field);
  10519. return spell->spell->GetSpellData(state, field);
  10520. }
  10521. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  10522. if (!lua_interface)
  10523. return 0;
  10524. LuaSpell* spell = lua_interface->GetSpell(state);
  10525. string field = lua_interface->GetStringValue(state, 2);
  10526. lua_interface->ResetFunctionStack(state);
  10527. int8 fieldArg = 3; // field value after the initial set
  10528. if (!spell) {
  10529. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  10530. return 0;
  10531. }
  10532. if (!spell->spell || !spell->spell->GetSpellData()) {
  10533. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  10534. return 0;
  10535. }
  10536. boost::to_lower(field);
  10537. bool valSet = false;
  10538. spell->spell->SetSpellData(state, field, fieldArg);
  10539. return valSet;
  10540. }
  10541. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10542. if (!lua_interface)
  10543. return 0;
  10544. LuaSpell* spell = lua_interface->GetSpell(state);
  10545. int8 idx = lua_interface->GetInt32Value(state, 2);
  10546. if (!spell) {
  10547. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10548. return 0;
  10549. }
  10550. if (!spell->spell || !spell->spell->GetSpellData()) {
  10551. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10552. return 0;
  10553. }
  10554. if (spell->spell->lua_data.size() <= idx)
  10555. {
  10556. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10557. return 0;
  10558. }
  10559. bool setVal = true;
  10560. LUAData* data = spell->spell->lua_data[idx];
  10561. switch (data->type)
  10562. {
  10563. case 0:
  10564. {
  10565. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10566. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10567. data->int_value = value;
  10568. data->int_value2 = value2;
  10569. break;
  10570. }
  10571. case 1:
  10572. {
  10573. float value = lua_interface->GetFloatValue(state, 3);
  10574. float value2 = lua_interface->GetFloatValue(state, 4);
  10575. data->float_value = value;
  10576. data->float_value2 = value2;
  10577. break;
  10578. }
  10579. case 2:
  10580. {
  10581. bool value = lua_interface->GetBooleanValue(state, 3);
  10582. data->bool_value = value;
  10583. break;
  10584. }
  10585. case 3:
  10586. {
  10587. string value = lua_interface->GetStringValue(state, 3);
  10588. string value2 = lua_interface->GetStringValue(state, 4);
  10589. data->string_value = value;
  10590. data->string_value2 = value2;
  10591. break;
  10592. }
  10593. default:
  10594. setVal = false;
  10595. }
  10596. lua_interface->ResetFunctionStack(state);
  10597. return setVal;
  10598. }
  10599. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10600. if (!lua_interface)
  10601. return 0;
  10602. LuaSpell* spell = lua_interface->GetSpell(state);
  10603. int8 idx = lua_interface->GetInt32Value(state, 2);
  10604. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10605. lua_interface->ResetFunctionStack(state);
  10606. if (!spell) {
  10607. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10608. return 0;
  10609. }
  10610. if (!spell->spell || !spell->spell->GetSpellData()) {
  10611. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10612. return 0;
  10613. }
  10614. if (spell->spell->lua_data.size() <= idx)
  10615. {
  10616. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10617. return 0;
  10618. }
  10619. bool setVal = true;
  10620. LUAData* data = spell->spell->lua_data[idx];
  10621. switch (data->type)
  10622. {
  10623. case 0:
  10624. {
  10625. if(!secondfield)
  10626. lua_interface->SetSInt32Value(state, data->int_value);
  10627. else
  10628. lua_interface->SetSInt32Value(state, data->int_value2);
  10629. break;
  10630. }
  10631. case 1:
  10632. {
  10633. if (!secondfield)
  10634. lua_interface->SetFloatValue(state, data->float_value);
  10635. else
  10636. lua_interface->SetFloatValue(state, data->float_value2);
  10637. break;
  10638. }
  10639. case 2:
  10640. {
  10641. lua_interface->SetBooleanValue(state, data->bool_value);
  10642. break;
  10643. }
  10644. case 3:
  10645. {
  10646. if (!secondfield)
  10647. lua_interface->SetStringValue(state, data->string_value.c_str());
  10648. else
  10649. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10650. break;
  10651. }
  10652. default:
  10653. setVal = false;
  10654. }
  10655. return setVal;
  10656. }
  10657. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10658. if (!lua_interface)
  10659. return 0;
  10660. LuaSpell* spell = lua_interface->GetSpell(state);
  10661. int8 idx = lua_interface->GetInt32Value(state, 2);
  10662. string field = lua_interface->GetStringValue(state, 3);
  10663. boost::to_lower(field);
  10664. if (!spell) {
  10665. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10666. lua_interface->ResetFunctionStack(state);
  10667. return 0;
  10668. }
  10669. if (!spell->spell || !spell->spell->GetSpellData()) {
  10670. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10671. lua_interface->ResetFunctionStack(state);
  10672. return 0;
  10673. }
  10674. if (spell->spell->effects.size() <= idx)
  10675. {
  10676. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10677. lua_interface->ResetFunctionStack(state);
  10678. return 0;
  10679. }
  10680. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10681. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10682. if (field == "description")
  10683. effect->description = string(lua_interface->GetStringValue(state, 4));
  10684. else if (field == "bullet")
  10685. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10686. else if (field == "percentage")
  10687. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10688. else { // no match
  10689. lua_interface->ResetFunctionStack(state);
  10690. return 0;
  10691. }
  10692. lua_interface->ResetFunctionStack(state);
  10693. return 1;
  10694. }
  10695. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10696. if (!lua_interface)
  10697. return 0;
  10698. LuaSpell* spell = lua_interface->GetSpell(state);
  10699. int8 idx = lua_interface->GetInt32Value(state, 2);
  10700. string field = lua_interface->GetStringValue(state, 3);
  10701. lua_interface->ResetFunctionStack(state);
  10702. boost::to_lower(field);
  10703. if (!spell) {
  10704. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10705. return 0;
  10706. }
  10707. if (!spell->spell || !spell->spell->GetSpellData()) {
  10708. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10709. return 0;
  10710. }
  10711. if (spell->spell->effects.size() <= idx)
  10712. {
  10713. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10714. return 0;
  10715. }
  10716. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10717. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10718. if (field == "description")
  10719. lua_interface->SetStringValue(state, effect->description.c_str());
  10720. else if (field == "bullet")
  10721. lua_interface->SetInt32Value(state, effect->subbullet);
  10722. else if (field == "percentage")
  10723. lua_interface->SetInt32Value(state, effect->percentage);
  10724. else // no match
  10725. return 0;
  10726. return 1;
  10727. }
  10728. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10729. if (!lua_interface)
  10730. return 0;
  10731. LuaSpell* spell = lua_interface->GetSpell(state);
  10732. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10733. Spawn* target = lua_interface->GetSpawn(state, 3);
  10734. lua_interface->ResetFunctionStack(state);
  10735. if (!target) {
  10736. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10737. return 0;
  10738. }
  10739. if (!target->IsEntity()) {
  10740. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10741. return 0;
  10742. }
  10743. if (!spell) {
  10744. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10745. return 0;
  10746. }
  10747. if (caster && !caster->IsEntity()) {
  10748. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10749. return 0;
  10750. }
  10751. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10752. return 0;
  10753. }
  10754. int EQ2Emu_lua_InWater(lua_State* state) {
  10755. if (!lua_interface)
  10756. return 0;
  10757. Spawn* spawn = lua_interface->GetSpawn(state);
  10758. lua_interface->ResetFunctionStack(state);
  10759. if (spawn) {
  10760. lua_interface->SetBooleanValue(state, spawn->InWater());
  10761. return 1;
  10762. }
  10763. return 0;
  10764. }
  10765. int EQ2Emu_lua_InLava(lua_State* state) {
  10766. if (!lua_interface)
  10767. return 0;
  10768. Spawn* spawn = lua_interface->GetSpawn(state);
  10769. lua_interface->ResetFunctionStack(state);
  10770. if (spawn) {
  10771. lua_interface->SetBooleanValue(state, spawn->InLava());
  10772. return 1;
  10773. }
  10774. return 0;
  10775. }
  10776. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  10777. if (!lua_interface)
  10778. return 0;
  10779. Spawn* attacker = lua_interface->GetSpawn(state);
  10780. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10781. int8 type = lua_interface->GetInt8Value(state, 3);
  10782. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10783. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10784. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10785. string spell_name = lua_interface->GetStringValue(state, 7);
  10786. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10787. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10788. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10789. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10790. lua_interface->ResetFunctionStack(state);
  10791. if (!attacker) {
  10792. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10793. return 0;
  10794. }
  10795. if (!attacker->IsEntity()) {
  10796. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10797. return 0;
  10798. }
  10799. if (!victim) {
  10800. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10801. return 0;
  10802. }
  10803. if (!victim->IsEntity()) {
  10804. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10805. return 0;
  10806. }
  10807. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  10808. return 0;
  10809. }
  10810. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  10811. if (!lua_interface)
  10812. return 0;
  10813. Spawn* spawn = lua_interface->GetSpawn(state);
  10814. lua_interface->ResetFunctionStack(state);
  10815. if (spawn) {
  10816. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  10817. return 1;
  10818. }
  10819. return 0;
  10820. }
  10821. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  10822. if (!lua_interface)
  10823. return 0;
  10824. Spawn* spawn = lua_interface->GetSpawn(state);
  10825. bool invul = lua_interface->GetBooleanValue(state, 2);
  10826. lua_interface->ResetFunctionStack(state);
  10827. if (spawn) {
  10828. spawn->SetInvulnerable(invul);
  10829. }
  10830. return 0;
  10831. }
  10832. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  10833. if (!lua_interface)
  10834. return 0;
  10835. string category = lua_interface->GetStringValue(state);
  10836. string name = lua_interface->GetStringValue(state, 2);
  10837. lua_interface->ResetFunctionStack(state);
  10838. Rule *ret = 0;
  10839. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10840. lua_interface->SetBooleanValue(state, ret->GetBool());
  10841. return 1;
  10842. }
  10843. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10844. return 0;
  10845. }
  10846. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  10847. if (!lua_interface)
  10848. return 0;
  10849. string category = lua_interface->GetStringValue(state);
  10850. string name = lua_interface->GetStringValue(state, 2);
  10851. lua_interface->ResetFunctionStack(state);
  10852. Rule *ret = 0;
  10853. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10854. lua_interface->SetInt32Value(state, ret->GetInt32());
  10855. return 1;
  10856. }
  10857. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10858. return 0;
  10859. }
  10860. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  10861. if (!lua_interface)
  10862. return 0;
  10863. string category = lua_interface->GetStringValue(state);
  10864. string name = lua_interface->GetStringValue(state, 2);
  10865. lua_interface->ResetFunctionStack(state);
  10866. Rule *ret = 0;
  10867. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10868. lua_interface->SetFloatValue(state, ret->GetFloat());
  10869. return 1;
  10870. }
  10871. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10872. return 0;
  10873. }
  10874. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  10875. if (!lua_interface)
  10876. return 0;
  10877. Spawn* spawn = lua_interface->GetSpawn(state);
  10878. string type = lua_interface->GetStringValue(state, 2);
  10879. lua_interface->ResetFunctionStack(state);
  10880. if (spawn) {
  10881. int res = 1;
  10882. boost::to_lower(type);
  10883. if(type == "assigned_aa")
  10884. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10885. else if ( type == "unassigned_aa")
  10886. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10887. else if ( type == "assigned_tradeskill_aa")
  10888. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10889. else if ( type == "unassigned_tradeskill_aa")
  10890. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10891. else if ( type == "assigned_prestige_aa")
  10892. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10893. else if ( type == "unassigned_prestige_aa")
  10894. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10895. else if ( type == "assigned_tradeskill_prestige_aa")
  10896. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10897. else if ( type == "unassigned_tradeskill_prestige_aa")
  10898. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10899. else
  10900. res = 0;
  10901. return res;
  10902. }
  10903. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10904. return 0;
  10905. }
  10906. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10907. if (!lua_interface)
  10908. return 0;
  10909. Spawn* spawn = lua_interface->GetSpawn(state);
  10910. string type = lua_interface->GetStringValue(state, 2);
  10911. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10912. lua_interface->ResetFunctionStack(state);
  10913. if (spawn) {
  10914. boost::to_lower(type);
  10915. if(type == "assigned_aa")
  10916. spawn->SetAssignedAA((sint16)value);
  10917. else if ( type == "unassigned_aa")
  10918. spawn->SetUnassignedAA((sint16)value);
  10919. else if ( type == "assigned_tradeskill_aa")
  10920. spawn->SetTradeskillAA((sint16)value);
  10921. else if ( type == "unassigned_tradeskill_aa")
  10922. spawn->SetUnassignedTradeskillAA((sint16)value);
  10923. else if ( type == "assigned_prestige_aa")
  10924. spawn->SetPrestigeAA((sint16)value);
  10925. else if ( type == "unassigned_prestige_aa")
  10926. spawn->SetUnassignedPrestigeAA((sint16)value);
  10927. else if ( type == "assigned_tradeskill_prestige_aa")
  10928. spawn->SetTradeskillPrestigeAA((sint16)value);
  10929. else if ( type == "unassigned_tradeskill_prestige_aa")
  10930. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10931. if(spawn->IsPlayer())
  10932. ((Player*)spawn)->SetCharSheetChanged(true);
  10933. }
  10934. return 0;
  10935. }
  10936. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10937. if (!lua_interface)
  10938. return 0;
  10939. string titleName = lua_interface->GetStringValue(state);
  10940. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10941. lua_interface->ResetFunctionStack(state);
  10942. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10943. lua_interface->SetSInt32Value(state, index);
  10944. return 1;
  10945. }
  10946. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10947. if (!lua_interface)
  10948. return 0;
  10949. Spawn* spawn = lua_interface->GetSpawn(state);
  10950. string titleName = lua_interface->GetStringValue(state, 2);
  10951. lua_interface->ResetFunctionStack(state);
  10952. if(!spawn->IsPlayer())
  10953. {
  10954. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10955. lua_interface->SetSInt32Value(state, -1);
  10956. return 1;
  10957. }
  10958. Player* player = (Player*)spawn;
  10959. // check if player already has the title, don't need to add twice
  10960. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10961. if ( playerHasTitle)
  10962. {
  10963. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10964. return 1;
  10965. }
  10966. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10967. if(!title)
  10968. {
  10969. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10970. lua_interface->SetSInt32Value(state, -1);
  10971. return 1;
  10972. }
  10973. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10974. if(returnIdx < 0)
  10975. {
  10976. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10977. }
  10978. lua_interface->SetSInt32Value(state, returnIdx);
  10979. player->GetClient()->SendTitleUpdate();
  10980. return 1;
  10981. }
  10982. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10983. if (!lua_interface)
  10984. return 0;
  10985. Spawn* spawn = lua_interface->GetSpawn(state);
  10986. string titleName = lua_interface->GetStringValue(state, 2);
  10987. lua_interface->ResetFunctionStack(state);
  10988. if(!spawn->IsPlayer())
  10989. {
  10990. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10991. return 0;
  10992. }
  10993. Player* player = (Player*)spawn;
  10994. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10995. if(!title)
  10996. {
  10997. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10998. return 0;
  10999. }
  11000. if(title->GetPrefix())
  11001. {
  11002. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title with name '%s' is not valid as a suffix, only prefix", lua_interface->GetScriptName(state), titleName.c_str());
  11003. return 0;
  11004. }
  11005. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  11006. player->GetClient()->SendTitleUpdate();
  11007. return 1;
  11008. }
  11009. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  11010. if (!lua_interface)
  11011. return 0;
  11012. Spawn* spawn = lua_interface->GetSpawn(state);
  11013. string titleName = lua_interface->GetStringValue(state, 2);
  11014. lua_interface->ResetFunctionStack(state);
  11015. if(!spawn->IsPlayer())
  11016. {
  11017. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11018. return 0;
  11019. }
  11020. Player* player = (Player*)spawn;
  11021. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11022. if(!title)
  11023. {
  11024. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11025. return 0;
  11026. }
  11027. if(!title->GetPrefix())
  11028. {
  11029. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title with name '%s' is not valid as a prefix, only suffix", lua_interface->GetScriptName(state), titleName.c_str());
  11030. return 0;
  11031. }
  11032. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  11033. player->GetClient()->SendTitleUpdate();
  11034. return 1;
  11035. }
  11036. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  11037. if (!lua_interface)
  11038. return 0;
  11039. Spawn* spawn = lua_interface->GetSpawn(state);
  11040. lua_interface->ResetFunctionStack(state);
  11041. if(!spawn->IsPlayer())
  11042. {
  11043. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11044. return 0;
  11045. }
  11046. Player* player = (Player*)spawn;
  11047. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  11048. player->GetClient()->SendTitleUpdate();
  11049. return 1;
  11050. }
  11051. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  11052. if (!lua_interface)
  11053. return 0;
  11054. Spawn* spawn = lua_interface->GetSpawn(state);
  11055. lua_interface->ResetFunctionStack(state);
  11056. if(!spawn->IsPlayer())
  11057. {
  11058. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11059. return 0;
  11060. }
  11061. Player* player = (Player*)spawn;
  11062. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  11063. player->GetClient()->SendTitleUpdate();
  11064. return 1;
  11065. }
  11066. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  11067. if (!lua_interface)
  11068. return 0;
  11069. Spawn* spawn = lua_interface->GetSpawn(state);
  11070. string field = lua_interface->GetStringValue(state, 2);
  11071. lua_interface->ResetFunctionStack(state);
  11072. if(!spawn || !spawn->IsEntity())
  11073. {
  11074. lua_interface->LogError("%s: LUA GetInfoStructString command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11075. return 0;
  11076. }
  11077. Entity* ent = (Entity*)spawn;
  11078. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  11079. return 1;
  11080. }
  11081. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  11082. if (!lua_interface)
  11083. return 0;
  11084. Spawn* spawn = lua_interface->GetSpawn(state);
  11085. string field = lua_interface->GetStringValue(state, 2);
  11086. lua_interface->ResetFunctionStack(state);
  11087. if(!spawn || !spawn->IsEntity())
  11088. {
  11089. lua_interface->LogError("%s: LUA GetInfoStructUInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11090. return 0;
  11091. }
  11092. Entity* ent = (Entity*)spawn;
  11093. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  11094. return 1;
  11095. }
  11096. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  11097. if (!lua_interface)
  11098. return 0;
  11099. Spawn* spawn = lua_interface->GetSpawn(state);
  11100. string field = lua_interface->GetStringValue(state, 2);
  11101. lua_interface->ResetFunctionStack(state);
  11102. if(!spawn || !spawn->IsEntity())
  11103. {
  11104. lua_interface->LogError("%s: LUA GetInfoStructSInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11105. return 0;
  11106. }
  11107. Entity* ent = (Entity*)spawn;
  11108. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  11109. return 1;
  11110. }
  11111. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  11112. if (!lua_interface)
  11113. return 0;
  11114. Spawn* spawn = lua_interface->GetSpawn(state);
  11115. string field = lua_interface->GetStringValue(state, 2);
  11116. lua_interface->ResetFunctionStack(state);
  11117. if(!spawn || !spawn->IsEntity())
  11118. {
  11119. lua_interface->LogError("%s: LUA GetInfoStructFloat command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11120. return 0;
  11121. }
  11122. Entity* ent = (Entity*)spawn;
  11123. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  11124. return 1;
  11125. }
  11126. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  11127. if (!lua_interface)
  11128. return 0;
  11129. Spawn* spawn = lua_interface->GetSpawn(state);
  11130. string field = lua_interface->GetStringValue(state, 2);
  11131. string value = lua_interface->GetStringValue(state, 3);
  11132. lua_interface->ResetFunctionStack(state);
  11133. if(!spawn || !spawn->IsEntity())
  11134. {
  11135. lua_interface->LogError("%s: LUA SetInfoStructString command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11136. return 0;
  11137. }
  11138. Entity* ent = (Entity*)spawn;
  11139. bool set_ = ent->SetInfoStructString(field, value);
  11140. lua_interface->SetBooleanValue(state, set_);
  11141. return 1;
  11142. }
  11143. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  11144. if (!lua_interface)
  11145. return 0;
  11146. Spawn* spawn = lua_interface->GetSpawn(state);
  11147. string field = lua_interface->GetStringValue(state, 2);
  11148. int64 value = lua_interface->GetInt64Value(state, 3);
  11149. lua_interface->ResetFunctionStack(state);
  11150. if(!spawn || !spawn->IsEntity())
  11151. {
  11152. lua_interface->LogError("%s: LUA SetInfoStructUInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11153. return 0;
  11154. }
  11155. Entity* ent = (Entity*)spawn;
  11156. bool set_ = ent->SetInfoStructUInt(field, value);
  11157. lua_interface->SetBooleanValue(state, set_);
  11158. return 1;
  11159. }
  11160. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  11161. if (!lua_interface)
  11162. return 0;
  11163. Spawn* spawn = lua_interface->GetSpawn(state);
  11164. string field = lua_interface->GetStringValue(state, 2);
  11165. sint64 value = lua_interface->GetSInt64Value(state, 3);
  11166. lua_interface->ResetFunctionStack(state);
  11167. if(!spawn || !spawn->IsEntity())
  11168. {
  11169. lua_interface->LogError("%s: LUA SetInfoStructSInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11170. return 0;
  11171. }
  11172. Entity* ent = (Entity*)spawn;
  11173. bool set_ = ent->SetInfoStructSInt(field, value);
  11174. lua_interface->SetBooleanValue(state, set_);
  11175. return 1;
  11176. }
  11177. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  11178. if (!lua_interface)
  11179. return 0;
  11180. Spawn* spawn = lua_interface->GetSpawn(state);
  11181. string field = lua_interface->GetStringValue(state, 2);
  11182. float value = lua_interface->GetFloatValue(state, 3);
  11183. lua_interface->ResetFunctionStack(state);
  11184. if(!spawn || !spawn->IsEntity())
  11185. {
  11186. lua_interface->LogError("%s: LUA SetInfoStructFloat command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
  11187. return 0;
  11188. }
  11189. Entity* ent = (Entity*)spawn;
  11190. bool set_ = ent->SetInfoStructFloat(field, value);
  11191. lua_interface->SetBooleanValue(state, set_);
  11192. return 1;
  11193. }
  11194. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  11195. if (!lua_interface)
  11196. return 0;
  11197. Spawn* spawn = lua_interface->GetSpawn(state);
  11198. bool value = lua_interface->GetBooleanValue(state, 2);
  11199. lua_interface->ResetFunctionStack(state);
  11200. if(!spawn || !spawn->IsPlayer())
  11201. {
  11202. lua_interface->LogError("%s: LUA SetCharSheetChanged command error: spawn is not valid, either does not exist or is not a player", lua_interface->GetScriptName(state));
  11203. return 0;
  11204. }
  11205. ((Player*)spawn)->SetCharSheetChanged(value);
  11206. return 0;
  11207. }
  11208. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  11209. if (!lua_interface)
  11210. return 0;
  11211. Spawn* spawn = lua_interface->GetSpawn(state);
  11212. std::string fromName = lua_interface->GetStringValue(state, 2);
  11213. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11214. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11215. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11216. int32 copper = lua_interface->GetInt32Value(state, 6);
  11217. int32 silver = lua_interface->GetInt32Value(state, 7);
  11218. int32 gold = lua_interface->GetInt32Value(state, 8);
  11219. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11220. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11221. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11222. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11223. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11224. lua_interface->ResetFunctionStack(state);
  11225. if(!spawn || !spawn->IsPlayer())
  11226. {
  11227. lua_interface->LogError("%s: LUA AddPlayerMail command error: spawn is not valid, either does not exist or is not a player", lua_interface->GetScriptName(state));
  11228. lua_interface->SetBooleanValue(state, false);
  11229. return 1;
  11230. }
  11231. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11232. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11233. lua_interface->SetBooleanValue(state, true);
  11234. return 1;
  11235. }
  11236. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  11237. if (!lua_interface)
  11238. return 0;
  11239. int32 char_id = lua_interface->GetInt32Value(state);
  11240. std::string fromName = lua_interface->GetStringValue(state, 2);
  11241. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11242. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11243. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11244. int32 copper = lua_interface->GetInt32Value(state, 6);
  11245. int32 silver = lua_interface->GetInt32Value(state, 7);
  11246. int32 gold = lua_interface->GetInt32Value(state, 8);
  11247. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11248. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11249. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11250. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11251. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11252. lua_interface->ResetFunctionStack(state);
  11253. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11254. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11255. lua_interface->SetBooleanValue(state, true);
  11256. return 1;
  11257. }
  11258. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  11259. Spawn* widget;
  11260. if (lua_interface) {
  11261. widget = lua_interface->GetSpawn(state);
  11262. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  11263. lua_interface->ResetFunctionStack(state);
  11264. if (widget && widget->IsWidget())
  11265. {
  11266. ((Widget*)widget)->OpenDoor();
  11267. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  11268. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11269. }
  11270. else
  11271. lua_interface->LogError("%s: LUA OpenDoor command error: spawn is not valid, either does not exist or is not a widget", lua_interface->GetScriptName(state));
  11272. }
  11273. return 0;
  11274. }
  11275. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  11276. Spawn* widget;
  11277. if (lua_interface) {
  11278. widget = lua_interface->GetSpawn(state);
  11279. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  11280. lua_interface->ResetFunctionStack(state);
  11281. if (widget && widget->IsWidget())
  11282. {
  11283. ((Widget*)widget)->CloseDoor();
  11284. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  11285. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11286. }
  11287. else
  11288. lua_interface->LogError("%s: LUA CloseDoor command error: spawn is not valid, either does not exist or is not a widget", lua_interface->GetScriptName(state));
  11289. }
  11290. return 0;
  11291. }
  11292. int EQ2Emu_lua_IsOpen(lua_State* state) {
  11293. if (!lua_interface)
  11294. return 0;
  11295. Spawn* widget = lua_interface->GetSpawn(state);
  11296. lua_interface->ResetFunctionStack(state);
  11297. if (widget && widget->IsWidget())
  11298. {
  11299. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  11300. return 1;
  11301. }
  11302. return 0;
  11303. }
  11304. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  11305. if (!lua_interface)
  11306. return 0;
  11307. sint32 min = lua_interface->GetSInt32Value(state);
  11308. sint32 max = lua_interface->GetSInt32Value(state, 2);
  11309. lua_interface->ResetFunctionStack(state);
  11310. sint32 result = MakeRandomInt(min, max);
  11311. lua_interface->SetSInt32Value(state, result);
  11312. return 1;
  11313. }
  11314. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  11315. if (!lua_interface)
  11316. return 0;
  11317. float min = lua_interface->GetFloatValue(state);
  11318. float max = lua_interface->GetFloatValue(state, 2);
  11319. lua_interface->ResetFunctionStack(state);
  11320. float result = MakeRandomFloat(min, max);
  11321. lua_interface->SetFloatValue(state, result);
  11322. return 1;
  11323. }
  11324. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  11325. if (!lua_interface)
  11326. return 0;
  11327. Spawn* spawn = lua_interface->GetSpawn(state);
  11328. int32 value = lua_interface->GetInt32Value(state, 2);
  11329. lua_interface->ResetFunctionStack(state);
  11330. if(!spawn)
  11331. {
  11332. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11333. lua_interface->SetBooleanValue(state, false);
  11334. return 1;
  11335. }
  11336. spawn->AddIconValue(value);
  11337. lua_interface->SetBooleanValue(state, true);
  11338. return 1;
  11339. }
  11340. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  11341. if (!lua_interface)
  11342. return 0;
  11343. Spawn* spawn = lua_interface->GetSpawn(state);
  11344. int32 value = lua_interface->GetInt32Value(state, 2);
  11345. lua_interface->ResetFunctionStack(state);
  11346. if(!spawn)
  11347. {
  11348. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11349. lua_interface->SetBooleanValue(state, false);
  11350. return 1;
  11351. }
  11352. spawn->RemoveIconValue(value);
  11353. lua_interface->SetBooleanValue(state, true);
  11354. return 1;
  11355. }
  11356. int EQ2Emu_lua_GetShardID(lua_State* state) {
  11357. Spawn* npc = lua_interface->GetSpawn(state);
  11358. lua_interface->ResetFunctionStack(state);
  11359. if (npc && npc->IsNPC()) {
  11360. NPC* shard = (NPC*)npc;
  11361. int32 shardid = shard->GetShardID();
  11362. lua_interface->SetInt32Value(state, shardid);
  11363. return 1;
  11364. }
  11365. lua_interface->SetInt32Value(state, 0);
  11366. return 1;
  11367. }
  11368. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  11369. Spawn* npc = lua_interface->GetSpawn(state);
  11370. lua_interface->ResetFunctionStack(state);
  11371. if (npc && npc->IsNPC()) {
  11372. NPC* shard = (NPC*)npc;
  11373. int32 charid = shard->GetShardCharID();
  11374. lua_interface->SetInt32Value(state, charid);
  11375. return 1;
  11376. }
  11377. lua_interface->SetInt32Value(state, 0);
  11378. return 1;
  11379. }
  11380. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  11381. Spawn* npc = lua_interface->GetSpawn(state);
  11382. lua_interface->ResetFunctionStack(state);
  11383. if (npc && npc->IsNPC()) {
  11384. NPC* shard = (NPC*)npc;
  11385. int64 timestamp = shard->GetShardCreatedTimestamp();
  11386. lua_interface->SetSInt64Value(state, timestamp);
  11387. return 1;
  11388. }
  11389. lua_interface->SetSInt64Value(state, 0);
  11390. return 1;
  11391. }
  11392. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  11393. if (!lua_interface)
  11394. return 0;
  11395. int32 shardid = lua_interface->GetInt32Value(state);
  11396. lua_interface->ResetFunctionStack(state);
  11397. if(shardid < 1)
  11398. lua_interface->SetBooleanValue(state, false);
  11399. else
  11400. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  11401. return 1;
  11402. }
  11403. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  11404. if (!lua_interface)
  11405. return 0;
  11406. Spawn* spawn = lua_interface->GetSpawn(state);
  11407. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  11408. if (spawn) {
  11409. spawn->PauseMovement(delay_in_ms);
  11410. }
  11411. lua_interface->ResetFunctionStack(state);
  11412. return 0;
  11413. }
  11414. int EQ2Emu_lua_StopMovement(lua_State* state) {
  11415. if (!lua_interface)
  11416. return 0;
  11417. Spawn* spawn = lua_interface->GetSpawn(state);
  11418. if (spawn) {
  11419. spawn->StopMovement();
  11420. }
  11421. lua_interface->ResetFunctionStack(state);
  11422. return 0;
  11423. }
  11424. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  11425. Player* player = (Player*)lua_interface->GetSpawn(state);
  11426. int8 level = lua_interface->GetInt8Value(state, 2);
  11427. lua_interface->ResetFunctionStack(state);
  11428. if (player && player->IsPlayer() && level > 0) {
  11429. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  11430. return 1;
  11431. }
  11432. return 0;
  11433. }
  11434. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  11435. Player* player = (Player*)lua_interface->GetSpawn(state);
  11436. int8 level = lua_interface->GetInt8Value(state, 2);
  11437. lua_interface->ResetFunctionStack(state);
  11438. if (player && player->IsPlayer() && level > 0) {
  11439. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  11440. return 1;
  11441. }
  11442. return 0;
  11443. }
  11444. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  11445. ZoneServer* zone = lua_interface->GetZone(state);
  11446. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11447. lua_interface->ResetFunctionStack(state);
  11448. if (zone) {
  11449. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  11450. if (spawn) {
  11451. lua_interface->SetSpawnValue(state, spawn);
  11452. return 1;
  11453. }
  11454. }
  11455. return 0;
  11456. }
  11457. int EQ2Emu_lua_SetRailID(lua_State* state) {
  11458. if (!lua_interface)
  11459. return 0;
  11460. Spawn* spawn = lua_interface->GetSpawn(state);
  11461. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11462. lua_interface->ResetFunctionStack(state);
  11463. bool res = false;
  11464. if(spawn && spawn->IsTransportSpawn())
  11465. {
  11466. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  11467. spawn->SetRailID(rail_id);
  11468. res = true;
  11469. }
  11470. else if (!spawn) {
  11471. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11472. }
  11473. else if(!spawn->IsTransportSpawn()) {
  11474. lua_interface->LogError("%s: LUA SetRailID command error: spawn %s is not a transport spawn, call AddTransportSpawn(NPC) first", lua_interface->GetScriptName(state), spawn->GetName());
  11475. }
  11476. lua_interface->SetBooleanValue(state, res);
  11477. return 1;
  11478. }
  11479. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  11480. if (!lua_interface)
  11481. return 0;
  11482. ZoneServer* zone = lua_interface->GetZone(state);
  11483. lua_interface->ResetFunctionStack(state);
  11484. if (zone) {
  11485. lua_interface->SetBooleanValue(state, zone->IsLoading());
  11486. return 1;
  11487. }
  11488. return 0;
  11489. }
  11490. int EQ2Emu_lua_IsRunning(lua_State* state) {
  11491. if (!lua_interface)
  11492. return 0;
  11493. Spawn* spawn = lua_interface->GetSpawn(state);
  11494. lua_interface->ResetFunctionStack(state);
  11495. if (spawn) {
  11496. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  11497. return 1;
  11498. }
  11499. return 0;
  11500. }
  11501. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  11502. if (!lua_interface)
  11503. return 0;
  11504. Spawn* player = lua_interface->GetSpawn(state);
  11505. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  11506. bool displayClient = lua_interface->GetInt32Value(state, 3);
  11507. lua_interface->ResetFunctionStack(state);
  11508. if (!player || !player->IsPlayer() || !player->GetClient()) {
  11509. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  11510. }
  11511. else if(!zoneID) {
  11512. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  11513. }
  11514. else
  11515. {
  11516. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  11517. return 1;
  11518. }
  11519. return 0;
  11520. }
  11521. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  11522. if (!lua_interface)
  11523. return 0;
  11524. int16 newYear = lua_interface->GetInt16Value(state, 1);
  11525. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  11526. int16 newHour = lua_interface->GetInt16Value(state, 3);
  11527. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  11528. lua_interface->ResetFunctionStack(state);
  11529. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  11530. world.GetWorldTimeStruct()->year = newYear;
  11531. world.GetWorldTimeStruct()->month = newMonth;
  11532. world.GetWorldTimeStruct()->hour = newHour;
  11533. world.GetWorldTimeStruct()->minute = newMinute;
  11534. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  11535. return 0;
  11536. }
  11537. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  11538. if (!lua_interface)
  11539. return 0;
  11540. lua_interface->ResetFunctionStack(state);
  11541. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11542. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  11543. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11544. return 1;
  11545. }
  11546. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11547. if (!lua_interface)
  11548. return 0;
  11549. lua_interface->ResetFunctionStack(state);
  11550. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11551. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11552. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11553. return 1;
  11554. }
  11555. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11556. if (!lua_interface)
  11557. return 0;
  11558. lua_interface->ResetFunctionStack(state);
  11559. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11560. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11561. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11562. return 1;
  11563. }
  11564. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11565. if (!lua_interface)
  11566. return 0;
  11567. lua_interface->ResetFunctionStack(state);
  11568. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11569. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11570. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11571. return 1;
  11572. }
  11573. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11574. if (!lua_interface)
  11575. return 0;
  11576. lua_interface->ResetFunctionStack(state);
  11577. world.SendTimeUpdate();
  11578. return 0;
  11579. }
  11580. int EQ2Emu_lua_ChangeFaction(lua_State* state) {
  11581. bool update_result = false;
  11582. Faction* faction = 0;
  11583. Spawn* spawn = lua_interface->GetSpawn(state);
  11584. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  11585. sint32 increase = lua_interface->GetInt32Value(state, 3);
  11586. lua_interface->ResetFunctionStack(state);
  11587. if(!spawn || !spawn->IsPlayer()) {
  11588. lua_interface->LogError("LUA ChangeFaction command error: player is not valid");
  11589. return 0;
  11590. }
  11591. Player* player = (Player*)spawn;
  11592. Client* client = player->GetClient();
  11593. if (faction_id > 0) {
  11594. bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
  11595. if(hasfaction == 0) {
  11596. //they do not have the faction. Lets get the default value and feed it in.
  11597. sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
  11598. //add the default faction for the player.
  11599. player->SetFactionValue(faction_id, defaultfaction);
  11600. }
  11601. if(increase >= 0) {
  11602. update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
  11603. faction = master_faction_list.GetFaction(faction_id);
  11604. if(faction && update_result)
  11605. client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
  11606. else if(faction)
  11607. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
  11608. lua_interface->SetBooleanValue(state, true);
  11609. return 1;
  11610. }
  11611. if(increase < 0){
  11612. //change the negative to a positive, since thats how decreasefaction() likes it.
  11613. increase *= -1;
  11614. update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
  11615. faction = master_faction_list.GetFaction(faction_id);
  11616. if(faction && update_result)
  11617. client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
  11618. else if(faction)
  11619. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
  11620. lua_interface->SetBooleanValue(state, true);
  11621. return 1;
  11622. }
  11623. }
  11624. lua_interface->SetBooleanValue(state, false);
  11625. return 1;
  11626. }
  11627. int EQ2Emu_lua_HasCoin(lua_State* state) {
  11628. bool hascoin = 0;
  11629. Player* player = (Player*)lua_interface->GetSpawn(state);
  11630. int32 coins = lua_interface->GetInt32Value(state, 2);
  11631. lua_interface->ResetFunctionStack(state);
  11632. if (player && player->IsPlayer()) {
  11633. hascoin = player->HasCoins(coins);
  11634. if(hascoin == 0) {
  11635. lua_interface->SetBooleanValue(state, false);
  11636. return 1;
  11637. }
  11638. if(hascoin == 1) {
  11639. lua_interface->SetBooleanValue(state, true);
  11640. return 1;
  11641. }
  11642. }
  11643. return 0;
  11644. }
  11645. int EQ2Emu_lua_GetLootTier(lua_State* state) {
  11646. int32 loot_tier = 0;
  11647. Spawn* spawn = lua_interface->GetSpawn(state);
  11648. lua_interface->ResetFunctionStack(state);
  11649. if (spawn) {
  11650. loot_tier = spawn->GetLootTier();
  11651. lua_interface->SetInt32Value(state, loot_tier);
  11652. return 1;
  11653. }
  11654. return 0;
  11655. }
  11656. int EQ2Emu_lua_SetLootTier(lua_State* state) {
  11657. if (!lua_interface)
  11658. return 0;
  11659. Spawn* spawn = lua_interface->GetSpawn(state);
  11660. int32 loot_tier = lua_interface->GetInt32Value(state, 2);
  11661. lua_interface->ResetFunctionStack(state);
  11662. if (spawn) {
  11663. spawn->SetLootTier(loot_tier);
  11664. lua_interface->SetBooleanValue(state, true);
  11665. return 1;
  11666. }
  11667. lua_interface->SetBooleanValue(state, false);
  11668. return 1;
  11669. }
  11670. int EQ2Emu_lua_GetLootDropType(lua_State* state) {
  11671. int32 loot_drop_type = 0;
  11672. Spawn* spawn = lua_interface->GetSpawn(state);
  11673. lua_interface->ResetFunctionStack(state);
  11674. if (spawn) {
  11675. loot_drop_type = spawn->GetLootDropType();
  11676. lua_interface->SetInt32Value(state, loot_drop_type);
  11677. return 1;
  11678. }
  11679. return 0;
  11680. }
  11681. int EQ2Emu_lua_SetLootDropType(lua_State* state) {
  11682. if (!lua_interface)
  11683. return 0;
  11684. Spawn* spawn = lua_interface->GetSpawn(state);
  11685. int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
  11686. lua_interface->ResetFunctionStack(state);
  11687. if (spawn) {
  11688. spawn->SetLootDropType(loot_drop_type);
  11689. lua_interface->SetBooleanValue(state, true);
  11690. return 1;
  11691. }
  11692. lua_interface->SetBooleanValue(state, false);
  11693. return 1;
  11694. }
  11695. int EQ2Emu_lua_DamageEquippedItems(lua_State* state) {
  11696. if (!lua_interface)
  11697. return 0;
  11698. Spawn* spawn = lua_interface->GetSpawn(state);
  11699. int8 damage_amount = lua_interface->GetInt32Value(state, 2);
  11700. if(damage_amount > 100) {
  11701. damage_amount = 100;
  11702. }
  11703. if (!spawn) {
  11704. lua_interface->LogError("%s: LUA DamageEquippedItems command error: spawn is not valid", lua_interface->GetScriptName(state));
  11705. lua_interface->ResetFunctionStack(state);
  11706. return 0;
  11707. }
  11708. lua_interface->ResetFunctionStack(state);
  11709. if (spawn->IsPlayer()) {
  11710. if (((Player*)spawn)->GetClient() && ((Player*)spawn)->DamageEquippedItems(damage_amount, ((Player*)spawn)->GetClient()))
  11711. lua_interface->SetBooleanValue(state, true);
  11712. else
  11713. lua_interface->SetBooleanValue(state, false);
  11714. }
  11715. else {
  11716. lua_interface->SetBooleanValue(state, false);
  11717. }
  11718. return 1;
  11719. }
  11720. int EQ2Emu_lua_CreateWidgetRegion(lua_State* state) {
  11721. ZoneServer* zone = lua_interface->GetZone(state);
  11722. int32 version = lua_interface->GetInt32Value(state, 2);
  11723. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11724. if(region_map == nullptr) {
  11725. lua_interface->LogError("%s: LUA CreateWidgetRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11726. lua_interface->ResetFunctionStack(state);
  11727. return 0;
  11728. }
  11729. string region_name = lua_interface->GetStringValue(state, 3);
  11730. string env_name = lua_interface->GetStringValue(state, 4);
  11731. int32 grid_id = lua_interface->GetInt32Value(state, 5);
  11732. int32 widget_id = lua_interface->GetInt32Value(state, 6);
  11733. float dist = lua_interface->GetFloatValue(state, 7);
  11734. region_map->InsertRegionNode(zone, version, region_name, env_name, grid_id, widget_id, dist);
  11735. lua_interface->ResetFunctionStack(state);
  11736. lua_interface->SetBooleanValue(state, true);
  11737. return 1;
  11738. }
  11739. int EQ2Emu_lua_RemoveRegion(lua_State* state) {
  11740. ZoneServer* zone = lua_interface->GetZone(state);
  11741. int32 version = lua_interface->GetInt32Value(state, 2);
  11742. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11743. if(region_map == nullptr) {
  11744. lua_interface->LogError("%s: LUA RemoveRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11745. lua_interface->ResetFunctionStack(state);
  11746. return 0;
  11747. }
  11748. string region_name = lua_interface->GetStringValue(state, 3);
  11749. region_map->RemoveRegionNode(region_name);
  11750. lua_interface->ResetFunctionStack(state);
  11751. lua_interface->SetBooleanValue(state, true);
  11752. return 1;
  11753. }
  11754. int EQ2Emu_lua_SetPlayerPOVGhost(lua_State* state) {
  11755. Client* client = nullptr;
  11756. Spawn* player = lua_interface->GetSpawn(state);
  11757. if (!player) {
  11758. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not valid");
  11759. lua_interface->SetBooleanValue(state, false);
  11760. lua_interface->ResetFunctionStack(state);
  11761. return 1;
  11762. }
  11763. if (!player->IsPlayer()) {
  11764. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not a player");
  11765. lua_interface->SetBooleanValue(state, false);
  11766. lua_interface->ResetFunctionStack(state);
  11767. return 1;
  11768. }
  11769. client = player->GetClient();
  11770. if (!client) {
  11771. lua_interface->LogError("LUA SetPlayerPOVGhost command error: could not find client");
  11772. lua_interface->SetBooleanValue(state, false);
  11773. lua_interface->ResetFunctionStack(state);
  11774. return 1;
  11775. }
  11776. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  11777. bool success_sight = client->SetPlayerPOVGhost(spawn);
  11778. lua_interface->ResetFunctionStack(state);
  11779. lua_interface->SetBooleanValue(state, success_sight);
  11780. return 1;
  11781. }
  11782. int EQ2Emu_lua_SetCastOnAggroComplete(lua_State* state) {
  11783. if (!lua_interface)
  11784. return 0;
  11785. bool result = false;
  11786. Spawn* spawn = lua_interface->GetSpawn(state);
  11787. bool cast_completed = (lua_interface->GetInt8Value(state, 2) == 1);
  11788. lua_interface->ResetFunctionStack(state);
  11789. if (!spawn)
  11790. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  11791. else if (!spawn->IsNPC())
  11792. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  11793. else
  11794. {
  11795. ((NPC*)spawn)->cast_on_aggro_completed = cast_completed;
  11796. result = true;
  11797. }
  11798. lua_interface->SetBooleanValue(state, result);
  11799. return 1;
  11800. }
  11801. int EQ2Emu_lua_IsCastOnAggroComplete(lua_State* state) {
  11802. if (!lua_interface)
  11803. return 0;
  11804. bool result = false;
  11805. Spawn* spawn = lua_interface->GetSpawn(state);
  11806. lua_interface->ResetFunctionStack(state);
  11807. if (!spawn)
  11808. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  11809. else if (!spawn->IsNPC())
  11810. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  11811. else
  11812. {
  11813. if(((NPC*)spawn)->cast_on_aggro_completed)
  11814. result = true;
  11815. }
  11816. lua_interface->SetBooleanValue(state, result);
  11817. return 1;
  11818. }
  11819. int EQ2Emu_lua_AddRecipeBookToPlayer(lua_State* state) {
  11820. Client* client = nullptr;
  11821. Spawn* player = lua_interface->GetSpawn(state);
  11822. int32 recipe_book_id = lua_interface->GetInt32Value(state, 2);
  11823. lua_interface->ResetFunctionStack(state);
  11824. if (!player) {
  11825. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not valid");
  11826. lua_interface->SetBooleanValue(state, false);
  11827. return 1;
  11828. }
  11829. if (!player->IsPlayer()) {
  11830. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not a player");
  11831. lua_interface->SetBooleanValue(state, false);
  11832. return 1;
  11833. }
  11834. client = player->GetClient();
  11835. if (!client) {
  11836. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: could not find client");
  11837. lua_interface->SetBooleanValue(state, false);
  11838. return 1;
  11839. }
  11840. bool result = client->AddRecipeBookToPlayer(recipe_book_id);
  11841. lua_interface->SetBooleanValue(state, result);
  11842. return 1;
  11843. }
  11844. int EQ2Emu_lua_RemoveRecipeFromPlayer(lua_State* state) {
  11845. Client* client = nullptr;
  11846. Spawn* player = lua_interface->GetSpawn(state);
  11847. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  11848. lua_interface->ResetFunctionStack(state);
  11849. if (!player) {
  11850. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not valid");
  11851. lua_interface->SetBooleanValue(state, false);
  11852. return 1;
  11853. }
  11854. if (!player->IsPlayer()) {
  11855. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not a player");
  11856. lua_interface->SetBooleanValue(state, false);
  11857. return 1;
  11858. }
  11859. client = player->GetClient();
  11860. if (!client) {
  11861. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: could not find client");
  11862. lua_interface->SetBooleanValue(state, false);
  11863. return 1;
  11864. }
  11865. bool result = client->RemoveRecipeFromPlayer(recipe_id);
  11866. lua_interface->SetBooleanValue(state, result);
  11867. return 1;
  11868. }
  11869. int EQ2Emu_lua_ReplaceWidgetFromClient(lua_State* state) {
  11870. Client* client = nullptr;
  11871. Spawn* player = lua_interface->GetSpawn(state);
  11872. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  11873. bool delete_widget = (lua_interface->GetInt8Value(state, 3) == 1);
  11874. // rest are all optional fields
  11875. float x = lua_interface->GetFloatValue(state, 4);
  11876. float y = lua_interface->GetFloatValue(state, 5);
  11877. float z = lua_interface->GetFloatValue(state, 6);
  11878. int32 grid_id = lua_interface->GetInt32Value(state, 7);
  11879. lua_interface->ResetFunctionStack(state);
  11880. if (!player) {
  11881. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not valid");
  11882. lua_interface->SetBooleanValue(state, false);
  11883. return 1;
  11884. }
  11885. if (!player->IsPlayer()) {
  11886. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not a player");
  11887. lua_interface->SetBooleanValue(state, false);
  11888. return 1;
  11889. }
  11890. if(!player->GetZone()) {
  11891. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
  11892. lua_interface->SetBooleanValue(state, false);
  11893. return 1;
  11894. }
  11895. client = player->GetClient();
  11896. if (!client) {
  11897. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: could not find client");
  11898. lua_interface->SetBooleanValue(state, false);
  11899. return 1;
  11900. }
  11901. if(!client->IsReadyForUpdates()) {
  11902. lua_interface->LogError("LUA ReplaceWidgetFromClient command failed: client has not signaled sys_client_avatar_ready");
  11903. lua_interface->SetBooleanValue(state, false);
  11904. return 1;
  11905. }
  11906. client->SendReplaceWidget(widget_id, delete_widget, x, y, z, grid_id);
  11907. lua_interface->SetBooleanValue(state, true);
  11908. return 1;
  11909. }
  11910. int EQ2Emu_lua_RemoveWidgetFromSpawnMap(lua_State* state) {
  11911. Client* client = nullptr;
  11912. Spawn* spawn = lua_interface->GetSpawn(state);
  11913. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  11914. lua_interface->ResetFunctionStack(state);
  11915. if (!spawn) {
  11916. lua_interface->LogError("LUA RemoveWidgetFromSpawnMap command error: spawn is not valid");
  11917. lua_interface->SetBooleanValue(state, false);
  11918. return 1;
  11919. }
  11920. if(!spawn->GetZone()) {
  11921. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
  11922. lua_interface->SetBooleanValue(state, false);
  11923. return 1;
  11924. }
  11925. spawn->AddIgnoredWidget(widget_id);
  11926. lua_interface->SetBooleanValue(state, true);
  11927. return 1;
  11928. }
  11929. int EQ2Emu_lua_RemoveWidgetFromZoneMap(lua_State* state) {
  11930. ZoneServer* zone = lua_interface->GetZone(state);
  11931. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  11932. lua_interface->ResetFunctionStack(state);
  11933. if(!zone) {
  11934. lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: zone is not valid");
  11935. lua_interface->SetBooleanValue(state, false);
  11936. return 1;
  11937. }
  11938. if(!zone->IsLoading()) {
  11939. lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: can only be called during zone loading, in preinit_zone_script ZoneScript function");
  11940. lua_interface->SetBooleanValue(state, false);
  11941. return 1;
  11942. }
  11943. zone->AddIgnoredWidget(widget_id);
  11944. lua_interface->SetBooleanValue(state, true);
  11945. return 1;
  11946. }