LuaFunctions.cpp 374 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262
  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. if (spawn) {
  156. const char* mp3 = 0;
  157. const char* text = 0;
  158. const char* emote = 0;
  159. if (mp3_string.length() > 0)
  160. mp3 = mp3_string.c_str();
  161. if (text_string.length() > 0)
  162. text = text_string.c_str();
  163. if (emote_string.length() > 0)
  164. emote = emote_string.c_str();
  165. Client* client = 0;
  166. if (player && player->IsPlayer())
  167. client = spawn->GetZone()->GetClientBySpawn(player);
  168. if (client) {
  169. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  170. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  171. }
  172. else
  173. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  174. }
  175. return 0;
  176. }
  177. int EQ2Emu_lua_PlaySound(lua_State* state) {
  178. if (!lua_interface)
  179. return 0;
  180. Spawn* spawn = lua_interface->GetSpawn(state);
  181. string sound_string = lua_interface->GetStringValue(state, 2);
  182. float x = lua_interface->GetFloatValue(state, 3);
  183. float y = lua_interface->GetFloatValue(state, 4);
  184. float z = lua_interface->GetFloatValue(state, 5);
  185. Spawn* player = lua_interface->GetSpawn(state, 6);
  186. if (spawn && sound_string.length() > 0) {
  187. Client* client = 0;
  188. if (player && player->IsPlayer())
  189. client = spawn->GetZone()->GetClientBySpawn(player);
  190. if (client)
  191. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  192. else
  193. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  194. }
  195. return 0;
  196. }
  197. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  198. if (!lua_interface)
  199. return 0;
  200. Spawn* spawn = lua_interface->GetSpawn(state);
  201. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  202. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  203. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  204. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  205. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  206. if (!spawn) {
  207. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  208. return 0;
  209. }
  210. if (quest_id > 0) {
  211. //Add this quest to the list of required quests for this spawn
  212. spawn->SetQuestsRequired(quest_id, quest_step);
  213. //If private spawn value set
  214. if (private_spawn) {
  215. //Set the spawn to be private when not granted access through this quest
  216. spawn->AddAllowAccessSpawn(spawn);
  217. spawn->SetPrivateQuestSpawn(true);
  218. }
  219. //This value allows access after a quest step, or the whole quest has been completed
  220. if (continued_access)
  221. spawn->SetQuestsRequiredContinuedAccess(true);
  222. //This value will override vis_flags in the vis packet
  223. if (flag_override > 0)
  224. spawn->SetQuestsRequiredOverride(flag_override);
  225. }
  226. return 0;
  227. }
  228. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  229. if (!lua_interface)
  230. return 0;
  231. Spawn* spawn = lua_interface->GetSpawn(state);
  232. float max_distance = lua_interface->GetFloatValue(state, 2);
  233. string variable = lua_interface->GetStringValue(state, 3);
  234. string value = lua_interface->GetStringValue(state, 4);
  235. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  236. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  237. return 0;
  238. }
  239. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  240. if (!lua_interface)
  241. return 0;
  242. Client* client = 0;
  243. Spawn* player = lua_interface->GetSpawn(state);
  244. if (!player) {
  245. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  246. return 0;
  247. }
  248. if (!player->IsPlayer()) {
  249. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  250. return 0;
  251. }
  252. if (player->GetZone())
  253. client = player->GetZone()->GetClientBySpawn(player);
  254. if (!client) {
  255. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  256. return 0;
  257. }
  258. float intensity = lua_interface->GetFloatValue(state, 2);
  259. int8 direction = lua_interface->GetInt8Value(state, 3);
  260. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  261. if (packet) {
  262. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  263. v1 = *(float *)(a1 + 4);
  264. if ( v1 > 0.0 )
  265. v2 = fminf(v1, 1.0);
  266. else
  267. v2 = 0.1;
  268. */
  269. packet->setDataByName("intensity", intensity);
  270. if ( client->GetVersion() > 546 )
  271. packet->setDataByName("direction", direction);
  272. client->QueuePacket(packet->serialize());
  273. safe_delete(packet);
  274. }
  275. return 0;
  276. }
  277. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  278. if (!lua_interface)
  279. return 0;
  280. Spawn* dead = lua_interface->GetSpawn(state);
  281. Spawn* killer = lua_interface->GetSpawn(state, 2);
  282. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  283. if (dead && dead->Alive() && dead->GetZone())
  284. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  285. return 0;
  286. }
  287. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  288. if (!lua_interface)
  289. return 0;
  290. Spawn* spawn = lua_interface->GetSpawn(state);
  291. float max_distance = lua_interface->GetFloatValue(state, 2);
  292. bool include_players = lua_interface->GetInt8Value(state, 3);
  293. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  294. if (max_distance > 0 && spawn && spawn->GetZone())
  295. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  296. return 0;
  297. }
  298. int EQ2Emu_lua_Despawn(lua_State* state) {
  299. if (!lua_interface)
  300. return 0;
  301. Spawn* spawn = lua_interface->GetSpawn(state);
  302. int32 delay = lua_interface->GetInt32Value(state, 2);
  303. if (spawn && spawn->GetZone())
  304. spawn->GetZone()->Despawn(spawn, delay);
  305. return 0;
  306. }
  307. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  308. if (!lua_interface)
  309. return 0;
  310. Spawn* spawn = lua_interface->GetSpawn(state);
  311. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  312. if (spawn) {
  313. spawn->info_changed = true;
  314. spawn->SetShowHandIcon(displayHandIcon);
  315. }
  316. return 0;
  317. }
  318. //this function is used to force an update packet to be sent.
  319. //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
  320. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  321. if (!lua_interface)
  322. return 0;
  323. Spawn* spawn = lua_interface->GetSpawn(state);
  324. if (spawn) {
  325. spawn->vis_changed = true;
  326. spawn->GetZone()->AddChangedSpawn(spawn);
  327. }
  328. return 0;
  329. }
  330. //this function is used to force an update packet to be sent.
  331. //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
  332. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  333. if (!lua_interface)
  334. return 0;
  335. Spawn* spawn = lua_interface->GetSpawn(state);
  336. if (spawn) {
  337. spawn->info_changed = true;
  338. spawn->GetZone()->AddChangedSpawn(spawn);
  339. }
  340. return 0;
  341. }
  342. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  343. if (!lua_interface)
  344. return 0;
  345. Spawn* spawn = lua_interface->GetSpawn(state);
  346. int32 new_state = lua_interface->GetInt32Value(state, 2);
  347. Spawn* player = lua_interface->GetSpawn(state, 3);
  348. lua_interface->ResetFunctionStack(state);
  349. if (spawn) {
  350. if(player)
  351. {
  352. if(player->IsPlayer())
  353. {
  354. Client* client = ((Player*)player)->GetClient();
  355. if(client)
  356. {
  357. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  358. lua_interface->SetBooleanValue(state, true);
  359. return 1;
  360. }
  361. else
  362. 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());
  363. }
  364. else
  365. 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());
  366. }
  367. else
  368. {
  369. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  370. lua_interface->SetBooleanValue(state, true);
  371. return 1;
  372. }
  373. }
  374. lua_interface->SetBooleanValue(state, false);
  375. return 1;
  376. }
  377. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  378. if (!lua_interface)
  379. return 0;
  380. Spawn* spawn = lua_interface->GetSpawn(state);
  381. string variable = lua_interface->GetStringValue(state, 2);
  382. string value = lua_interface->GetStringValue(state, 3);
  383. 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.
  384. bool temporary_flag = true;
  385. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  386. if(num_args >= 5)
  387. 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
  388. int32 type = commands.GetSpawnSetType(variable);
  389. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  390. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag);
  391. return 0;
  392. }
  393. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  394. if (!lua_interface)
  395. return 0;
  396. Spawn* spawn = lua_interface->GetSpawn(state);
  397. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  398. if (spawn && spawn_id > 0) {
  399. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  400. if (closest_spawn) {
  401. lua_interface->SetSpawnValue(state, closest_spawn);
  402. return 1;
  403. }
  404. }
  405. return 0;
  406. }
  407. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  408. if (!lua_interface)
  409. return 0;
  410. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  411. int32 position = lua_interface->GetInt32Value(state, 2);
  412. if (spawnList) {
  413. if (spawnList->size() > position) {
  414. lua_interface->SetSpawnValue(state, spawnList->at(position));
  415. return 1;
  416. }
  417. else {
  418. return 0;
  419. }
  420. return spawnList->size();
  421. }
  422. return 0;
  423. }
  424. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  425. if (!lua_interface)
  426. return 0;
  427. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  428. if (spawnList) {
  429. return spawnList->size();
  430. }
  431. return 0;
  432. }
  433. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  434. if (!lua_interface)
  435. return 0;
  436. vector<Spawn*>* spawnList = new vector<Spawn*>();
  437. lua_interface->SetSpawnListValue(state, spawnList);
  438. return 1;
  439. }
  440. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  441. if (!lua_interface)
  442. return 0;
  443. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  444. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  445. if (spawnList) {
  446. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  447. if (it == spawnList->end())
  448. spawnList->push_back(spawn);
  449. }
  450. return 0;
  451. }
  452. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  453. if (!lua_interface)
  454. return 0;
  455. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  456. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  457. if (spawnList) {
  458. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  459. if(it != spawnList->end())
  460. spawnList->erase(it);
  461. }
  462. return 0;
  463. }
  464. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  465. if (!lua_interface)
  466. return 0;
  467. Spawn* spawn = lua_interface->GetSpawn(state);
  468. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  469. if (spawn) {
  470. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  471. if (spawns.size() > 0) {
  472. vector<Spawn*>* spawnList = new vector<Spawn*>();
  473. vector<Spawn*>::iterator itr;
  474. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  475. spawnList->push_back(*itr);
  476. }
  477. lua_interface->SetSpawnListValue(state, spawnList);
  478. return 1;
  479. }
  480. }
  481. return 0;
  482. }
  483. int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
  484. if (!lua_interface)
  485. return 0;
  486. Spawn* spawn = lua_interface->GetSpawn(state);
  487. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  488. if (spawn) {
  489. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
  490. if (spawns.size() > 0) {
  491. vector<Spawn*>* spawnList = new vector<Spawn*>();
  492. vector<Spawn*>::iterator itr;
  493. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  494. spawnList->push_back(*itr);
  495. }
  496. lua_interface->SetSpawnListValue(state, spawnList);
  497. return 1;
  498. }
  499. }
  500. return 0;
  501. }
  502. int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
  503. if (!lua_interface)
  504. return 0;
  505. Spawn* spawn = lua_interface->GetSpawn(state);
  506. if (spawn) {
  507. vector<Spawn*> spawns = spawn->GetPassengersOnRail();
  508. if (spawns.size() > 0) {
  509. lua_createtable(state, spawns.size(), 0);
  510. int newTable = lua_gettop(state);
  511. for (int32 i = 0; i < spawns.size(); i++) {
  512. lua_interface->SetSpawnValue(state, spawns.at(i));
  513. lua_rawseti(state, newTable, i + 1);
  514. }
  515. return 1;
  516. }
  517. }
  518. return 0;
  519. }
  520. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  521. if (!lua_interface)
  522. return 0;
  523. string variable_name = lua_interface->GetStringValue(state);
  524. Variable* var = variables.FindVariable(variable_name);
  525. if (var) {
  526. lua_interface->SetStringValue(state, var->GetValue());
  527. return 1;
  528. }
  529. return 0;
  530. }
  531. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  532. if (!lua_interface)
  533. return 0;
  534. int32 total_coins = lua_interface->GetInt32Value(state);
  535. if (total_coins == 0) {
  536. lua_interface->SetStringValue(state, "0 copper");
  537. return 1;
  538. }
  539. char tmp[64] = { 0 };
  540. string message = "";
  541. int32 val = 0;
  542. if (total_coins >= 1000000) {
  543. val = total_coins / 1000000;
  544. total_coins -= 1000000 * val;
  545. sprintf(tmp, " %u Platinum", val);
  546. message.append(tmp);
  547. memset(tmp, 0, 64);
  548. }
  549. if (total_coins >= 10000) {
  550. val = total_coins / 10000;
  551. total_coins -= 10000 * val;
  552. sprintf(tmp, " %u Gold", val);
  553. message.append(tmp);
  554. memset(tmp, 0, 64);
  555. }
  556. if (total_coins >= 100) {
  557. val = total_coins / 100;
  558. total_coins -= 100 * val;
  559. sprintf(tmp, " %u Silver", val);
  560. message.append(tmp);
  561. memset(tmp, 0, 64);
  562. }
  563. if (total_coins > 0) {
  564. sprintf(tmp, " %u Copper", (int32)total_coins);
  565. message.append(tmp);
  566. }
  567. lua_interface->SetStringValue(state, message.c_str());
  568. return 1;
  569. }
  570. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  571. ZoneServer* zone = lua_interface->GetZone(state);
  572. int32 group_id = lua_interface->GetInt32Value(state, 2);
  573. if (zone) {
  574. Spawn* spawn = zone->GetSpawnGroup(group_id);
  575. if (spawn) {
  576. lua_interface->SetSpawnValue(state, spawn);
  577. return 1;
  578. }
  579. }
  580. return 0;
  581. }
  582. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  583. ZoneServer* zone = lua_interface->GetZone(state);
  584. int32 location_id = lua_interface->GetInt32Value(state, 2);
  585. if (zone) {
  586. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  587. if (spawn) {
  588. lua_interface->SetSpawnValue(state, spawn);
  589. return 1;
  590. }
  591. }
  592. return 0;
  593. }
  594. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  595. Spawn* spawn = lua_interface->GetSpawn(state);
  596. if (spawn) {
  597. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  598. return 1;
  599. }
  600. return 0;
  601. }
  602. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  603. Spawn* spawn = lua_interface->GetSpawn(state);
  604. if (spawn) {
  605. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  606. return 1;
  607. }
  608. return 0;
  609. }
  610. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  611. if (!lua_interface)
  612. return 0;
  613. Spawn* spawn = lua_interface->GetSpawn(state);
  614. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  615. lua_interface->ResetFunctionStack(state);
  616. if (spawn) {
  617. spawn->SetSpawnGroupID(new_group_id);
  618. lua_interface->SetBooleanValue(state, true);
  619. return 1;
  620. }
  621. lua_interface->SetBooleanValue(state, false);
  622. return 1;
  623. }
  624. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  625. if (!lua_interface)
  626. return 0;
  627. Spawn* spawn = lua_interface->GetSpawn(state);
  628. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  629. lua_interface->ResetFunctionStack(state);
  630. if (spawn) {
  631. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  632. lua_interface->SetBooleanValue(state, true);
  633. return 1;
  634. }
  635. lua_interface->SetBooleanValue(state, false);
  636. return 1;
  637. }
  638. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  639. Spawn* spawn = lua_interface->GetSpawn(state);
  640. if (spawn) {
  641. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  642. return 1;
  643. }
  644. return 0;
  645. }
  646. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  647. Spawn* spawn = lua_interface->GetSpawn(state);
  648. if (spawn) {
  649. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  650. return 1;
  651. }
  652. return 0;
  653. }
  654. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  655. Player* player = (Player*)lua_interface->GetSpawn(state);
  656. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  657. if (player && player->IsPlayer() && faction_id > 0) {
  658. lua_interface->SetInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  659. return 1;
  660. }
  661. return 0;
  662. }
  663. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  664. if (!lua_interface)
  665. return 0;
  666. Spawn* spawn = lua_interface->GetSpawn(state);
  667. int32 value = lua_interface->GetInt32Value(state, 2);
  668. if (spawn) {
  669. spawn->SetFactionID(value);
  670. }
  671. return 0;
  672. }
  673. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  674. Spawn* spawn = lua_interface->GetSpawn(state);
  675. if (spawn) {
  676. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  677. return 1;
  678. }
  679. return 0;
  680. }
  681. int EQ2Emu_lua_GetGender(lua_State* state) {
  682. Spawn* spawn = lua_interface->GetSpawn(state);
  683. if (spawn) {
  684. lua_interface->SetInt32Value(state, spawn->GetGender());
  685. return 1;
  686. }
  687. return 0;
  688. }
  689. int EQ2Emu_lua_GetTarget(lua_State* state) {
  690. Spawn* spawn = lua_interface->GetSpawn(state);
  691. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  692. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  693. return 1;
  694. }
  695. return 0;
  696. }
  697. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  698. if (!lua_interface)
  699. return 0;
  700. Spawn* spawn = lua_interface->GetSpawn(state);
  701. string mp3_string = lua_interface->GetStringValue(state, 2);
  702. int32 key1 = lua_interface->GetInt32Value(state, 3);
  703. int32 key2 = lua_interface->GetInt32Value(state, 4);
  704. Spawn* player = lua_interface->GetSpawn(state, 5);
  705. if (spawn && mp3_string.length() > 0) {
  706. Client* client = 0;
  707. if (player && player->IsPlayer())
  708. client = spawn->GetZone()->GetClientBySpawn(player);
  709. if (client) {
  710. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  711. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  712. }
  713. else
  714. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  715. }
  716. return 0;
  717. }
  718. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  719. if (!lua_interface)
  720. return 0;
  721. Spawn* spawn = lua_interface->GetSpawn(state);
  722. if (spawn) {
  723. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  724. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  725. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  726. return 3;
  727. }
  728. return 0;
  729. }
  730. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  731. if (!lua_interface)
  732. return 0;
  733. Spawn* spawn = lua_interface->GetSpawn(state);
  734. if (spawn) {
  735. int32 item_id = lua_interface->GetInt32Value(state, 2);
  736. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  737. return 1;
  738. }
  739. return 0;
  740. }
  741. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  742. if (!lua_interface)
  743. return 0;
  744. Spawn* spawn = lua_interface->GetSpawn(state);
  745. if (spawn && spawn->IsEntity()) {
  746. int32 item_id = lua_interface->GetInt32Value(state, 2);
  747. int16 charges = lua_interface->GetInt16Value(state, 3);
  748. if (charges == 0)
  749. charges = 1;
  750. ((Entity*)spawn)->AddLootItem(item_id, charges);
  751. }
  752. return 0;
  753. }
  754. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  755. if (!lua_interface)
  756. return 0;
  757. Spawn* spawn = lua_interface->GetSpawn(state);
  758. if (spawn && spawn->IsEntity()) {
  759. int32 item_id = lua_interface->GetInt32Value(state, 2);
  760. Item* item = spawn->LootItem(item_id);
  761. safe_delete(item);
  762. }
  763. return 0;
  764. }
  765. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  766. if (!lua_interface)
  767. return 0;
  768. Spawn* spawn = lua_interface->GetSpawn(state);
  769. if (spawn) {
  770. int32 val = lua_interface->GetInt32Value(state, 2);
  771. spawn->AddLootCoins(val);
  772. }
  773. return 0;
  774. }
  775. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  776. if (!lua_interface)
  777. return 0;
  778. Spawn* entity = lua_interface->GetSpawn(state);
  779. Spawn* player = lua_interface->GetSpawn(state, 2);
  780. if (entity && player && player->IsPlayer()) {
  781. int32 coins = lua_interface->GetInt32Value(state, 3);
  782. vector<Item*>* items = 0;
  783. int i = 0;
  784. int32 item_id = 0;
  785. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  786. if (items == 0)
  787. items = new vector<Item*>;
  788. if (master_item_list.GetItem(item_id))
  789. items->push_back(master_item_list.GetItem(item_id));
  790. i++;
  791. }
  792. Client* client = 0;
  793. client = player->GetZone()->GetClientBySpawn(player);
  794. if (client)
  795. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  796. if(coins > 0)
  797. entity->AddLootCoins(coins);
  798. safe_delete(items);
  799. }
  800. return 0;
  801. }
  802. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  803. if (!lua_interface)
  804. return 0;
  805. Spawn* entity = lua_interface->GetSpawn(state);
  806. Spawn* player = lua_interface->GetSpawn(state, 2);
  807. int32 item_id = lua_interface->GetInt32Value(state, 3);
  808. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  809. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  810. return 1;
  811. }
  812. return 0;
  813. }
  814. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  815. if (!lua_interface)
  816. return 0;
  817. Spawn* entity = lua_interface->GetSpawn(state);
  818. Spawn* player = lua_interface->GetSpawn(state, 2);
  819. if (entity && player && player->IsPlayer()) {
  820. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  821. return 1;
  822. }
  823. return 0;
  824. }
  825. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  826. if (!lua_interface)
  827. return 0;
  828. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  829. safe_delete(conversation);
  830. conversation = new vector<ConversationOption>();
  831. lua_interface->SetConversationValue(state, conversation);
  832. return 1;
  833. }
  834. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  835. if (!lua_interface)
  836. return 0;
  837. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  838. if (conversation) {
  839. ConversationOption conv_option;
  840. conv_option.option = lua_interface->GetStringValue(state, 2);
  841. conv_option.function = lua_interface->GetStringValue(state, 3);
  842. if (conv_option.option.length() > 0)
  843. conversation->push_back(conv_option);
  844. }
  845. return 0;
  846. }
  847. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  848. if (!lua_interface)
  849. return 0;
  850. Spawn* npc = lua_interface->GetSpawn(state);
  851. Spawn* player = lua_interface->GetSpawn(state, 2);
  852. if (npc && player && player->IsPlayer() && player->GetZone()) {
  853. Client* client = player->GetZone()->GetClientBySpawn(player);
  854. if (client) {
  855. int32 conversation_id = client->GetConversationID(npc, 0);
  856. client->CloseDialog(conversation_id);
  857. }
  858. }
  859. return 0;
  860. }
  861. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  862. if (!lua_interface)
  863. return 0;
  864. Item* item = lua_interface->GetItem(state);
  865. Spawn* player = lua_interface->GetSpawn(state, 2);
  866. if (item && player && player->IsPlayer() && player->GetZone()) {
  867. Client* client = player->GetZone()->GetClientBySpawn(player);
  868. if (client) {
  869. int32 conversation_id = client->GetConversationID(0, item);
  870. client->CloseDialog(conversation_id);
  871. }
  872. }
  873. return 0;
  874. }
  875. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  876. if (!lua_interface)
  877. return 0;
  878. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  879. Spawn* spawn = 0;
  880. Item* item = 0;
  881. int8 type = lua_interface->GetInt8Value(state, 2);
  882. if (type == 1 || type == 3)
  883. spawn = lua_interface->GetSpawn(state, 3);
  884. else if (type == 2 || type == 4)
  885. item = lua_interface->GetItem(state, 3);
  886. Spawn* player = lua_interface->GetSpawn(state, 4);
  887. string text = lua_interface->GetStringValue(state, 5);
  888. string mp3 = lua_interface->GetStringValue(state, 6);
  889. int32 key1 = lua_interface->GetInt32Value(state, 7);
  890. int32 key2 = lua_interface->GetInt32Value(state, 8);
  891. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  892. Client* client = player->GetZone()->GetClientBySpawn(player);
  893. if (client) {
  894. if (spawn) {
  895. // Need to do this so the function works the same as it did before
  896. if (type == 1)
  897. type++;
  898. if (mp3.length() > 0)
  899. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  900. else
  901. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  902. }
  903. else {
  904. if (mp3.length() > 0)
  905. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  906. else
  907. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  908. }
  909. }
  910. }
  911. safe_delete(conversation);
  912. lua_interface->SetConversationValue(state, NULL);
  913. return 0;
  914. }
  915. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  916. if(!lua_interface)
  917. return 0;
  918. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  919. Item* item = lua_interface->GetItem(state, 2);
  920. Spawn* player = lua_interface->GetSpawn(state, 3);
  921. string text = lua_interface->GetStringValue(state, 4);
  922. string mp3 = lua_interface->GetStringValue(state, 5);
  923. int32 key1 = lua_interface->GetInt32Value(state, 6);
  924. int32 key2 = lua_interface->GetInt32Value(state, 7);
  925. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  926. Client* client = player->GetZone()->GetClientBySpawn(player);
  927. if(client){
  928. if(mp3.length() > 0)
  929. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  930. else
  931. client->DisplayConversation(item, conversation, (char*)text.c_str());
  932. }
  933. safe_delete(conversation);
  934. }
  935. return 0;
  936. }*/
  937. int EQ2Emu_lua_StartConversation(lua_State* state) {
  938. if (!lua_interface)
  939. return 0;
  940. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  941. Spawn* source = lua_interface->GetSpawn(state, 2);
  942. Spawn* player = lua_interface->GetSpawn(state, 3);
  943. string text = lua_interface->GetStringValue(state, 4);
  944. string mp3 = lua_interface->GetStringValue(state, 5);
  945. int32 key1 = lua_interface->GetInt32Value(state, 6);
  946. int32 key2 = lua_interface->GetInt32Value(state, 7);
  947. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  948. Client* client = source->GetZone()->GetClientBySpawn(player);
  949. if (mp3.length() > 0)
  950. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  951. else
  952. client->DisplayConversation(source, 1, conversation, text.c_str());
  953. safe_delete(conversation);
  954. lua_interface->SetConversationValue(state, NULL);
  955. }
  956. else
  957. 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);
  958. return 0;
  959. }
  960. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  961. if (!lua_interface)
  962. return 0;
  963. Spawn* spawn = lua_interface->GetSpawn(state);
  964. float distance = lua_interface->GetFloatValue(state, 2);
  965. string in_range_function = lua_interface->GetStringValue(state, 3);
  966. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  967. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  968. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  969. return 0;
  970. }
  971. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  972. ZoneServer* zone = lua_interface->GetZone(state);
  973. float x = lua_interface->GetFloatValue(state, 2);
  974. float y = lua_interface->GetFloatValue(state, 3);
  975. float z = lua_interface->GetFloatValue(state, 4);
  976. float max_variation = lua_interface->GetFloatValue(state, 5);
  977. string in_range_function = lua_interface->GetStringValue(state, 6);
  978. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  979. if (zone && in_range_function.length() > 0)
  980. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  981. return 0;
  982. }
  983. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  984. if (!lua_interface)
  985. return 0;
  986. Spawn* spawn = lua_interface->GetSpawn(state);
  987. if (spawn && spawn->IsEntity()) {
  988. int32 val = lua_interface->GetInt32Value(state, 2);
  989. ((Entity*)spawn)->SetLootCoins(val);
  990. }
  991. return 0;
  992. }
  993. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  994. if (!lua_interface)
  995. return 0;
  996. Spawn* spawn = lua_interface->GetSpawn(state);
  997. if (spawn && spawn->IsEntity()) {
  998. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  999. return 1;
  1000. }
  1001. return 0;
  1002. }
  1003. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1004. if (!lua_interface)
  1005. return 0;
  1006. Spawn* spawn = lua_interface->GetSpawn(state);
  1007. float x = lua_interface->GetFloatValue(state, 2);
  1008. float y = lua_interface->GetFloatValue(state, 3);
  1009. float z = lua_interface->GetFloatValue(state, 4);
  1010. float speed = lua_interface->GetFloatValue(state, 5);
  1011. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1012. string function = lua_interface->GetStringValue(state, 7);
  1013. if (spawn) {
  1014. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str());
  1015. spawn->GetZone()->AddMovementNPC(spawn);
  1016. }
  1017. lua_interface->ResetFunctionStack(state);
  1018. return 0;
  1019. }
  1020. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1021. if (!lua_interface)
  1022. return 0;
  1023. Spawn* spawn = lua_interface->GetSpawn(state);
  1024. if (spawn) {
  1025. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1026. return 1;
  1027. }
  1028. return 0;
  1029. }
  1030. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1031. if (!lua_interface)
  1032. return 0;
  1033. Spawn* spawn = lua_interface->GetSpawn(state);
  1034. if (spawn && spawn->IsPlayer()) {
  1035. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1036. return 1;
  1037. }
  1038. lua_interface->SetInt32Value(state, 0);
  1039. return 1;
  1040. }
  1041. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1042. if (!lua_interface)
  1043. return 0;
  1044. Spawn* spawn = lua_interface->GetSpawn(state);
  1045. Spawn* target = lua_interface->GetSpawn(state, 2);
  1046. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1047. bool reset_action_state = true;
  1048. if(num_args > 2)
  1049. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1050. if (spawn && target) {
  1051. if (spawn->IsEntity())
  1052. // ((Entity*)spawn)->FaceTarget(target);
  1053. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1054. }
  1055. lua_interface->ResetFunctionStack(state);
  1056. return 0;
  1057. }
  1058. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1059. if (!lua_interface)
  1060. return 0;
  1061. Spawn* spawn = lua_interface->GetSpawn(state);
  1062. float x = lua_interface->GetFloatValue(state, 2);
  1063. float y = lua_interface->GetFloatValue(state, 3);
  1064. float z = lua_interface->GetFloatValue(state, 4);
  1065. float speed = lua_interface->GetFloatValue(state, 5);
  1066. string lua_function = lua_interface->GetStringValue(state, 6);
  1067. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1068. if (spawn) {
  1069. if (speed == 0)
  1070. speed = spawn->GetSpeed();
  1071. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1072. }
  1073. lua_interface->ResetFunctionStack(state);
  1074. return 0;
  1075. }
  1076. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1077. if (!lua_interface)
  1078. return 0;
  1079. Spawn* spawn = lua_interface->GetSpawn(state);
  1080. if (spawn) {
  1081. spawn->ClearRunningLocations();
  1082. }
  1083. return 0;
  1084. }
  1085. int EQ2Emu_lua_Say(lua_State* state) {
  1086. if (!lua_interface)
  1087. return 0;
  1088. Spawn* spawn = lua_interface->GetSpawn(state);
  1089. string message = lua_interface->GetStringValue(state, 2);
  1090. Spawn* player = lua_interface->GetSpawn(state, 3);
  1091. int32 language = lua_interface->GetInt32Value(state, 4);
  1092. if (spawn && message.length() > 0) {
  1093. Client* client = 0;
  1094. if (player && player->IsPlayer())
  1095. client = spawn->GetZone()->GetClientBySpawn(player);
  1096. if (client)
  1097. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1098. else
  1099. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1100. }
  1101. lua_interface->ResetFunctionStack(state);
  1102. return 0;
  1103. }
  1104. int EQ2Emu_lua_Shout(lua_State* state) {
  1105. if (!lua_interface)
  1106. return 0;
  1107. Spawn* spawn = lua_interface->GetSpawn(state);
  1108. string message = lua_interface->GetStringValue(state, 2);
  1109. Spawn* player = lua_interface->GetSpawn(state, 3);
  1110. float dist = lua_interface->GetFloatValue(state, 4);
  1111. if (spawn && message.length() > 0) {
  1112. Client* client = 0;
  1113. if (player && player->IsPlayer())
  1114. client = spawn->GetZone()->GetClientBySpawn(player);
  1115. if (client)
  1116. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1117. else
  1118. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1119. }
  1120. lua_interface->ResetFunctionStack(state);
  1121. return 0;
  1122. }
  1123. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1124. if (!lua_interface)
  1125. return 0;
  1126. Spawn* spawn = lua_interface->GetSpawn(state);
  1127. string message = lua_interface->GetStringValue(state, 2);
  1128. Spawn* player = lua_interface->GetSpawn(state, 3);
  1129. if (spawn && message.length() > 0) {
  1130. Client* client = 0;
  1131. if (player && player->IsPlayer())
  1132. client = spawn->GetZone()->GetClientBySpawn(player);
  1133. if (client)
  1134. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1135. else
  1136. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1137. }
  1138. lua_interface->ResetFunctionStack(state);
  1139. return 0;
  1140. }
  1141. int EQ2Emu_lua_Emote(lua_State* state) {
  1142. if (!lua_interface)
  1143. return 0;
  1144. Spawn* spawn = lua_interface->GetSpawn(state);
  1145. string message = lua_interface->GetStringValue(state, 2);
  1146. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1147. Spawn* player = lua_interface->GetSpawn(state, 4);
  1148. char* to = 0;
  1149. if (spawn2)
  1150. to = spawn2->GetName();
  1151. if (spawn && message.length() > 0) {
  1152. Client* client = 0;
  1153. if (player && player->IsPlayer())
  1154. client = spawn->GetZone()->GetClientBySpawn(player);
  1155. if (client)
  1156. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1157. else
  1158. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1159. }
  1160. lua_interface->ResetFunctionStack(state);
  1161. return 0;
  1162. }
  1163. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1164. if (!lua_interface)
  1165. return 0;
  1166. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1167. if (!luaspell)
  1168. return 0;
  1169. Spawn* caster = luaspell->caster;
  1170. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1171. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1172. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1173. Spawn* target = lua_interface->GetSpawn(state, 4);
  1174. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1175. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1176. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1177. lua_interface->ResetFunctionStack(state);
  1178. boost::to_lower(heal_type);
  1179. if (caster && caster->IsEntity()) {
  1180. bool success = false;
  1181. luaspell->resisted = false;
  1182. if (target) {
  1183. float distance = caster->GetDistance(target, true);
  1184. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1185. success = true;
  1186. }
  1187. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1188. Spawn* target = 0;
  1189. ZoneServer* zone = luaspell->caster->GetZone();
  1190. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1191. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1192. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1193. float distance = caster->GetDistance(target, true);
  1194. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1195. }
  1196. }
  1197. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1198. success = true;
  1199. }
  1200. if (success) {
  1201. if (caster->GetZone())
  1202. caster->GetZone()->TriggerCharSheetTimer();
  1203. }
  1204. }
  1205. return 0;
  1206. }
  1207. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1208. if (!lua_interface)
  1209. return 0;
  1210. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1211. if (!luaspell)
  1212. return 0;
  1213. Spawn* caster = luaspell->caster;
  1214. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1215. float percentage = lua_interface->GetFloatValue(state, 2);
  1216. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1217. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1218. Spawn* target = lua_interface->GetSpawn(state, 5);
  1219. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1220. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1221. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1222. lua_interface->ResetFunctionStack(state);
  1223. boost::to_lower(heal_type);
  1224. int32 min_heal = 0, max_heal = 0;
  1225. if (caster && caster->IsEntity() && target) {
  1226. if(percentage <= 0.0f)
  1227. {
  1228. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1229. return 0;
  1230. }
  1231. if(heal_type == "power")
  1232. {
  1233. if(current_value)
  1234. {
  1235. if(caster_value)
  1236. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1237. else
  1238. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1239. }
  1240. else
  1241. {
  1242. if(caster_value)
  1243. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1244. else
  1245. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1246. }
  1247. }
  1248. else
  1249. {
  1250. if(current_value)
  1251. {
  1252. if(caster_value)
  1253. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1254. else
  1255. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1256. }
  1257. else
  1258. {
  1259. if(caster_value)
  1260. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1261. else
  1262. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1263. }
  1264. }
  1265. bool success = false;
  1266. luaspell->resisted = false;
  1267. if (target) {
  1268. float distance = caster->GetDistance(target, true);
  1269. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1270. success = true;
  1271. }
  1272. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1273. Spawn* target = 0;
  1274. ZoneServer* zone = luaspell->caster->GetZone();
  1275. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1276. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1277. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1278. float distance = caster->GetDistance(target, true);
  1279. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1280. }
  1281. }
  1282. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1283. success = true;
  1284. }
  1285. if (success) {
  1286. if (caster->GetZone())
  1287. caster->GetZone()->TriggerCharSheetTimer();
  1288. }
  1289. }
  1290. return 0;
  1291. }
  1292. int EQ2Emu_lua_AddItem(lua_State* state) {
  1293. if (!lua_interface)
  1294. return 0;
  1295. Spawn* spawn = lua_interface->GetSpawn(state);
  1296. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1297. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1298. // default of 1 quantity to add
  1299. if (quantity == 0)
  1300. quantity = 1;
  1301. if (spawn && spawn->IsPlayer()) {
  1302. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1303. if (client && item_id > 0) {
  1304. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1305. return 1;
  1306. }
  1307. }
  1308. lua_interface->SetBooleanValue(state, false);
  1309. return 1;
  1310. }
  1311. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1312. if (!lua_interface)
  1313. return 0;
  1314. Spawn* spawn = lua_interface->GetSpawn(state);
  1315. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1316. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1317. string location = lua_interface->GetStringValue(state, 4);
  1318. if (spawn && spawn->IsPlayer()) {
  1319. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1320. if (client && item_id > 0) {
  1321. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1322. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, 1));
  1323. else
  1324. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  1325. if (send_messages) {
  1326. Item* item = master_item_list.GetItem(item_id);
  1327. if (item) {
  1328. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1329. string popup_text = "You receive " + item->name;
  1330. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1331. }
  1332. }
  1333. return 1;
  1334. }
  1335. }
  1336. lua_interface->SetBooleanValue(state, false);
  1337. return 1;
  1338. }
  1339. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1340. Spawn* spawn = lua_interface->GetSpawn(state);
  1341. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1342. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1343. // default of 1 to remove
  1344. if (quantity == 0)
  1345. quantity = 1;
  1346. Client* client;
  1347. Item* item;
  1348. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1349. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1350. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1351. if (client->RemoveItem(item, quantity)) {
  1352. lua_interface->SetBooleanValue(state, true);
  1353. return 1;
  1354. }
  1355. }
  1356. }
  1357. }
  1358. lua_interface->SetBooleanValue(state, false);
  1359. return 1;
  1360. }
  1361. int EQ2Emu_lua_HasItem(lua_State* state) {
  1362. Spawn* player = lua_interface->GetSpawn(state);
  1363. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1364. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1365. if (player && player->IsPlayer()) {
  1366. bool hasItem = false;
  1367. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1368. if (!hasItem)
  1369. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1370. lua_interface->SetBooleanValue(state, hasItem);
  1371. return 1;
  1372. }
  1373. lua_interface->SetBooleanValue(state, false);
  1374. return 1;
  1375. }
  1376. int EQ2Emu_lua_Spawn(lua_State* state) {
  1377. if (!lua_interface)
  1378. return 0;
  1379. ZoneServer* zone = lua_interface->GetZone(state);
  1380. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1381. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1382. float x = lua_interface->GetFloatValue(state, 4);
  1383. float y = lua_interface->GetFloatValue(state, 5);
  1384. float z = lua_interface->GetFloatValue(state, 6);
  1385. float heading = lua_interface->GetFloatValue(state, 7);
  1386. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1387. Spawn* spawn = zone->GetSpawn(spawn_id);
  1388. if (!spawn)
  1389. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1390. else {
  1391. spawn->SetX(x);
  1392. spawn->SetZ(z);
  1393. spawn->SetY(y,true,true);
  1394. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1395. spawn->SetHeading(heading);
  1396. if (restricted_npc)
  1397. spawn->AddAllowAccessSpawn(spawn);
  1398. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1399. bool scriptActive = false;
  1400. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1401. scriptActive = true;
  1402. spawn->SetSpawnScript(string(spawn_script));
  1403. }
  1404. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1405. zone->AddSpawn(spawn);
  1406. if (scriptActive) {
  1407. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1408. }
  1409. lua_interface->SetSpawnValue(state, spawn);
  1410. return 1;
  1411. }
  1412. }
  1413. else {
  1414. string output = "Invalid paramaters to LUA Spawn command: \n";
  1415. if (!zone)
  1416. output = output.append("\t").append("Missing zone reference. \n");
  1417. if (spawn_id == 0)
  1418. output = output.append("\t").append("Missing spawn_id.");
  1419. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1420. }
  1421. return 0;
  1422. }
  1423. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1424. if (!lua_interface)
  1425. return 0;
  1426. ZoneServer* zone = lua_interface->GetZone(state);
  1427. if (zone) {
  1428. lua_interface->SetStringValue(state, zone->GetZoneName());
  1429. return 1;
  1430. }
  1431. return 0;
  1432. }
  1433. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1434. if (!lua_interface)
  1435. return 0;
  1436. ZoneServer* zone = lua_interface->GetZone(state);
  1437. if (zone) {
  1438. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1439. return 1;
  1440. }
  1441. return 0;
  1442. }
  1443. int EQ2Emu_lua_GetZone(lua_State* state) {
  1444. if (!lua_interface)
  1445. return 0;
  1446. int32 zone_id = lua_interface->GetInt32Value(state);
  1447. ZoneServer* zone = 0;
  1448. if (zone_id > 0)
  1449. zone = zone_list.Get(zone_id);
  1450. else {
  1451. string zone_name = lua_interface->GetStringValue(state);
  1452. if (zone_name.length() > 0) {
  1453. zone = zone_list.Get(zone_name.c_str());
  1454. }
  1455. else {
  1456. Spawn* spawn = lua_interface->GetSpawn(state);
  1457. if (spawn)
  1458. zone = spawn->GetZone();
  1459. }
  1460. }
  1461. if (zone) {
  1462. lua_interface->SetZoneValue(state, zone);
  1463. return 1;
  1464. }
  1465. return 0;
  1466. }
  1467. int EQ2Emu_lua_AddHate(lua_State* state) {
  1468. Spawn* entity = lua_interface->GetSpawn(state);
  1469. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1470. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1471. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1472. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1473. if (entity && entity->IsEntity() && amount != 0) {
  1474. if (luaspell) {
  1475. ZoneServer* zone = luaspell->caster->GetZone();
  1476. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1477. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1478. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1479. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1480. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1481. if (send_packet)
  1482. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1483. }
  1484. }
  1485. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1486. }
  1487. else if (npc && npc->IsNPC() && npc->GetZone())
  1488. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1489. }
  1490. return 0;
  1491. }
  1492. int EQ2Emu_lua_Zone(lua_State* state) {
  1493. if (!lua_interface)
  1494. return 0;
  1495. ZoneServer* zone = lua_interface->GetZone(state);
  1496. Spawn* player = lua_interface->GetSpawn(state, 2);
  1497. Client* client = 0;
  1498. if (player && player->IsPlayer())
  1499. client = player->GetZone()->GetClientBySpawn(player);
  1500. float x = lua_interface->GetFloatValue(state, 3);
  1501. float y = lua_interface->GetFloatValue(state, 4);
  1502. float z = lua_interface->GetFloatValue(state, 5);
  1503. float heading = lua_interface->GetFloatValue(state, 6);
  1504. if (zone && client) {
  1505. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1506. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1507. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1508. {
  1509. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1510. return 0;
  1511. }
  1512. if (x != 0 || y != 0 || z != 0) {
  1513. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1514. player->SetX(x);
  1515. player->SetY(y);
  1516. player->SetZ(z);
  1517. player->SetHeading(heading);
  1518. client->Zone(zone->GetZoneName(), false);
  1519. }
  1520. else
  1521. client->Zone(zone->GetZoneName());
  1522. }
  1523. else
  1524. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1525. return 0;
  1526. }
  1527. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1528. if (!lua_interface)
  1529. return 0;
  1530. Spawn* spawn = lua_interface->GetSpawn(state);
  1531. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1532. if (spawn && spawn2)
  1533. spawn->AddAllowAccessSpawn(spawn2);
  1534. return 0;
  1535. }
  1536. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1537. if (!lua_interface)
  1538. return 0;
  1539. Spawn* target = lua_interface->GetSpawn(state);
  1540. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1541. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1542. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1543. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1544. if (!target) {
  1545. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1546. return 0;
  1547. }
  1548. if (!target->IsEntity()) {
  1549. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1550. return 0;
  1551. }
  1552. if (spell_id <= 0) {
  1553. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1554. return 0;
  1555. }
  1556. if (caster && !caster->IsEntity()) {
  1557. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1558. return 0;
  1559. }
  1560. if (spell_tier == 0)
  1561. spell_tier = 1;
  1562. if (!caster)
  1563. caster = target;
  1564. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1565. return 0;
  1566. }
  1567. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1568. if (!lua_interface)
  1569. return 0;
  1570. Spawn* target = lua_interface->GetSpawn(state);
  1571. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1572. if (!luaspell)
  1573. return 0;
  1574. Spawn* caster = luaspell->caster;
  1575. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1576. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1577. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1578. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1579. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1580. //lua_interface->ResetFunctionStack(state);
  1581. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1582. vector<int16> faction_req;
  1583. vector<int16> race_req;
  1584. int32 class_req = 0;
  1585. int32 i = 0;
  1586. int8 f = 0;
  1587. int8 r = 0;
  1588. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1589. if (class_id < 100) {
  1590. class_req += pow(2.0, double(class_id - 1));
  1591. }
  1592. else if (class_id > 100 && class_id < 1000) {
  1593. race_req.push_back(class_id);
  1594. r++;
  1595. }
  1596. else {
  1597. faction_req.push_back(class_id);
  1598. f++;
  1599. }
  1600. i++;
  1601. }
  1602. if (caster && caster->IsEntity()) {
  1603. bool race_match = false;
  1604. bool success = false;
  1605. luaspell->resisted = false;
  1606. if (luaspell->targets.size() > 0) {
  1607. ZoneServer* zone = luaspell->caster->GetZone();
  1608. Spawn* target = 0;
  1609. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1610. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1611. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1612. if (race_req.size() > 0) {
  1613. for (int8 i = 0; i < race_req.size(); i++) {
  1614. if (target->GetLuaRaceId() == race_req[i]) {
  1615. race_match = true;
  1616. }
  1617. }
  1618. }
  1619. else
  1620. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1621. if (race_match == true) {
  1622. float distance = caster->GetDistance(target, true);
  1623. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1624. }
  1625. }
  1626. }
  1627. success = true;
  1628. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1629. }
  1630. else if (target) {
  1631. //check class and race/faction here
  1632. if (race_req.size() > 0) {
  1633. for (int8 i = 0; i < race_req.size(); i++) {
  1634. if (target->GetLuaRaceId() == race_req[i]) {
  1635. race_match = true;
  1636. }
  1637. }
  1638. }
  1639. else
  1640. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1641. if (race_match == true) {
  1642. float distance = caster->GetDistance(target, true);
  1643. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1644. success = true;
  1645. }
  1646. }
  1647. if (success) {
  1648. Spell* spell = luaspell->spell;
  1649. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1650. ((Player*)caster)->InCombat(true);
  1651. if (caster->GetZone())
  1652. caster->GetZone()->TriggerCharSheetTimer();
  1653. }
  1654. }
  1655. }
  1656. return 0;
  1657. }
  1658. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1659. if (!lua_interface)
  1660. return 0;
  1661. Spawn* spawn = lua_interface->GetSpawn(state);
  1662. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1663. lua_interface->ResetFunctionStack(state);
  1664. if (spawn && value != 0) {
  1665. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1666. spawn->SetPower(spawn->GetTotalPower());
  1667. else
  1668. spawn->SetPower(spawn->GetPower() + value);
  1669. }
  1670. return 0;
  1671. }
  1672. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1673. if (!lua_interface)
  1674. return 0;
  1675. Spawn* spawn = lua_interface->GetSpawn(state);
  1676. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1677. lua_interface->ResetFunctionStack(state);
  1678. if (spawn && value != 0) {
  1679. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1680. spawn->SetHP(spawn->GetTotalHP());
  1681. else
  1682. spawn->SetHP(spawn->GetHP() + value);
  1683. }
  1684. return 0;
  1685. }
  1686. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1687. if (!lua_interface)
  1688. return 0;
  1689. Spawn* spawn = lua_interface->GetSpawn(state);
  1690. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1691. lua_interface->ResetFunctionStack(state);
  1692. if (spawn && value != 0) {
  1693. spawn->SetPower(spawn->GetPower() + value);
  1694. if (value > spawn->GetTotalHPBase())
  1695. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1696. }
  1697. return 0;
  1698. }
  1699. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1700. if (!lua_interface)
  1701. return 0;
  1702. Spawn* spawn = lua_interface->GetSpawn(state);
  1703. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1704. lua_interface->ResetFunctionStack(state);
  1705. if (spawn && value != 0) {
  1706. spawn->SetHP(spawn->GetHP() + value);
  1707. if (value > spawn->GetTotalHPBase())
  1708. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1709. }
  1710. return 0;
  1711. }
  1712. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1713. if (!lua_interface)
  1714. return 0;
  1715. Spawn* spawn = lua_interface->GetSpawn(state);
  1716. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1717. lua_interface->ResetFunctionStack(state);
  1718. if (spawn) {
  1719. spawn->SetHP(value);
  1720. if (value > spawn->GetTotalHPBase())
  1721. spawn->SetTotalHP(value);
  1722. }
  1723. return 0;
  1724. }
  1725. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1726. if (!lua_interface)
  1727. return 0;
  1728. Spawn* spawn = lua_interface->GetSpawn(state);
  1729. float value = lua_interface->GetFloatValue(state, 2);
  1730. lua_interface->ResetFunctionStack(state);
  1731. if (spawn && spawn->IsEntity() && value > 0)
  1732. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1733. if (spawn->IsPlayer())
  1734. ((Player*)spawn)->SetCharSheetChanged(true);
  1735. return 0;
  1736. }
  1737. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1738. if (!lua_interface)
  1739. return 0;
  1740. Spawn* spawn = lua_interface->GetSpawn(state);
  1741. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1742. lua_interface->ResetFunctionStack(state);
  1743. if (spawn && spawn->IsEntity() && value > 0)
  1744. ((Entity*)spawn)->SetTotalHPBase(value);
  1745. return 0;
  1746. }
  1747. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1748. if (!lua_interface)
  1749. return 0;
  1750. Spawn* spawn = lua_interface->GetSpawn(state);
  1751. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1752. lua_interface->ResetFunctionStack(state);
  1753. if (spawn && value > 0) {
  1754. spawn->SetPower(value);
  1755. if (value > spawn->GetTotalPowerBase())
  1756. spawn->SetTotalPower(value);
  1757. }
  1758. return 0;
  1759. }
  1760. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1761. if (!lua_interface)
  1762. return 0;
  1763. Spawn* spawn = lua_interface->GetSpawn(state);
  1764. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1765. lua_interface->ResetFunctionStack(state);
  1766. if (spawn && spawn->IsEntity() && value > 0)
  1767. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1768. return 0;
  1769. }
  1770. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1771. if (!lua_interface)
  1772. return 0;
  1773. Spawn* spawn = lua_interface->GetSpawn(state);
  1774. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1775. lua_interface->ResetFunctionStack(state);
  1776. if (spawn && spawn->IsEntity() && value > 0)
  1777. ((Entity*)spawn)->SetTotalPowerBase(value);
  1778. return 0;
  1779. }
  1780. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1781. if (!lua_interface)
  1782. return 0;
  1783. Spawn* spawn = lua_interface->GetSpawn(state);
  1784. float x = lua_interface->GetFloatValue(state, 2);
  1785. float y = lua_interface->GetFloatValue(state, 3);
  1786. float z = lua_interface->GetFloatValue(state, 4);
  1787. float heading = lua_interface->GetFloatValue(state, 5);
  1788. lua_interface->ResetFunctionStack(state);
  1789. if (spawn) {
  1790. spawn->SetX(x);
  1791. spawn->SetY(y);
  1792. spawn->SetZ(z);
  1793. if (heading != 0)
  1794. spawn->SetHeading(heading);
  1795. spawn->SetSpawnOrigX(spawn->GetX());
  1796. spawn->SetSpawnOrigY(spawn->GetY());
  1797. spawn->SetSpawnOrigZ(spawn->GetZ());
  1798. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1799. if (spawn->IsPlayer()) {
  1800. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1801. if (client) {
  1802. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1803. client->QueuePacket(packet);
  1804. }
  1805. }
  1806. }
  1807. return 0;
  1808. }
  1809. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1810. if (!lua_interface)
  1811. return 0;
  1812. Spawn* spawn = lua_interface->GetSpawn(state);
  1813. float value = lua_interface->GetFloatValue(state, 2);
  1814. lua_interface->ResetFunctionStack(state);
  1815. if (spawn) {
  1816. spawn->SetHeading(value);
  1817. if (spawn->IsPlayer()) {
  1818. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1819. if (client) {
  1820. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1821. client->QueuePacket(packet);
  1822. }
  1823. }
  1824. }
  1825. return 0;
  1826. }
  1827. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1828. if (!lua_interface)
  1829. return 0;
  1830. Spawn* spawn = lua_interface->GetSpawn(state);
  1831. int16 value = lua_interface->GetInt16Value(state, 2);
  1832. lua_interface->ResetFunctionStack(state);
  1833. if (spawn)
  1834. spawn->SetModelType(value);
  1835. return 0;
  1836. }
  1837. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1838. if (!lua_interface)
  1839. return 0;
  1840. Spawn* spawn = lua_interface->GetSpawn(state);
  1841. int8 value = lua_interface->GetInt8Value(state, 2);
  1842. lua_interface->ResetFunctionStack(state);
  1843. if (spawn) {
  1844. if (spawn->IsPlayer())
  1845. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1846. else
  1847. spawn->SetAdventureClass(value);
  1848. }
  1849. return 0;
  1850. }
  1851. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1852. if (!lua_interface)
  1853. return 0;
  1854. Spawn* spawn = lua_interface->GetSpawn(state);
  1855. int8 value = lua_interface->GetInt8Value(state, 2);
  1856. lua_interface->ResetFunctionStack(state);
  1857. if (spawn) {
  1858. spawn->SetTradeskillClass(value);
  1859. if (spawn->IsEntity()) {
  1860. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1861. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1862. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1863. }
  1864. if (spawn->IsPlayer())
  1865. ((Player*)spawn)->SetCharSheetChanged(true);
  1866. }
  1867. return 0;
  1868. }
  1869. int EQ2Emu_lua_SetMount(lua_State* state) {
  1870. if (!lua_interface)
  1871. return 0;
  1872. Spawn* spawn = lua_interface->GetSpawn(state);
  1873. int16 value = lua_interface->GetInt16Value(state, 2);
  1874. if (spawn && spawn->IsEntity()) {
  1875. ((Entity*)spawn)->SetMount(value);
  1876. EQ2_Color color;
  1877. color.red = 255;
  1878. color.green = 255;
  1879. color.blue = 255;
  1880. ((Entity*)spawn)->SetMountColor(&color);
  1881. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1882. }
  1883. return 0;
  1884. }
  1885. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1886. if (!lua_interface)
  1887. return 0;
  1888. Spawn* spawn = lua_interface->GetSpawn(state);
  1889. EQ2_Color mount_color;
  1890. EQ2_Color saddle_color;
  1891. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1892. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1893. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1894. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1895. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1896. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1897. if (spawn && spawn->IsEntity()) {
  1898. ((Entity*)spawn)->SetMountColor(&mount_color);
  1899. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1900. }
  1901. return 0;
  1902. }
  1903. int EQ2Emu_lua_GetMount(lua_State* state) {
  1904. if (!lua_interface)
  1905. return 0;
  1906. Spawn* spawn = lua_interface->GetSpawn(state);
  1907. if (spawn && spawn->IsEntity()) {
  1908. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1909. return 1;
  1910. }
  1911. return 0;
  1912. }
  1913. int EQ2Emu_lua_GetRace(lua_State* state) {
  1914. if (!lua_interface)
  1915. return 0;
  1916. Spawn* spawn = lua_interface->GetSpawn(state);
  1917. if (spawn)
  1918. {
  1919. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1920. lua_interface->SetInt32Value(state, spawn->GetRace());
  1921. return 1;
  1922. }
  1923. return 0;
  1924. }
  1925. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  1926. if (!lua_interface)
  1927. return 0;
  1928. Spawn* spawn = lua_interface->GetSpawn(state);
  1929. if (spawn) {
  1930. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  1931. return 1;
  1932. }
  1933. return 0;
  1934. }
  1935. int EQ2Emu_lua_GetClass(lua_State* state) {
  1936. Spawn* spawn = lua_interface->GetSpawn(state);
  1937. if (spawn) {
  1938. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  1939. return 1;
  1940. }
  1941. return 0;
  1942. }
  1943. int EQ2Emu_lua_GetClassName(lua_State* state) {
  1944. Spawn* spawn = lua_interface->GetSpawn(state);
  1945. if (spawn) {
  1946. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  1947. return 1;
  1948. }
  1949. return 0;
  1950. }
  1951. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  1952. if (!lua_interface)
  1953. return 0;
  1954. Spawn* spawn = lua_interface->GetSpawn(state);
  1955. float value = lua_interface->GetFloatValue(state, 2);
  1956. lua_interface->ResetFunctionStack(state);
  1957. if (spawn) {
  1958. spawn->SetSpeed(value);
  1959. ((Entity*)spawn)->SetSpeed(value);
  1960. if (spawn->IsPlayer()) {
  1961. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1962. if (client) {
  1963. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  1964. if (packet) {
  1965. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  1966. packet->setDataByName("speed", value);
  1967. packet->setDataByName("size", 0.51);
  1968. EQ2Packet* app = packet->serialize();
  1969. client->QueuePacket(app);
  1970. safe_delete(packet);
  1971. }
  1972. }
  1973. }
  1974. }
  1975. return 0;
  1976. }
  1977. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  1978. if (!lua_interface)
  1979. return 0;
  1980. Spawn* spawn = lua_interface->GetSpawn(state);
  1981. const int16 type = lua_interface->GetInt16Value(state, 2);
  1982. const float value = lua_interface->GetFloatValue(state, 3);
  1983. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1984. int64 class_req = 0;
  1985. int32 class_id = 0;
  1986. vector<int16> faction_req;
  1987. vector<int16> race_req;
  1988. int32 i = 0;
  1989. int8 f = 0;
  1990. int8 r = 0;
  1991. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1992. if (class_id < 100) {
  1993. class_req += pow(2.0, double(class_id - 1));
  1994. }
  1995. else if (class_id > 100 && class_id < 1000) {
  1996. race_req.push_back(class_id);
  1997. r++;
  1998. }
  1999. else {
  2000. faction_req.push_back(class_id);
  2001. f++;
  2002. }
  2003. i++;
  2004. }
  2005. if (value != 0 && type >= 0) {
  2006. if (luaspell && luaspell->spell && luaspell->caster) {
  2007. ZoneServer* zone = luaspell->caster->GetZone();
  2008. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2009. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2010. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2011. if (target) {
  2012. if (target->IsPlayer()) {
  2013. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2014. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2015. if (((Player*)target)->GetGroupMemberInfo())
  2016. ((Player*)target)->UpdateGroupMemberInfo();
  2017. ((Player*)target)->SetCharSheetChanged(true);
  2018. }
  2019. else if (target->IsNPC())
  2020. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2021. else
  2022. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2023. }
  2024. }
  2025. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2026. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2027. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2028. }
  2029. else if (spawn && spawn->IsEntity()) {
  2030. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2031. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2032. if (spawn->IsPlayer())
  2033. ((Player*)spawn)->SetCharSheetChanged(true);
  2034. }
  2035. else
  2036. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2037. }
  2038. else
  2039. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2040. return 0;
  2041. }
  2042. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2043. if (!lua_interface)
  2044. return 0;
  2045. Spawn* spawn = lua_interface->GetSpawn(state);
  2046. int16 type = lua_interface->GetInt16Value(state, 2);
  2047. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2048. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2049. if (!spawn) {
  2050. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2051. return 0;
  2052. }
  2053. if (!spawn->IsEntity()) {
  2054. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2055. return 0;
  2056. }
  2057. if (value == 0) {
  2058. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2059. return 0;
  2060. }
  2061. if (!luaspell || !luaspell->spell) {
  2062. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2063. return 0;
  2064. }
  2065. int32 class_req = 0;
  2066. vector<int16> faction_req;
  2067. vector<int16> race_req;
  2068. int32 class_id = 0;
  2069. int32 i = 0;
  2070. int8 f = 0;
  2071. int8 r = 0;
  2072. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2073. if (class_id < 100) {
  2074. class_req += pow(2.0, double(class_id - 1));
  2075. }
  2076. else if (class_id > 100 && class_id < 1000) {
  2077. race_req.push_back(class_id);
  2078. r++;
  2079. }
  2080. else {
  2081. faction_req.push_back(class_id);
  2082. f++;
  2083. }
  2084. i++;
  2085. }
  2086. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2087. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2088. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2089. if (spawn->IsPlayer())
  2090. ((Player*)spawn)->SetCharSheetChanged(true);
  2091. return 0;
  2092. }
  2093. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2094. if (!lua_interface)
  2095. return 0;
  2096. Spawn* spawn = lua_interface->GetSpawn(state);
  2097. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2098. if (!spawn) {
  2099. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2100. return 0;
  2101. }
  2102. if (!spawn->IsEntity()) {
  2103. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2104. return 0;
  2105. }
  2106. if (!luaspell || !luaspell->spell) {
  2107. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2108. return 0;
  2109. }
  2110. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2111. if (spawn->IsPlayer())
  2112. ((Player*)spawn)->SetCharSheetChanged(true);
  2113. return 0;
  2114. }
  2115. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2116. if (!lua_interface)
  2117. return 0;
  2118. Spawn* spawn = lua_interface->GetSpawn(state);
  2119. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2120. if (luaspell && luaspell->spell) {
  2121. ZoneServer* zone = luaspell->caster->GetZone();
  2122. Spawn* target = 0;
  2123. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2124. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2125. target = zone->GetSpawnByID(luaspell->targets[i]);
  2126. if (target && target->IsEntity()) {
  2127. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2128. if (target->IsPlayer())
  2129. ((Player*)target)->SetCharSheetChanged(true);
  2130. }
  2131. }
  2132. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2133. }
  2134. else if (spawn && spawn->IsEntity()) {
  2135. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2136. if (spawn->IsPlayer())
  2137. ((Player*)spawn)->SetCharSheetChanged(true);
  2138. }
  2139. return 0;
  2140. }
  2141. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2142. if (!lua_interface)
  2143. return 0;
  2144. Spawn* spawn = lua_interface->GetSpawn(state);
  2145. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2146. float value = lua_interface->GetFloatValue(state, 3);
  2147. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2148. if (value != 0) {
  2149. int32 spell_id = 0;
  2150. if (luaspell && luaspell->spell && luaspell->caster) {
  2151. spell_id = luaspell->spell->GetSpellID();
  2152. ZoneServer* zone = luaspell->caster->GetZone();
  2153. Spawn* target = 0;
  2154. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2155. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2156. target = zone->GetSpawnByID(luaspell->targets[i]);
  2157. if (target && target->Alive()) {
  2158. if (target->IsPlayer()) {
  2159. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2160. Client* client = target->GetZone()->GetClientBySpawn(target);
  2161. if (client) {
  2162. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2163. if (packet)
  2164. client->QueuePacket(packet);
  2165. }
  2166. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2167. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2168. }
  2169. else if (target->IsNPC()) {
  2170. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2171. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2172. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2173. }
  2174. else
  2175. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2176. }
  2177. }
  2178. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2179. }
  2180. else if (spawn) {
  2181. if (spawn->IsPlayer()) {
  2182. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2183. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2184. if (client) {
  2185. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2186. if (packet)
  2187. client->QueuePacket(packet);
  2188. }
  2189. }
  2190. else if (spawn->IsNPC())
  2191. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2192. else
  2193. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2194. }
  2195. }
  2196. else
  2197. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2198. return 0;
  2199. }
  2200. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2201. if (!lua_interface)
  2202. return 0;
  2203. Spawn* spawn = lua_interface->GetSpawn(state);
  2204. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2205. if (spawn && spawn->IsPlayer()) {
  2206. int32 spell_id = 0;
  2207. if (luaspell && luaspell->spell) {
  2208. spell_id = luaspell->spell->GetSpellID();
  2209. ZoneServer* zone = luaspell->caster->GetZone();
  2210. Spawn* target = 0;
  2211. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2212. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2213. target = zone->GetSpawnByID(luaspell->targets[i]);
  2214. if (target) {
  2215. if (target->IsPlayer()) {
  2216. ((Player*)target)->RemoveSkillBonus(spell_id);
  2217. Client* client = target->GetZone()->GetClientBySpawn(target);
  2218. if (client) {
  2219. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2220. if (packet)
  2221. client->QueuePacket(packet);
  2222. }
  2223. }
  2224. else if (target->IsNPC())
  2225. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2226. else
  2227. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2228. }
  2229. }
  2230. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2231. }
  2232. else if (spawn) {
  2233. if (spawn->IsPlayer()) {
  2234. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2235. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2236. if (client) {
  2237. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2238. if (packet)
  2239. client->QueuePacket(packet);
  2240. }
  2241. }
  2242. else if (spawn->IsNPC())
  2243. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2244. else
  2245. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2246. }
  2247. }
  2248. return 0;
  2249. }
  2250. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2251. if (!lua_interface)
  2252. return 0;
  2253. Spawn* spawn = lua_interface->GetSpawn(state);
  2254. int8 type = lua_interface->GetInt32Value(state, 2);
  2255. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2256. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2257. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2258. ZoneServer* zone = luaspell->caster->GetZone();
  2259. Spawn* target = 0;
  2260. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2261. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2262. target = zone->GetSpawnByID(luaspell->targets[i]);
  2263. if (target && target->IsEntity()) {
  2264. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2265. ((Entity*)target)->AddMezSpell(luaspell);
  2266. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2267. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2268. if (target->IsNPC())
  2269. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2270. }
  2271. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2272. ((Entity*)target)->AddStifleSpell(luaspell);
  2273. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2274. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2275. if (target->IsNPC())
  2276. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2277. }
  2278. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2279. ((Entity*)target)->AddDazeSpell(luaspell);
  2280. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2281. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2282. if (target->IsNPC())
  2283. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2284. }
  2285. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2286. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2287. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2288. ((Entity*)target)->AddStunSpell(luaspell);
  2289. if (target->IsNPC())
  2290. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2291. }
  2292. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2293. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2294. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2295. ((Entity*)target)->AddRootSpell(luaspell);
  2296. if (target->IsNPC())
  2297. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2298. }
  2299. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2300. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2301. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2302. ((Entity*)target)->AddFearSpell(luaspell);
  2303. if (target->IsNPC())
  2304. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2305. }
  2306. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2307. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2308. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2309. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2310. }
  2311. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2312. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2313. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2314. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2315. }
  2316. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2317. ((Entity*)target)->AddSnareSpell(luaspell);
  2318. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2319. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2320. if (target->IsNPC())
  2321. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2322. }
  2323. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2324. ((Entity*)target)->AddFlightSpell(luaspell);
  2325. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2326. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2327. }
  2328. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2329. ((Entity*)target)->AddGlideSpell(luaspell);
  2330. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2331. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2332. }
  2333. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2334. ((Entity*)target)->AddSafefallSpell(luaspell);
  2335. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2336. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2337. }
  2338. else
  2339. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2340. }
  2341. else
  2342. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  2343. }
  2344. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2345. }
  2346. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2347. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2348. ((Entity*)spawn)->AddMezSpell(luaspell);
  2349. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2350. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2351. }
  2352. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2353. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2354. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2355. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2356. }
  2357. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2358. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2359. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2360. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2361. }
  2362. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2363. ((Entity*)spawn)->AddStunSpell(luaspell);
  2364. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2365. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2366. }
  2367. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2368. ((Entity*)spawn)->AddRootSpell(luaspell);
  2369. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2370. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2371. }
  2372. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2373. ((Entity*)spawn)->AddFearSpell(luaspell);
  2374. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2375. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2376. }
  2377. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2378. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2379. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2380. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2381. }
  2382. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2383. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2384. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2385. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2386. }
  2387. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2388. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2389. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2390. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2391. }
  2392. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2393. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2394. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2395. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2396. }
  2397. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2398. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2399. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2400. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2401. }
  2402. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2403. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2404. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2405. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2406. }
  2407. else
  2408. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2409. }
  2410. else
  2411. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  2412. return 0;
  2413. }
  2414. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2415. if (!lua_interface)
  2416. return 0;
  2417. Spawn* spawn = lua_interface->GetSpawn(state);
  2418. int8 type = lua_interface->GetInt8Value(state, 2);
  2419. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2420. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2421. if (spawn && spawn->IsEntity()) {
  2422. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2423. ZoneServer* zone = luaspell->caster->GetZone();
  2424. Spawn* target = 0;
  2425. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2426. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2427. target = zone->GetSpawnByID(luaspell->targets[i]);
  2428. if (target) {
  2429. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2430. ((Entity*)target)->RemoveMezSpell(luaspell);
  2431. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2432. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2433. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2434. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2435. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2436. ((Entity*)target)->RemoveStunSpell(luaspell);
  2437. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2438. ((Entity*)target)->RemoveRootSpell(luaspell);
  2439. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2440. ((Entity*)target)->RemoveFearSpell(luaspell);
  2441. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2442. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2443. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2444. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2445. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2446. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2447. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2448. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2449. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2450. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2451. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2452. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2453. else
  2454. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2455. }
  2456. }
  2457. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2458. }
  2459. else if (only_remove_spawn) {
  2460. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2461. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2462. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2463. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2464. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2465. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2466. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2467. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2468. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2469. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2470. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2471. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2472. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2473. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2474. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2475. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2476. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2477. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2478. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2479. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2480. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2481. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2482. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2483. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2484. else
  2485. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2486. }
  2487. }
  2488. return 0;
  2489. }
  2490. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2491. if (!lua_interface)
  2492. return 0;
  2493. Spawn* spawn = lua_interface->GetSpawn(state);
  2494. int8 type = lua_interface->GetInt8Value(state, 2);
  2495. bool hasEffect = false;
  2496. if (!spawn)
  2497. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2498. else if (!spawn->IsEntity())
  2499. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2500. else if (type < CONTROL_MAX_EFFECTS)
  2501. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2502. else
  2503. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2504. lua_interface->SetBooleanValue(state, hasEffect);
  2505. return 1;
  2506. }
  2507. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2508. if (!lua_interface)
  2509. return 0;
  2510. Spawn* spawn = lua_interface->GetSpawn(state);
  2511. float distance = 0.0f;
  2512. if (!spawn)
  2513. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2514. else if (!spawn->IsNPC())
  2515. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2516. else
  2517. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2518. lua_interface->SetFloatValue(state, distance);
  2519. return 1;
  2520. }
  2521. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2522. if (!lua_interface)
  2523. return 0;
  2524. Spawn* spawn = lua_interface->GetSpawn(state);
  2525. float distance = 0.0f;
  2526. if (!spawn)
  2527. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2528. else if (!spawn->IsNPC())
  2529. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2530. else
  2531. distance = ((NPC*)spawn)->GetAggroRadius();
  2532. lua_interface->SetFloatValue(state, distance);
  2533. return 1;
  2534. }
  2535. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2536. if (!lua_interface)
  2537. return 0;
  2538. Spawn* spawn = lua_interface->GetSpawn(state);
  2539. float distance = lua_interface->GetFloatValue(state, 2);
  2540. bool override = lua_interface->GetBooleanValue(state, 3);
  2541. bool result = false;
  2542. lua_interface->ResetFunctionStack(state);
  2543. if (!spawn)
  2544. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2545. else if (!spawn->IsNPC())
  2546. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2547. else
  2548. {
  2549. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2550. result = true;
  2551. }
  2552. lua_interface->SetBooleanValue(state, result);
  2553. return 1;
  2554. }
  2555. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2556. if (!lua_interface)
  2557. return 0;
  2558. Spawn* spawn = lua_interface->GetSpawn(state);
  2559. int16 value = lua_interface->GetInt16Value(state, 2);
  2560. if (spawn && spawn->IsEntity()) {
  2561. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2562. if (spawn->IsPlayer())
  2563. ((Player*)spawn)->SetCharSheetChanged(true);
  2564. }
  2565. return 0;
  2566. }
  2567. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2568. if (!lua_interface)
  2569. return 0;
  2570. Spawn* spawn = lua_interface->GetSpawn(state);
  2571. int16 value = lua_interface->GetInt16Value(state, 2);
  2572. if (spawn && spawn->IsEntity()) {
  2573. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2574. if (spawn->IsPlayer())
  2575. ((Player*)spawn)->SetCharSheetChanged(true);
  2576. }
  2577. return 0;
  2578. }
  2579. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2580. if (!lua_interface)
  2581. return 0;
  2582. Spawn* spawn = lua_interface->GetSpawn(state);
  2583. int16 value = lua_interface->GetInt16Value(state, 2);
  2584. if (spawn && spawn->IsEntity()) {
  2585. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2586. if (spawn->IsPlayer())
  2587. ((Player*)spawn)->SetCharSheetChanged(true);
  2588. }
  2589. return 0;
  2590. }
  2591. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2592. if (!lua_interface)
  2593. return 0;
  2594. Spawn* spawn = lua_interface->GetSpawn(state);
  2595. int16 value = lua_interface->GetInt16Value(state, 2);
  2596. if (spawn && spawn->IsEntity()) {
  2597. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2598. if (spawn->IsPlayer())
  2599. ((Player*)spawn)->SetCharSheetChanged(true);
  2600. }
  2601. return 0;
  2602. }
  2603. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2604. if (!lua_interface)
  2605. return 0;
  2606. Spawn* spawn = lua_interface->GetSpawn(state);
  2607. int16 value = lua_interface->GetInt16Value(state, 2);
  2608. if (spawn && spawn->IsEntity()) {
  2609. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2610. if (spawn->IsPlayer())
  2611. ((Player*)spawn)->SetCharSheetChanged(true);
  2612. }
  2613. return 0;
  2614. }
  2615. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2616. if (!lua_interface)
  2617. return 0;
  2618. Spawn* spawn = lua_interface->GetSpawn(state);
  2619. int8 value = lua_interface->GetInt8Value(state, 2);
  2620. if (spawn && spawn->IsEntity()) {
  2621. ((Entity*)spawn)->SetDeity(value);
  2622. if (spawn->IsPlayer())
  2623. ((Player*)spawn)->SetCharSheetChanged(true);
  2624. }
  2625. lua_interface->ResetFunctionStack(state);
  2626. return 0;
  2627. }
  2628. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2629. if (!lua_interface)
  2630. return 0;
  2631. Spawn* spawn = lua_interface->GetSpawn(state);
  2632. if (spawn && spawn->IsEntity()) {
  2633. int8 deity = ((Entity*)spawn)->GetDeity();
  2634. lua_interface->SetInt32Value(state, deity);
  2635. return 1;
  2636. }
  2637. return 0;
  2638. }
  2639. int EQ2Emu_lua_SetInt(lua_State* state) {
  2640. if (!lua_interface)
  2641. return 0;
  2642. Spawn* spawn = lua_interface->GetSpawn(state);
  2643. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2644. if (spawn && spawn->IsEntity()) {
  2645. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2646. if (spawn->IsPlayer())
  2647. ((Player*)spawn)->SetCharSheetChanged(true);
  2648. }
  2649. return 0;
  2650. }
  2651. int EQ2Emu_lua_SetWis(lua_State* state) {
  2652. if (!lua_interface)
  2653. return 0;
  2654. Spawn* spawn = lua_interface->GetSpawn(state);
  2655. float value = lua_interface->GetFloatValue(state, 2);
  2656. if (spawn && spawn->IsEntity()) {
  2657. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2658. if (spawn->IsPlayer())
  2659. ((Player*)spawn)->SetCharSheetChanged(true);
  2660. }
  2661. return 0;
  2662. }
  2663. int EQ2Emu_lua_SetSta(lua_State* state) {
  2664. if (!lua_interface)
  2665. return 0;
  2666. Spawn* spawn = lua_interface->GetSpawn(state);
  2667. float value = lua_interface->GetFloatValue(state, 2);
  2668. if (spawn && spawn->IsEntity()) {
  2669. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2670. if (spawn->IsPlayer())
  2671. ((Player*)spawn)->SetCharSheetChanged(true);
  2672. }
  2673. return 0;
  2674. }
  2675. int EQ2Emu_lua_SetStr(lua_State* state) {
  2676. if (!lua_interface)
  2677. return 0;
  2678. Spawn* spawn = lua_interface->GetSpawn(state);
  2679. float value = lua_interface->GetFloatValue(state, 2);
  2680. if (spawn && spawn->IsEntity()) {
  2681. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2682. if (spawn->IsPlayer())
  2683. ((Player*)spawn)->SetCharSheetChanged(true);
  2684. }
  2685. return 0;
  2686. }
  2687. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2688. if (!lua_interface)
  2689. return 0;
  2690. Spawn* spawn = lua_interface->GetSpawn(state);
  2691. float value = lua_interface->GetFloatValue(state, 2);
  2692. if (spawn && spawn->IsEntity()) {
  2693. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2694. if (spawn->IsPlayer())
  2695. ((Player*)spawn)->SetCharSheetChanged(true);
  2696. }
  2697. return 0;
  2698. }
  2699. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2700. if (!lua_interface)
  2701. return 0;
  2702. Spawn* spawn = lua_interface->GetSpawn(state);
  2703. if (spawn) {
  2704. lua_interface->SetInt32Value(state, spawn->GetHP());
  2705. return 1;
  2706. }
  2707. return 0;
  2708. }
  2709. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2710. if (!lua_interface)
  2711. return 0;
  2712. Spawn* spawn = lua_interface->GetSpawn(state);
  2713. if (spawn) {
  2714. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2715. return 1;
  2716. }
  2717. return 0;
  2718. }
  2719. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2720. if (!lua_interface)
  2721. return 0;
  2722. Spawn* spawn = lua_interface->GetSpawn(state);
  2723. if (spawn) {
  2724. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2725. return 1;
  2726. }
  2727. return 0;
  2728. }
  2729. int EQ2Emu_lua_GetName(lua_State* state) {
  2730. if (!lua_interface)
  2731. return 0;
  2732. Spawn* spawn = lua_interface->GetSpawn(state);
  2733. if (spawn) {
  2734. lua_interface->SetStringValue(state, spawn->GetName());
  2735. return 1;
  2736. }
  2737. return 0;
  2738. }
  2739. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2740. Spawn* spawn = lua_interface->GetSpawn(state);
  2741. if (spawn) {
  2742. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2743. return 1;
  2744. }
  2745. return 0;
  2746. }
  2747. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2748. if (!lua_interface)
  2749. return 0;
  2750. Spawn* spawn = lua_interface->GetSpawn(state);
  2751. if (spawn) {
  2752. lua_interface->SetInt32Value(state, spawn->GetPower());
  2753. return 1;
  2754. }
  2755. return 0;
  2756. }
  2757. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2758. if (!lua_interface)
  2759. return 0;
  2760. Spawn* spawn = lua_interface->GetSpawn(state);
  2761. if (spawn) {
  2762. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2763. return 1;
  2764. }
  2765. return 0;
  2766. }
  2767. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2768. if (!lua_interface)
  2769. return 0;
  2770. Spawn* spawn = lua_interface->GetSpawn(state);
  2771. if (spawn) {
  2772. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2773. return 1;
  2774. }
  2775. return 0;
  2776. }
  2777. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2778. if (!lua_interface)
  2779. return 0;
  2780. Spawn* spawn = lua_interface->GetSpawn(state);
  2781. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2782. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2783. if (spawn && spawn2) {
  2784. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2785. lua_interface->SetFloatValue(state, distance);
  2786. return 1;
  2787. }
  2788. return 0;
  2789. }
  2790. int EQ2Emu_lua_GetX(lua_State* state) {
  2791. if (!lua_interface)
  2792. return 0;
  2793. Spawn* spawn = lua_interface->GetSpawn(state);
  2794. if (spawn) {
  2795. lua_interface->SetFloatValue(state, spawn->GetX());
  2796. return 1;
  2797. }
  2798. return 0;
  2799. }
  2800. int EQ2Emu_lua_GetY(lua_State* state) {
  2801. if (!lua_interface)
  2802. return 0;
  2803. Spawn* spawn = lua_interface->GetSpawn(state);
  2804. if (spawn) {
  2805. lua_interface->SetFloatValue(state, spawn->GetY());
  2806. return 1;
  2807. }
  2808. return 0;
  2809. }
  2810. int EQ2Emu_lua_GetZ(lua_State* state) {
  2811. if (!lua_interface)
  2812. return 0;
  2813. Spawn* spawn = lua_interface->GetSpawn(state);
  2814. if (spawn) {
  2815. lua_interface->SetFloatValue(state, spawn->GetZ());
  2816. return 1;
  2817. }
  2818. return 0;
  2819. }
  2820. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2821. if (!lua_interface)
  2822. return 0;
  2823. Spawn* spawn = lua_interface->GetSpawn(state);
  2824. if (spawn) {
  2825. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2826. return 1;
  2827. }
  2828. return 0;
  2829. }
  2830. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2831. if (!lua_interface)
  2832. return 0;
  2833. Spawn* spawn = lua_interface->GetSpawn(state);
  2834. if (spawn) {
  2835. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2836. return 1;
  2837. }
  2838. return 0;
  2839. }
  2840. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2841. if (!lua_interface)
  2842. return 0;
  2843. Spawn* spawn = lua_interface->GetSpawn(state);
  2844. if (spawn) {
  2845. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2846. return 1;
  2847. }
  2848. return 0;
  2849. }
  2850. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2851. if (!lua_interface)
  2852. return 0;
  2853. Spawn* spawn = lua_interface->GetSpawn(state);
  2854. if (spawn && spawn->IsEntity()) {
  2855. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2856. return 1;
  2857. }
  2858. return 0;
  2859. }
  2860. int EQ2Emu_lua_GetInt(lua_State* state) {
  2861. if (!lua_interface)
  2862. return 0;
  2863. Spawn* spawn = lua_interface->GetSpawn(state);
  2864. if (spawn && spawn->IsEntity()) {
  2865. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2866. return 1;
  2867. }
  2868. return 0;
  2869. }
  2870. int EQ2Emu_lua_GetWis(lua_State* state) {
  2871. if (!lua_interface)
  2872. return 0;
  2873. Spawn* spawn = lua_interface->GetSpawn(state);
  2874. if (spawn && spawn->IsEntity()) {
  2875. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2876. return 1;
  2877. }
  2878. return 0;
  2879. }
  2880. int EQ2Emu_lua_GetSta(lua_State* state) {
  2881. if (!lua_interface)
  2882. return 0;
  2883. Spawn* spawn = lua_interface->GetSpawn(state);
  2884. if (spawn && spawn->IsEntity()) {
  2885. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2886. return 1;
  2887. }
  2888. return 0;
  2889. }
  2890. int EQ2Emu_lua_GetStr(lua_State* state) {
  2891. if (!lua_interface)
  2892. return 0;
  2893. Spawn* spawn = lua_interface->GetSpawn(state);
  2894. if (spawn && spawn->IsEntity()) {
  2895. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2896. return 1;
  2897. }
  2898. return 0;
  2899. }
  2900. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2901. if (!lua_interface)
  2902. return 0;
  2903. Spawn* spawn = lua_interface->GetSpawn(state);
  2904. if (spawn && spawn->IsEntity()) {
  2905. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2906. return 1;
  2907. }
  2908. return 0;
  2909. }
  2910. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2911. if (!lua_interface)
  2912. return 0;
  2913. Spawn* spawn = lua_interface->GetSpawn(state);
  2914. if (spawn && spawn->IsEntity()) {
  2915. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2916. return 1;
  2917. }
  2918. return 0;
  2919. }
  2920. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2921. if (!lua_interface)
  2922. return 0;
  2923. Spawn* spawn = lua_interface->GetSpawn(state);
  2924. if (spawn && spawn->IsEntity()) {
  2925. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  2926. return 1;
  2927. }
  2928. return 0;
  2929. }
  2930. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  2931. if (!lua_interface)
  2932. return 0;
  2933. Spawn* spawn = lua_interface->GetSpawn(state);
  2934. if (spawn && spawn->IsEntity()) {
  2935. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  2936. return 1;
  2937. }
  2938. return 0;
  2939. }
  2940. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  2941. if (!lua_interface)
  2942. return 0;
  2943. Spawn* spawn = lua_interface->GetSpawn(state);
  2944. if (spawn && spawn->IsEntity()) {
  2945. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  2946. return 1;
  2947. }
  2948. return 0;
  2949. }
  2950. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  2951. if (!lua_interface)
  2952. return 0;
  2953. Spawn* spawn = lua_interface->GetSpawn(state);
  2954. if (spawn && spawn->IsEntity()) {
  2955. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  2956. return 1;
  2957. }
  2958. return 0;
  2959. }
  2960. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  2961. if (!lua_interface)
  2962. return 0;
  2963. Spawn* player = lua_interface->GetSpawn(state);
  2964. if (!player || !player->IsPlayer()) {
  2965. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  2966. return 0;
  2967. }
  2968. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2969. if (quest_id <= 0) {
  2970. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  2971. return 0;
  2972. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  2973. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  2974. return 0;
  2975. }
  2976. int32 step = lua_interface->GetInt32Value(state, 3);
  2977. if (step > 0) {
  2978. Client* client = player->GetZone()->GetClientBySpawn(player);
  2979. if (client)
  2980. client->AddPendingQuestUpdate(quest_id, step);
  2981. } else {
  2982. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  2983. }
  2984. return 0;
  2985. }
  2986. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  2987. Spawn* player = lua_interface->GetSpawn(state);
  2988. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2989. int32 step = lua_interface->GetInt32Value(state, 3);
  2990. int32 progress = lua_interface->GetInt32Value(state, 4);
  2991. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2992. Client* client = player->GetZone()->GetClientBySpawn(player);
  2993. if (client)
  2994. client->AddPendingQuestUpdate(quest_id, step, progress);
  2995. }
  2996. return 0;
  2997. }
  2998. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  2999. if (!lua_interface)
  3000. return 0;
  3001. Spawn* player = lua_interface->GetSpawn(state);
  3002. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3003. if (player && player->IsPlayer() && quest_id > 0) {
  3004. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3005. return 1;
  3006. }
  3007. return 0;
  3008. }
  3009. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3010. if (!lua_interface)
  3011. return 0;
  3012. Spawn* player = lua_interface->GetSpawn(state);
  3013. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3014. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3015. if (player && player->IsPlayer() && quest_id > 0) {
  3016. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3017. return 1;
  3018. }
  3019. return 0;
  3020. }
  3021. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3022. if (!lua_interface)
  3023. return 0;
  3024. Spawn* player = lua_interface->GetSpawn(state);
  3025. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3026. if (player && player->IsPlayer() && quest_id > 0) {
  3027. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3028. return 1;
  3029. }
  3030. return 0;
  3031. }
  3032. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3033. if (!lua_interface)
  3034. return 0;
  3035. Quest* quest = lua_interface->GetQuest(state);
  3036. string name = lua_interface->GetStringValue(state, 2);
  3037. string type = lua_interface->GetStringValue(state, 3);
  3038. string zone = lua_interface->GetStringValue(state, 4);
  3039. int16 level = lua_interface->GetInt16Value(state, 5);
  3040. string description = lua_interface->GetStringValue(state, 6);
  3041. bool load = true;
  3042. if (!quest) {
  3043. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3044. load = false;
  3045. }
  3046. if (load && name.length() == 0) {
  3047. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3048. load = false;
  3049. }
  3050. if (load && type.length() == 0) {
  3051. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3052. load = false;
  3053. }
  3054. if (load && zone.length() == 0) {
  3055. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3056. load = false;
  3057. }
  3058. if (load && description.length() == 0) {
  3059. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3060. load = false;
  3061. }
  3062. if (load && level == 0) {
  3063. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3064. load = false;
  3065. }
  3066. if (load)
  3067. quest->RegisterQuest(name, type, zone, level, description);
  3068. return 0;
  3069. }
  3070. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3071. if (!lua_interface)
  3072. return 0;
  3073. Quest* quest = lua_interface->GetQuest(state);
  3074. if (quest) {
  3075. int8 level = lua_interface->GetInt16Value(state, 2);
  3076. quest->SetPrereqLevel(level);
  3077. }
  3078. return 0;
  3079. }
  3080. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3081. if (!lua_interface)
  3082. return 0;
  3083. Quest* quest = lua_interface->GetQuest(state);
  3084. if (quest) {
  3085. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3086. quest->AddPrereqQuest(quest_id);
  3087. }
  3088. return 0;
  3089. }
  3090. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3091. if (!lua_interface)
  3092. return 0;
  3093. Quest* quest = lua_interface->GetQuest(state);
  3094. if (quest) {
  3095. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3096. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3097. if (quantity == 0)
  3098. quantity = 1;
  3099. Item* master_item = master_item_list.GetItem(item_id);
  3100. if (master_item) {
  3101. Item* item = new Item(master_item);
  3102. item->details.count = quantity;
  3103. quest->AddPrereqItem(item);
  3104. }
  3105. }
  3106. return 0;
  3107. }
  3108. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3109. if (!lua_interface)
  3110. return 0;
  3111. Spawn* player = lua_interface->GetSpawn(state);
  3112. if(!player || !player->IsPlayer()) {
  3113. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3114. return 0;
  3115. }
  3116. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3117. if (quest_id > 0) {
  3118. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3119. return 1;
  3120. } else {
  3121. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3122. }
  3123. return 0;
  3124. }
  3125. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3126. if (!lua_interface)
  3127. return 0;
  3128. Quest* quest = lua_interface->GetQuest(state);
  3129. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3130. if (quest && spawn_id > 0)
  3131. quest->SetQuestReturnNPC(spawn_id);
  3132. return 0;
  3133. }
  3134. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3135. if (!lua_interface)
  3136. return 0;
  3137. Spawn* spawn = lua_interface->GetSpawn(state);
  3138. if (!spawn) {
  3139. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3140. return 0;
  3141. }
  3142. int32 time = lua_interface->GetInt32Value(state, 2);
  3143. if (time <= 0) {
  3144. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3145. return 0;
  3146. }
  3147. string function = lua_interface->GetStringValue(state, 3);
  3148. if (function.length() == 0) {
  3149. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3150. return 0;
  3151. }
  3152. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3153. Spawn* player = lua_interface->GetSpawn(state, 5);
  3154. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3155. if ( time < 10)
  3156. time = 10;
  3157. timer->timer = Timer::GetCurrentTime2() + time;
  3158. timer->function = function;
  3159. timer->spawn = spawn->GetID();
  3160. timer->player = player ? player->GetID() : 0;
  3161. if (max_count == 0)
  3162. max_count = 1;
  3163. timer->max_count = max_count;
  3164. timer->current_count = 0;
  3165. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3166. return 0;
  3167. }
  3168. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3169. if (!lua_interface)
  3170. return 0;
  3171. Spawn* player = lua_interface->GetSpawn(state);
  3172. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3173. if (player && player->IsPlayer() && quest_id > 0) {
  3174. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3175. return 1;
  3176. }
  3177. return 0;
  3178. }
  3179. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3180. if (!lua_interface)
  3181. return 0;
  3182. Spawn* player = lua_interface->GetSpawn(state);
  3183. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3184. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3185. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3186. if (quest)
  3187. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3188. return 1;
  3189. }
  3190. return 0;
  3191. }
  3192. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3193. if (!lua_interface)
  3194. return 0;
  3195. Spawn* player = lua_interface->GetSpawn(state);
  3196. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3197. if (player && player->IsPlayer() && quest_id > 0) {
  3198. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3199. return 1;
  3200. }
  3201. return 0;
  3202. }
  3203. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3204. if (!lua_interface)
  3205. return 0;
  3206. Spawn* npc = lua_interface->GetSpawn(state);
  3207. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3208. if (npc && !npc->IsPlayer() && quest_id > 0)
  3209. npc->AddProvidedQuest(quest_id);
  3210. return 0;
  3211. }
  3212. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3213. if (!lua_interface)
  3214. return 0;
  3215. Spawn* npc = lua_interface->GetSpawn(state);
  3216. Spawn* player = lua_interface->GetSpawn(state, 2);
  3217. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3218. bool forced = lua_interface->GetBooleanValue(state, 4);
  3219. /* NPC is allowed to be null */
  3220. if (player && player->IsPlayer() && quest_id > 0) {
  3221. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3222. if (master_quest) {
  3223. Client* client = player->GetZone()->GetClientBySpawn(player);
  3224. if (!client) {
  3225. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3226. }
  3227. Quest* quest = new Quest(master_quest);
  3228. if (!quest) {
  3229. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3230. }
  3231. if (client && quest) {
  3232. if (npc)
  3233. quest->SetQuestGiver(npc->GetDatabaseID());
  3234. else
  3235. quest->SetQuestGiver(0);
  3236. client->AddPendingQuest(quest, forced);
  3237. }
  3238. }
  3239. else {
  3240. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3241. }
  3242. }
  3243. else {
  3244. 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);
  3245. }
  3246. return 0;
  3247. }
  3248. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3249. if (!lua_interface)
  3250. return 0;
  3251. Quest* quest = lua_interface->GetQuest(state);
  3252. if (quest) {
  3253. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3254. quest->AddPrereqClass(class_id);
  3255. }
  3256. return 0;
  3257. }
  3258. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3259. if (!lua_interface)
  3260. return 0;
  3261. Quest* quest = lua_interface->GetQuest(state);
  3262. if (quest) {
  3263. int8 race = lua_interface->GetInt8Value(state, 2);
  3264. quest->AddPrereqRace(race);
  3265. }
  3266. return 0;
  3267. }
  3268. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3269. if (!lua_interface)
  3270. return 0;
  3271. Quest* quest = lua_interface->GetQuest(state);
  3272. if (quest) {
  3273. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3274. quest->AddPrereqModelType(model_type);
  3275. }
  3276. return 0;
  3277. }
  3278. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3279. if (!lua_interface)
  3280. return 0;
  3281. Quest* quest = lua_interface->GetQuest(state);
  3282. if (!quest) {
  3283. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3284. return 0;
  3285. }
  3286. int8 level = lua_interface->GetInt8Value(state, 2);
  3287. quest->SetPrereqTSLevel(level);
  3288. return 0;
  3289. }
  3290. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3291. if (!lua_interface)
  3292. return 0;
  3293. Quest* quest = lua_interface->GetQuest(state);
  3294. if (!quest) {
  3295. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3296. return 0;
  3297. }
  3298. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3299. quest->AddPrereqTradeskillClass(class_id);
  3300. return 0;
  3301. }
  3302. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3303. if (!lua_interface)
  3304. return 0;
  3305. Quest* quest = lua_interface->GetQuest(state);
  3306. if (quest) {
  3307. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3308. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3309. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3310. quest->AddPrereqFaction(faction_id, min, max);
  3311. }
  3312. return 0;
  3313. }
  3314. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3315. if (!lua_interface)
  3316. return 0;
  3317. Quest* quest = lua_interface->GetQuest(state);
  3318. if (quest) {
  3319. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3320. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3321. if (quantity == 0)
  3322. quantity = 1;
  3323. Item* master_item = master_item_list.GetItem(item_id);
  3324. if (master_item) {
  3325. Item* item = new Item(master_item);
  3326. item->details.count = quantity;
  3327. quest->AddSelectableRewardItem(item);
  3328. }
  3329. }
  3330. return 0;
  3331. }
  3332. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3333. if (!lua_interface)
  3334. return 0;
  3335. Quest* quest = lua_interface->GetQuest(state);
  3336. if (quest) {
  3337. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3338. vector<Item*>* items = quest->GetRewardItems();
  3339. if (items) {
  3340. vector<Item*>::iterator itr;
  3341. for (itr = items->begin(); itr != items->end(); itr++) {
  3342. if (*itr && (*itr)->details.item_id == item_id) {
  3343. lua_interface->SetBooleanValue(state, true);
  3344. return 1;
  3345. }
  3346. }
  3347. }
  3348. }
  3349. lua_interface->SetBooleanValue(state, false);
  3350. return 1;
  3351. }
  3352. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3353. if (!lua_interface)
  3354. return 0;
  3355. Quest* quest = lua_interface->GetQuest(state);
  3356. if (quest) {
  3357. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3358. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3359. if (quantity == 0)
  3360. quantity = 1;
  3361. Item* master_item = master_item_list.GetItem(item_id);
  3362. if (master_item) {
  3363. Item* item = new Item(master_item);
  3364. item->details.count = quantity;
  3365. quest->AddRewardItem(item);
  3366. }
  3367. }
  3368. return 0;
  3369. }
  3370. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3371. if (!lua_interface)
  3372. return 0;
  3373. Quest* quest = lua_interface->GetQuest(state);
  3374. if (quest) {
  3375. int32 copper = lua_interface->GetInt32Value(state, 2);
  3376. int32 silver = lua_interface->GetInt32Value(state, 3);
  3377. int32 gold = lua_interface->GetInt32Value(state, 4);
  3378. int32 plat = lua_interface->GetInt32Value(state, 5);
  3379. quest->AddRewardCoins(copper, silver, gold, plat);
  3380. }
  3381. return 0;
  3382. }
  3383. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3384. if (!lua_interface)
  3385. return 0;
  3386. Quest* quest = lua_interface->GetQuest(state);
  3387. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3388. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3389. if (quest && faction_id > 0 && amount != 0)
  3390. quest->AddRewardFaction(faction_id, amount);
  3391. return 0;
  3392. }
  3393. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3394. if (!lua_interface)
  3395. return 0;
  3396. Quest* quest = lua_interface->GetQuest(state);
  3397. if (quest) {
  3398. int32 status = lua_interface->GetInt32Value(state, 2);
  3399. quest->SetRewardStatus(status);
  3400. }
  3401. return 0;
  3402. }
  3403. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3404. if (!lua_interface)
  3405. return 0;
  3406. Quest* quest = lua_interface->GetQuest(state);
  3407. if (quest) {
  3408. int32 status = lua_interface->GetInt32Value(state, 2);
  3409. quest->SetStatusTmpReward(status);
  3410. }
  3411. return 0;
  3412. }
  3413. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3414. if (!lua_interface)
  3415. return 0;
  3416. Quest* quest = lua_interface->GetQuest(state);
  3417. if (quest) {
  3418. int64 coins = lua_interface->GetInt64Value(state, 2);
  3419. quest->SetCoinTmpReward(coins);
  3420. }
  3421. return 0;
  3422. }
  3423. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3424. if (!lua_interface)
  3425. return 0;
  3426. Quest* quest = lua_interface->GetQuest(state);
  3427. if (quest) {
  3428. string comment = lua_interface->GetStringValue(state, 2);
  3429. quest->SetRewardComment(comment);
  3430. }
  3431. return 0;
  3432. }
  3433. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3434. if (!lua_interface)
  3435. return 0;
  3436. Quest* quest = lua_interface->GetQuest(state);
  3437. if (quest) {
  3438. int32 exp = lua_interface->GetInt32Value(state, 2);
  3439. quest->SetRewardXP(exp);
  3440. }
  3441. return 0;
  3442. }
  3443. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3444. Quest* quest = lua_interface->GetQuest(state);
  3445. if (quest) {
  3446. int32 step = lua_interface->GetInt32Value(state, 2);
  3447. string description = lua_interface->GetStringValue(state, 3);
  3448. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3449. float percentage = lua_interface->GetFloatValue(state, 5);
  3450. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3451. int16 icon = lua_interface->GetInt16Value(state, 7);
  3452. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3453. const char* taskgroup = 0;
  3454. if (str_taskgroup.length() > 0)
  3455. taskgroup = str_taskgroup.c_str();
  3456. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, 0, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3457. if (quest_step && icon && quantity > 0)
  3458. quest_step->SetIcon(icon);
  3459. }
  3460. return 0;
  3461. }
  3462. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3463. if (!lua_interface)
  3464. return 0;
  3465. Quest* quest = lua_interface->GetQuest(state);
  3466. if (quest) {
  3467. int32 step = lua_interface->GetInt32Value(state, 2);
  3468. string description = lua_interface->GetStringValue(state, 3);
  3469. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3470. float percentage = lua_interface->GetFloatValue(state, 5);
  3471. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3472. int16 icon = lua_interface->GetInt16Value(state, 7);
  3473. const char* taskgroup = 0;
  3474. if (str_taskgroup.length() > 0)
  3475. taskgroup = str_taskgroup.c_str();
  3476. int32 npc_id = 0;
  3477. vector<int32>* ids = 0;
  3478. int i = 0;
  3479. while ((npc_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3480. if (ids == 0)
  3481. ids = new vector<int32>;
  3482. ids->push_back(npc_id);
  3483. i++;
  3484. }
  3485. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_KILL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3486. if (quest_step && icon > 0 && quantity > 0)
  3487. quest_step->SetIcon(icon);
  3488. if (quest->GetPlayer()) {
  3489. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3490. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3491. }
  3492. safe_delete(ids);
  3493. }
  3494. return 0;
  3495. }
  3496. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3497. if (!lua_interface)
  3498. return 0;
  3499. Quest* quest = lua_interface->GetQuest(state);
  3500. if (quest) {
  3501. int32 step = lua_interface->GetInt32Value(state, 2);
  3502. string description = lua_interface->GetStringValue(state, 3);
  3503. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3504. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3505. int16 icon = lua_interface->GetInt16Value(state, 6);
  3506. const char* taskgroup = 0;
  3507. if (str_taskgroup.length() > 0)
  3508. taskgroup = str_taskgroup.c_str();
  3509. int32 npc_id = 0;
  3510. vector<int32>* ids = 0;
  3511. int i = 0;
  3512. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3513. if (ids == 0)
  3514. ids = new vector<int32>;
  3515. ids->push_back(npc_id);
  3516. i++;
  3517. }
  3518. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3519. if (quest_step && icon > 0)
  3520. quest_step->SetIcon(icon);
  3521. if (quest->GetPlayer()) {
  3522. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3523. if(client)
  3524. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3525. }
  3526. safe_delete(ids);
  3527. }
  3528. return 0;
  3529. }
  3530. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3531. if (!lua_interface)
  3532. return 0;
  3533. Quest* quest = lua_interface->GetQuest(state);
  3534. if (quest) {
  3535. int32 step = lua_interface->GetInt32Value(state, 2);
  3536. string description = lua_interface->GetStringValue(state, 3);
  3537. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3538. float percentage = lua_interface->GetFloatValue(state, 5);
  3539. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3540. int16 icon = lua_interface->GetInt16Value(state, 7);
  3541. const char* taskgroup = 0;
  3542. if (str_taskgroup.length() > 0)
  3543. taskgroup = str_taskgroup.c_str();
  3544. int32 item_id = 0;
  3545. vector<int32>* ids = 0;
  3546. int i = 0;
  3547. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3548. if (ids == 0)
  3549. ids = new vector<int32>;
  3550. ids->push_back(item_id);
  3551. i++;
  3552. }
  3553. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3554. if (quest_step && icon > 0 && quantity > 0)
  3555. quest_step->SetIcon(icon);
  3556. if (quest->GetPlayer()) {
  3557. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3558. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3559. }
  3560. safe_delete(ids);
  3561. }
  3562. return 0;
  3563. }
  3564. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3565. if (!lua_interface)
  3566. return 0;
  3567. Quest* quest = lua_interface->GetQuest(state);
  3568. if (quest) {
  3569. int32 step = lua_interface->GetInt32Value(state, 2);
  3570. string description = lua_interface->GetStringValue(state, 3);
  3571. float max_variation = lua_interface->GetFloatValue(state, 4);
  3572. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3573. int16 icon = lua_interface->GetInt16Value(state, 6);
  3574. const char* taskgroup = 0;
  3575. if (str_taskgroup.length() > 0)
  3576. taskgroup = str_taskgroup.c_str();
  3577. vector<Location>* locations = 0;
  3578. int i = 7;
  3579. while (true) {
  3580. Location loc;
  3581. loc.x = lua_interface->GetFloatValue(state, i);
  3582. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3583. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3584. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3585. break;
  3586. if (locations == 0)
  3587. locations = new vector<Location>;
  3588. locations->push_back(loc);
  3589. i += 3;
  3590. }
  3591. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3592. if (quest_step && icon > 0)
  3593. quest_step->SetIcon(icon);
  3594. if (quest->GetPlayer()) {
  3595. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3596. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3597. }
  3598. }
  3599. return 0;
  3600. }
  3601. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3602. if (!lua_interface)
  3603. return 0;
  3604. Quest* quest = lua_interface->GetQuest(state);
  3605. if (quest) {
  3606. int32 step = lua_interface->GetInt32Value(state, 2);
  3607. string description = lua_interface->GetStringValue(state, 3);
  3608. float max_variation = lua_interface->GetFloatValue(state, 4);
  3609. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3610. int16 icon = lua_interface->GetInt16Value(state, 6);
  3611. const char* taskgroup = 0;
  3612. if (str_taskgroup.length() > 0)
  3613. taskgroup = str_taskgroup.c_str();
  3614. vector<Location>* locations = 0;
  3615. int i = 7;
  3616. while (true) {
  3617. Location loc;
  3618. loc.x = lua_interface->GetFloatValue(state, i);
  3619. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3620. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3621. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3622. break;
  3623. if (locations == 0)
  3624. locations = new vector<Location>;
  3625. locations->push_back(loc);
  3626. i += 3;
  3627. }
  3628. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3629. if (quest_step && icon > 0)
  3630. quest_step->SetIcon(icon);
  3631. if (quest->GetPlayer()) {
  3632. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3633. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3634. }
  3635. }
  3636. return 0;
  3637. }
  3638. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3639. Quest* quest = lua_interface->GetQuest(state);
  3640. if (quest) {
  3641. int32 step = lua_interface->GetInt32Value(state, 2);
  3642. string description = lua_interface->GetStringValue(state, 3);
  3643. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3644. float percentage = lua_interface->GetFloatValue(state, 5);
  3645. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3646. int16 icon = lua_interface->GetInt16Value(state, 7);
  3647. const char* taskgroup = 0;
  3648. if (str_taskgroup.length() > 0)
  3649. taskgroup = str_taskgroup.c_str();
  3650. int32 spell_id = 0;
  3651. vector<int32>* ids = 0;
  3652. int i = 0;
  3653. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3654. if (ids == 0)
  3655. ids = new vector<int32>;
  3656. ids->push_back(spell_id);
  3657. i++;
  3658. }
  3659. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3660. if (quest_step && icon > 0 && quantity > 0)
  3661. quest_step->SetIcon(icon);
  3662. if (quest->GetPlayer()) {
  3663. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3664. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3665. }
  3666. safe_delete(ids);
  3667. }
  3668. return 0;
  3669. }
  3670. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3671. if (!lua_interface)
  3672. return 0;
  3673. Quest* quest = lua_interface->GetQuest(state);
  3674. if (quest) {
  3675. int32 step = lua_interface->GetInt32Value(state, 2);
  3676. string description = lua_interface->GetStringValue(state, 3);
  3677. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3678. float percentage = lua_interface->GetFloatValue(state, 5);
  3679. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3680. int16 icon = lua_interface->GetInt16Value(state, 7);
  3681. const char* taskgroup = 0;
  3682. if (str_taskgroup.length() > 0)
  3683. taskgroup = str_taskgroup.c_str();
  3684. int32 item_id = 0;
  3685. vector<int32>* ids = 0;
  3686. int i = 0;
  3687. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3688. if (ids == 0)
  3689. ids = new vector<int32>;
  3690. ids->push_back(item_id);
  3691. i++;
  3692. }
  3693. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3694. if (quest_step && icon > 0 && quantity > 0)
  3695. quest_step->SetIcon(icon);
  3696. if (quest->GetPlayer()) {
  3697. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3698. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3699. }
  3700. safe_delete(ids);
  3701. }
  3702. return 0;
  3703. }
  3704. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3705. if (!lua_interface)
  3706. return 0;
  3707. Quest* quest = lua_interface->GetQuest(state);
  3708. if (quest) {
  3709. int32 step = lua_interface->GetInt32Value(state, 2);
  3710. string description = lua_interface->GetStringValue(state, 3);
  3711. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3712. float percentage = lua_interface->GetFloatValue(state, 5);
  3713. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3714. int16 icon = lua_interface->GetInt16Value(state, 7);
  3715. const char* taskgroup = 0;
  3716. if (str_taskgroup.length() > 0)
  3717. taskgroup = str_taskgroup.c_str();
  3718. int32 item_id = 0;
  3719. vector<int32>* ids = 0;
  3720. int i = 0;
  3721. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3722. if (ids == 0)
  3723. ids = new vector<int32>;
  3724. ids->push_back(item_id);
  3725. i++;
  3726. }
  3727. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3728. if (quest_step && icon > 0 && quantity > 0)
  3729. quest_step->SetIcon(icon);
  3730. if (quest->GetPlayer()) {
  3731. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3732. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3733. }
  3734. safe_delete(ids);
  3735. }
  3736. return 0;
  3737. }
  3738. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3739. if (!lua_interface)
  3740. return 0;
  3741. Quest* quest = lua_interface->GetQuest(state);
  3742. if (quest) {
  3743. string action = lua_interface->GetStringValue(state, 2);
  3744. if (action.length() > 0)
  3745. quest->SetCompleteAction(action);
  3746. }
  3747. return 0;
  3748. }
  3749. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3750. if (!lua_interface)
  3751. return 0;
  3752. Quest* quest = lua_interface->GetQuest(state);
  3753. if (quest) {
  3754. int32 step = lua_interface->GetInt32Value(state, 2);
  3755. string action = lua_interface->GetStringValue(state, 3);
  3756. if (step > 0 && action.length() > 0)
  3757. quest->AddCompleteAction(step, action);
  3758. }
  3759. return 0;
  3760. }
  3761. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3762. if (!lua_interface)
  3763. return 0;
  3764. Quest* quest = lua_interface->GetQuest(state);
  3765. if (quest) {
  3766. int32 step = lua_interface->GetInt32Value(state, 2);
  3767. string action = lua_interface->GetStringValue(state, 3);
  3768. if (step > 0 && action.length() > 0)
  3769. quest->AddProgressAction(step, action);
  3770. }
  3771. return 0;
  3772. }
  3773. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3774. if (!lua_interface)
  3775. return 0;
  3776. Quest* quest = lua_interface->GetQuest(state);
  3777. string description = lua_interface->GetStringValue(state, 2);
  3778. if (quest && description.length() > 0)
  3779. quest->SetDescription(description);
  3780. return 0;
  3781. }
  3782. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3783. if (!lua_interface)
  3784. return 0;
  3785. Quest* quest = lua_interface->GetQuest(state);
  3786. string description = lua_interface->GetStringValue(state, 2);
  3787. if (quest && description.length() > 0)
  3788. quest->SetCompletedDescription(description);
  3789. return 0;
  3790. }
  3791. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3792. if (!lua_interface)
  3793. return 0;
  3794. Quest* quest = lua_interface->GetQuest(state);
  3795. int32 step = lua_interface->GetInt32Value(state, 2);
  3796. string description = lua_interface->GetStringValue(state, 3);
  3797. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3798. if (quest && step > 0 && description.length() > 0) {
  3799. quest->SetTaskGroupDescription(step, description, display_bullets);
  3800. /* if (quest->GetPlayer()) {
  3801. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3802. if (client)
  3803. client->SendQuestUpdateStep(quest, step, false);
  3804. }*/
  3805. }
  3806. return 0;
  3807. }
  3808. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  3809. if (!lua_interface)
  3810. return 0;
  3811. Quest* quest = lua_interface->GetQuest(state);
  3812. int32 step = lua_interface->GetInt32Value(state, 2);
  3813. string description = lua_interface->GetStringValue(state, 3);
  3814. if (quest && step > 0 && description.length() > 0) {
  3815. quest->SetStepDescription(step, description);
  3816. /*if (quest->GetPlayer()) {
  3817. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3818. if (client)
  3819. client->SendQuestUpdateStepImmediately(quest, step);
  3820. }*/
  3821. }
  3822. return 0;
  3823. }
  3824. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  3825. Quest* quest = lua_interface->GetQuest(state);
  3826. string zone = lua_interface->GetStringValue(state, 2);
  3827. if (quest && zone.length() > 0)
  3828. quest->SetZone(zone);
  3829. return 0;
  3830. }
  3831. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  3832. if (!lua_interface)
  3833. return 0;
  3834. Quest* quest = lua_interface->GetQuest(state);
  3835. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3836. lua_interface->ResetFunctionStack(state);
  3837. if (quest && spawn) {
  3838. if (spawn->IsPlayer()) {
  3839. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3840. if (client)
  3841. {
  3842. client->AddPendingQuestAcceptReward(quest);
  3843. client->AddPendingQuestReward(quest);
  3844. }
  3845. }
  3846. }
  3847. return 0;
  3848. }
  3849. int EQ2Emu_lua_Harvest(lua_State* state) {
  3850. if (!lua_interface)
  3851. return 0;
  3852. Spawn* player = lua_interface->GetSpawn(state);
  3853. Spawn* node = lua_interface->GetSpawn(state, 2);
  3854. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  3855. Client* client = player->GetZone()->GetClientBySpawn(player);
  3856. if (client) {
  3857. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  3858. ((GroundSpawn*)node)->ProcessHarvest(client);
  3859. if (((GroundSpawn*)node)->GetNumberHarvests() == 0)
  3860. player->GetZone()->RemoveSpawn(node, true);
  3861. }
  3862. }
  3863. else if (player && player->IsPlayer()) {
  3864. Client* client = player->GetZone()->GetClientBySpawn(player);
  3865. if (client)
  3866. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  3867. }
  3868. return 0;
  3869. }
  3870. int EQ2Emu_lua_Bind(lua_State* state) {
  3871. if (!lua_interface)
  3872. return 0;
  3873. Spawn* spawn = lua_interface->GetSpawn(state);
  3874. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  3875. float x = lua_interface->GetFloatValue(state, 3);
  3876. float y = lua_interface->GetFloatValue(state, 4);
  3877. float z = lua_interface->GetFloatValue(state, 5);
  3878. float h = lua_interface->GetFloatValue(state, 6);
  3879. if (!spawn) {
  3880. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  3881. return 0;
  3882. }
  3883. if (!spawn->IsPlayer()) {
  3884. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  3885. return 0;
  3886. }
  3887. if (zone_id == 0) {
  3888. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3889. if (!client) {
  3890. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  3891. return 0;
  3892. }
  3893. if (!client->Bind())
  3894. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  3895. }
  3896. else {
  3897. Player* player = (Player*)spawn;
  3898. player->GetPlayerInfo()->SetBindZone(zone_id);
  3899. player->GetPlayerInfo()->SetBindX(x);
  3900. player->GetPlayerInfo()->SetBindY(y);
  3901. player->GetPlayerInfo()->SetBindZ(z);
  3902. player->GetPlayerInfo()->SetBindHeading(h);
  3903. }
  3904. return 0;
  3905. }
  3906. int EQ2Emu_lua_Gate(lua_State* state) {
  3907. if (!lua_interface)
  3908. return 0;
  3909. Spawn* spawn = lua_interface->GetSpawn(state);
  3910. if (spawn) {
  3911. if (spawn->IsPlayer()) {
  3912. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3913. if (client) {
  3914. if (!client->Gate())
  3915. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  3916. }
  3917. }
  3918. }
  3919. return 0;
  3920. }
  3921. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  3922. if (!lua_interface)
  3923. return 0;
  3924. bool ret = false;
  3925. Spawn* spawn = lua_interface->GetSpawn(state);
  3926. if (spawn) {
  3927. if (spawn->IsPlayer()) {
  3928. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3929. if (client)
  3930. ret = client->BindAllowed();
  3931. }
  3932. }
  3933. lua_interface->SetBooleanValue(state, ret);
  3934. return 1;
  3935. }
  3936. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  3937. if (!lua_interface)
  3938. return 0;
  3939. bool ret = false;
  3940. Spawn* spawn = lua_interface->GetSpawn(state);
  3941. if (spawn) {
  3942. if (spawn->IsPlayer()) {
  3943. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3944. if (client)
  3945. ret = client->GateAllowed();
  3946. }
  3947. }
  3948. lua_interface->SetBooleanValue(state, ret);
  3949. return 1;
  3950. }
  3951. int EQ2Emu_lua_IsAlive(lua_State* state) {
  3952. Spawn* spawn = lua_interface->GetSpawn(state);
  3953. if (spawn) {
  3954. lua_interface->SetBooleanValue(state, spawn->Alive());
  3955. return 1;
  3956. }
  3957. return 0;
  3958. }
  3959. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  3960. if (!lua_interface)
  3961. return 0;
  3962. Spawn* spawn = lua_interface->GetSpawn(state);
  3963. if (spawn && spawn->IsEntity()) {
  3964. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  3965. return 1;
  3966. }
  3967. return 0;
  3968. }
  3969. int EQ2Emu_lua_SendMessage(lua_State* state) {
  3970. Spawn* spawn = lua_interface->GetSpawn(state);
  3971. string message = lua_interface->GetStringValue(state, 2);
  3972. string color_str = lua_interface->GetStringValue(state, 3);
  3973. int8 color = CHANNEL_NARRATIVE;
  3974. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  3975. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3976. if (client) {
  3977. if (color_str.length() > 0) {
  3978. // leave for backwards compat, but all future should just use the number
  3979. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  3980. color = CHANNEL_COLOR_RED;
  3981. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  3982. color = CHANNEL_COLOR_YELLOW;
  3983. else
  3984. {
  3985. // use a number to specify the channel as per Commands/Commands.h defines
  3986. color = (int8)atoul(color_str.c_str());
  3987. }
  3988. }
  3989. client->SimpleMessage(color, message.c_str());
  3990. }
  3991. }
  3992. return 0;
  3993. }
  3994. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  3995. Spawn* spawn = lua_interface->GetSpawn(state);
  3996. string message = lua_interface->GetStringValue(state, 2);
  3997. int8 red = lua_interface->GetInt8Value(state, 3);
  3998. int8 green = lua_interface->GetInt8Value(state, 4);
  3999. int8 blue = lua_interface->GetInt8Value(state, 5);
  4000. if (!spawn) {
  4001. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4002. return 0;
  4003. }
  4004. int32 words = ::CountWordsInString(message.c_str());
  4005. if (words < 5)
  4006. words = 5;
  4007. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4008. if (client)
  4009. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4010. return 0;
  4011. }
  4012. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4013. Spawn* spawn = lua_interface->GetSpawn(state);
  4014. int8 param = lua_interface->GetInt8Value(state, 2);
  4015. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4016. int8 value = lua_interface->GetInt8Value(state, 4);
  4017. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4018. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4019. if (client) {
  4020. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4021. switch (param) {
  4022. case 1: {
  4023. packet->setDataByName("parameter1", param_value);
  4024. break;
  4025. }
  4026. case 2: {
  4027. packet->setDataByName("parameter2", param_value);
  4028. break;
  4029. }
  4030. case 3: {
  4031. packet->setDataByName("parameter3", param_value);
  4032. break;
  4033. }
  4034. case 4: {
  4035. packet->setDataByName("parameter4", param_value);
  4036. break;
  4037. }
  4038. case 5: {
  4039. packet->setDataByName("parameter5", param_value);
  4040. break;
  4041. }
  4042. }
  4043. packet->setDataByName("value", value);
  4044. client->QueuePacket(packet->serialize());
  4045. safe_delete(packet);
  4046. }
  4047. }
  4048. return 0;
  4049. }
  4050. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4051. Spawn* spawn = lua_interface->GetSpawn(state);
  4052. if (spawn && spawn->IsPlayer()) {
  4053. if (((Player*)spawn)->GetIsTracking())
  4054. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4055. else
  4056. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4057. }
  4058. return 0;
  4059. }
  4060. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4061. Spawn* player = lua_interface->GetSpawn(state);
  4062. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4063. string name = lua_interface->GetStringValue(state, 3);
  4064. float distance = lua_interface->GetFloatValue(state, 4);
  4065. string command = lua_interface->GetStringValue(state, 5);
  4066. string error_text = lua_interface->GetStringValue(state, 6);
  4067. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4068. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4069. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4070. if (spawn) {
  4071. if (distance == 0)
  4072. distance = 10.0f;
  4073. if (command.length() == 0)
  4074. command = name;
  4075. if (command.length() < 1 && name.length() < 1)
  4076. {
  4077. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4078. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4079. spawn->RemovePrimaryCommands();
  4080. }
  4081. else
  4082. {
  4083. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4084. }
  4085. }
  4086. return 0;
  4087. }
  4088. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4089. if (!lua_interface)
  4090. return 0;
  4091. Spawn* player = lua_interface->GetSpawn(state);
  4092. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4093. int16 tier = lua_interface->GetInt16Value(state, 3);
  4094. if (player && player->IsPlayer()) {
  4095. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4096. return 1;
  4097. }
  4098. return 0;
  4099. }
  4100. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4101. if (!lua_interface)
  4102. return 0;
  4103. Spawn* player = lua_interface->GetSpawn(state);
  4104. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4105. int16 tier = lua_interface->GetInt16Value(state, 3);
  4106. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4107. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4108. bool add_to_hotbar = true;
  4109. if (num_args > 4) {
  4110. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4111. }
  4112. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4113. if (player && spell && player->IsPlayer()) {
  4114. Client* client = player->GetClient();
  4115. if (client) {
  4116. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4117. {
  4118. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4119. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4120. client->GetPlayer()->UnlockSpell(spell);
  4121. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4122. }
  4123. else
  4124. {
  4125. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4126. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4127. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4128. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4129. client->GetPlayer()->UnlockSpell(spell);
  4130. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4131. }
  4132. //if (client ) {
  4133. // ((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);
  4134. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4135. if (outapp)
  4136. client->QueuePacket(outapp);
  4137. }
  4138. }
  4139. return 0;
  4140. }
  4141. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4142. if (!lua_interface)
  4143. return 0;
  4144. Spawn* player = lua_interface->GetSpawn(state);
  4145. if (player && player->IsPlayer()) {
  4146. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4147. return 1;
  4148. }
  4149. return 0;
  4150. }
  4151. int EQ2Emu_lua_Attack(lua_State* state) {
  4152. if (lua_interface) {
  4153. Spawn* npc = lua_interface->GetSpawn(state);
  4154. Spawn* player = lua_interface->GetSpawn(state, 2);
  4155. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4156. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4157. }
  4158. return 0;
  4159. }
  4160. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4161. if (lua_interface) {
  4162. Spawn* target = lua_interface->GetSpawn(state);
  4163. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4164. if (target && target->GetZone())
  4165. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4166. }
  4167. return 0;
  4168. }
  4169. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4170. Spawn* player;
  4171. if (lua_interface) {
  4172. player = lua_interface->GetSpawn(state);
  4173. if (player && player->IsPlayer()) {
  4174. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4175. return 1;
  4176. }
  4177. }
  4178. return 0;
  4179. }
  4180. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4181. Spawn* player;
  4182. Client* client;
  4183. if (lua_interface) {
  4184. player = lua_interface->GetSpawn(state);
  4185. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4186. if ((client = player->GetZone()->GetClientBySpawn(player)))
  4187. client->HandInCollections();
  4188. }
  4189. return 0;
  4190. }
  4191. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4192. Spawn* widget;
  4193. if (lua_interface) {
  4194. widget = lua_interface->GetSpawn(state);
  4195. if (widget && widget->IsWidget())
  4196. ((Widget*)widget)->HandleUse(nullptr, "");
  4197. }
  4198. return 0;
  4199. }
  4200. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4201. Spawn* spawn = 0;
  4202. int32 primary_list = 0;
  4203. int32 secondary_list = 0;
  4204. if (lua_interface) {
  4205. spawn = lua_interface->GetSpawn(state);
  4206. primary_list = lua_interface->GetInt32Value(state, 2);
  4207. secondary_list = lua_interface->GetInt32Value(state, 3);
  4208. if (!spawn->IsNPC()) {
  4209. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4210. return 0;
  4211. }
  4212. NPC* npc = (NPC*)spawn;
  4213. npc->SetPrimarySpellList(primary_list);
  4214. npc->SetSecondarySpellList(secondary_list);
  4215. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4216. }
  4217. return 0;
  4218. }
  4219. int EQ2Emu_lua_GetPet(lua_State* state) {
  4220. if (!lua_interface)
  4221. return 0;
  4222. Spawn* spawn = lua_interface->GetSpawn(state);
  4223. if (spawn) {
  4224. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4225. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4226. return 1;
  4227. }
  4228. }
  4229. return 0;
  4230. }
  4231. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4232. if (!lua_interface)
  4233. return 0;
  4234. Spawn* spawn = lua_interface->GetSpawn(state);
  4235. if (spawn) {
  4236. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4237. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4238. return 1;
  4239. }
  4240. }
  4241. return 0;
  4242. }
  4243. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4244. if (!lua_interface)
  4245. return 0;
  4246. Spawn* spawn = lua_interface->GetSpawn(state);
  4247. if (spawn) {
  4248. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4249. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4250. return 1;
  4251. }
  4252. }
  4253. return 0;
  4254. }
  4255. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4256. if (!lua_interface)
  4257. return 0;
  4258. Spawn* spawn = lua_interface->GetSpawn(state);
  4259. if (spawn) {
  4260. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4261. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4262. return 1;
  4263. }
  4264. }
  4265. return 0;
  4266. }
  4267. int EQ2Emu_lua_Charm(lua_State* state) {
  4268. if (!lua_interface)
  4269. return 0;
  4270. Spawn* owner = lua_interface->GetSpawn(state);
  4271. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4272. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4273. if (!luaspell) {
  4274. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4275. return 0;
  4276. }
  4277. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4278. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4279. pet->SetPet(true);
  4280. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4281. ((NPC*)pet)->SetOwner((Entity*)owner);
  4282. // If owner is player and player does not have a summoned pet set the players charsheet
  4283. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4284. Player* player = (Player*)owner;
  4285. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4286. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4287. player->GetInfoStruct()->set_pet_movement(2);
  4288. player->GetInfoStruct()->set_pet_behavior(3);
  4289. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4290. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4291. // Make sure the values get sent to the client
  4292. player->SetCharSheetChanged(true);
  4293. }
  4294. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4295. pet->SetSpawnScript("");
  4296. // Set faction to the same as the owner
  4297. pet->SetFactionID(owner->GetFactionID());
  4298. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4299. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4300. // Clear hate list
  4301. ((NPC*)pet)->Brain()->ClearHate();
  4302. // Set the brain to a pet brain
  4303. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4304. }
  4305. return 0;
  4306. }
  4307. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4308. if (!lua_interface)
  4309. return 0;
  4310. Spawn* spawn = lua_interface->GetSpawn(state);
  4311. if (!spawn) {
  4312. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4313. return 0;
  4314. }
  4315. vector<Spawn*> groupMembers;
  4316. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4317. groupMembers = *spawn->GetSpawnGroup();
  4318. }
  4319. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4320. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4321. deque<GroupMemberInfo*>::iterator itr;
  4322. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4323. if (group)
  4324. {
  4325. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4326. deque<GroupMemberInfo*>* members = group->GetMembers();
  4327. GroupMemberInfo* info = 0;
  4328. for (itr = members->begin(); itr != members->end(); itr++) {
  4329. info = *itr;
  4330. if (info->client)
  4331. groupMembers.push_back(info->client->GetPlayer());
  4332. }
  4333. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4334. }
  4335. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4336. }
  4337. else
  4338. return 0;
  4339. lua_createtable(state, groupMembers.size(), 0);
  4340. int newTable = lua_gettop(state);
  4341. for (int32 i = 0; i < groupMembers.size(); i++) {
  4342. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4343. lua_rawseti(state, newTable, i + 1);
  4344. }
  4345. return 1;
  4346. }
  4347. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4348. if (!lua_interface)
  4349. return 0;
  4350. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4351. lua_interface->SetOptionWindowValue(state, option_window);
  4352. return 1;
  4353. }
  4354. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4355. if (!lua_interface)
  4356. return 0;
  4357. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4358. if (option_window) {
  4359. OptionWindowOption option_window_option;
  4360. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4361. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4362. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4363. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4364. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4365. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4366. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4367. option_window->push_back(option_window_option);
  4368. }
  4369. return 0;
  4370. }
  4371. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4372. if (!lua_interface)
  4373. return 0;
  4374. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4375. Spawn* player = lua_interface->GetSpawn(state, 2);
  4376. string window_title = lua_interface->GetStringValue(state, 3);
  4377. string cancel_command = lua_interface->GetStringValue(state, 4);
  4378. Client* client = player->GetZone()->GetClientBySpawn(player);
  4379. if (option_window && window_title.length() > 0 && client) {
  4380. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4381. if (!packet)
  4382. return 0;
  4383. packet->setDataByName("title_text", window_title.c_str());
  4384. if (cancel_command.length() > 0)
  4385. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4386. packet->setArrayLengthByName("num_selections", option_window->size());
  4387. vector<OptionWindowOption>::iterator itr;
  4388. int8 i = 0;
  4389. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4390. OptionWindowOption opt = *itr;
  4391. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4392. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4393. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4394. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4395. if (opt.optionCommand.length() > 0)
  4396. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4397. if (opt.optionConfirmTitle.length() > 0)
  4398. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4399. i++;
  4400. }
  4401. client->QueuePacket(packet->serialize());
  4402. safe_delete(option_window);
  4403. safe_delete(packet);
  4404. }
  4405. return 0;
  4406. }
  4407. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4408. if (!lua_interface)
  4409. return 0;
  4410. Spawn* spawn = lua_interface->GetSpawn(state);
  4411. if (spawn) {
  4412. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4413. return 1;
  4414. }
  4415. else
  4416. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4417. return 0;
  4418. }
  4419. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4420. if (!lua_interface)
  4421. return 0;
  4422. Spawn* spawn = lua_interface->GetSpawn(state);
  4423. if (spawn) {
  4424. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4425. return 1;
  4426. }
  4427. else
  4428. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4429. return 0;
  4430. }
  4431. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4432. if (!lua_interface)
  4433. return 0;
  4434. Spawn* spawn = lua_interface->GetSpawn(state);
  4435. if (spawn) {
  4436. int8 class_id = spawn->GetTradeskillClass();
  4437. // Need to add 42 for the offset in the array
  4438. class_id += 44;
  4439. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4440. return 1;
  4441. }
  4442. else
  4443. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4444. return 0;
  4445. }
  4446. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4447. if (!lua_interface)
  4448. return 0;
  4449. Spawn* spawn = lua_interface->GetSpawn(state);
  4450. int16 level = lua_interface->GetInt8Value(state, 2);
  4451. if (spawn) {
  4452. if (spawn->IsPlayer())
  4453. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4454. else
  4455. spawn->SetTSLevel(level);
  4456. }
  4457. else
  4458. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4459. return 0;
  4460. }
  4461. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4462. if (!lua_interface)
  4463. return 0;
  4464. Spawn* spawn = lua_interface->GetSpawn(state);
  4465. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4466. if (spawn) {
  4467. spawn->SetAttackable(attackable);
  4468. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4469. }
  4470. return 0;
  4471. }
  4472. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4473. // Check to see if we have a valid lua_interface
  4474. if (!lua_interface)
  4475. return 0;
  4476. // Get the spawn that is getting the pet
  4477. Spawn* spawn = lua_interface->GetSpawn(state);
  4478. // Get the DB ID of the pet
  4479. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4480. // The max level the pet can gain
  4481. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4482. // Get the spell that this command was called from
  4483. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4484. // Check to make sure the spawn pointer is valid
  4485. if (!spawn) {
  4486. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4487. return 0;
  4488. }
  4489. // Check to make sure the spawn is an entity
  4490. if (!spawn->IsEntity()) {
  4491. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4492. return 0;
  4493. }
  4494. // Check to make sure the spawn doesn't already have a pet of this type
  4495. if (((Entity*)spawn)->GetPet()) {
  4496. if (spawn->IsPlayer()) {
  4497. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4498. if (client)
  4499. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4500. }
  4501. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4502. return 0;
  4503. }
  4504. // Check to see if the DB ID for the pet is set
  4505. if (pet_id == 0) {
  4506. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4507. return 0;
  4508. }
  4509. // Check to see if the pointer to the spell is valid
  4510. if (!luaspell) {
  4511. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4512. return 0;
  4513. }
  4514. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4515. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4516. if (!pet) {
  4517. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4518. return 0;
  4519. }
  4520. // Check to make sure the pet is an npc
  4521. if (!pet->IsNPC()) {
  4522. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4523. return 0;
  4524. }
  4525. // Spawn the pet at the same location as the owner
  4526. pet->SetX(spawn->GetX());
  4527. pet->SetY(spawn->GetY());
  4528. pet->SetZ(spawn->GetZ());
  4529. pet->SetLocation(spawn->GetLocation());
  4530. pet->SetHeading(spawn->GetHeading());
  4531. spawn->GetZone()->AddSpawn(pet);
  4532. /*
  4533. const char* spawn_script = world.GetSpawnScript(pet_id);
  4534. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4535. spawn->SetSpawnScript(string(spawn_script));
  4536. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4537. }*/
  4538. // Get a random pet name
  4539. string random_pet_name;
  4540. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4541. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4542. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4543. // If player set various values for the char sheet (pet window)
  4544. if (spawn->IsPlayer()) {
  4545. Player* player = (Player*)spawn;
  4546. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4547. player->GetInfoStruct()->set_pet_name(random_pet_name);
  4548. player->GetInfoStruct()->set_pet_movement(2);
  4549. player->GetInfoStruct()->set_pet_behavior(3);
  4550. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4551. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4552. // Make sure the values get sent to the client
  4553. player->SetCharSheetChanged(true);
  4554. }
  4555. // Set the pets name
  4556. pet->SetName(random_pet_name.c_str());
  4557. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4558. if (max_level > 0)
  4559. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4560. else
  4561. pet->SetLevel(spawn->GetLevel());
  4562. // Set the max level this pet can reach
  4563. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4564. // Set the faction of the pet to the same faction as the owner
  4565. pet->SetFactionID(spawn->GetFactionID());
  4566. // Set the spawn as a pet
  4567. pet->SetPet(true);
  4568. // Give a pointer of the owner to the pet
  4569. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4570. // Give a pointer of the pet to the owner
  4571. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4572. // Set the pet type
  4573. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4574. // Set the spell id used to create this pet
  4575. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4576. // Set the spell tier used to create this pet
  4577. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4578. // Set the pets spawn type to 6
  4579. pet->SetSpawnType(6);
  4580. // Set the pets brain
  4581. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4582. // Check to see if the pet has a subtitle
  4583. if (strlen(pet->GetSubTitle()) > 0) {
  4584. // Add the players name to the front of the sub title
  4585. string pet_subtitle;
  4586. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4587. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4588. // Set the pets subtitle to the new one
  4589. pet->SetSubTitle(pet_subtitle.c_str());
  4590. }
  4591. // Add the "Pet Options" entity command to the pet
  4592. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4593. // Set the pet as the return value for this function
  4594. lua_interface->SetSpawnValue(state, pet);
  4595. return 1;
  4596. }
  4597. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4598. if (!lua_interface)
  4599. return 0;
  4600. Spawn* spawn = lua_interface->GetSpawn(state);
  4601. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4602. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4603. if (!spawn) {
  4604. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4605. return 0;
  4606. }
  4607. if (!spawn->IsEntity()) {
  4608. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4609. return 0;
  4610. }
  4611. if (((Entity*)spawn)->GetDeityPet()) {
  4612. if (spawn->IsPlayer()) {
  4613. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4614. if (client)
  4615. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4616. }
  4617. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4618. return 0;
  4619. }
  4620. if (pet_id == 0) {
  4621. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4622. return 0;
  4623. }
  4624. if (!luaspell) {
  4625. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4626. return 0;
  4627. }
  4628. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4629. if (!pet) {
  4630. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4631. return 0;
  4632. }
  4633. if (!pet->IsNPC()) {
  4634. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4635. return 0;
  4636. }
  4637. pet->SetX(spawn->GetX());
  4638. pet->SetY(spawn->GetY());
  4639. pet->SetZ(spawn->GetZ());
  4640. pet->SetLocation(spawn->GetLocation());
  4641. pet->SetHeading(spawn->GetHeading());
  4642. spawn->GetZone()->AddSpawn(pet);
  4643. string random_pet_name;
  4644. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4645. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4646. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4647. pet->SetName(random_pet_name.c_str());
  4648. pet->SetLevel(spawn->GetLevel());
  4649. pet->SetFactionID(spawn->GetFactionID());
  4650. pet->SetPet(true);
  4651. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4652. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4653. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4654. pet->SetSpawnType(6);
  4655. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4656. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4657. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4658. if (strlen(pet->GetSubTitle()) > 0) {
  4659. string pet_subtitle;
  4660. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4661. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4662. pet->SetSubTitle(pet_subtitle.c_str());
  4663. }
  4664. // deity and cosmetic pets are not attackable
  4665. pet->SetAttackable(false);
  4666. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4667. lua_interface->SetSpawnValue(state, pet);
  4668. return 1;
  4669. }
  4670. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4671. if (!lua_interface)
  4672. return 0;
  4673. Spawn* spawn = lua_interface->GetSpawn(state);
  4674. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4675. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4676. if (!spawn) {
  4677. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4678. return 0;
  4679. }
  4680. if (!spawn->IsEntity()) {
  4681. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4682. return 0;
  4683. }
  4684. if (((Entity*)spawn)->GetCosmeticPet()) {
  4685. if (spawn->IsPlayer()) {
  4686. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4687. if (client)
  4688. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4689. }
  4690. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4691. return 0;
  4692. }
  4693. if (pet_id == 0) {
  4694. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4695. return 0;
  4696. }
  4697. if (!luaspell) {
  4698. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4699. return 0;
  4700. }
  4701. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4702. if (!pet) {
  4703. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4704. return 0;
  4705. }
  4706. if (!pet->IsNPC()) {
  4707. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4708. return 0;
  4709. }
  4710. pet->SetX(spawn->GetX());
  4711. pet->SetY(spawn->GetY());
  4712. pet->SetZ(spawn->GetZ());
  4713. pet->SetLocation(spawn->GetLocation());
  4714. pet->SetHeading(spawn->GetHeading());
  4715. spawn->GetZone()->AddSpawn(pet);
  4716. string random_pet_name;
  4717. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4718. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4719. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4720. pet->SetName(random_pet_name.c_str());
  4721. pet->SetLevel(spawn->GetLevel());
  4722. pet->SetFactionID(spawn->GetFactionID());
  4723. pet->SetPet(true);
  4724. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4725. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4726. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4727. pet->SetSpawnType(6);
  4728. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4729. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4730. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4731. if (strlen(pet->GetSubTitle()) > 0) {
  4732. string pet_subtitle;
  4733. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4734. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4735. pet->SetSubTitle(pet_subtitle.c_str());
  4736. }
  4737. pet->SetAttackable(false);
  4738. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4739. lua_interface->SetSpawnValue(state, pet);
  4740. return 1;
  4741. }
  4742. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4743. if (!lua_interface)
  4744. return 0;
  4745. Spawn* spawn = lua_interface->GetSpawn(state);
  4746. if (!spawn) {
  4747. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4748. return 0;
  4749. }
  4750. if (!spawn->IsPet()) {
  4751. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4752. return 0;
  4753. }
  4754. if (!((NPC*)spawn)->IsDismissing())
  4755. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  4756. return 0;
  4757. }
  4758. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4759. if (!lua_interface)
  4760. return 0;
  4761. Quest* quest = lua_interface->GetQuest(state);
  4762. if (!quest) {
  4763. 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));
  4764. return 0;
  4765. }
  4766. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4767. if (feather_color > 0)
  4768. quest->SetFeatherColor(feather_color);
  4769. return 0;
  4770. }
  4771. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4772. if (!lua_interface)
  4773. return 0;
  4774. Spawn* spawn = lua_interface->GetSpawn(state);
  4775. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4776. if (!spawn) {
  4777. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4778. return 0;
  4779. }
  4780. if (!spawn2) {
  4781. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4782. return 0;
  4783. }
  4784. spawn->RemoveSpawnAccess(spawn2);
  4785. return 0;
  4786. }
  4787. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  4788. if (!lua_interface)
  4789. return 0;
  4790. ZoneServer* zone = lua_interface->GetZone(state);
  4791. int32 location_id = lua_interface->GetInt32Value(state, 2);
  4792. if (!zone) {
  4793. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  4794. return 0;
  4795. }
  4796. if (location_id == 0) {
  4797. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  4798. return 0;
  4799. }
  4800. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  4801. if (!location) {
  4802. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  4803. return 0;
  4804. }
  4805. Spawn* spawn = 0;
  4806. if (location->entities[0]) {
  4807. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  4808. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  4809. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  4810. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  4811. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  4812. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  4813. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  4814. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  4815. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  4816. spawn = zone->AddSignSpawn(location, location->entities[0]);
  4817. if (spawn) {
  4818. const char* script = 0;
  4819. for (int x = 0; x < 3; x++) {
  4820. switch (x) {
  4821. case 0:
  4822. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  4823. break;
  4824. case 1:
  4825. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  4826. break;
  4827. case 2:
  4828. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  4829. break;
  4830. }
  4831. if (script && lua_interface->GetSpawnScript(script) != 0) {
  4832. spawn->SetSpawnScript(string(script));
  4833. break;
  4834. }
  4835. }
  4836. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4837. lua_interface->SetSpawnValue(state, spawn);
  4838. return 1;
  4839. }
  4840. else {
  4841. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  4842. safe_delete(spawn);
  4843. }
  4844. }
  4845. return 0;
  4846. }
  4847. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  4848. if (!lua_interface)
  4849. return 0;
  4850. Spawn* caster = lua_interface->GetSpawn(state);
  4851. Spawn* target = lua_interface->GetSpawn(state, 2);
  4852. int32 id = lua_interface->GetInt32Value(state, 3);
  4853. string command = lua_interface->GetStringValue(state, 4);
  4854. if (!caster) {
  4855. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  4856. return 0;
  4857. }
  4858. if (!target) {
  4859. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  4860. return 0;
  4861. }
  4862. if (!caster->IsPlayer()) {
  4863. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  4864. return 0;
  4865. }
  4866. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  4867. if (!entity_command) {
  4868. 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());
  4869. return 0;
  4870. }
  4871. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  4872. if (!client) {
  4873. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  4874. return 0;
  4875. }
  4876. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  4877. return 0;
  4878. }
  4879. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  4880. if (!lua_interface)
  4881. return 0;
  4882. Spawn* spawn = lua_interface->GetSpawn(state);
  4883. if (!spawn) {
  4884. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  4885. return 0;
  4886. }
  4887. if (!spawn->IsNPC()) {
  4888. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  4889. return 0;
  4890. }
  4891. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  4892. return 0;
  4893. }
  4894. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  4895. if (!lua_interface)
  4896. return 0;
  4897. Spawn* spawn = lua_interface->GetSpawn(state);
  4898. int16 tick = lua_interface->GetInt16Value(state, 2);
  4899. if (!spawn) {
  4900. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  4901. return 0;
  4902. }
  4903. if (!spawn->IsNPC()) {
  4904. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  4905. return 0;
  4906. }
  4907. if (tick < 20) {
  4908. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  4909. return 0;
  4910. }
  4911. ((NPC*)spawn)->Brain()->SetTick(tick);
  4912. return 0;
  4913. }
  4914. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  4915. if (!lua_interface)
  4916. return 0;
  4917. Spawn* spawn = lua_interface->GetSpawn(state);
  4918. Spawn* target = lua_interface->GetSpawn(state, 2);
  4919. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  4920. if (!spawn) {
  4921. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4922. return 0;
  4923. }
  4924. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  4925. spawn->SetFollowTarget(target, follow_distance);
  4926. return 0;
  4927. }
  4928. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  4929. if (!lua_interface)
  4930. return 0;
  4931. Spawn* spawn = lua_interface->GetSpawn(state);
  4932. if (!spawn) {
  4933. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4934. return 0;
  4935. }
  4936. Spawn* target = spawn->GetFollowTarget();
  4937. if (target) {
  4938. lua_interface->SetSpawnValue(state, target);
  4939. return 1;
  4940. }
  4941. return 0;
  4942. }
  4943. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  4944. if (!lua_interface)
  4945. return 0;
  4946. Spawn* spawn = lua_interface->GetSpawn(state);
  4947. if (!spawn) {
  4948. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  4949. return 0;
  4950. }
  4951. if (spawn->following)
  4952. spawn->following = false;
  4953. else
  4954. spawn->following = true;
  4955. return 0;
  4956. }
  4957. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  4958. if (!lua_interface)
  4959. return 0;
  4960. Spawn* spawn = lua_interface->GetSpawn(state);
  4961. if (!spawn) {
  4962. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  4963. return 0;
  4964. }
  4965. lua_interface->SetBooleanValue(state, spawn->following);
  4966. return 1;
  4967. }
  4968. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  4969. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  4970. // I will attempt to explain how this function works for future refrence
  4971. // Fist lets make sure lua_interface is valid, if not return out
  4972. if (!lua_interface)
  4973. return 0;
  4974. // Next we grab the first 2 params same as we usually would
  4975. Spawn* spawn = lua_interface->GetSpawn(state);
  4976. string var = lua_interface->GetStringValue(state, 2);
  4977. // 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
  4978. // 1 = Spawn
  4979. // 2 = Zone
  4980. // 3 = Item
  4981. // 4 = Quest
  4982. // 5 = String
  4983. // 6 = nil (null)
  4984. int8 dataType = 0;
  4985. // Define pointers for each potential type
  4986. Spawn* spawnVal = 0;
  4987. ZoneServer* zone = 0;
  4988. Item* item = 0;
  4989. Quest* quest = 0;
  4990. string val;
  4991. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  4992. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  4993. // options window are also light user data be we do not handle those.
  4994. // We check with lua_islightuserdata(lua_State*, index)
  4995. if (lua_islightuserdata(state, 3)) {
  4996. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  4997. // and convert it to LUAUserData*
  4998. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  4999. // Check to make sure the data we got is valid, if not give an error
  5000. if (!data || !data->IsCorrectlyInitialized()) {
  5001. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5002. }
  5003. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5004. else if (data->IsSpawn()) {
  5005. spawnVal = data->spawn;
  5006. dataType = 1;
  5007. }
  5008. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5009. else if (data->IsZone()) {
  5010. zone = data->zone;
  5011. dataType = 2;
  5012. }
  5013. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5014. else if (data->IsItem()) {
  5015. item = data->item;
  5016. dataType = 3;
  5017. }
  5018. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5019. else if (data->IsQuest()) {
  5020. quest = data->quest;
  5021. dataType = 4;
  5022. }
  5023. }
  5024. // Wasn't light user data, check if it is nil(null)
  5025. else if (lua_isnil(state, 3)) {
  5026. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5027. dataType = 6;
  5028. }
  5029. // Wasn't light user data or nil (null), must be a string
  5030. else {
  5031. // Set the string and dataType variable
  5032. val = lua_interface->GetStringValue(state, 3);
  5033. dataType = 5;
  5034. }
  5035. // We now have all the params, lets check to make sure they are valid
  5036. if (!spawn) {
  5037. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5038. return 0;
  5039. }
  5040. if (var.length() == 0) {
  5041. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5042. return 0;
  5043. }
  5044. if (dataType == 0) {
  5045. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5046. return 0;
  5047. }
  5048. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5049. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5050. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5051. switch (dataType) {
  5052. case 1:
  5053. // 1 = Spawn
  5054. spawn->AddTempVariable(var, spawnVal);
  5055. break;
  5056. case 2:
  5057. // 2 = Zone
  5058. spawn->AddTempVariable(var, zone);
  5059. break;
  5060. case 3:
  5061. // 3 = Item
  5062. spawn->AddTempVariable(var, item);
  5063. break;
  5064. case 4:
  5065. // 4 = Quest
  5066. spawn->AddTempVariable(var, quest);
  5067. break;
  5068. case 5:
  5069. // 5 = String
  5070. spawn->AddTempVariable(var, val);
  5071. break;
  5072. case 6:
  5073. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5074. spawn->DeleteTempVariable(var);
  5075. break;
  5076. }
  5077. // And we are done so return out
  5078. return 0;
  5079. }
  5080. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5081. if (!lua_interface)
  5082. return 0;
  5083. Spawn* spawn = lua_interface->GetSpawn(state);
  5084. string var = lua_interface->GetStringValue(state, 2);
  5085. if (!spawn) {
  5086. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5087. return 0;
  5088. }
  5089. if (var.length() == 0) {
  5090. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5091. return 0;
  5092. }
  5093. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5094. int8 type = spawn->GetTempVariableType(var);
  5095. Spawn* spawn2 = 0;
  5096. ZoneServer* zone = 0;
  5097. Item* item = 0;
  5098. Quest* quest = 0;
  5099. // Set the lua function return value based on the type of data the variable contains
  5100. switch (type) {
  5101. case 1:
  5102. spawn2 = spawn->GetTempVariableSpawn(var);
  5103. if (!spawn2)
  5104. return 0;
  5105. lua_interface->SetSpawnValue(state, spawn2);
  5106. break;
  5107. case 2:
  5108. zone = spawn->GetTempVariableZone(var);
  5109. if (!zone)
  5110. return 0;
  5111. lua_interface->SetZoneValue(state, zone);
  5112. break;
  5113. case 3:
  5114. item = spawn->GetTempVariableItem(var);
  5115. if (!item)
  5116. return 0;
  5117. lua_interface->SetItemValue(state, item);
  5118. break;
  5119. case 4:
  5120. quest = spawn->GetTempVariableQuest(var);
  5121. if (!quest)
  5122. return 0;
  5123. lua_interface->SetQuestValue(state, quest);
  5124. break;
  5125. case 5:
  5126. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5127. break;
  5128. default:
  5129. // Not a valid type then the variable was not set so return out
  5130. return 0;
  5131. }
  5132. // Return value was set so return out
  5133. return 1;
  5134. }
  5135. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5136. {
  5137. if (!lua_interface)
  5138. return 0;
  5139. Quest* quest = lua_interface->GetQuest(state);
  5140. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5141. string description = lua_interface->GetStringValue(state, 3);
  5142. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5143. if (!quest) {
  5144. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5145. lua_interface->SetBooleanValue(state, false);
  5146. return 1;
  5147. }
  5148. if (!spawn) {
  5149. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5150. lua_interface->SetBooleanValue(state, false);
  5151. return 1;
  5152. }
  5153. if (!spawn->IsPlayer()) {
  5154. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5155. lua_interface->SetBooleanValue(state, false);
  5156. return 1;
  5157. }
  5158. if (item_id == 0) {
  5159. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5160. lua_interface->SetBooleanValue(state, false);
  5161. return 1;
  5162. }
  5163. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5164. if (!client) {
  5165. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  5166. lua_interface->SetBooleanValue(state, false);
  5167. return 1;
  5168. }
  5169. Item* item = master_item_list.GetItem(item_id);
  5170. if (!item) {
  5171. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5172. lua_interface->SetBooleanValue(state, false);
  5173. return 1;
  5174. }
  5175. Item* firstItem = new Item(item);
  5176. quest->AddTmpRewardItem(firstItem);
  5177. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5178. bool itemsAddedSuccessfully = true;
  5179. if(num_args > 4)
  5180. {
  5181. for(int8 n=5;n<num_args+1;n++)
  5182. {
  5183. int32 new_item = lua_interface->GetInt32Value(state, n);
  5184. Item* tmpItem = master_item_list.GetItem(new_item);
  5185. if(tmpItem)
  5186. {
  5187. Item* newTmpItem = new Item(tmpItem);
  5188. quest->AddTmpRewardItem(newTmpItem);
  5189. }
  5190. else
  5191. itemsAddedSuccessfully = false;
  5192. }
  5193. }
  5194. client->AddPendingQuestAcceptReward(quest);
  5195. client->DisplayQuestComplete(quest, true, description);
  5196. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5197. return 1;
  5198. }
  5199. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5200. if (!lua_interface)
  5201. return 0;
  5202. Quest* quest = lua_interface->GetQuest(state);
  5203. if (!quest) {
  5204. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5205. return 0;
  5206. }
  5207. quest->SetRepeatable(true);
  5208. return 0;
  5209. }
  5210. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5211. if (!lua_interface)
  5212. return 0;
  5213. Spawn* spawn = lua_interface->GetSpawn(state);
  5214. if (!spawn) {
  5215. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5216. return 0;
  5217. }
  5218. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5219. string ret = classes.GetClassNameCase(base_class);
  5220. if (ret.length() > 0) {
  5221. lua_interface->SetStringValue(state, ret.c_str());
  5222. return 1;
  5223. }
  5224. return 0;
  5225. }
  5226. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5227. if (!lua_interface)
  5228. return 0;
  5229. Spawn* player = lua_interface->GetSpawn(state);
  5230. if (player && player->IsPlayer()) {
  5231. Client* client = player->GetClient();
  5232. if (client)
  5233. client->SendWaypoints();
  5234. }
  5235. return 0;
  5236. }
  5237. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5238. if (!lua_interface)
  5239. return 0;
  5240. Spawn* player = lua_interface->GetSpawn(state);
  5241. string name = lua_interface->GetStringValue(state, 2);
  5242. int32 type = lua_interface->GetInt32Value(state, 3);
  5243. if (type == 0)
  5244. type = 2;
  5245. if (name.length() > 0) {
  5246. if (player && player->IsPlayer()) {
  5247. Client* client = player->GetClient();
  5248. if (client)
  5249. client->AddWaypoint(name, type);
  5250. }
  5251. }
  5252. return 0;
  5253. }
  5254. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5255. if (!lua_interface)
  5256. return 0;
  5257. Spawn* player = lua_interface->GetSpawn(state);
  5258. string name = lua_interface->GetStringValue(state, 2);
  5259. if (name.length() > 0) {
  5260. if (player && player->IsPlayer()) {
  5261. Client* client = player->GetClient();
  5262. if (client)
  5263. client->RemoveWaypoint(name);
  5264. }
  5265. }
  5266. return 0;
  5267. }
  5268. int EQ2Emu_lua_AddWard(lua_State* state) {
  5269. if (!lua_interface)
  5270. return 0;
  5271. int32 damage = lua_interface->GetInt32Value(state);
  5272. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5273. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5274. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5275. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5276. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5277. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5278. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5279. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5280. bool ward_was_added = false;
  5281. ZoneServer* zone = spell->caster->GetZone();
  5282. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5283. for (int32 i = 0; i < spell->targets.size(); i++) {
  5284. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5285. if (!target)
  5286. continue;
  5287. if (target->IsEntity()) {
  5288. // If the ward is already active remove it
  5289. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5290. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5291. // Create new ward info
  5292. WardInfo* ward = new WardInfo;
  5293. ward->Spell = spell;
  5294. ward->BaseDamage = damage;
  5295. ward->DamageLeft = damage;
  5296. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5297. ward->keepWard = keepWard;
  5298. ward->WardType = wardType;
  5299. if (damageAbsorptionPercent > 100)
  5300. damageAbsorptionPercent = 100;
  5301. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5302. if (damageAbsorptionMaxHealthPercent > 100)
  5303. damageAbsorptionMaxHealthPercent = 100;
  5304. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5305. ward->RedirectDamagePercent = redirectDamagePercent;
  5306. ward->LastRedirectDamage = 0;
  5307. ward->LastAbsorbedDamage = 0;
  5308. ward->HitCount = 0;
  5309. spell->num_triggers = maxHitCount;
  5310. spell->had_triggers = true;
  5311. spell->cancel_after_all_triggers = false;
  5312. ward->MaxHitCount = maxHitCount;
  5313. if (wardType == WARD_TYPE_MAGICAL)
  5314. ward->DamageType = damageTypes;
  5315. // Add the ward to the entity
  5316. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5317. ward_was_added = true;
  5318. }
  5319. }
  5320. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5321. if (ward_was_added && spell->caster->IsPlayer()) {
  5322. spell->had_dmg_remaining = true;
  5323. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5324. }
  5325. return 0;
  5326. }
  5327. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5328. if (!lua_interface)
  5329. return 0;
  5330. int32 amount = lua_interface->GetInt32Value(state);
  5331. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5332. WardInfo* ward = 0;
  5333. ZoneServer* zone = spell->caster->GetZone();
  5334. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5335. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5336. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5337. ward = target->GetWard(spell->spell->GetSpellID());
  5338. if (target && ward) {
  5339. ward->DamageLeft += amount;
  5340. if (ward->DamageLeft > ward->BaseDamage)
  5341. ward->DamageLeft = ward->BaseDamage;
  5342. for (int32 i = 0; i < spell->targets.size(); i++) {
  5343. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5344. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5345. }
  5346. }
  5347. }
  5348. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5349. if (ward && spell->caster->IsPlayer())
  5350. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5351. return 0;
  5352. }
  5353. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5354. if (!lua_interface)
  5355. return 0;
  5356. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5357. if (!spell) {
  5358. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5359. return 0;
  5360. }
  5361. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5362. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5363. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5364. if (ward) {
  5365. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5366. return 1;
  5367. }
  5368. }
  5369. return 0;
  5370. }
  5371. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5372. if (!lua_interface)
  5373. return 0;
  5374. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5375. if (!spell) {
  5376. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5377. return 0;
  5378. }
  5379. string type = lua_interface->GetStringValue(state, 2);
  5380. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5381. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5382. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5383. if (ward) {
  5384. if (boost::iequals(type, "damageleft"))
  5385. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5386. else if (boost::iequals(type, "basedamage"))
  5387. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5388. else if (boost::iequals(type, "keepward"))
  5389. lua_interface->SetBooleanValue(state, ward->keepWard);
  5390. else if (boost::iequals(type, "wardtype"))
  5391. lua_interface->SetInt32Value(state, ward->WardType);
  5392. else if (boost::iequals(type, "dmgabsorptionpct"))
  5393. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5394. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5395. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5396. else if (boost::iequals(type, "redirectdamagepercent"))
  5397. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5398. else if (boost::iequals(type, "lastredirectdamage"))
  5399. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5400. else if (boost::iequals(type, "lastabsorbeddamage"))
  5401. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5402. else if (boost::iequals(type, "hitcount"))
  5403. lua_interface->SetInt32Value(state, ward->HitCount);
  5404. else if (boost::iequals(type, "maxhitcount"))
  5405. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5406. else
  5407. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5408. return 1;
  5409. }
  5410. }
  5411. return 0;
  5412. }
  5413. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5414. if (!lua_interface)
  5415. return 0;
  5416. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5417. ZoneServer* zone = spell->caster->GetZone();
  5418. Spawn* target = 0;
  5419. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5420. for (int32 i = 0; i < spell->targets.size(); i++) {
  5421. target = zone->GetSpawnByID(spell->targets.at(i));
  5422. if (target && target->IsEntity()) {
  5423. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5424. }
  5425. }
  5426. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5427. return 0;
  5428. }
  5429. int EQ2Emu_lua_Interrupt(lua_State* state)
  5430. {
  5431. if (!lua_interface)
  5432. return 0;
  5433. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5434. Spawn* target = lua_interface->GetSpawn(state, 2);
  5435. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5436. if (!caster)
  5437. {
  5438. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5439. return 0;
  5440. }
  5441. if (!target)
  5442. {
  5443. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5444. return 0;
  5445. }
  5446. if (!spell) {
  5447. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5448. return 0;
  5449. }
  5450. if (!target->IsEntity() && !spell)
  5451. {
  5452. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5453. return 0;
  5454. }
  5455. if (!target && spell) {
  5456. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5457. for (int8 i = 0; i < spell->targets.size(); i++) {
  5458. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5459. if (!target || !target->IsEntity())
  5460. continue;
  5461. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5462. }
  5463. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5464. }
  5465. else
  5466. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5467. return 0;
  5468. }
  5469. int EQ2Emu_lua_Stealth(lua_State* state) {
  5470. if (!lua_interface)
  5471. return 0;
  5472. int8 type = lua_interface->GetInt8Value(state);
  5473. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5474. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5475. if (!spell) {
  5476. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5477. return 0;
  5478. }
  5479. ZoneServer* zone = spell->caster->GetZone();
  5480. if (spawn) {
  5481. if (spawn->IsEntity()) {
  5482. if (type == 1) {
  5483. ((Entity*)spawn)->AddStealthSpell(spell);
  5484. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5485. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5486. }
  5487. else if (type == 2) {
  5488. ((Entity*)spawn)->AddInvisSpell(spell);
  5489. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5490. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5491. }
  5492. return 0;
  5493. }
  5494. else {
  5495. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5496. return 0;
  5497. }
  5498. }
  5499. else {
  5500. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5501. for (int32 i = 0; i < spell->targets.size(); i++) {
  5502. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5503. if (!spawn || !spawn->IsEntity())
  5504. continue;
  5505. if (type == 1) {
  5506. ((Entity*)spawn)->AddStealthSpell(spell);
  5507. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5508. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5509. }
  5510. else if (type == 2) {
  5511. ((Entity*)spawn)->AddInvisSpell(spell);
  5512. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5513. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5514. }
  5515. else {
  5516. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5517. break;
  5518. }
  5519. }
  5520. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5521. }
  5522. return 0;
  5523. }
  5524. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5525. if (!lua_interface)
  5526. return 0;
  5527. Spawn* spawn = lua_interface->GetSpawn(state);
  5528. if (!spawn) {
  5529. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5530. return 0;
  5531. }
  5532. if (spawn->IsEntity()) {
  5533. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5534. return 1;
  5535. }
  5536. else
  5537. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5538. return 0;
  5539. }
  5540. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5541. if (!lua_interface)
  5542. return 0;
  5543. Spawn* spawn = lua_interface->GetSpawn(state);
  5544. if (!spawn) {
  5545. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5546. return 0;
  5547. }
  5548. if (spawn->IsEntity()) {
  5549. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5550. return 1;
  5551. }
  5552. else
  5553. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5554. return 0;
  5555. }
  5556. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5557. if (!lua_interface)
  5558. return 0;
  5559. Spawn* player = lua_interface->GetSpawn(state);
  5560. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5561. lua_interface->ResetFunctionStack(state);
  5562. if (!player->IsPlayer()) {
  5563. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5564. return 0;
  5565. }
  5566. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5567. return 1;
  5568. }
  5569. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5570. if (!lua_interface)
  5571. return 0;
  5572. Spawn* player = lua_interface->GetSpawn(state);
  5573. int8 slot = lua_interface->GetInt8Value(state, 2);
  5574. lua_interface->ResetFunctionStack(state);
  5575. if (!player) {
  5576. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5577. return 0;
  5578. }
  5579. if (!player->IsPlayer()) {
  5580. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5581. return 0;
  5582. }
  5583. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5584. if (!item) {
  5585. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5586. return 0;
  5587. }
  5588. lua_interface->SetItemValue(state, item);
  5589. return 1;
  5590. }
  5591. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5592. if (!lua_interface)
  5593. return 0;
  5594. Spawn* player = lua_interface->GetSpawn(state);
  5595. int32 id = lua_interface->GetInt32Value(state, 2);
  5596. lua_interface->ResetFunctionStack(state);
  5597. if (!player) {
  5598. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5599. return 0;
  5600. }
  5601. if (!player->IsPlayer()) {
  5602. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5603. return 0;
  5604. }
  5605. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5606. if (!item) {
  5607. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5608. return 0;
  5609. }
  5610. lua_interface->SetItemValue(state, item);
  5611. return 1;
  5612. }
  5613. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  5614. if (!lua_interface)
  5615. return 0;
  5616. Spawn* spawn = lua_interface->GetSpawn(state);
  5617. int8 slot = lua_interface->GetInt8Value(state, 2);
  5618. int32 item_id = lua_interface->GetInt32Value(state, 3);
  5619. lua_interface->ResetFunctionStack(state);
  5620. if (!spawn) {
  5621. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5622. return 0;
  5623. }
  5624. if (!spawn->IsEntity()) {
  5625. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5626. return 0;
  5627. }
  5628. Item* item = master_item_list.GetItem(item_id);
  5629. if (!item) {
  5630. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  5631. return 0;
  5632. }
  5633. Item* copy = new Item(item);
  5634. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  5635. if(result)
  5636. {
  5637. ((Entity*)spawn)->SetEquipment(copy, slot);
  5638. spawn->vis_changed = true;
  5639. if(spawn->IsPlayer())
  5640. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5641. }
  5642. else
  5643. {
  5644. safe_delete(copy);
  5645. }
  5646. lua_interface->SetBooleanValue(state, result);
  5647. return 1;
  5648. }
  5649. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  5650. if (!lua_interface)
  5651. return 0;
  5652. Spawn* spawn = lua_interface->GetSpawn(state);
  5653. int8 slot = lua_interface->GetInt8Value(state, 2);
  5654. Item* item = lua_interface->GetItem(state, 3);
  5655. lua_interface->ResetFunctionStack(state);
  5656. if (!spawn) {
  5657. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5658. return 0;
  5659. }
  5660. if (!spawn->IsEntity()) {
  5661. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5662. return 0;
  5663. }
  5664. if (!item) {
  5665. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  5666. return 0;
  5667. }
  5668. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  5669. if(result)
  5670. {
  5671. ((Entity*)spawn)->SetEquipment(item, slot);
  5672. spawn->vis_changed = true;
  5673. if(spawn->IsPlayer())
  5674. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5675. }
  5676. lua_interface->SetBooleanValue(state, result);
  5677. return 1;
  5678. }
  5679. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  5680. if (!lua_interface)
  5681. return 0;
  5682. Spawn* spawn = lua_interface->GetSpawn(state);
  5683. int8 slot = lua_interface->GetInt8Value(state, 2);
  5684. bool no_delete_item = (lua_interface->GetBooleanValue(state, 2) == false); // if not set then we default to deleting it, otherwise if set to true we don't delete
  5685. lua_interface->ResetFunctionStack(state);
  5686. if (!spawn) {
  5687. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5688. return 0;
  5689. }
  5690. if (!spawn->IsEntity()) {
  5691. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5692. return 0;
  5693. }
  5694. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  5695. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  5696. spawn->vis_changed = true;
  5697. if(spawn->IsPlayer())
  5698. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5699. lua_interface->SetBooleanValue(state, true);
  5700. return 1;
  5701. }
  5702. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  5703. if (!lua_interface)
  5704. return 0;
  5705. Spawn* spawn = lua_interface->GetSpawn(state);
  5706. int8 slot = lua_interface->GetInt8Value(state, 2);
  5707. int16 type = lua_interface->GetInt16Value(state, 3);
  5708. int8 r = lua_interface->GetInt8Value(state, 4);
  5709. int8 g = lua_interface->GetInt8Value(state, 5);
  5710. int8 b = lua_interface->GetInt8Value(state, 6);
  5711. int8 h_r = lua_interface->GetInt8Value(state, 7);
  5712. int8 h_g = lua_interface->GetInt8Value(state, 8);
  5713. int8 h_b = lua_interface->GetInt8Value(state, 9);
  5714. lua_interface->ResetFunctionStack(state);
  5715. if (!spawn) {
  5716. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  5717. return 0;
  5718. }
  5719. if (!spawn->IsEntity()) {
  5720. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5721. return 0;
  5722. }
  5723. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  5724. spawn->vis_changed = true;
  5725. lua_interface->SetBooleanValue(state, true);
  5726. return 1;
  5727. }
  5728. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  5729. if (!lua_interface)
  5730. return 0;
  5731. Spawn* player = lua_interface->GetSpawn(state);
  5732. int32 id = lua_interface->GetInt32Value(state, 2);
  5733. int8 count = lua_interface->GetInt8Value(state, 3);
  5734. bool include_bank = lua_interface->GetInt8Value(state, 4);
  5735. lua_interface->ResetFunctionStack(state);
  5736. if (!player) {
  5737. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5738. return 0;
  5739. }
  5740. if (!player->IsPlayer()) {
  5741. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5742. return 0;
  5743. }
  5744. if (!count)
  5745. count = 1;
  5746. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  5747. if (!item) {
  5748. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  5749. return 0;
  5750. }
  5751. lua_interface->SetItemValue(state, item);
  5752. return 1;
  5753. }
  5754. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  5755. if (!lua_interface)
  5756. return 0;
  5757. Spawn* spawn = lua_interface->GetSpawn(state);
  5758. int32 anim = lua_interface->GetInt32Value(state, 2);
  5759. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  5760. int8 type = lua_interface->GetInt8Value(state, 4);
  5761. if (!spawn) {
  5762. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  5763. return 0;
  5764. }
  5765. if (spawn2) {
  5766. if (spawn2->IsPlayer()) {
  5767. if (type != 1 && type != 2)
  5768. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  5769. else
  5770. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  5771. return 0;
  5772. }
  5773. else {
  5774. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  5775. return 0;
  5776. }
  5777. }
  5778. else
  5779. spawn->GetZone()->PlayAnimation(spawn, anim);
  5780. return 0;
  5781. }
  5782. int EQ2Emu_lua_IsPet(lua_State* state) {
  5783. if (!lua_interface)
  5784. return 0;
  5785. Spawn* spawn = lua_interface->GetSpawn(state);
  5786. if (!spawn) {
  5787. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5788. return 0;
  5789. }
  5790. lua_interface->SetBooleanValue(state, spawn->IsPet());
  5791. return 1;
  5792. }
  5793. int EQ2Emu_lua_GetOwner(lua_State* state) {
  5794. if (!lua_interface)
  5795. return 0;
  5796. Spawn* spawn = lua_interface->GetSpawn(state);
  5797. if (!spawn) {
  5798. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  5799. return 0;
  5800. }
  5801. if (!spawn->IsNPC()) {
  5802. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5803. return 0;
  5804. }
  5805. if (((NPC*)spawn)->GetOwner()) {
  5806. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  5807. return 1;
  5808. }
  5809. return 0;
  5810. }
  5811. int EQ2Emu_lua_SetTarget(lua_State* state) {
  5812. if (!lua_interface)
  5813. return 0;
  5814. Spawn* spawn = lua_interface->GetSpawn(state);
  5815. Spawn* target = lua_interface->GetSpawn(state, 2);
  5816. if (!spawn) {
  5817. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5818. return 0;
  5819. }
  5820. if (!spawn) {
  5821. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  5822. return 0;
  5823. }
  5824. spawn->SetTarget(target);
  5825. return 0;
  5826. }
  5827. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  5828. if (!lua_interface)
  5829. return 0;
  5830. Spawn* spawn = lua_interface->GetSpawn(state);
  5831. bool val = lua_interface->GetBooleanValue(state, 2);
  5832. if (!spawn) {
  5833. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  5834. return 0;
  5835. }
  5836. if (!spawn->IsEntity()) {
  5837. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5838. return 0;
  5839. }
  5840. ((Entity*)spawn)->InCombat(val);
  5841. if (val) {
  5842. spawn->ClearRunningLocations();
  5843. spawn->CalculateRunningLocation(true);
  5844. }
  5845. return 0;
  5846. }
  5847. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  5848. if (!lua_interface)
  5849. return 0;
  5850. Spawn* spawn1 = lua_interface->GetSpawn(state);
  5851. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5852. if (!spawn1) {
  5853. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5854. return 0;
  5855. }
  5856. if (!spawn2) {
  5857. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5858. return 0;
  5859. }
  5860. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  5861. return 1;
  5862. }
  5863. int EQ2Emu_lua_Runback(lua_State* state) {
  5864. if (!lua_interface)
  5865. return 0;
  5866. Spawn* spawn = lua_interface->GetSpawn(state);
  5867. if (!spawn) {
  5868. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  5869. return 0;
  5870. }
  5871. if (!spawn->IsNPC()) {
  5872. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5873. return 0;
  5874. }
  5875. ((NPC*)spawn)->Runback();
  5876. return 0;
  5877. }
  5878. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  5879. if (!lua_interface)
  5880. return 0;
  5881. Spawn* spawn = lua_interface->GetSpawn(state);
  5882. if (!spawn) {
  5883. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  5884. return 0;
  5885. }
  5886. if (!spawn->IsNPC()) {
  5887. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5888. return 0;
  5889. }
  5890. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  5891. return 1;
  5892. }
  5893. int EQ2Emu_lua_IsCasting(lua_State* state) {
  5894. if (!lua_interface)
  5895. return 0;
  5896. Spawn* spawn = lua_interface->GetSpawn(state);
  5897. if (!spawn) {
  5898. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  5899. return 0;
  5900. }
  5901. if (!spawn->IsEntity()) {
  5902. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5903. return 0;
  5904. }
  5905. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  5906. return 1;
  5907. }
  5908. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  5909. if (!lua_interface)
  5910. return 0;
  5911. Spawn* spawn = lua_interface->GetSpawn(state);
  5912. if (!spawn) {
  5913. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5914. return 0;
  5915. }
  5916. if (!spawn->IsEntity()) {
  5917. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5918. return 0;
  5919. }
  5920. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  5921. return 1;
  5922. }
  5923. int EQ2Emu_lua_IsStunned(lua_State* state) {
  5924. if (!lua_interface)
  5925. return 0;
  5926. Spawn* spawn = lua_interface->GetSpawn(state);
  5927. if (!spawn) {
  5928. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5929. return 0;
  5930. }
  5931. if (!spawn->IsEntity()) {
  5932. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5933. return 0;
  5934. }
  5935. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  5936. return 1;
  5937. }
  5938. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  5939. if (!lua_interface)
  5940. return 0;
  5941. Spawn* spawn = lua_interface->GetSpawn(state);
  5942. if (!spawn) {
  5943. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5944. return 0;
  5945. }
  5946. if (!spawn->IsEntity()) {
  5947. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5948. return 0;
  5949. }
  5950. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  5951. return 1;
  5952. }
  5953. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  5954. if (!lua_interface)
  5955. return 0;
  5956. Spawn* spawn = lua_interface->GetSpawn(state);
  5957. Spawn* target = lua_interface->GetSpawn(state, 2);
  5958. float distance = lua_interface->GetFloatValue(state, 3);
  5959. if (!spawn) {
  5960. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  5961. return 0;
  5962. }
  5963. if (!target) {
  5964. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5965. return 0;
  5966. }
  5967. if (!spawn->IsNPC()) {
  5968. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5969. return 0;
  5970. }
  5971. if (!target->IsEntity()) {
  5972. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  5973. return 0;
  5974. }
  5975. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  5976. return 1;
  5977. }
  5978. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  5979. if (!lua_interface)
  5980. return 0;
  5981. Spawn* spawn = lua_interface->GetSpawn(state);
  5982. Spawn* target = lua_interface->GetSpawn(state, 2);
  5983. float distance = lua_interface->GetFloatValue(state, 3);
  5984. if (!spawn) {
  5985. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  5986. return 0;
  5987. }
  5988. if (!target) {
  5989. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  5990. return 0;
  5991. }
  5992. if (!spawn->IsNPC()) {
  5993. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5994. return 0;
  5995. }
  5996. if (!target->IsEntity()) {
  5997. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  5998. return 0;
  5999. }
  6000. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6001. return 0;
  6002. }
  6003. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6004. if (!lua_interface)
  6005. return 0;
  6006. Spawn* spawn = lua_interface->GetSpawn(state);
  6007. if (!spawn) {
  6008. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6009. return 0;
  6010. }
  6011. if (!spawn->IsNPC()) {
  6012. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6013. return 0;
  6014. }
  6015. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6016. return 1;
  6017. }
  6018. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6019. if (!lua_interface)
  6020. return 0;
  6021. Spawn* spawn = lua_interface->GetSpawn(state);
  6022. if (!spawn) {
  6023. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6024. return 0;
  6025. }
  6026. if (!spawn->IsNPC()) {
  6027. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6028. return 0;
  6029. }
  6030. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6031. return 1;
  6032. }
  6033. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6034. if (!lua_interface)
  6035. return 0;
  6036. Spawn* spawn = lua_interface->GetSpawn(state);
  6037. if (!spawn) {
  6038. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6039. return 0;
  6040. }
  6041. if (!spawn->IsNPC()) {
  6042. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6043. return 0;
  6044. }
  6045. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6046. if (hated) {
  6047. lua_interface->SetSpawnValue(state, hated);
  6048. return 1;
  6049. }
  6050. return 0;
  6051. }
  6052. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6053. if (!lua_interface)
  6054. return 0;
  6055. Spawn* spawn = lua_interface->GetSpawn(state);
  6056. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6057. if (!spawn) {
  6058. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6059. return 0;
  6060. }
  6061. if (!spawn->IsNPC()) {
  6062. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6063. return 0;
  6064. }
  6065. if (!hated) {
  6066. ((NPC*)spawn)->Brain()->ClearHate();
  6067. return 0;
  6068. }
  6069. else
  6070. {
  6071. if (!hated->IsEntity()) {
  6072. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6073. return 0;
  6074. }
  6075. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6076. return 0;
  6077. }
  6078. return 0;
  6079. }
  6080. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6081. if (!lua_interface)
  6082. return 0;
  6083. Spawn* spawn = lua_interface->GetSpawn(state);
  6084. if (!spawn) {
  6085. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6086. return 0;
  6087. }
  6088. if (!spawn->IsNPC()) {
  6089. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6090. return 0;
  6091. }
  6092. ((NPC*)spawn)->Brain()->ClearEncounter();
  6093. return 0;
  6094. }
  6095. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6096. if (!lua_interface)
  6097. return 0;
  6098. Spawn* spawn = lua_interface->GetSpawn(state);
  6099. if (!spawn) {
  6100. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6101. return 0;
  6102. }
  6103. if (!spawn->IsNPC()) {
  6104. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6105. return 0;
  6106. }
  6107. // Temp list to store hate list
  6108. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6109. if (encounterList->size() == 0) {
  6110. safe_delete(encounterList);
  6111. return 0;
  6112. }
  6113. lua_createtable(state, encounterList->size(), 0);
  6114. int newTable = lua_gettop(state);
  6115. for (int32 i = 0; i < encounterList->size(); i++) {
  6116. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6117. if (temp)
  6118. lua_interface->SetSpawnValue(state, temp);
  6119. lua_rawseti(state, newTable, i + 1);
  6120. }
  6121. safe_delete(encounterList);
  6122. return 1;
  6123. }
  6124. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6125. if (!lua_interface)
  6126. return 0;
  6127. Spawn* spawn = lua_interface->GetSpawn(state);
  6128. if (!spawn) {
  6129. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6130. return 0;
  6131. }
  6132. if (!spawn->IsNPC()) {
  6133. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6134. return 0;
  6135. }
  6136. // Temp list to store hate list
  6137. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6138. if (hateList->size() == 0) {
  6139. safe_delete(hateList);
  6140. return 0;
  6141. }
  6142. lua_createtable(state, hateList->size(), 0);
  6143. int newTable = lua_gettop(state);
  6144. for (int32 i = 0; i < hateList->size(); i++) {
  6145. lua_interface->SetSpawnValue(state, hateList->at(i));
  6146. lua_rawseti(state, newTable, i + 1);
  6147. }
  6148. safe_delete(hateList);
  6149. return 1;
  6150. }
  6151. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6152. if (!lua_interface)
  6153. return 0;
  6154. Spawn* spawn = lua_interface->GetSpawn(state);
  6155. if (!spawn) {
  6156. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6157. return 0;
  6158. }
  6159. if (spawn->IsPlayer()) {
  6160. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6161. lua_interface->SetBooleanValue(state, true);
  6162. else
  6163. lua_interface->SetBooleanValue(state, false);
  6164. return 1;
  6165. }
  6166. else {
  6167. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6168. return 1;
  6169. }
  6170. }
  6171. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6172. if (!lua_interface)
  6173. return 0;
  6174. Quest* quest = lua_interface->GetQuest(state);
  6175. if (!quest) {
  6176. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6177. return 0;
  6178. }
  6179. quest->SetCompletedFlag(true);
  6180. return 0;
  6181. }
  6182. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6183. if (!lua_interface)
  6184. return 0;
  6185. Spawn* spawn = lua_interface->GetSpawn(state);
  6186. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6187. int8 tier = lua_interface->GetInt8Value(state, 3);
  6188. if (!spawn) {
  6189. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6190. return 0;
  6191. }
  6192. if (!spawn->IsEntity()) {
  6193. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6194. return 0;
  6195. }
  6196. if (spellID == 0) {
  6197. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6198. return 0;
  6199. }
  6200. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6201. if (effect) {
  6202. if (tier > 0) {
  6203. // If a tier was passed chec to see if it is the same as the effect
  6204. if (tier == effect->tier)
  6205. lua_interface->SetBooleanValue(state, true);
  6206. else
  6207. lua_interface->SetBooleanValue(state, false);
  6208. return 1;
  6209. }
  6210. else {
  6211. // Have an effect but no tier was passed so return true
  6212. lua_interface->SetBooleanValue(state, true);
  6213. }
  6214. return 1;
  6215. }
  6216. // no effect so return false
  6217. lua_interface->SetBooleanValue(state, false);
  6218. return 1;
  6219. }
  6220. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6221. if (!lua_interface)
  6222. return 0;
  6223. Spawn* spawn = lua_interface->GetSpawn(state);
  6224. int32 id = lua_interface->GetInt32Value(state, 2);
  6225. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6226. Spawn* spawn2 = 0;
  6227. vector<Spawn*> list;
  6228. if (!spawn) {
  6229. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6230. return 0;
  6231. }
  6232. //If zone not provided, use spawn's zone
  6233. if (!zone)
  6234. zone = spawn->GetZone();
  6235. list = zone->GetSpawnsByID(id);
  6236. if (list.size() == 0) {
  6237. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6238. return 0;
  6239. }
  6240. vector<Spawn*>::iterator itr = list.begin();
  6241. for (int8 i = 0; i < list.size(); i++) {
  6242. spawn2 = itr[i];
  6243. if (spawn2)
  6244. spawn2->AddAllowAccessSpawn(spawn);
  6245. }
  6246. return 0;
  6247. }
  6248. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6249. if (!lua_interface)
  6250. return 0;
  6251. Spawn* spawn = lua_interface->GetSpawn(state);
  6252. int32 id = lua_interface->GetInt32Value(state, 2);
  6253. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6254. Spawn* spawn2 = 0;
  6255. if (!spawn) {
  6256. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6257. return 0;
  6258. }
  6259. //If zone not provided, use spawn's zone
  6260. if (!zone)
  6261. zone = spawn->GetZone();
  6262. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6263. vector<Spawn*>::iterator itr = list.begin();
  6264. if (list.size() == 0) {
  6265. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6266. return 0;
  6267. }
  6268. for (int8 i = 0; i < list.size(); i++) {
  6269. spawn2 = itr[i];
  6270. if (spawn2)
  6271. spawn2->RemoveSpawnAccess(spawn);
  6272. }
  6273. return 0;
  6274. }
  6275. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6276. if (!lua_interface)
  6277. return 0;
  6278. Quest* quest = lua_interface->GetQuest(state);
  6279. if (!quest) {
  6280. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6281. return 0;
  6282. }
  6283. quest->SetYellowName(true);
  6284. return 0;
  6285. }
  6286. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6287. if (!lua_interface)
  6288. return 0;
  6289. Spawn* spawn = lua_interface->GetSpawn(state);
  6290. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6291. if (!spawn) {
  6292. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6293. return 0;
  6294. }
  6295. if (!spawn->IsPlayer()) {
  6296. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6297. return 0;
  6298. }
  6299. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6300. return 1;
  6301. }
  6302. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6303. if (!lua_interface)
  6304. return 0;
  6305. Spawn* spawn = lua_interface->GetSpawn(state);
  6306. if (!spawn) {
  6307. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6308. return 0;
  6309. }
  6310. if (!spawn->IsPlayer()) {
  6311. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6312. return 0;
  6313. }
  6314. ZoneServer* zone = spawn->GetZone();
  6315. if (!zone) {
  6316. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6317. return 0;
  6318. }
  6319. Instance_Type iType = zone->GetInstanceType();
  6320. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6321. iType == GROUP_LOCKOUT_INSTANCE ||
  6322. iType == RAID_LOCKOUT_INSTANCE ||
  6323. iType == SOLO_PERSIST_INSTANCE ||
  6324. iType == GROUP_PERSIST_INSTANCE ||
  6325. iType == RAID_PERSIST_INSTANCE) {
  6326. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6327. if (data) {
  6328. // Check to see if the timer has already been set, if it has return out.
  6329. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6330. return 0;
  6331. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6332. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6333. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6334. if (client) {
  6335. string time_msg = "";
  6336. int32 time = data->success_lockout_time;
  6337. int16 hour;
  6338. int8 min;
  6339. int8 sec;
  6340. hour = time / 3600;
  6341. time = time % 3600;
  6342. min = time / 60;
  6343. time = time % 60;
  6344. sec = time;
  6345. if (hour > 0) {
  6346. char temp[10];
  6347. sprintf(temp, " %i", hour);
  6348. time_msg.append(temp);
  6349. time_msg.append(" hour");
  6350. time_msg.append((hour > 1) ? "s" : "");
  6351. }
  6352. if (min > 0) {
  6353. char temp[5];
  6354. sprintf(temp, " %i", min);
  6355. time_msg.append(temp);
  6356. time_msg.append(" minute");
  6357. time_msg.append((min > 1) ? "s" : "");
  6358. }
  6359. // Only add seconds if minutes and hours are 0
  6360. if (hour == 0 && min == 0 && sec > 0) {
  6361. char temp[5];
  6362. sprintf(temp, " %i", sec);
  6363. time_msg.append(temp);
  6364. time_msg.append(" second");
  6365. time_msg.append((sec > 1) ? "s" : "");
  6366. }
  6367. 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());
  6368. }
  6369. }
  6370. else
  6371. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6372. }
  6373. else
  6374. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6375. return 0;
  6376. }
  6377. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6378. if (!lua_interface)
  6379. return 0;
  6380. Spawn* spawn = lua_interface->GetSpawn(state);
  6381. if (!spawn) {
  6382. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6383. return 0;
  6384. }
  6385. if (!spawn->IsPlayer()) {
  6386. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6387. return 0;
  6388. }
  6389. ZoneServer* zone = spawn->GetZone();
  6390. if (!zone) {
  6391. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6392. return 0;
  6393. }
  6394. Instance_Type iType = zone->GetInstanceType();
  6395. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6396. iType == GROUP_LOCKOUT_INSTANCE ||
  6397. iType == RAID_LOCKOUT_INSTANCE ||
  6398. iType == SOLO_PERSIST_INSTANCE ||
  6399. iType == GROUP_PERSIST_INSTANCE ||
  6400. iType == RAID_PERSIST_INSTANCE) {
  6401. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6402. if (data) {
  6403. // Check to see if the timer has already been set, if it has return out.
  6404. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6405. return 0;
  6406. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6407. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6408. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6409. if (client) {
  6410. string time_msg = "";
  6411. int32 time = data->failure_lockout_time;
  6412. int16 hour;
  6413. int8 min;
  6414. int8 sec;
  6415. hour = time / 3600;
  6416. time = time % 3600;
  6417. min = time / 60;
  6418. time = time % 60;
  6419. sec = time;
  6420. if (hour > 0) {
  6421. char temp[10];
  6422. sprintf(temp, " %i", hour);
  6423. time_msg.append(temp);
  6424. time_msg.append(" hour");
  6425. time_msg.append((hour > 1) ? "s" : "");
  6426. }
  6427. if (min > 0) {
  6428. char temp[5];
  6429. sprintf(temp, " %i", min);
  6430. time_msg.append(temp);
  6431. time_msg.append(" minute");
  6432. time_msg.append((min > 1) ? "s" : "");
  6433. }
  6434. // Only add seconds if minutes and hours are 0
  6435. if (hour == 0 && min == 0 && sec > 0) {
  6436. char temp[5];
  6437. sprintf(temp, " %i", sec);
  6438. time_msg.append(temp);
  6439. time_msg.append(" second");
  6440. time_msg.append((sec > 1) ? "s" : "");
  6441. }
  6442. 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());
  6443. }
  6444. }
  6445. else
  6446. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6447. }
  6448. else
  6449. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6450. return 0;
  6451. }
  6452. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6453. if (!lua_interface)
  6454. return 0;
  6455. Spawn* spawn = lua_interface->GetSpawn(state);
  6456. if (!spawn) {
  6457. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6458. return 0;
  6459. }
  6460. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6461. return 1;
  6462. }
  6463. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6464. if (!lua_interface)
  6465. return 0;
  6466. Spawn* player = lua_interface->GetSpawn(state);
  6467. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6468. if (!player) {
  6469. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6470. return 0;
  6471. }
  6472. if (!player->IsPlayer()) {
  6473. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6474. return 0;
  6475. }
  6476. if (!ground) {
  6477. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6478. return 0;
  6479. }
  6480. if (!ground->IsGroundSpawn()) {
  6481. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6482. return 0;
  6483. }
  6484. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6485. if (!groundspawn_entries) {
  6486. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6487. return 0;
  6488. }
  6489. Skill* skill = 0;
  6490. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6491. if (collection_skill == "Collecting")
  6492. skill = ((Player*)player)->GetSkillByName("Gathering");
  6493. else
  6494. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6495. if (!skill) {
  6496. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6497. return 0;
  6498. }
  6499. vector<GroundSpawnEntry*>::iterator itr;
  6500. GroundSpawnEntry* entry = 0;
  6501. bool can_harvest = false;
  6502. sint32 min_skill = -1;
  6503. int16 totalSkill = skill->current_val;
  6504. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  6505. if(skillID != 0xFFFFFFFF)
  6506. {
  6507. ((Entity*)player)->MStats.lock();
  6508. totalSkill += ((Entity*)player)->stats[skillID];
  6509. ((Entity*)player)->MStats.unlock();
  6510. }
  6511. // first, iterate through groundspawn_entries, discard tables player cannot use
  6512. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6513. {
  6514. entry = *itr;
  6515. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6516. min_skill = entry->min_skill_level;
  6517. // if player lacks skill, skip table
  6518. if (entry->min_skill_level > totalSkill)
  6519. continue;
  6520. // if bonus, but player lacks level, skip table
  6521. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6522. continue;
  6523. can_harvest = true;
  6524. break;
  6525. }
  6526. lua_interface->SetBooleanValue(state, can_harvest);
  6527. // If false, send the message to the client
  6528. if (!can_harvest) {
  6529. Client* client = player->GetZone()->GetClientBySpawn(player);
  6530. if (client) {
  6531. string msg = "You do not have enough skill to ";
  6532. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6533. msg.append("gather");
  6534. else if (collection_skill == "Mining")
  6535. msg.append("mine");
  6536. else if (collection_skill == "Trapping")
  6537. msg.append("trap");
  6538. else if (collection_skill == "Foresting")
  6539. msg.append("forest");
  6540. else if (collection_skill == "Fishing")
  6541. msg.append("catch");
  6542. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6543. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  6544. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6545. }
  6546. }
  6547. return 1;
  6548. }
  6549. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6550. if (!lua_interface)
  6551. return 0;
  6552. Spawn* player = lua_interface->GetSpawn(state);
  6553. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6554. if (!player) {
  6555. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6556. return 0;
  6557. }
  6558. if (!player->IsPlayer()) {
  6559. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6560. return 0;
  6561. }
  6562. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6563. lua_interface->SetBooleanValue(state, ret);
  6564. return 1;
  6565. }
  6566. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6567. // Check to see if we have a valid lua_interface
  6568. if (!lua_interface)
  6569. return 0;
  6570. // Get the spawn that is getting the pet
  6571. Spawn* spawn = lua_interface->GetSpawn(state);
  6572. Spawn* target = lua_interface->GetSpawn(state, 2);
  6573. // Get the DB ID of the pet
  6574. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6575. float x = lua_interface->GetFloatValue(state, 4);
  6576. float y = lua_interface->GetFloatValue(state, 5);
  6577. float z = lua_interface->GetFloatValue(state, 6);
  6578. // Get the spell that this command was called from
  6579. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6580. // Check to make sure the spawn pointer is valid
  6581. if (!spawn) {
  6582. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6583. return 0;
  6584. }
  6585. // Check to make sure the spawn is an entity
  6586. if (!spawn->IsEntity()) {
  6587. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6588. return 0;
  6589. }
  6590. if (!target) {
  6591. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6592. return 0;
  6593. }
  6594. if (!target->IsEntity()) {
  6595. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6596. return 0;
  6597. }
  6598. // Check to see if the DB ID for the pet is set
  6599. if (pet_id == 0) {
  6600. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6601. return 0;
  6602. }
  6603. // Check to see if the pointer to the spell is valid
  6604. if (!luaspell) {
  6605. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6606. return 0;
  6607. }
  6608. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6609. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6610. if (!pet) {
  6611. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6612. return 0;
  6613. }
  6614. // Check to make sure the pet is an npc
  6615. if (!pet->IsNPC()) {
  6616. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6617. return 0;
  6618. }
  6619. if (x == 0)
  6620. x = spawn->GetX();
  6621. if (y == 0)
  6622. y = spawn->GetY();
  6623. if (z == 0)
  6624. z = spawn->GetZ();
  6625. // Spawn the pet at the same location as the owner
  6626. pet->SetX(x);
  6627. pet->SetY(y);
  6628. pet->SetZ(z);
  6629. pet->SetLocation(spawn->GetLocation());
  6630. pet->SetHeading(spawn->GetHeading());
  6631. spawn->GetZone()->AddSpawn(pet);
  6632. /*
  6633. const char* spawn_script = world.GetSpawnScript(pet_id);
  6634. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6635. spawn->SetSpawnScript(string(spawn_script));
  6636. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6637. }*/
  6638. // Get a random pet name
  6639. string random_pet_name;
  6640. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6641. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6642. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6643. // Set the pets name
  6644. pet->SetName(random_pet_name.c_str());
  6645. // Set the level of the pet to the owners level
  6646. pet->SetLevel(spawn->GetLevel());
  6647. // Set the faction of the pet to the same faction as the owner
  6648. pet->SetFactionID(spawn->GetFactionID());
  6649. // Set the spawn as a pet
  6650. pet->SetPet(true);
  6651. // Give a pointer of the owner to the pet
  6652. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6653. // Set the pet type
  6654. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6655. // Set the spell id used to create this pet
  6656. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6657. // Set the spell tier used to create this pet
  6658. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6659. // Set the pets spawn type to 6
  6660. pet->SetSpawnType(6);
  6661. // Set the pets brain
  6662. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6663. // Check to see if the pet has a subtitle
  6664. if (strlen(pet->GetSubTitle()) > 0) {
  6665. // Add the players name to the front of the sub title
  6666. string pet_subtitle;
  6667. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6668. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6669. // Set the pets subtitle to the new one
  6670. pet->SetSubTitle(pet_subtitle.c_str());
  6671. }
  6672. // Set the pet as the return value for this function
  6673. lua_interface->SetSpawnValue(state, pet);
  6674. return 1;
  6675. }
  6676. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6677. if (!lua_interface)
  6678. return 0;
  6679. Spawn* spawn = lua_interface->GetSpawn(state);
  6680. Spawn* player = lua_interface->GetSpawn(state, 2);
  6681. float max_distance = lua_interface->GetFloatValue(state, 3);
  6682. string type = lua_interface->GetStringValue(state, 4);
  6683. if (!spawn || (spawn && spawn->IsPlayer())) {
  6684. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6685. return 0;
  6686. }
  6687. if (!player || (player && !player->IsPlayer())) {
  6688. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6689. return 0;
  6690. }
  6691. Client* client = 0;
  6692. if (player->GetZone())
  6693. client = player->GetZone()->GetClientBySpawn(player);
  6694. if (!client) {
  6695. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6696. return 0;
  6697. }
  6698. //Set max_distance to default if not set or not proper value
  6699. if (max_distance <= 0)
  6700. max_distance = 500;
  6701. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6702. if (packet) {
  6703. float unknown2_3 = 0;
  6704. int8 placement_mode = 0;
  6705. if (type == "wall") {
  6706. placement_mode = 2;
  6707. unknown2_3 = 150;
  6708. }
  6709. else if (type == "ceiling")
  6710. placement_mode = 1;
  6711. packet->setDataByName("placement_mode", placement_mode);
  6712. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  6713. packet->setDataByName("model_type", spawn->GetModelType());
  6714. packet->setDataByName("unknown", 1); //size
  6715. packet->setDataByName("unknown2", 1); //size 2
  6716. packet->setDataByName("unknown2", .5, 1); //size 3
  6717. packet->setDataByName("unknown2", 3, 2);
  6718. packet->setDataByName("unknown2", unknown2_3, 3);
  6719. packet->setDataByName("max_distance", max_distance);
  6720. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  6721. client->QueuePacket(packet->serialize());
  6722. safe_delete(packet);
  6723. }
  6724. return 0;
  6725. }
  6726. int EQ2Emu_lua_GetItemType(lua_State* state) {
  6727. if (!lua_interface)
  6728. return 0;
  6729. Item* item = lua_interface->GetItem(state);
  6730. if (!item) {
  6731. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  6732. return 0;
  6733. }
  6734. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  6735. return 1;
  6736. }
  6737. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  6738. if (!lua_interface)
  6739. return 0;
  6740. Spawn* spawn = lua_interface->GetSpawn(state);
  6741. if (!spawn) {
  6742. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6743. return 0;
  6744. }
  6745. if (spawn->GetZone())
  6746. spawn->GetZone()->AddTransportSpawn(spawn);
  6747. return 0;
  6748. }
  6749. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  6750. if (!lua_interface)
  6751. return 0;
  6752. Spawn* spawn = lua_interface->GetSpawn(state);
  6753. if (!spawn) {
  6754. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6755. return 0;
  6756. }
  6757. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  6758. return 1;
  6759. }
  6760. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  6761. if (!lua_interface)
  6762. return 0;
  6763. Skill* skill = lua_interface->GetSkill(state);
  6764. if (!skill) {
  6765. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6766. return 0;
  6767. }
  6768. lua_interface->SetInt32Value(state, skill->current_val);
  6769. return 1;
  6770. }
  6771. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  6772. if (!lua_interface)
  6773. return 0;
  6774. Skill* skill = lua_interface->GetSkill(state);
  6775. if (!skill) {
  6776. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6777. return 0;
  6778. }
  6779. lua_interface->SetInt32Value(state, skill->max_val);
  6780. return 1;
  6781. }
  6782. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  6783. if (!lua_interface)
  6784. return 0;
  6785. Skill* skill = lua_interface->GetSkill(state);
  6786. if (!skill) {
  6787. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  6788. return 0;
  6789. }
  6790. lua_interface->SetStringValue(state, skill->name.data.c_str());
  6791. return 1;
  6792. }
  6793. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  6794. if (!lua_interface)
  6795. return 0;
  6796. Skill* skill = lua_interface->GetSkill(state);
  6797. int16 value = lua_interface->GetInt16Value(state, 2);
  6798. if (!skill) {
  6799. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6800. return 0;
  6801. }
  6802. skill->max_val = value;
  6803. if (skill->max_val < skill->current_val)
  6804. skill->current_val = skill->max_val;
  6805. return 0;
  6806. }
  6807. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  6808. if (!lua_interface)
  6809. return 0;
  6810. Skill* skill = lua_interface->GetSkill(state);
  6811. int16 value = lua_interface->GetInt16Value(state, 2);
  6812. if (!skill) {
  6813. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  6814. return 0;
  6815. }
  6816. if (value > skill->max_val)
  6817. skill->current_val = skill->max_val;
  6818. else
  6819. skill->current_val = value;
  6820. return 0;
  6821. }
  6822. int EQ2Emu_lua_HasSkill(lua_State* state) {
  6823. if (!lua_interface)
  6824. return 0;
  6825. Spawn* player = lua_interface->GetSpawn(state);
  6826. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6827. if (skill_id > 0 && player && player->IsPlayer()) {
  6828. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  6829. return 1;
  6830. }
  6831. return 0;
  6832. }
  6833. int EQ2Emu_lua_AddSkill(lua_State* state) {
  6834. if (!lua_interface)
  6835. return 0;
  6836. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6837. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6838. int16 current_val = lua_interface->GetInt16Value(state, 3);
  6839. int16 max_val = lua_interface->GetInt16Value(state, 4);
  6840. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  6841. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  6842. if (player_spawn && player_spawn->IsPlayer()) {
  6843. Player* player = (Player*)player_spawn;
  6844. bool added = false;
  6845. if (!player->skill_list.HasSkill(skill_id)) {
  6846. player->AddSkill(skill_id, current_val, max_val, true);
  6847. added = true;
  6848. }
  6849. 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
  6850. Client* client = player->GetClient();
  6851. if (client) {
  6852. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6853. if (packet)
  6854. client->QueuePacket(packet);
  6855. }
  6856. }
  6857. if (added) {
  6858. lua_interface->SetBooleanValue(state, true);
  6859. return 1;
  6860. }
  6861. }
  6862. else {
  6863. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6864. }
  6865. }
  6866. else {
  6867. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  6868. }
  6869. lua_interface->SetBooleanValue(state, false);
  6870. return 1;
  6871. }
  6872. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  6873. if (!lua_interface)
  6874. return 0;
  6875. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6876. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  6877. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  6878. if (skill_id > 0) {
  6879. if (player_spawn && player_spawn->IsPlayer()) {
  6880. Player* player = (Player*)player_spawn;
  6881. if (player->skill_list.HasSkill(skill_id)) {
  6882. player->RemovePlayerSkill(skill_id);
  6883. if (!more_to_remove) {
  6884. Client* client = player->GetClient();
  6885. if (client) {
  6886. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6887. if (packet)
  6888. client->QueuePacket(packet);
  6889. }
  6890. }
  6891. }
  6892. }
  6893. else {
  6894. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6895. }
  6896. }
  6897. else {
  6898. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  6899. }
  6900. return 0;
  6901. }
  6902. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  6903. if (!lua_interface)
  6904. return 0;
  6905. Spawn* player_spawn = lua_interface->GetSpawn(state);
  6906. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  6907. int16 amount = lua_interface->GetInt8Value(state, 3);
  6908. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  6909. if (amount > 0 && skill_type < 100) {
  6910. if (player_spawn && player_spawn->IsPlayer()) {
  6911. Player* player = (Player*)player_spawn;
  6912. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  6913. if (!more_to_increase) {
  6914. Client* client = player->GetClient();
  6915. if (client) {
  6916. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  6917. if (packet)
  6918. client->QueuePacket(packet);
  6919. }
  6920. }
  6921. }
  6922. else {
  6923. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  6924. }
  6925. }
  6926. else {
  6927. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  6928. }
  6929. return 0;
  6930. }
  6931. int EQ2Emu_lua_GetSkill(lua_State* state) {
  6932. if (!lua_interface)
  6933. return 0;
  6934. Spawn* spawn = lua_interface->GetSpawn(state);
  6935. string name = lua_interface->GetStringValue(state, 2);
  6936. if (!spawn) {
  6937. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  6938. return 0;
  6939. }
  6940. if (!spawn->IsEntity()) {
  6941. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6942. return 0;
  6943. }
  6944. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  6945. if (skill) {
  6946. lua_interface->SetSkillValue(state, skill);
  6947. return 1;
  6948. }
  6949. return 0;
  6950. }
  6951. int EQ2Emu_lua_AddProc(lua_State* state) {
  6952. if (!lua_interface)
  6953. return 0;
  6954. Spawn* spawn = lua_interface->GetSpawn(state);
  6955. int8 type = lua_interface->GetInt8Value(state, 2);
  6956. float chance = lua_interface->GetFloatValue(state, 3);
  6957. Item* item = lua_interface->GetItem(state, 4);
  6958. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  6959. LuaSpell* spell = 0;
  6960. if (!spawn && (!spell || !use_all_spelltargets)) {
  6961. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6962. return 0;
  6963. }
  6964. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  6965. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  6966. return 0;
  6967. }
  6968. if (!item)
  6969. spell = lua_interface->GetCurrentSpell(state);
  6970. if (!item && !spell) {
  6971. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  6972. return 0;
  6973. }
  6974. if (spell && use_all_spelltargets) {
  6975. Spawn* target;
  6976. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6977. for (int8 i = 0; i < spell->targets.size(); i++) {
  6978. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6979. if (!target || !target->IsEntity())
  6980. continue;
  6981. ((Entity*)target)->AddProc(type, chance, item, spell);
  6982. }
  6983. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6984. }
  6985. else
  6986. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  6987. return 0;
  6988. }
  6989. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  6990. if (!lua_interface)
  6991. return 0;
  6992. Spawn* spawn = lua_interface->GetSpawn(state);
  6993. Item* item = lua_interface->GetItem(state, 2);
  6994. LuaSpell* spell = 0;
  6995. if (!spawn) {
  6996. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  6997. return 0;
  6998. }
  6999. if (!spawn->IsEntity()) {
  7000. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7001. return 0;
  7002. }
  7003. if (!item)
  7004. spell = lua_interface->GetCurrentSpell(state);
  7005. if (!item && !spell) {
  7006. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7007. return 0;
  7008. }
  7009. if (spell) {
  7010. Spawn* target;
  7011. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7012. for (int8 i = 0; i < spell->targets.size(); i++) {
  7013. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7014. if (!target || !target->IsEntity())
  7015. continue;
  7016. ((Entity*)target)->RemoveProc(item, spell);
  7017. }
  7018. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7019. spell->caster->RemoveProc(item, spell);
  7020. }
  7021. else
  7022. ((Entity*)spawn)->RemoveProc(item, spell);
  7023. return 0;
  7024. }
  7025. int EQ2Emu_lua_Knockback(lua_State* state) {
  7026. if (!lua_interface)
  7027. return 0;
  7028. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7029. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7030. int32 duration = lua_interface->GetInt32Value(state, 3);
  7031. float vertical = lua_interface->GetFloatValue(state, 4);
  7032. float horizontal = lua_interface->GetFloatValue(state, 5);
  7033. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7034. if (!target_spawn) {
  7035. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7036. return 0;
  7037. }
  7038. if (!spawn) {
  7039. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7040. return 0;
  7041. }
  7042. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7043. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  7044. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7045. if (packet) {
  7046. packet->setDataByName("target_x", target_spawn->GetX());
  7047. packet->setDataByName("target_y", target_spawn->GetY());
  7048. packet->setDataByName("target_z", target_spawn->GetZ());
  7049. packet->setDataByName("vertical_movement", vertical);
  7050. packet->setDataByName("horizontal_movement", horizontal);
  7051. if (use_heading)
  7052. packet->setDataByName("use_player_heading", 1);
  7053. client->QueuePacket(packet->serialize());
  7054. }
  7055. safe_delete(packet);
  7056. }
  7057. return 0;
  7058. }
  7059. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7060. if (!lua_interface)
  7061. return 0;
  7062. Spawn* spawn = lua_interface->GetSpawn(state);
  7063. if (!spawn) {
  7064. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7065. return 0;
  7066. }
  7067. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7068. return 1;
  7069. }
  7070. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7071. if (!lua_interface)
  7072. return 0;
  7073. Spawn* caster = lua_interface->GetSpawn(state);
  7074. Spawn* target = lua_interface->GetSpawn(state, 2);
  7075. string name = lua_interface->GetStringValue(state, 3);
  7076. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7077. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7078. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7079. string success_msg = lua_interface->GetStringValue(state, 7);
  7080. string effect_msg = lua_interface->GetStringValue(state, 8);
  7081. if (!caster) {
  7082. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7083. return 0;
  7084. }
  7085. if (!caster->IsEntity()) {
  7086. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7087. return 0;
  7088. }
  7089. if (!target) {
  7090. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7091. return 0;
  7092. }
  7093. if (!target->IsEntity()) {
  7094. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7095. return 0;
  7096. }
  7097. if (name.length() == 0) {
  7098. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7099. return 0;
  7100. }
  7101. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7102. return 0;
  7103. }
  7104. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7105. if (!lua_interface)
  7106. return 0;
  7107. string name = lua_interface->GetStringValue(state);
  7108. if (name.length() == 0) {
  7109. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7110. return 0;
  7111. }
  7112. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7113. if (!skill) {
  7114. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7115. return 0;
  7116. }
  7117. lua_interface->SetInt32Value(state, skill->skill_id);
  7118. return 1;
  7119. }
  7120. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7121. if (!lua_interface)
  7122. return 0;
  7123. Spawn* spawn = lua_interface->GetSpawn(state);
  7124. if (!spawn) {
  7125. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7126. return 0;
  7127. }
  7128. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7129. return 1;
  7130. }
  7131. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7132. if (!lua_interface)
  7133. return 0;
  7134. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7135. if (!luaspell) {
  7136. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7137. return 0;
  7138. }
  7139. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7140. return 1;
  7141. }
  7142. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7143. if (!lua_interface)
  7144. return 0;
  7145. Spawn* spawn = lua_interface->GetSpawn(state);
  7146. Spawn* target = lua_interface->GetSpawn(state, 2);
  7147. if (!spawn) {
  7148. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7149. return 0;
  7150. }
  7151. if (!spawn->IsEntity()) {
  7152. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7153. return 0;
  7154. }
  7155. if (!target) {
  7156. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7157. return 0;
  7158. }
  7159. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7160. return 1;
  7161. }
  7162. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7163. if (!lua_interface)
  7164. return 0;
  7165. Spawn* spawn = lua_interface->GetSpawn(state);
  7166. Spawn* target = lua_interface->GetSpawn(state, 2);
  7167. if (!spawn) {
  7168. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7169. return 0;
  7170. }
  7171. if (!spawn->IsEntity()) {
  7172. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7173. return 0;
  7174. }
  7175. if (!target) {
  7176. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7177. return 0;
  7178. }
  7179. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7180. return 1;
  7181. }
  7182. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7183. if (!lua_interface)
  7184. return 0;
  7185. Item* item = lua_interface->GetItem(state);
  7186. if (!item) {
  7187. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7188. return 0;
  7189. }
  7190. lua_interface->SetInt32Value(state, item->details.count);
  7191. return 1;
  7192. }
  7193. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7194. if (!lua_interface)
  7195. return 0;
  7196. Item* item = lua_interface->GetItem(state);
  7197. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7198. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7199. if (!item) {
  7200. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7201. return 0;
  7202. }
  7203. if (!owner) {
  7204. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7205. return 0;
  7206. }
  7207. if (!owner->IsPlayer()) {
  7208. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7209. return 0;
  7210. }
  7211. if (item->stack_count < new_count) {
  7212. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7213. return 0;
  7214. }
  7215. if (new_count > 0) {
  7216. item->details.count = new_count;
  7217. item->save_needed = true;
  7218. }
  7219. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7220. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7221. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7222. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7223. else
  7224. {
  7225. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7226. return 0;
  7227. }
  7228. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  7229. if (!client)
  7230. return 0;
  7231. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7232. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7233. if (app)
  7234. client->QueuePacket(app);
  7235. return 0;
  7236. }
  7237. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7238. if (!lua_interface)
  7239. return 0;
  7240. int32 time = lua_interface->GetInt32Value(state);
  7241. string function = lua_interface->GetStringValue(state, 2);
  7242. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7243. Spawn* target = lua_interface->GetSpawn(state, 4);
  7244. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7245. if (time == 0) {
  7246. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7247. return 0;
  7248. }
  7249. if (function.length() == 0) {
  7250. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7251. return 0;
  7252. }
  7253. if (!spell) {
  7254. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7255. return 0;
  7256. }
  7257. SpellScriptTimer* timer = new SpellScriptTimer;
  7258. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7259. #ifdef WIN32
  7260. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7261. #else
  7262. bzero(timer, sizeof(SpellScriptTimer));
  7263. #endif*/
  7264. timer->caster = 0;
  7265. timer->deleteWhenDone = false;
  7266. timer->target = 0;
  7267. timer->time = Timer::GetCurrentTime2() + time;
  7268. timer->customFunction = function;
  7269. timer->spell = spell;
  7270. if (caster)
  7271. timer->caster = caster->GetID();
  7272. if (target)
  7273. timer->target = target->GetID();
  7274. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7275. return 0;
  7276. }
  7277. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7278. if (!lua_interface)
  7279. return 0;
  7280. float hp_perc = lua_interface->GetFloatValue(state);
  7281. float power_perc = lua_interface->GetFloatValue(state, 2);
  7282. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7283. Spawn* target = lua_interface->GetSpawn(state, 4);
  7284. string heal_name = lua_interface->GetStringValue(state, 5);
  7285. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7286. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7287. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7288. if (!spell) {
  7289. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7290. return 0;
  7291. }
  7292. Entity* caster = spell->caster;
  7293. if (!caster) {
  7294. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7295. return 0;
  7296. }
  7297. Client* client = 0;
  7298. PendingResurrection* rez = 0;
  7299. ZoneServer* zone = spell->caster->GetZone();
  7300. if (!target) {
  7301. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7302. if (spell->targets.size() > 0) {
  7303. vector<int32> spell_targets = spell->targets;
  7304. for (int8 i = 0; i < spell_targets.size(); i++) {
  7305. target = zone->GetSpawnByID(spell_targets.at(i));
  7306. if (!target)
  7307. continue;
  7308. if (!target->IsPlayer())
  7309. continue;
  7310. client = target->GetZone()->GetClientBySpawn(target);
  7311. if (!client)
  7312. continue;
  7313. rez = client->GetCurrentRez();
  7314. if (rez->active)
  7315. continue;
  7316. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7317. rez->active = true;
  7318. rez->caster = caster;
  7319. rez->expire_timer = new Timer;
  7320. int32 duration = spell->spell->GetSpellDuration();
  7321. rez->expire_timer->Start(duration * 100);
  7322. rez->hp_perc = hp_perc;
  7323. rez->mp_perc = power_perc;
  7324. rez->range = spell->spell->GetSpellData()->range;
  7325. rez->spell_name = spell->spell->GetName();
  7326. if (heal_name.length() > 0)
  7327. rez->heal_name = heal_name;
  7328. else
  7329. rez->heal_name = rez->spell_name;
  7330. rez->no_calcs = no_calcs;
  7331. rez->crit_mod = crit_mod;
  7332. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7333. if (send_window)
  7334. client->SendResurrectionWindow();
  7335. else {
  7336. target->GetZone()->ResurrectSpawn(target, client);
  7337. rez->should_delete = true;
  7338. }
  7339. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7340. }
  7341. }
  7342. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7343. }
  7344. else {
  7345. client = target->GetZone()->GetClientBySpawn(target);
  7346. if (!client)
  7347. return 0;
  7348. rez = client->GetCurrentRez();
  7349. if (rez->active)
  7350. return 0;
  7351. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7352. rez->active = true;
  7353. rez->caster = caster;
  7354. rez->expire_timer = new Timer;
  7355. int32 duration = spell->spell->GetSpellDuration();
  7356. rez->expire_timer->Start(duration * 100);
  7357. rez->hp_perc = hp_perc;
  7358. rez->mp_perc = power_perc;
  7359. rez->range = spell->spell->GetSpellData()->range;
  7360. rez->spell_name = spell->spell->GetName();
  7361. if (heal_name.length() > 0)
  7362. rez->heal_name = heal_name;
  7363. else
  7364. rez->heal_name = rez->spell_name;
  7365. rez->no_calcs = no_calcs;
  7366. rez->crit_mod = crit_mod;
  7367. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7368. if (send_window)
  7369. client->SendResurrectionWindow();
  7370. else {
  7371. target->GetZone()->ResurrectSpawn(target, client);
  7372. rez->should_delete = true;
  7373. }
  7374. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7375. }
  7376. return 0;
  7377. }
  7378. int EQ2Emu_lua_SetVision(lua_State* state) {
  7379. if (!lua_interface)
  7380. return 0;
  7381. Spawn* spawn = lua_interface->GetSpawn(state);
  7382. int8 vision = lua_interface->GetInt8Value(state, 2);
  7383. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7384. if (!spawn) {
  7385. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7386. return 0;
  7387. }
  7388. if (!spawn->IsEntity()) {
  7389. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7390. return 0;
  7391. }
  7392. if (spell && spell->targets.size() > 0) {
  7393. ZoneServer* zone = spell->caster->GetZone();
  7394. for (int8 i = 0; i < spell->targets.size(); i++) {
  7395. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7396. if (target && target->IsEntity()) {
  7397. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7398. if (target->IsPlayer())
  7399. ((Player*)target)->SetCharSheetChanged(true);
  7400. }
  7401. }
  7402. }
  7403. else {
  7404. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7405. if (spawn->IsPlayer())
  7406. ((Player*)spawn)->SetCharSheetChanged(true);
  7407. }
  7408. return 0;
  7409. }
  7410. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7411. if (!lua_interface)
  7412. return 0;
  7413. Spawn* spawn = lua_interface->GetSpawn(state);
  7414. float intensity = lua_interface->GetFloatValue(state, 2);
  7415. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7416. if (!spawn) {
  7417. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7418. return 0;
  7419. }
  7420. if (!spawn->IsEntity()) {
  7421. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7422. return 0;
  7423. }
  7424. if (spell && spell->targets.size() > 0) {
  7425. ZoneServer* zone = spell->caster->GetZone();
  7426. for (int8 i = 0; i < spell->targets.size(); i++) {
  7427. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7428. if (target && target->IsEntity()) {
  7429. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7430. if (target->IsPlayer())
  7431. ((Player*)target)->SetCharSheetChanged(true);
  7432. }
  7433. }
  7434. }
  7435. else {
  7436. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7437. if (spawn->IsPlayer())
  7438. ((Player*)spawn)->SetCharSheetChanged(true);
  7439. }
  7440. return 0;
  7441. }
  7442. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7443. if (!lua_interface)
  7444. return 0;
  7445. Spawn* spawn = lua_interface->GetSpawn(state);
  7446. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7447. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7448. if (!spawn) {
  7449. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7450. return 0;
  7451. }
  7452. if (!spawn->IsEntity()) {
  7453. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7454. return 0;
  7455. }
  7456. if (spell && spell->targets.size() > 0) {
  7457. ZoneServer* zone = spell->caster->GetZone();
  7458. for (int8 i = 0; i < spell->targets.size(); i++) {
  7459. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7460. if (target && target->IsEntity()) {
  7461. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7462. if (target->IsPlayer())
  7463. ((Player*)target)->SetCharSheetChanged(true);
  7464. }
  7465. }
  7466. }
  7467. else {
  7468. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7469. if (spawn->IsPlayer())
  7470. ((Player*)spawn)->SetCharSheetChanged(true);
  7471. }
  7472. return 0;
  7473. }
  7474. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7475. if (!lua_interface)
  7476. return 0;
  7477. Item* item = lua_interface->GetItem(state);
  7478. int8 type = lua_interface->GetInt32Value(state, 2);
  7479. if (!item) {
  7480. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7481. return 0;
  7482. }
  7483. if (type == 1)
  7484. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7485. else if (type == 2)
  7486. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7487. return 1;
  7488. }
  7489. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7490. if (!lua_interface)
  7491. return 0;
  7492. Spawn* target = lua_interface->GetSpawn(state);
  7493. float val = lua_interface->GetFloatValue(state, 2);
  7494. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7495. // Added from Gangrenous post
  7496. if (spell && spell->resisted)
  7497. return 0;
  7498. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7499. if (val > 1.0f)
  7500. val = 1.0f - (val / 100.0f);
  7501. if (spell && spell->spell && spell->targets.size() > 0) {
  7502. ZoneServer* zone = spell->caster->GetZone();
  7503. for (int32 i = 0; i != spell->targets.size(); i++) {
  7504. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7505. if (spawn && spawn->IsEntity()) {
  7506. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7507. if (spawn->IsPlayer())
  7508. ((Player*)spawn)->SetCharSheetChanged(true);
  7509. }
  7510. }
  7511. }
  7512. else {
  7513. if (target && target->IsEntity()) {
  7514. ((Entity*)target)->SetSpeedMultiplier(val);
  7515. if (target->IsPlayer())
  7516. ((Player*)target)->SetCharSheetChanged(true);
  7517. }
  7518. }
  7519. return 0;
  7520. }
  7521. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7522. if (!lua_interface)
  7523. return 0;
  7524. Spawn* spawn = lua_interface->GetSpawn(state);
  7525. int16 model = lua_interface->GetInt16Value(state, 2);
  7526. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7527. if (spell && spell->spell && spell->targets.size() > 0) {
  7528. ZoneServer* zone = spell->caster->GetZone();
  7529. for (int32 i = 0; i < spell->targets.size(); i++) {
  7530. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7531. if (target)
  7532. target->SetIllusionModel(model);
  7533. }
  7534. }
  7535. else {
  7536. if (!spawn) {
  7537. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7538. return 0;
  7539. }
  7540. spawn->SetIllusionModel(model);
  7541. }
  7542. return 0;
  7543. }
  7544. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7545. if (!lua_interface)
  7546. return 0;
  7547. Spawn* spawn = lua_interface->GetSpawn(state);
  7548. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7549. if (spell && spell->spell && spell->targets.size() > 0) {
  7550. ZoneServer* zone = spell->caster->GetZone();
  7551. for (int32 i = 0; i < spell->targets.size(); i++) {
  7552. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7553. if (target)
  7554. target->SetIllusionModel(0);
  7555. }
  7556. }
  7557. else {
  7558. if (!spawn) {
  7559. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7560. return 0;
  7561. }
  7562. spawn->SetIllusionModel(0);
  7563. }
  7564. return 0;
  7565. }
  7566. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7567. if (!lua_interface)
  7568. return 0;
  7569. Spawn* caster = lua_interface->GetSpawn(state);
  7570. Spawn* target = lua_interface->GetSpawn(state, 2);
  7571. float chance = lua_interface->GetFloatValue(state, 3);
  7572. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7573. if (!caster) {
  7574. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7575. return 0;
  7576. }
  7577. if (!caster->IsEntity()) {
  7578. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7579. return 0;
  7580. }
  7581. if (!target) {
  7582. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7583. return 0;
  7584. }
  7585. if (!target->IsEntity()) {
  7586. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7587. return 0;
  7588. }
  7589. if (chance <= 0) {
  7590. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7591. return 0;
  7592. }
  7593. if (!spell) {
  7594. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7595. return 0;
  7596. }
  7597. if (((Entity*)caster)->GetThreatTransfer()) {
  7598. return 0;
  7599. }
  7600. ThreatTransfer* transfer = new ThreatTransfer;
  7601. transfer->Target = target->GetID();
  7602. transfer->Amount = chance;
  7603. transfer->Spell = spell;
  7604. ((Entity*)caster)->SetThreatTransfer(transfer);
  7605. return 0;
  7606. }
  7607. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7608. if (!lua_interface)
  7609. return 0;
  7610. Spawn* spawn = lua_interface->GetSpawn(state);
  7611. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7612. if (!spawn) {
  7613. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7614. return 0;
  7615. }
  7616. if (!spell) {
  7617. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7618. return 0;
  7619. }
  7620. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7621. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7622. ((Entity*)spawn)->SetThreatTransfer(0);
  7623. safe_delete(transfer);
  7624. }
  7625. return 0;
  7626. }
  7627. int EQ2Emu_lua_CureByType(lua_State* state) {
  7628. if (!lua_interface)
  7629. return 0;
  7630. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7631. if (!spell) {
  7632. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7633. return 0;
  7634. }
  7635. int8 cure_count = lua_interface->GetInt8Value(state);
  7636. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7637. string cure_name = lua_interface->GetStringValue(state, 3);
  7638. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7639. Spawn* target = lua_interface->GetSpawn(state, 5);
  7640. if (target) {
  7641. if (!target->IsEntity()) {
  7642. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7643. return 0;
  7644. }
  7645. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7646. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7647. }
  7648. else {
  7649. ZoneServer* zone = spell->caster->GetZone();
  7650. vector<int32> targets = spell->targets;
  7651. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7652. for (int8 i = 0; i < targets.size(); i++) {
  7653. target = zone->GetSpawnByID(targets.at(i));
  7654. if (!target || !target->IsEntity())
  7655. continue;
  7656. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7657. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7658. }
  7659. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7660. }
  7661. return 0;
  7662. }
  7663. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7664. if (!lua_interface)
  7665. return 0;
  7666. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7667. if (!spell) {
  7668. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7669. return 0;
  7670. }
  7671. int8 cure_count = lua_interface->GetInt8Value(state);
  7672. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7673. string cure_name = lua_interface->GetStringValue(state, 3);
  7674. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7675. Spawn* target = lua_interface->GetSpawn(state, 5);
  7676. if (target) {
  7677. if (!target->IsEntity()) {
  7678. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7679. return 0;
  7680. }
  7681. if (((Entity*)target)->GetDetCount() > 0)
  7682. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7683. }
  7684. else {
  7685. ZoneServer* zone = spell->caster->GetZone();
  7686. vector<int32> targets = spell->targets;
  7687. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7688. for (int8 i = 0; i < targets.size(); i++) {
  7689. target = zone->GetSpawnByID(targets.at(i));
  7690. if (!target || !target->IsEntity())
  7691. continue;
  7692. if (((Entity*)target)->GetDetCount() > 0)
  7693. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7694. }
  7695. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7696. }
  7697. return 0;
  7698. }
  7699. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  7700. if (!lua_interface)
  7701. return 0;
  7702. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7703. if (!spell) {
  7704. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  7705. return 0;
  7706. }
  7707. if (!spell->caster) {
  7708. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  7709. return 0;
  7710. }
  7711. if (!spell->caster->GetZone()) {
  7712. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  7713. return 0;
  7714. }
  7715. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7716. return 0;
  7717. }
  7718. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  7719. if (!lua_interface)
  7720. return 0;
  7721. Spawn* spawn = lua_interface->GetSpawn(state);
  7722. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7723. if (!spell) {
  7724. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  7725. return 0;
  7726. }
  7727. if (spawn && spawn->IsEntity())
  7728. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7729. else {
  7730. ZoneServer* zone = spell->caster->GetZone();
  7731. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7732. for (int32 i = 0; i < spell->targets.size(); i++) {
  7733. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7734. if (!spawn || !spawn->IsEntity())
  7735. continue;
  7736. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7737. }
  7738. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7739. }
  7740. return 0;
  7741. }
  7742. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  7743. if (!lua_interface)
  7744. return 0;
  7745. Spawn* spawn = lua_interface->GetSpawn(state);
  7746. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7747. if (!spell) {
  7748. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  7749. return 0;
  7750. }
  7751. if (spawn && spawn->IsEntity())
  7752. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7753. else {
  7754. ZoneServer* zone = spell->caster->GetZone();
  7755. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7756. for (int32 i = 0; i < spell->targets.size(); i++) {
  7757. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7758. if (!spawn || !spawn->IsEntity())
  7759. continue;
  7760. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7761. }
  7762. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7763. }
  7764. return 0;
  7765. }
  7766. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  7767. if (!lua_interface)
  7768. return 0;
  7769. Spawn* caster = lua_interface->GetSpawn(state);
  7770. int8 class_id = lua_interface->GetInt8Value(state, 2);
  7771. if (!caster) {
  7772. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  7773. return 0;
  7774. }
  7775. if (!caster->IsPlayer()) {
  7776. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  7777. return 0;
  7778. }
  7779. Spawn* target = caster->GetTarget();
  7780. if (!target) {
  7781. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  7782. return 0;
  7783. }
  7784. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  7785. if (!client) {
  7786. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  7787. return 0;
  7788. }
  7789. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  7790. if (ho) {
  7791. ho->SetTarget(target->GetID());
  7792. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  7793. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  7794. if (((Entity*)caster)->GetGroupMemberInfo()) {
  7795. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7796. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  7797. deque<GroupMemberInfo*>::iterator itr;
  7798. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  7799. if (group)
  7800. {
  7801. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  7802. deque<GroupMemberInfo*>* members = group->GetMembers();
  7803. for (itr = members->begin(); itr != members->end(); itr++) {
  7804. if ((*itr)->client)
  7805. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  7806. }
  7807. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  7808. }
  7809. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  7810. }
  7811. else
  7812. safe_delete(ho);
  7813. }
  7814. else {
  7815. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  7816. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  7817. }
  7818. else
  7819. safe_delete(ho);
  7820. }
  7821. }
  7822. return 0;
  7823. }
  7824. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  7825. if (!lua_interface)
  7826. return 0;
  7827. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7828. if (!spell) {
  7829. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7830. return 0;
  7831. }
  7832. int16 triggerCount = lua_interface->GetInt16Value(state);
  7833. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  7834. if (!triggerCount) {
  7835. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  7836. return 0;
  7837. }
  7838. spell->num_triggers = triggerCount;
  7839. spell->had_triggers = true;
  7840. spell->cancel_after_all_triggers = cancel_after_triggers;
  7841. return 0;
  7842. }
  7843. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  7844. if (!lua_interface)
  7845. return 0;
  7846. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7847. if (!spell) {
  7848. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7849. return 0;
  7850. }
  7851. lua_interface->SetInt32Value(state, spell->num_triggers);
  7852. return 1;
  7853. }
  7854. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  7855. if (!lua_interface)
  7856. return 0;
  7857. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7858. if (!spell) {
  7859. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  7860. return 0;
  7861. }
  7862. int16 remove_count = lua_interface->GetInt16Value(state);
  7863. if (!remove_count)
  7864. remove_count = 1;
  7865. if (remove_count >= spell->num_triggers) {
  7866. spell->num_triggers = 0;
  7867. if (spell->cancel_after_all_triggers)
  7868. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7869. }
  7870. else {
  7871. spell->num_triggers -= remove_count;
  7872. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  7873. }
  7874. return 0;
  7875. }
  7876. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  7877. if (!lua_interface)
  7878. return 0;
  7879. Spawn* spawn = lua_interface->GetSpawn(state);
  7880. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  7881. if (!spawn) {
  7882. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  7883. return 0;
  7884. }
  7885. if (!copy_spawn) {
  7886. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  7887. return 0;
  7888. }
  7889. spawn->CopySpawnAppearance(copy_spawn);
  7890. return 0;
  7891. }
  7892. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  7893. Spawn* spawn = lua_interface->GetSpawn(state);
  7894. int8 type = lua_interface->GetInt8Value(state, 2);
  7895. if (!spawn) {
  7896. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  7897. return 0;
  7898. }
  7899. else if (!spawn->IsEntity()) {
  7900. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  7901. return 0;
  7902. }
  7903. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  7904. return 1;
  7905. }
  7906. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  7907. if (!lua_interface)
  7908. return 0;
  7909. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7910. int8 type = lua_interface->GetInt8Value(state);
  7911. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7912. if (!spell) {
  7913. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7914. return 0;
  7915. }
  7916. if (spawn) {
  7917. if (!spawn->IsEntity()) {
  7918. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7919. return 0;
  7920. }
  7921. Entity* entity = ((Entity*)spawn);
  7922. entity->AddImmunity(spell, type);
  7923. }
  7924. else {
  7925. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7926. for (int8 i = 0; i < spell->targets.size(); i++) {
  7927. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7928. if (!spawn || !spawn->IsEntity())
  7929. continue;
  7930. Entity* entity = ((Entity*)spawn);
  7931. entity->AddImmunity(spell, type);
  7932. }
  7933. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7934. }
  7935. return 0;
  7936. }
  7937. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  7938. if (!lua_interface)
  7939. return 0;
  7940. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7941. int8 type = lua_interface->GetInt8Value(state);
  7942. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7943. if (!spell) {
  7944. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  7945. return 0;
  7946. }
  7947. if (spawn) {
  7948. if (!spawn->IsEntity()) {
  7949. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7950. return 0;
  7951. }
  7952. Entity* entity = ((Entity*)spawn);
  7953. entity->RemoveImmunity(spell, type);
  7954. }
  7955. else {
  7956. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7957. for (int8 i = 0; i < spell->targets.size(); i++) {
  7958. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7959. if (!spawn || !spawn->IsEntity())
  7960. continue;
  7961. Entity* entity = ((Entity*)spawn);
  7962. entity->RemoveImmunity(spell, type);
  7963. }
  7964. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7965. }
  7966. return 0;
  7967. }
  7968. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  7969. if (!lua_interface)
  7970. return 0;
  7971. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7972. if (!spell) {
  7973. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  7974. return 0;
  7975. }
  7976. float snare = lua_interface->GetFloatValue(state);
  7977. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7978. // convert the val to the speed multipler value (100 - val)
  7979. float val = 100.0 - snare;
  7980. val /= 100.0;
  7981. if (spawn) {
  7982. if (!spawn->IsEntity()) {
  7983. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  7984. return 0;
  7985. }
  7986. ((Entity*)spawn)->SetSnareValue(spell, val);
  7987. }
  7988. else {
  7989. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7990. for (int8 i = 0; i < spell->targets.size(); i++) {
  7991. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7992. if (!spawn || !spawn->IsEntity())
  7993. continue;
  7994. ((Entity*)spawn)->SetSnareValue(spell, val);
  7995. }
  7996. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7997. }
  7998. return 0;
  7999. }
  8000. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8001. if (!lua_interface)
  8002. return 0;
  8003. Spawn* spawn = lua_interface->GetSpawn(state);
  8004. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8005. if (!spawn) {
  8006. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8007. return 0;
  8008. }
  8009. if (race_id == 0) {
  8010. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8011. return 0;
  8012. }
  8013. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8014. return 1;
  8015. }
  8016. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8017. if (!lua_interface)
  8018. return 0;
  8019. Spawn* spawn = lua_interface->GetSpawn(state);
  8020. if (!spawn) {
  8021. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8022. return 0;
  8023. }
  8024. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8025. return 1;
  8026. }
  8027. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8028. if (!lua_interface)
  8029. return 0;
  8030. Spawn* spawn = lua_interface->GetSpawn(state);
  8031. if (!spawn) {
  8032. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8033. return 0;
  8034. }
  8035. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8036. return 1;
  8037. }
  8038. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8039. if (!lua_interface)
  8040. return 0;
  8041. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8042. if (!spell) {
  8043. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8044. return 0;
  8045. }
  8046. lua_interface->SetStringValue(state, spell->spell->GetName());
  8047. return 1;
  8048. }
  8049. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8050. if (!lua_interface)
  8051. return 0;
  8052. Quest* quest = lua_interface->GetQuest(state);
  8053. if (!quest) {
  8054. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8055. return 0;
  8056. }
  8057. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8058. return 1;
  8059. }
  8060. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8061. if (!lua_interface)
  8062. return 0;
  8063. Quest* quest = lua_interface->GetQuest(state);
  8064. int32 flags = lua_interface->GetInt32Value(state, 2);
  8065. if (!quest) {
  8066. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8067. return 0;
  8068. }
  8069. quest->SetQuestFlags(flags);
  8070. return 0;
  8071. }
  8072. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8073. if (!lua_interface)
  8074. return 0;
  8075. Quest* quest = lua_interface->GetQuest(state);
  8076. Spawn* player = lua_interface->GetSpawn(state, 2);
  8077. int32 step = lua_interface->GetInt32Value(state, 3);
  8078. int32 duration = lua_interface->GetInt32Value(state, 4);
  8079. string action = lua_interface->GetStringValue(state, 5);
  8080. if (!quest) {
  8081. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8082. return 0;
  8083. }
  8084. if (!player) {
  8085. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8086. return 0;
  8087. }
  8088. if (!player->IsPlayer()) {
  8089. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8090. return 0;
  8091. }
  8092. if (step == 0) {
  8093. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8094. return 0;
  8095. }
  8096. if (duration == 0) {
  8097. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8098. return 0;
  8099. }
  8100. if (action.length() == 0) {
  8101. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8102. return 0;
  8103. }
  8104. Client* client = player->GetZone()->GetClientBySpawn(player);
  8105. if (!client) {
  8106. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8107. return 0;
  8108. }
  8109. quest->SetTimerStep(step);
  8110. quest->AddFailedAction(step, action);
  8111. quest->SetStepTimer(duration);
  8112. client->AddQuestTimer(quest->GetQuestID());
  8113. return 0;
  8114. }
  8115. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8116. if (!lua_interface)
  8117. return 0;
  8118. Quest* quest = lua_interface->GetQuest(state);
  8119. Spawn* player = lua_interface->GetSpawn(state, 2);
  8120. if (!quest) {
  8121. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8122. return 0;
  8123. }
  8124. if (!player) {
  8125. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8126. return 0;
  8127. }
  8128. if (!player->IsPlayer()) {
  8129. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8130. return 0;
  8131. }
  8132. Client* client = player->GetZone()->GetClientBySpawn(player);
  8133. if (!client) {
  8134. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8135. return 0;
  8136. }
  8137. quest->SetTimerStep(0);
  8138. quest->SetStepTimer(0);
  8139. client->RemoveQuestTimer(quest->GetQuestID());
  8140. return 0;
  8141. }
  8142. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8143. if (!lua_interface)
  8144. return 0;
  8145. Spawn* player = lua_interface->GetSpawn(state);
  8146. Quest* quest = lua_interface->GetQuest(state, 2);
  8147. int32 step = lua_interface->GetInt32Value(state, 3);
  8148. if (!player) {
  8149. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8150. return 0;
  8151. }
  8152. if (!player->IsPlayer()) {
  8153. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8154. return 0;
  8155. }
  8156. if (!quest) {
  8157. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8158. return 0;
  8159. }
  8160. if (step == 0) {
  8161. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8162. return 0;
  8163. }
  8164. Client* client = player->GetZone()->GetClientBySpawn(player);
  8165. if (!client) {
  8166. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8167. return 0;
  8168. }
  8169. if (quest->RemoveQuestStep(step, client)) {
  8170. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8171. client->GetCurrentZone()->SendQuestUpdates(client);
  8172. }
  8173. else
  8174. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8175. return 0;
  8176. }
  8177. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8178. if (!lua_interface)
  8179. return 0;
  8180. Quest* quest = lua_interface->GetQuest(state, 1);
  8181. int32 step = lua_interface->GetInt32Value(state, 2);
  8182. string desc = lua_interface->GetStringValue(state, 3);
  8183. string task_group = lua_interface->GetStringValue(state, 4);
  8184. if (!quest) {
  8185. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8186. return 0;
  8187. }
  8188. if (step == 0) {
  8189. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8190. return 0;
  8191. }
  8192. QuestStep* quest_step = quest->GetQuestStep(step);
  8193. if (!quest_step) {
  8194. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8195. return 0;
  8196. }
  8197. quest_step->SetStepProgress(0);
  8198. quest_step->SetTaskGroup(task_group);
  8199. quest_step->SetDescription(desc);
  8200. return 0;
  8201. }
  8202. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8203. if (!lua_interface)
  8204. return 0;
  8205. Quest* quest = lua_interface->GetQuest(state);
  8206. int32 step = lua_interface->GetInt32Value(state, 2);
  8207. string action = lua_interface->GetStringValue(state, 3);
  8208. if (!quest) {
  8209. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8210. return 0;
  8211. }
  8212. if (step == 0) {
  8213. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8214. return 0;
  8215. }
  8216. if (action.length() == 0) {
  8217. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8218. return 0;
  8219. }
  8220. quest->AddFailedAction(step, action);
  8221. return 0;
  8222. }
  8223. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8224. if (!lua_interface)
  8225. return 0;
  8226. Spawn* player = lua_interface->GetSpawn(state);
  8227. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8228. int32 step = lua_interface->GetInt32Value(state, 3);
  8229. if (!player) {
  8230. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8231. return 0;
  8232. }
  8233. if (!player->IsPlayer()) {
  8234. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8235. return 0;
  8236. }
  8237. if (quest_id == 0) {
  8238. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8239. return 0;
  8240. }
  8241. if (step == 0) {
  8242. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8243. return 0;
  8244. }
  8245. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8246. if (!quest) {
  8247. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8248. return 0;
  8249. }
  8250. quest->StepFailed(step);
  8251. return 0;
  8252. }
  8253. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8254. if (!lua_interface)
  8255. return 0;
  8256. Spawn* player = lua_interface->GetSpawn(state);
  8257. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8258. if (!player) {
  8259. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8260. return 0;
  8261. }
  8262. if (!player->IsPlayer()) {
  8263. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8264. return 0;
  8265. }
  8266. if (quest_id == 0) {
  8267. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8268. return 0;
  8269. }
  8270. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8271. if (!quest) {
  8272. lua_interface->SetInt32Value(state, 0);
  8273. return 1;
  8274. }
  8275. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8276. return 1;
  8277. }
  8278. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8279. if (!lua_interface)
  8280. return 0;
  8281. string name = lua_interface->GetStringValue(state);
  8282. string value = lua_interface->GetStringValue(state, 2);
  8283. string comment = lua_interface->GetStringValue(state, 3);
  8284. if (name.length() == 0) {
  8285. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8286. return 0;
  8287. }
  8288. if (value.length() == 0) {
  8289. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8290. return 0;
  8291. }
  8292. string varname = string("lua_").append(name);
  8293. Variable* var = variables.FindVariable(varname);
  8294. if (var)
  8295. var->SetValue(value.c_str());
  8296. else {
  8297. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8298. variables.AddVariable(var);
  8299. }
  8300. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8301. return 0;
  8302. }
  8303. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8304. if (!lua_interface)
  8305. return 0;
  8306. string name = lua_interface->GetStringValue(state);
  8307. if (name.length() == 0) {
  8308. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8309. return 0;
  8310. }
  8311. string varname = string("lua_").append(name);
  8312. Variable* var = variables.FindVariable(varname);
  8313. if (var)
  8314. lua_interface->SetStringValue(state, var->GetValue());
  8315. else
  8316. lua_interface->SetStringValue(state, "NULL");
  8317. return 1;
  8318. }
  8319. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8320. if (!lua_interface)
  8321. return 0;
  8322. Spawn* player = lua_interface->GetSpawn(state);
  8323. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8324. if (!player) {
  8325. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8326. return 0;
  8327. }
  8328. if (!player->IsPlayer()) {
  8329. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8330. return 0;
  8331. }
  8332. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8333. return 1;
  8334. }
  8335. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8336. if (!lua_interface)
  8337. return 0;
  8338. Spawn* player = lua_interface->GetSpawn(state);
  8339. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8340. if (!player) {
  8341. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8342. return 0;
  8343. }
  8344. if (!player->IsPlayer()) {
  8345. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8346. return 0;
  8347. }
  8348. Language* language = master_languages_list.GetLanguage(language_id);
  8349. if (language)
  8350. {
  8351. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8352. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID());
  8353. }
  8354. return 0;
  8355. }
  8356. int EQ2Emu_lua_IsNight(lua_State* state) {
  8357. if (!lua_interface)
  8358. return 0;
  8359. ZoneServer* zone = lua_interface->GetZone(state);
  8360. if (!zone) {
  8361. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8362. return 0;
  8363. }
  8364. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8365. return 1;
  8366. }
  8367. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8368. if (!lua_interface)
  8369. return 0;
  8370. Spawn* spawn = lua_interface->GetSpawn(state);
  8371. if (!spawn) {
  8372. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8373. return 0;
  8374. }
  8375. if (!spawn->IsWidget()) {
  8376. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8377. return 0;
  8378. }
  8379. ((Widget*)spawn)->SetMultiFloorLift(true);
  8380. if (spawn->GetZone())
  8381. spawn->GetZone()->AddTransportSpawn(spawn);
  8382. return 0;
  8383. }
  8384. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8385. if (!lua_interface)
  8386. return 0;
  8387. Spawn* player = lua_interface->GetSpawn(state);
  8388. int32 path = lua_interface->GetInt32Value(state, 2);
  8389. if (!player) {
  8390. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8391. return 0;
  8392. }
  8393. if (!player->IsPlayer()) {
  8394. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8395. return 0;
  8396. }
  8397. if (path == 0) {
  8398. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8399. return 0;
  8400. }
  8401. Client* client = player->GetZone()->GetClientBySpawn(player);
  8402. if (!client) {
  8403. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8404. return 0;
  8405. }
  8406. client->SendFlightAutoMount(path);
  8407. return 0;
  8408. }
  8409. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8410. if (!lua_interface)
  8411. return 0;
  8412. Spawn* player = lua_interface->GetSpawn(state);
  8413. if (!player) {
  8414. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8415. return 0;
  8416. }
  8417. if (!player->IsPlayer()) {
  8418. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8419. return 0;
  8420. }
  8421. Client* client = player->GetZone()->GetClientBySpawn(player);
  8422. if (!client) {
  8423. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8424. return 0;
  8425. }
  8426. client->EndAutoMount();
  8427. return 0;
  8428. }
  8429. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8430. if (!lua_interface)
  8431. return 0;
  8432. Spawn* player = lua_interface->GetSpawn(state);
  8433. if (!player) {
  8434. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8435. return 0;
  8436. }
  8437. if (!player->IsPlayer()) {
  8438. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8439. return 0;
  8440. }
  8441. Client* client = player->GetZone()->GetClientBySpawn(player);
  8442. if (!client) {
  8443. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8444. return 0;
  8445. }
  8446. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8447. return 1;
  8448. }
  8449. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8450. if (!lua_interface)
  8451. return 0;
  8452. Spawn* player = lua_interface->GetSpawn(state);
  8453. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8454. int32 value = lua_interface->GetInt32Value(state, 3);
  8455. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8456. if (!player) {
  8457. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8458. return 0;
  8459. }
  8460. if (!player->IsPlayer()) {
  8461. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8462. return 0;
  8463. }
  8464. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8465. return 0;
  8466. }
  8467. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8468. if (!lua_interface)
  8469. return 0;
  8470. Spawn* player = lua_interface->GetSpawn(state);
  8471. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8472. if (!player) {
  8473. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8474. return 0;
  8475. }
  8476. if (!player->IsPlayer()) {
  8477. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8478. return 0;
  8479. }
  8480. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8481. if (!hd)
  8482. return 0;
  8483. lua_interface->SetInt32Value(state, hd->Value);
  8484. lua_interface->SetInt32Value(state, hd->Value2);
  8485. return 2;
  8486. }
  8487. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8488. if (!lua_interface)
  8489. return 0;
  8490. Spawn* spawn = lua_interface->GetSpawn(state);
  8491. int32 grid = lua_interface->GetInt32Value(state, 2);
  8492. if (!spawn) {
  8493. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8494. return 0;
  8495. }
  8496. if (grid == 0) {
  8497. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8498. return 0;
  8499. }
  8500. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8501. return 0;
  8502. }
  8503. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8504. if (!lua_interface)
  8505. return 0;
  8506. Spawn* spawn = lua_interface->GetSpawn(state);
  8507. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8508. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8509. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8510. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8511. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8512. if (!spawn) {
  8513. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8514. return 0;
  8515. }
  8516. //Add this quest to the list of required quests for this spawn
  8517. spawn->SetRequiredHistory(event_id, value1, value2);
  8518. //If private spawn value set
  8519. if (private_spawn) {
  8520. //Set the spawn to be private when not granted access via history
  8521. spawn->AddAllowAccessSpawn(spawn);
  8522. spawn->SetPrivateQuestSpawn(true);
  8523. }
  8524. //This value will override vis_flags in the vis packet
  8525. if (flag_override > 0)
  8526. spawn->SetQuestsRequiredOverride(flag_override);
  8527. return 0;
  8528. }
  8529. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8530. if (!lua_interface)
  8531. return 0;
  8532. Spawn* player = lua_interface->GetSpawn(state);
  8533. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8534. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8535. if (!player) {
  8536. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8537. return 0;
  8538. }
  8539. if (!player->IsPlayer()) {
  8540. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8541. return 0;
  8542. }
  8543. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8544. return 1;
  8545. }
  8546. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8547. if (!lua_interface)
  8548. return 0;
  8549. Spawn* player = lua_interface->GetSpawn(state);
  8550. int8 level = lua_interface->GetInt8Value(state, 2);
  8551. if (!player) {
  8552. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8553. return 0;
  8554. }
  8555. if (!player->IsPlayer()) {
  8556. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8557. return 0;
  8558. }
  8559. if (level == 0) {
  8560. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8561. return 0;
  8562. }
  8563. Client* client = player->GetZone()->GetClientBySpawn(player);
  8564. if (!client) {
  8565. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8566. return 0;
  8567. }
  8568. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8569. return 0;
  8570. }
  8571. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8572. if (!lua_interface)
  8573. return 0;
  8574. Spawn* player = lua_interface->GetSpawn(state);
  8575. int32 amount = lua_interface->GetInt32Value(state, 2);
  8576. if (!player) {
  8577. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8578. return 0;
  8579. }
  8580. if (!player->IsPlayer()) {
  8581. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8582. return 0;
  8583. }
  8584. if (amount == 0) {
  8585. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8586. return 0;
  8587. }
  8588. ((Player*)player)->AddCoins(amount);
  8589. return 0;
  8590. }
  8591. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8592. if (!lua_interface)
  8593. return 0;
  8594. Spawn* player = lua_interface->GetSpawn(state);
  8595. int32 amount = lua_interface->GetInt32Value(state, 2);
  8596. if (!player) {
  8597. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8598. return 0;
  8599. }
  8600. if (!player->IsPlayer()) {
  8601. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8602. return 0;
  8603. }
  8604. if (amount == 0) {
  8605. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8606. return 0;
  8607. }
  8608. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8609. return 1;
  8610. }
  8611. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8612. if (!lua_interface)
  8613. return 0;
  8614. ZoneServer* zone = lua_interface->GetZone(state);
  8615. if (!zone) {
  8616. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8617. return 0;
  8618. }
  8619. vector<Entity*> players = zone->GetPlayers();
  8620. if (players.size() == 0)
  8621. return 0;
  8622. lua_createtable(state, players.size(), 0);
  8623. int newTable = lua_gettop(state);
  8624. for (int32 i = 0; i < players.size(); i++) {
  8625. lua_interface->SetSpawnValue(state, players.at(i));
  8626. lua_rawseti(state, newTable, i + 1);
  8627. }
  8628. return 1;
  8629. }
  8630. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8631. if (!lua_interface)
  8632. return 0;
  8633. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8634. if (!zone) {
  8635. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8636. return 0;
  8637. }
  8638. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8639. //Map of <placement_id, location_id>
  8640. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8641. map<int32, int32>::iterator itr;
  8642. vector<Spawn*> group;
  8643. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8644. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8645. if (!location) {
  8646. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8647. return 0;
  8648. }
  8649. Spawn* spawn = 0;
  8650. if (location->entities[0]) {
  8651. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8652. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8653. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8654. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8655. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8656. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8657. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8658. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8659. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8660. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8661. if (spawn) {
  8662. const char* script = 0;
  8663. for (int x = 0; x < 3; x++) {
  8664. switch (x) {
  8665. case 0:
  8666. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8667. break;
  8668. case 1:
  8669. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  8670. break;
  8671. case 2:
  8672. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  8673. break;
  8674. }
  8675. if (script && lua_interface->GetSpawnScript(script) != 0) {
  8676. spawn->SetSpawnScript(string(script));
  8677. break;
  8678. }
  8679. }
  8680. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  8681. lua_interface->SetSpawnValue(state, spawn);
  8682. group.push_back(spawn);
  8683. }
  8684. else {
  8685. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  8686. safe_delete(spawn);
  8687. }
  8688. }
  8689. }
  8690. if (!group.empty()) {
  8691. lua_createtable(state, group.size(), 0);
  8692. int newTable = lua_gettop(state);
  8693. for (int32 i = 0; i < group.size(); i++) {
  8694. lua_interface->SetSpawnValue(state, group[i]);
  8695. lua_rawseti(state, newTable, i + 1);
  8696. }
  8697. }
  8698. else
  8699. lua_pushnil(state);
  8700. return 1;
  8701. }
  8702. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  8703. if (!lua_interface)
  8704. return 0;
  8705. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8706. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  8707. int16 leeway = lua_interface->GetInt16Value(state, 3);
  8708. if (!spawn) {
  8709. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  8710. return 0;
  8711. }
  8712. if (anim_id == 0) {
  8713. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  8714. return 0;
  8715. }
  8716. if (leeway == 0)
  8717. leeway = 5000;
  8718. spawn->SetSpawnAnim(anim_id);
  8719. spawn->SetSpawnAnimLeeway(leeway);
  8720. return 0;
  8721. }
  8722. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  8723. if (!lua_interface)
  8724. return 0;
  8725. Spawn* player = lua_interface->GetSpawn(state);
  8726. if (!player) {
  8727. return 0;
  8728. }
  8729. Client* client = player->GetZone()->GetClientBySpawn(player);
  8730. if (!client) {
  8731. return 0;
  8732. }
  8733. lua_interface->SetInt32Value(state, client->GetVersion());
  8734. return 1;
  8735. }
  8736. int EQ2Emu_lua_GetItemID(lua_State* state) {
  8737. if (!lua_interface)
  8738. return 0;
  8739. Item* item = lua_interface->GetItem(state);
  8740. if (!item) {
  8741. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  8742. return 0;
  8743. }
  8744. lua_interface->SetInt32Value(state, item->details.item_id);
  8745. return 1;
  8746. }
  8747. int EQ2Emu_lua_IsEntity(lua_State* state) {
  8748. if (!lua_interface)
  8749. return 0;
  8750. Spawn* spawn = lua_interface->GetSpawn(state);
  8751. if (!spawn) {
  8752. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  8753. return 0;
  8754. }
  8755. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  8756. return 1;
  8757. }
  8758. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  8759. if (!lua_interface)
  8760. return 0;
  8761. Spawn* spawn = lua_interface->GetSpawn(state);
  8762. if (!spawn) {
  8763. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  8764. return 0;
  8765. }
  8766. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  8767. return 1;
  8768. }
  8769. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  8770. if (!lua_interface)
  8771. return 0;
  8772. Spawn* spawn = lua_interface->GetSpawn(state);
  8773. if (!spawn) {
  8774. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  8775. return 0;
  8776. }
  8777. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  8778. return 1;
  8779. }
  8780. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  8781. if (!lua_interface)
  8782. return 0;
  8783. Spawn* spawn = lua_interface->GetSpawn(state);
  8784. if (!spawn) {
  8785. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  8786. return 0;
  8787. }
  8788. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  8789. return 1;
  8790. }
  8791. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  8792. if (!lua_interface)
  8793. return 0;
  8794. Spawn* spawn = lua_interface->GetSpawn(state);
  8795. float pct = lua_interface->GetFloatValue(state, 2);
  8796. if (!spawn) {
  8797. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  8798. return 0;
  8799. }
  8800. if (pct == 0) {
  8801. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  8802. return 0;
  8803. }
  8804. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  8805. lua_interface->SetInt32Value(state, amount);
  8806. return 1;
  8807. }
  8808. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  8809. if (!lua_interface)
  8810. return 0;
  8811. Spawn* spawn = lua_interface->GetSpawn(state);
  8812. float pct = lua_interface->GetFloatValue(state, 2);
  8813. if (!spawn) {
  8814. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  8815. return 0;
  8816. }
  8817. if (pct == 0) {
  8818. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  8819. return 0;
  8820. }
  8821. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  8822. lua_interface->SetInt32Value(state, amount);
  8823. return 1;
  8824. }
  8825. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  8826. if (!lua_interface)
  8827. return 0;
  8828. Spawn* spawn = lua_interface->GetSpawn(state);
  8829. if (!spawn) {
  8830. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8831. return 0;
  8832. }
  8833. if (!spawn->IsPlayer()) {
  8834. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  8835. return 0;
  8836. }
  8837. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  8838. return 1;
  8839. }
  8840. int EQ2Emu_lua_Evac(lua_State* state) {
  8841. if (!lua_interface)
  8842. return 0;
  8843. Spawn* target = lua_interface->GetSpawn(state);
  8844. if (target) {
  8845. float x = target->GetZone()->GetSafeX();
  8846. float y = target->GetZone()->GetSafeY();
  8847. float z = target->GetZone()->GetSafeZ();
  8848. float h = target->GetZone()->GetSafeHeading();
  8849. target->SetX(x);
  8850. target->SetY(y);
  8851. target->SetZ(z);
  8852. target->SetHeading(h);
  8853. target->SetSpawnOrigX(target->GetX());
  8854. target->SetSpawnOrigY(target->GetY());
  8855. target->SetSpawnOrigZ(target->GetZ());
  8856. target->SetSpawnOrigHeading(target->GetHeading());
  8857. if (target->IsPlayer()) {
  8858. Client* client = target->GetZone()->GetClientBySpawn(target);
  8859. if (client) {
  8860. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8861. if (packet)
  8862. {
  8863. packet->setDataByName("x", x);
  8864. packet->setDataByName("y", y);
  8865. packet->setDataByName("z", z);
  8866. client->QueuePacket(packet->serialize());
  8867. safe_delete(packet);
  8868. }
  8869. }
  8870. }
  8871. }
  8872. else {
  8873. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8874. ZoneServer* zone = spell->caster->GetZone();
  8875. float x = spell->caster->GetZone()->GetSafeX();
  8876. float y = spell->caster->GetZone()->GetSafeY();
  8877. float z = spell->caster->GetZone()->GetSafeZ();
  8878. float h = spell->caster->GetZone()->GetSafeHeading();
  8879. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8880. for (int32 i = 0; i < spell->targets.size(); i++) {
  8881. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  8882. if (!target2)
  8883. continue;
  8884. target2->SetX(x);
  8885. target2->SetY(y);
  8886. target2->SetZ(z);
  8887. target2->SetHeading(h);
  8888. target2->SetSpawnOrigX(target2->GetX());
  8889. target2->SetSpawnOrigY(target2->GetY());
  8890. target2->SetSpawnOrigZ(target2->GetZ());
  8891. target2->SetSpawnOrigHeading(target2->GetHeading());
  8892. if (target2->IsPlayer()) {
  8893. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  8894. if (client) {
  8895. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8896. if (packet)
  8897. {
  8898. client->SetReloadingZone(true);
  8899. packet->setDataByName("x", x);
  8900. packet->setDataByName("y", y);
  8901. packet->setDataByName("z", z);
  8902. client->QueuePacket(packet->serialize());
  8903. safe_delete(packet);
  8904. }
  8905. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  8906. client->GetCurrentZone()->RemoveSpawn(client->GetPlayer(), false, false, false, false);
  8907. }
  8908. }
  8909. }
  8910. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8911. }
  8912. return 0;
  8913. }
  8914. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  8915. if (!lua_interface)
  8916. return 0;
  8917. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8918. if (!luaspell) {
  8919. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8920. return 0;
  8921. }
  8922. int8 tier = luaspell->spell->GetSpellTier();
  8923. lua_interface->SetInt32Value(state, tier);
  8924. return 1;
  8925. }
  8926. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  8927. if (!lua_interface)
  8928. return 0;
  8929. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8930. if (!luaspell) {
  8931. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8932. return 0;
  8933. }
  8934. int32 spell_id = luaspell->spell->GetSpellID();
  8935. lua_interface->SetInt32Value(state, spell_id);
  8936. return 1;
  8937. }
  8938. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  8939. if (!lua_interface)
  8940. return 0;
  8941. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8942. if (!spawn) {
  8943. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8944. return 0;
  8945. }
  8946. if (!spawn->IsPlayer()) {
  8947. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8948. return 0;
  8949. }
  8950. ZoneServer* zone = spawn->GetZone();
  8951. if (!zone) {
  8952. return 0;
  8953. }
  8954. Client* client = zone->GetClientBySpawn(spawn);
  8955. if (!client) {
  8956. return 0;
  8957. }
  8958. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  8959. return 0;
  8960. }
  8961. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  8962. if (!lua_interface)
  8963. return 0;
  8964. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8965. if (!spawn) {
  8966. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8967. return 0;
  8968. }
  8969. if (!spawn->IsPlayer()) {
  8970. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8971. return 0;
  8972. }
  8973. ZoneServer* zone = spawn->GetZone();
  8974. if (!zone) {
  8975. return 0;
  8976. }
  8977. Client* client = zone->GetClientBySpawn(spawn);
  8978. if (!client) {
  8979. return 0;
  8980. }
  8981. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  8982. return 0;
  8983. }
  8984. int EQ2Emu_lua_ProcHate(lua_State* state) {
  8985. if (!lua_interface)
  8986. return 0;
  8987. Spawn* caster = lua_interface->GetSpawn(state);
  8988. Spawn* target = lua_interface->GetSpawn(state, 2);
  8989. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  8990. string spell_name = lua_interface->GetStringValue(state, 4);
  8991. if (!caster) {
  8992. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8993. return 0;
  8994. }
  8995. if (!caster->IsEntity()) {
  8996. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  8997. return 0;
  8998. }
  8999. if (!target) {
  9000. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9001. return 0;
  9002. }
  9003. if (!target->IsEntity()) {
  9004. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9005. return 0;
  9006. }
  9007. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9008. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9009. return 0;
  9010. }
  9011. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9012. if (!lua_interface)
  9013. return 0;
  9014. Spawn* player = lua_interface->GetSpawn(state);
  9015. int32 amount = lua_interface->GetInt32Value(state, 2);
  9016. if (player && player->IsPlayer() && amount > 0) {
  9017. ((Player*)player)->AddXP(amount);
  9018. ((Player*)player)->SetCharSheetChanged(true);
  9019. Client* client = player->GetZone()->GetClientBySpawn(player);
  9020. if (client) {
  9021. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  9022. }
  9023. }
  9024. return 0;
  9025. }
  9026. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9027. if (!lua_interface)
  9028. return 0;
  9029. Spawn* player = lua_interface->GetSpawn(state);
  9030. int8 type = lua_interface->GetInt8Value(state, 2);
  9031. string text = lua_interface->GetStringValue(state, 3);
  9032. Client* client = 0;
  9033. if (player && player->IsPlayer())
  9034. client = player->GetZone()->GetClientBySpawn(player);
  9035. if (!client || text.length() == 0) {
  9036. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9037. return 0;
  9038. }
  9039. client->SimpleMessage(type, text.c_str());
  9040. return 0;
  9041. }
  9042. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9043. if (!lua_interface)
  9044. return 0;
  9045. Spawn* player = lua_interface->GetSpawn(state);
  9046. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9047. Client* client = 0;
  9048. if (player && player->IsPlayer())
  9049. client = player->GetZone()->GetClientBySpawn(player);
  9050. if (!client || !spawn) {
  9051. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9052. return 0;
  9053. }
  9054. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9055. if (!items) {
  9056. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9057. return 0;
  9058. }
  9059. client->Loot(spawn->GetLootCoins(), items, spawn);
  9060. return 0;
  9061. }
  9062. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9063. if (!lua_interface)
  9064. return 0;
  9065. Spawn* spawnref = lua_interface->GetSpawn(state);
  9066. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9067. if (spawn_id > 0 && spawnref) {
  9068. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9069. if (spawns.size() == 0) {
  9070. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9071. return 0;
  9072. }
  9073. Spawn* spawn = 0;
  9074. int16 index = MakeRandomInt(0, spawns.size());
  9075. if (index >= spawns.size() || index < 0)
  9076. index = 0;
  9077. spawn = spawns[index];
  9078. lua_interface->SetSpawnValue(state, spawn);
  9079. return 1;
  9080. }
  9081. else {
  9082. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9083. }
  9084. return 0;
  9085. }
  9086. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9087. Spawn* player = lua_interface->GetSpawn(state);
  9088. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9089. string name = lua_interface->GetStringValue(state, 3);
  9090. float distance = lua_interface->GetFloatValue(state, 4);
  9091. string command = lua_interface->GetStringValue(state, 5);
  9092. string error_text = lua_interface->GetStringValue(state, 6);
  9093. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9094. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9095. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9096. if (distance == 0)
  9097. distance = 10.0f;
  9098. if (command.length() == 0)
  9099. command = name;
  9100. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9101. if (spawns.size() == 0) {
  9102. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9103. return 0;
  9104. }
  9105. Spawn* spawn = 0;
  9106. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9107. spawn = *itr;
  9108. if (spawn) {
  9109. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9110. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9111. }
  9112. }
  9113. }
  9114. return 0;
  9115. }
  9116. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9117. if (!lua_interface)
  9118. return 0;
  9119. Client* client = 0;
  9120. Spawn* player = lua_interface->GetSpawn(state);
  9121. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9122. if (player && player->IsPlayer() && player->GetZone())
  9123. client = player->GetZone()->GetClientBySpawn(player);
  9124. else{
  9125. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9126. return 0;
  9127. }
  9128. if (client) {
  9129. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9130. if (packet) {
  9131. packet->setDataByName("goal_num", goal_num);
  9132. client->QueuePacket(packet->serialize());
  9133. safe_delete(packet);
  9134. }
  9135. }
  9136. return 0;
  9137. }
  9138. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9139. if (!lua_interface)
  9140. return 0;
  9141. Client* client = 0;
  9142. Spawn* player = lua_interface->GetSpawn(state);
  9143. if (player && player->IsPlayer() && player->GetZone())
  9144. client = player->GetZone()->GetClientBySpawn(player);
  9145. else {
  9146. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9147. return 0;
  9148. }
  9149. if (client) {
  9150. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9151. }
  9152. return 0;
  9153. }
  9154. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9155. if (!lua_interface)
  9156. return 0;
  9157. Client* client = 0;
  9158. Spawn* player = lua_interface->GetSpawn(state);
  9159. float duration = lua_interface->GetFloatValue(state, 2);
  9160. string text = lua_interface->GetStringValue(state, 3);
  9161. string voice = lua_interface->GetStringValue(state, 4);
  9162. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9163. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9164. string signal = lua_interface->GetStringValue(state, 7);
  9165. string goal1 = lua_interface->GetStringValue(state, 8);
  9166. string task1 = lua_interface->GetStringValue(state, 9);
  9167. string goal2 = lua_interface->GetStringValue(state, 10);
  9168. string task2 = lua_interface->GetStringValue(state, 11);
  9169. string goal3 = lua_interface->GetStringValue(state, 12);
  9170. string task3 = lua_interface->GetStringValue(state, 13);
  9171. string goal4 = lua_interface->GetStringValue(state, 14);
  9172. string task4 = lua_interface->GetStringValue(state, 15);
  9173. if (!player) {
  9174. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9175. return 0;
  9176. }
  9177. if (!player->IsPlayer()) {
  9178. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9179. return 0;
  9180. }
  9181. else
  9182. client = ((Player*)player)->GetClient();
  9183. if (!client) {
  9184. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9185. return 0;
  9186. }
  9187. if (text.length() == 0) {
  9188. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9189. return 0;
  9190. }
  9191. if (duration >= 0 && duration < 2)
  9192. duration = 2;
  9193. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9194. if (packet) {
  9195. packet->setDataByName("open_seconds_max", duration);
  9196. packet->setDataByName("text", text.c_str());
  9197. packet->setDataByName("voice", voice.c_str());
  9198. int8 num_goals = 1;
  9199. if (task2.length() > 0)
  9200. num_goals++;
  9201. if (task3.length() > 0)
  9202. num_goals++;
  9203. if (task4.length() > 0)
  9204. num_goals++;
  9205. packet->setArrayLengthByName("num_goals", num_goals);
  9206. for (int8 i = 0; i < num_goals; i++) {
  9207. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9208. }
  9209. if (goal1.length() > 0)
  9210. packet->setArrayDataByName("goal_text", goal1.c_str());
  9211. if (goal2.length() > 0)
  9212. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9213. if (goal3.length() > 0)
  9214. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9215. if (goal4.length() > 0)
  9216. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9217. packet->setSubArrayDataByName("task_text", task1.c_str());
  9218. if (task2.length() > 0)
  9219. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9220. if (task3.length() > 0)
  9221. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9222. if (task4.length() > 0)
  9223. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9224. packet->setDataByName("complete_sound", "click");
  9225. packet->setDataByName("signal", signal.c_str());
  9226. packet->setDataByName("voice_key1", voice_key1);
  9227. packet->setDataByName("voice_key2", voice_key2);
  9228. client->QueuePacket(packet->serialize());
  9229. safe_delete(packet);
  9230. }
  9231. return 0;
  9232. }
  9233. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9234. if (!lua_interface)
  9235. return 0;
  9236. Client* client = 0;
  9237. Spawn* player = lua_interface->GetSpawn(state);
  9238. string window = lua_interface->GetStringValue(state, 2);
  9239. int8 show = lua_interface->GetInt8Value(state, 3);
  9240. if (!player) {
  9241. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9242. return 0;
  9243. }
  9244. if (!player->IsPlayer()) {
  9245. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9246. return 0;
  9247. }
  9248. else
  9249. client = ((Player*)player)->GetClient();
  9250. if (!client) {
  9251. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9252. return 0;
  9253. }
  9254. if (window.length() == 0) {
  9255. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9256. return 0;
  9257. }
  9258. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9259. if (packet) {
  9260. packet->setDataByName("window", window.c_str());
  9261. packet->setDataByName("show", show);
  9262. client->QueuePacket(packet->serialize());
  9263. safe_delete(packet);
  9264. }
  9265. return 0;
  9266. }
  9267. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9268. //See GameEvents.txt for options that can be used for this function
  9269. if (!lua_interface)
  9270. return 0;
  9271. Client* client = 0;
  9272. Spawn* player = lua_interface->GetSpawn(state);
  9273. string event_name = lua_interface->GetStringValue(state, 2);
  9274. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9275. if (!player || !player->IsPlayer()) {
  9276. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9277. return 0;
  9278. }
  9279. if (player->GetZone())
  9280. client = player->GetZone()->GetClientBySpawn(player);
  9281. if (!client) {
  9282. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9283. return 0;
  9284. }
  9285. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9286. if (packet) {
  9287. packet->setDataByName("event_name", event_name.c_str());
  9288. packet->setDataByName("enabled", enabled);
  9289. client->QueuePacket(packet->serialize());
  9290. safe_delete(packet);
  9291. }
  9292. return 0;
  9293. }
  9294. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9295. if (!lua_interface)
  9296. return 0;
  9297. Spawn* player = lua_interface->GetSpawn(state);
  9298. if (player && player->IsPlayer()) {
  9299. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9300. return 1;
  9301. }
  9302. return 0;
  9303. }
  9304. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9305. if (!lua_interface)
  9306. return 0;
  9307. Spawn* player = lua_interface->GetSpawn(state);
  9308. int8 step = lua_interface->GetInt8Value(state, 2);
  9309. if (player && player->IsPlayer() && step > 0) {
  9310. ((Player*)player)->SetTutorialStep(step);
  9311. }
  9312. return 0;
  9313. }
  9314. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9315. if (!lua_interface)
  9316. return 0;
  9317. Client* client = 0;
  9318. Spawn* player = lua_interface->GetSpawn(state);
  9319. string window = lua_interface->GetStringValue(state, 2);
  9320. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9321. if (!player) {
  9322. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9323. return 0;
  9324. }
  9325. if (!player->IsPlayer()) {
  9326. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9327. return 0;
  9328. }
  9329. else
  9330. client = ((Player*)player)->GetClient();
  9331. if (!client) {
  9332. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9333. return 0;
  9334. }
  9335. if (window.length() == 0) {
  9336. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9337. return 0;
  9338. }
  9339. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9340. if (packet) {
  9341. packet->setDataByName("window", window.c_str());
  9342. packet->setDataByName("flash_seconds", flash_seconds);
  9343. client->QueuePacket(packet->serialize());
  9344. safe_delete(packet);
  9345. }
  9346. return 0;
  9347. }
  9348. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9349. if (!lua_interface)
  9350. return 0;
  9351. Spawn* spawn = lua_interface->GetSpawn(state);
  9352. Spawn* target = lua_interface->GetSpawn(state, 2);
  9353. if (spawn && target)
  9354. return spawn->CheckLoS(target);
  9355. return 0;
  9356. }
  9357. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9358. if (!lua_interface)
  9359. return 0;
  9360. Spawn* spawn = lua_interface->GetSpawn(state);
  9361. float x = lua_interface->GetFloatValue(state, 2);
  9362. float y = lua_interface->GetFloatValue(state, 3);
  9363. float z = lua_interface->GetFloatValue(state, 4);
  9364. if (spawn)
  9365. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9366. return 0;
  9367. }
  9368. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9369. if (!lua_interface)
  9370. return 0;
  9371. ZoneServer* zone = lua_interface->GetZone(state);
  9372. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9373. if (zone)
  9374. zone->SetExpansionFlag(xpackFlag);
  9375. return 0;
  9376. }
  9377. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9378. if (!lua_interface)
  9379. return 0;
  9380. ZoneServer* zone = lua_interface->GetZone(state);
  9381. if (zone) {
  9382. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9383. return 1;
  9384. }
  9385. return 0;
  9386. }
  9387. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9388. if (!lua_interface)
  9389. return 0;
  9390. ZoneServer* zone = lua_interface->GetZone(state);
  9391. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9392. if (zone)
  9393. zone->SetHolidayFlag(holidayFlag);
  9394. return 0;
  9395. }
  9396. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9397. if (!lua_interface)
  9398. return 0;
  9399. ZoneServer* zone = lua_interface->GetZone(state);
  9400. if (zone) {
  9401. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9402. return 1;
  9403. }
  9404. return 0;
  9405. }
  9406. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9407. if (!lua_interface)
  9408. return 0;
  9409. Spawn* spawn = lua_interface->GetSpawn(state);
  9410. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9411. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9412. float distance = lua_interface->GetFloatValue(state, 4);
  9413. string in_range_function = lua_interface->GetStringValue(state, 5);
  9414. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9415. if (spawn && distance > 0 && in_range_function.length() > 0)
  9416. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9417. return 0;
  9418. }
  9419. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9420. if (!lua_interface)
  9421. return 0;
  9422. Spawn* spawn = lua_interface->GetSpawn(state);
  9423. Spawn* target = lua_interface->GetSpawn(state, 2);
  9424. if (spawn && target)
  9425. {
  9426. if (spawn->IsPlayer() && target->IsEntity())
  9427. {
  9428. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9429. return 1;
  9430. }
  9431. else if (spawn->IsEntity() && target->IsEntity())
  9432. {
  9433. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9434. return 1;
  9435. }
  9436. }
  9437. return 0;
  9438. }
  9439. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9440. if (!lua_interface)
  9441. return 0;
  9442. Spawn* spawn = lua_interface->GetSpawn(state);
  9443. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9444. if (spawn && spawn->IsEntity())
  9445. {
  9446. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9447. if (spawn->IsPlayer())
  9448. {
  9449. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9450. if (client)
  9451. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9452. }
  9453. }
  9454. return 0;
  9455. }
  9456. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9457. if (!lua_interface)
  9458. return 0;
  9459. Spawn* spawn = lua_interface->GetSpawn(state);
  9460. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9461. if (spawn && spawn->IsEntity())
  9462. {
  9463. ((Entity*)spawn)->SetSeeHideSpell(val);
  9464. if (spawn->IsPlayer())
  9465. {
  9466. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9467. if (client)
  9468. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9469. }
  9470. }
  9471. return 0;
  9472. }
  9473. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9474. {
  9475. if (!lua_interface)
  9476. return 0;
  9477. Spawn* player = lua_interface->GetSpawn(state);
  9478. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9479. string command = lua_interface->GetStringValue(state, 3);
  9480. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9481. lua_interface->ResetFunctionStack(state);
  9482. if (spawn && player && player->IsPlayer())
  9483. {
  9484. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9485. bool res = false;
  9486. if (cmd)
  9487. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9488. lua_interface->SetBooleanValue(state, res);
  9489. return 1;
  9490. }
  9491. return 0;
  9492. }
  9493. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  9494. {
  9495. if (!lua_interface)
  9496. return 0;
  9497. Spawn* spawn = lua_interface->GetSpawn(state);
  9498. int32 charID = lua_interface->GetInt32Value(state, 2);
  9499. string command = lua_interface->GetStringValue(state, 3);
  9500. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9501. lua_interface->ResetFunctionStack(state);
  9502. if (spawn && charID)
  9503. {
  9504. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9505. bool res = false;
  9506. if (cmd)
  9507. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  9508. lua_interface->SetBooleanValue(state, res);
  9509. return 1;
  9510. }
  9511. return 0;
  9512. }
  9513. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9514. {
  9515. if (!lua_interface)
  9516. return 0;
  9517. Spawn* spawn = lua_interface->GetSpawn(state);
  9518. string command = lua_interface->GetStringValue(state, 2);
  9519. lua_interface->ResetFunctionStack(state);
  9520. if (spawn && command.length() > 0)
  9521. spawn->RemovePrimaryEntityCommand(command.c_str());
  9522. return 0;
  9523. }
  9524. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9525. if (!lua_interface)
  9526. return 0;
  9527. Spawn* spawn = lua_interface->GetSpawn(state);
  9528. float distance = lua_interface->GetFloatValue(state, 2);
  9529. string command = lua_interface->GetStringValue(state, 3);
  9530. Spawn* player = lua_interface->GetSpawn(state, 4);
  9531. lua_interface->ResetFunctionStack(state);
  9532. if (spawn) {
  9533. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9534. }
  9535. return 0;
  9536. }
  9537. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9538. if (!lua_interface)
  9539. return 0;
  9540. Spawn* spawn = lua_interface->GetSpawn(state);
  9541. Spawn* player = lua_interface->GetSpawn(state, 2);
  9542. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9543. lua_interface->ResetFunctionStack(state);
  9544. if (spawn && player && transport_id && player->IsPlayer()) {
  9545. Client* client = 0;
  9546. if (player && player->IsPlayer())
  9547. client = player->GetZone()->GetClientBySpawn(player);
  9548. if (!client)
  9549. return 0;
  9550. vector<TransportDestination*> destinations;
  9551. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9552. if (destinations.size())
  9553. {
  9554. client->SetTemporaryTransportID(transport_id);
  9555. client->ProcessTeleport(spawn, &destinations, transport_id);
  9556. }
  9557. else
  9558. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9559. }
  9560. return 0;
  9561. }
  9562. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9563. if (!lua_interface)
  9564. return 0;
  9565. Spawn* player = lua_interface->GetSpawn(state);
  9566. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9567. lua_interface->ResetFunctionStack(state);
  9568. if (player && player->IsPlayer()) {
  9569. Client* client = 0;
  9570. if (player && player->IsPlayer())
  9571. client = player->GetZone()->GetClientBySpawn(player);
  9572. if (!client)
  9573. return 0;
  9574. client->SetTemporaryTransportID(transport_id);
  9575. }
  9576. return 0;
  9577. }
  9578. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9579. if (!lua_interface)
  9580. return 0;
  9581. Spawn* player = lua_interface->GetSpawn(state);
  9582. lua_interface->ResetFunctionStack(state);
  9583. if (player && player->IsPlayer()) {
  9584. Client* client = 0;
  9585. if (player && player->IsPlayer())
  9586. client = player->GetZone()->GetClientBySpawn(player);
  9587. if (!client)
  9588. return 0;
  9589. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9590. return 1;
  9591. }
  9592. return 0;
  9593. }
  9594. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  9595. if (!lua_interface)
  9596. return 0;
  9597. Spawn* spawn = lua_interface->GetSpawn(state);
  9598. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  9599. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9600. if (!spawn) {
  9601. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9602. return 0;
  9603. }
  9604. if (!spawn->IsEntity()) {
  9605. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9606. return 0;
  9607. }
  9608. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  9609. {
  9610. 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);
  9611. return 0;
  9612. }
  9613. lua_interface->ResetFunctionStack(state);
  9614. if (spell && spell->targets.size() > 0) {
  9615. ZoneServer* zone = spell->caster->GetZone();
  9616. for (int8 i = 0; i < spell->targets.size(); i++) {
  9617. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  9618. if (target && target->IsEntity()) {
  9619. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  9620. if (target->IsPlayer())
  9621. ((Player*)target)->SetCharSheetChanged(true);
  9622. }
  9623. }
  9624. }
  9625. else {
  9626. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  9627. if (spawn->IsPlayer())
  9628. ((Player*)spawn)->SetCharSheetChanged(true);
  9629. }
  9630. return 0;
  9631. }
  9632. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  9633. if (!lua_interface)
  9634. return 0;
  9635. Spawn* spawn = lua_interface->GetSpawn(state);
  9636. lua_interface->ResetFunctionStack(state);
  9637. if (!spawn) {
  9638. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9639. return 0;
  9640. }
  9641. if (!spawn->IsEntity()) {
  9642. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9643. return 0;
  9644. }
  9645. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  9646. return 1;
  9647. }
  9648. int EQ2Emu_lua_GetSpell(lua_State* state) {
  9649. if (!lua_interface)
  9650. return 0;
  9651. int32 spell_id = lua_interface->GetInt32Value(state);
  9652. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  9653. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  9654. if (spell_id > 0) {
  9655. if (spell_tier == 0)
  9656. spell_tier = 1;
  9657. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  9658. LuaSpell* lua_spell = 0;
  9659. if(custom_lua_script.size() > 0)
  9660. {
  9661. // attempt to load the custom script since it isn't already loaded
  9662. // we will re-obtain the lua_spell further below
  9663. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  9664. {
  9665. 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());
  9666. lua_interface->LoadLuaSpell(custom_lua_script);
  9667. }
  9668. }
  9669. else
  9670. custom_lua_script = spell->GetSpellData()->lua_script;
  9671. if (!lua_spell && lua_interface)
  9672. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  9673. if (!lua_spell)
  9674. {
  9675. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  9676. return 0;
  9677. }
  9678. lua_spell->spell = new Spell(spell);
  9679. lua_interface->AddCustomSpell(lua_spell);
  9680. lua_interface->SetSpellValue(state, lua_spell);
  9681. return 1;
  9682. }
  9683. return 0;
  9684. }
  9685. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  9686. if (!lua_interface)
  9687. return 0;
  9688. LuaSpell* spell = lua_interface->GetSpell(state);
  9689. string field = lua_interface->GetStringValue(state, 2);
  9690. if (!spell) {
  9691. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  9692. return 0;
  9693. }
  9694. if (!spell->spell || !spell->spell->GetSpellData()) {
  9695. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  9696. return 0;
  9697. }
  9698. boost::to_lower(field);
  9699. return spell->spell->GetSpellData(state, field);
  9700. }
  9701. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  9702. if (!lua_interface)
  9703. return 0;
  9704. LuaSpell* spell = lua_interface->GetSpell(state);
  9705. string field = lua_interface->GetStringValue(state, 2);
  9706. int8 fieldArg = 3; // field value after the initial set
  9707. if (!spell) {
  9708. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  9709. return 0;
  9710. }
  9711. if (!spell->spell || !spell->spell->GetSpellData()) {
  9712. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  9713. return 0;
  9714. }
  9715. boost::to_lower(field);
  9716. bool valSet = false;
  9717. spell->spell->SetSpellData(state, field, fieldArg);
  9718. return valSet;
  9719. }
  9720. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  9721. if (!lua_interface)
  9722. return 0;
  9723. LuaSpell* spell = lua_interface->GetSpell(state);
  9724. int8 idx = lua_interface->GetInt32Value(state, 2);
  9725. if (!spell) {
  9726. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9727. return 0;
  9728. }
  9729. if (!spell->spell || !spell->spell->GetSpellData()) {
  9730. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  9731. return 0;
  9732. }
  9733. if (spell->spell->lua_data.size() <= idx)
  9734. {
  9735. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9736. return 0;
  9737. }
  9738. bool setVal = true;
  9739. LUAData* data = spell->spell->lua_data[idx];
  9740. switch (data->type)
  9741. {
  9742. case 0:
  9743. {
  9744. sint32 value = lua_interface->GetSInt32Value(state, 3);
  9745. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  9746. data->int_value = value;
  9747. data->int_value2 = value2;
  9748. break;
  9749. }
  9750. case 1:
  9751. {
  9752. float value = lua_interface->GetFloatValue(state, 3);
  9753. float value2 = lua_interface->GetFloatValue(state, 4);
  9754. data->float_value = value;
  9755. data->float_value2 = value2;
  9756. break;
  9757. }
  9758. case 2:
  9759. {
  9760. bool value = lua_interface->GetBooleanValue(state, 3);
  9761. data->bool_value = value;
  9762. break;
  9763. }
  9764. case 3:
  9765. {
  9766. string value = lua_interface->GetStringValue(state, 3);
  9767. string value2 = lua_interface->GetStringValue(state, 4);
  9768. data->string_value = value;
  9769. data->string_value2 = value2;
  9770. break;
  9771. }
  9772. default:
  9773. setVal = false;
  9774. }
  9775. return setVal;
  9776. }
  9777. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  9778. if (!lua_interface)
  9779. return 0;
  9780. LuaSpell* spell = lua_interface->GetSpell(state);
  9781. int8 idx = lua_interface->GetInt32Value(state, 2);
  9782. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  9783. if (!spell) {
  9784. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9785. return 0;
  9786. }
  9787. if (!spell->spell || !spell->spell->GetSpellData()) {
  9788. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  9789. return 0;
  9790. }
  9791. if (spell->spell->lua_data.size() <= idx)
  9792. {
  9793. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9794. return 0;
  9795. }
  9796. bool setVal = true;
  9797. LUAData* data = spell->spell->lua_data[idx];
  9798. switch (data->type)
  9799. {
  9800. case 0:
  9801. {
  9802. if(!secondfield)
  9803. lua_interface->SetSInt32Value(state, data->int_value);
  9804. else
  9805. lua_interface->SetSInt32Value(state, data->int_value2);
  9806. break;
  9807. }
  9808. case 1:
  9809. {
  9810. if (!secondfield)
  9811. lua_interface->SetFloatValue(state, data->float_value);
  9812. else
  9813. lua_interface->SetFloatValue(state, data->float_value2);
  9814. break;
  9815. }
  9816. case 2:
  9817. {
  9818. lua_interface->SetBooleanValue(state, data->bool_value);
  9819. break;
  9820. }
  9821. case 3:
  9822. {
  9823. if (!secondfield)
  9824. lua_interface->SetStringValue(state, data->string_value.c_str());
  9825. else
  9826. lua_interface->SetStringValue(state, data->string_value2.c_str());
  9827. break;
  9828. }
  9829. default:
  9830. setVal = false;
  9831. }
  9832. return setVal;
  9833. }
  9834. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  9835. if (!lua_interface)
  9836. return 0;
  9837. LuaSpell* spell = lua_interface->GetSpell(state);
  9838. int8 idx = lua_interface->GetInt32Value(state, 2);
  9839. string field = lua_interface->GetStringValue(state, 3);
  9840. boost::to_lower(field);
  9841. if (!spell) {
  9842. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9843. return 0;
  9844. }
  9845. if (!spell->spell || !spell->spell->GetSpellData()) {
  9846. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9847. return 0;
  9848. }
  9849. if (spell->spell->effects.size() <= idx)
  9850. {
  9851. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9852. return 0;
  9853. }
  9854. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9855. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9856. if (field == "description")
  9857. effect->description = string(lua_interface->GetStringValue(state, 4));
  9858. else if (field == "bullet")
  9859. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  9860. else if (field == "percentage")
  9861. effect->percentage = lua_interface->GetInt8Value(state, 4);
  9862. else // no match
  9863. return 0;
  9864. return 1;
  9865. }
  9866. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  9867. if (!lua_interface)
  9868. return 0;
  9869. LuaSpell* spell = lua_interface->GetSpell(state);
  9870. int8 idx = lua_interface->GetInt32Value(state, 2);
  9871. string field = lua_interface->GetStringValue(state, 3);
  9872. boost::to_lower(field);
  9873. if (!spell) {
  9874. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9875. return 0;
  9876. }
  9877. if (!spell->spell || !spell->spell->GetSpellData()) {
  9878. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  9879. return 0;
  9880. }
  9881. if (spell->spell->effects.size() <= idx)
  9882. {
  9883. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  9884. return 0;
  9885. }
  9886. // do we need to lock? eh probably not this should only be used before use of the custom spell
  9887. SpellDisplayEffect* effect = spell->spell->effects[idx];
  9888. if (field == "description")
  9889. lua_interface->SetStringValue(state, effect->description.c_str());
  9890. else if (field == "bullet")
  9891. lua_interface->SetInt32Value(state, effect->subbullet);
  9892. else if (field == "percentage")
  9893. lua_interface->SetInt32Value(state, effect->percentage);
  9894. else // no match
  9895. return 0;
  9896. return 1;
  9897. }
  9898. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  9899. if (!lua_interface)
  9900. return 0;
  9901. LuaSpell* spell = lua_interface->GetSpell(state);
  9902. Spawn* caster = lua_interface->GetSpawn(state, 2);
  9903. Spawn* target = lua_interface->GetSpawn(state, 3);
  9904. if (!target) {
  9905. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9906. return 0;
  9907. }
  9908. if (!target->IsEntity()) {
  9909. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  9910. return 0;
  9911. }
  9912. if (!spell) {
  9913. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  9914. return 0;
  9915. }
  9916. if (caster && !caster->IsEntity()) {
  9917. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  9918. return 0;
  9919. }
  9920. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  9921. return 0;
  9922. }
  9923. int EQ2Emu_lua_InWater(lua_State* state) {
  9924. if (!lua_interface)
  9925. return 0;
  9926. Spawn* spawn = lua_interface->GetSpawn(state);
  9927. lua_interface->ResetFunctionStack(state);
  9928. if (spawn) {
  9929. lua_interface->SetBooleanValue(state, spawn->InWater());
  9930. return 1;
  9931. }
  9932. return 0;
  9933. }
  9934. int EQ2Emu_lua_InLava(lua_State* state) {
  9935. if (!lua_interface)
  9936. return 0;
  9937. Spawn* spawn = lua_interface->GetSpawn(state);
  9938. lua_interface->ResetFunctionStack(state);
  9939. if (spawn) {
  9940. lua_interface->SetBooleanValue(state, spawn->InLava());
  9941. return 1;
  9942. }
  9943. return 0;
  9944. }
  9945. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  9946. if (!lua_interface)
  9947. return 0;
  9948. Spawn* attacker = lua_interface->GetSpawn(state);
  9949. Spawn* victim = lua_interface->GetSpawn(state, 2);
  9950. int8 type = lua_interface->GetInt8Value(state, 3);
  9951. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  9952. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  9953. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  9954. string spell_name = lua_interface->GetStringValue(state, 7);
  9955. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  9956. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  9957. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  9958. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  9959. lua_interface->ResetFunctionStack(state);
  9960. if (!attacker) {
  9961. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9962. return 0;
  9963. }
  9964. if (!attacker->IsEntity()) {
  9965. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  9966. return 0;
  9967. }
  9968. if (!victim) {
  9969. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9970. return 0;
  9971. }
  9972. if (!victim->IsEntity()) {
  9973. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  9974. return 0;
  9975. }
  9976. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  9977. return 0;
  9978. }
  9979. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  9980. if (!lua_interface)
  9981. return 0;
  9982. Spawn* spawn = lua_interface->GetSpawn(state);
  9983. lua_interface->ResetFunctionStack(state);
  9984. if (spawn) {
  9985. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  9986. return 1;
  9987. }
  9988. return 0;
  9989. }
  9990. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  9991. if (!lua_interface)
  9992. return 0;
  9993. Spawn* spawn = lua_interface->GetSpawn(state);
  9994. bool invul = lua_interface->GetBooleanValue(state, 2);
  9995. lua_interface->ResetFunctionStack(state);
  9996. if (spawn) {
  9997. spawn->SetInvulnerable(invul);
  9998. }
  9999. return 0;
  10000. }
  10001. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  10002. if (!lua_interface)
  10003. return 0;
  10004. string category = lua_interface->GetStringValue(state);
  10005. string name = lua_interface->GetStringValue(state, 2);
  10006. lua_interface->ResetFunctionStack(state);
  10007. Rule *ret = 0;
  10008. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10009. lua_interface->SetBooleanValue(state, ret->GetBool());
  10010. return 1;
  10011. }
  10012. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10013. return 0;
  10014. }
  10015. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  10016. if (!lua_interface)
  10017. return 0;
  10018. string category = lua_interface->GetStringValue(state);
  10019. string name = lua_interface->GetStringValue(state, 2);
  10020. lua_interface->ResetFunctionStack(state);
  10021. Rule *ret = 0;
  10022. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10023. lua_interface->SetInt32Value(state, ret->GetInt32());
  10024. return 1;
  10025. }
  10026. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10027. return 0;
  10028. }
  10029. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  10030. if (!lua_interface)
  10031. return 0;
  10032. string category = lua_interface->GetStringValue(state);
  10033. string name = lua_interface->GetStringValue(state, 2);
  10034. lua_interface->ResetFunctionStack(state);
  10035. Rule *ret = 0;
  10036. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10037. lua_interface->SetFloatValue(state, ret->GetFloat());
  10038. return 1;
  10039. }
  10040. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10041. return 0;
  10042. }
  10043. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  10044. if (!lua_interface)
  10045. return 0;
  10046. Spawn* spawn = lua_interface->GetSpawn(state);
  10047. string type = lua_interface->GetStringValue(state, 2);
  10048. lua_interface->ResetFunctionStack(state);
  10049. if (spawn) {
  10050. int res = 1;
  10051. boost::to_lower(type);
  10052. if(type == "assigned_aa")
  10053. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10054. else if ( type == "unassigned_aa")
  10055. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10056. else if ( type == "assigned_tradeskill_aa")
  10057. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10058. else if ( type == "unassigned_tradeskill_aa")
  10059. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10060. else if ( type == "assigned_prestige_aa")
  10061. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10062. else if ( type == "unassigned_prestige_aa")
  10063. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10064. else if ( type == "assigned_tradeskill_prestige_aa")
  10065. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10066. else if ( type == "unassigned_tradeskill_prestige_aa")
  10067. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10068. else
  10069. res = 0;
  10070. return res;
  10071. }
  10072. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10073. return 0;
  10074. }
  10075. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10076. if (!lua_interface)
  10077. return 0;
  10078. Spawn* spawn = lua_interface->GetSpawn(state);
  10079. string type = lua_interface->GetStringValue(state, 2);
  10080. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10081. lua_interface->ResetFunctionStack(state);
  10082. if (spawn) {
  10083. boost::to_lower(type);
  10084. if(type == "assigned_aa")
  10085. spawn->SetAssignedAA((sint16)value);
  10086. else if ( type == "unassigned_aa")
  10087. spawn->SetUnassignedAA((sint16)value);
  10088. else if ( type == "assigned_tradeskill_aa")
  10089. spawn->SetTradeskillAA((sint16)value);
  10090. else if ( type == "unassigned_tradeskill_aa")
  10091. spawn->SetUnassignedTradeskillAA((sint16)value);
  10092. else if ( type == "assigned_prestige_aa")
  10093. spawn->SetPrestigeAA((sint16)value);
  10094. else if ( type == "unassigned_prestige_aa")
  10095. spawn->SetUnassignedPrestigeAA((sint16)value);
  10096. else if ( type == "assigned_tradeskill_prestige_aa")
  10097. spawn->SetTradeskillPrestigeAA((sint16)value);
  10098. else if ( type == "unassigned_tradeskill_prestige_aa")
  10099. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10100. if(spawn->IsPlayer())
  10101. ((Player*)spawn)->SetCharSheetChanged(true);
  10102. }
  10103. return 0;
  10104. }
  10105. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10106. if (!lua_interface)
  10107. return 0;
  10108. string titleName = lua_interface->GetStringValue(state);
  10109. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10110. lua_interface->ResetFunctionStack(state);
  10111. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10112. lua_interface->SetSInt32Value(state, index);
  10113. return 1;
  10114. }
  10115. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10116. if (!lua_interface)
  10117. return 0;
  10118. Spawn* spawn = lua_interface->GetSpawn(state);
  10119. string titleName = lua_interface->GetStringValue(state, 2);
  10120. lua_interface->ResetFunctionStack(state);
  10121. if(!spawn->IsPlayer())
  10122. {
  10123. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10124. lua_interface->SetSInt32Value(state, -1);
  10125. return 1;
  10126. }
  10127. Player* player = (Player*)spawn;
  10128. // check if player already has the title, don't need to add twice
  10129. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10130. if ( playerHasTitle)
  10131. {
  10132. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10133. return 1;
  10134. }
  10135. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10136. if(!title)
  10137. {
  10138. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10139. lua_interface->SetSInt32Value(state, -1);
  10140. return 1;
  10141. }
  10142. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10143. if(returnIdx < 0)
  10144. {
  10145. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10146. }
  10147. lua_interface->SetSInt32Value(state, returnIdx);
  10148. player->GetClient()->SendTitleUpdate();
  10149. return 1;
  10150. }
  10151. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10152. if (!lua_interface)
  10153. return 0;
  10154. Spawn* spawn = lua_interface->GetSpawn(state);
  10155. string titleName = lua_interface->GetStringValue(state, 2);
  10156. lua_interface->ResetFunctionStack(state);
  10157. if(!spawn->IsPlayer())
  10158. {
  10159. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10160. return 0;
  10161. }
  10162. Player* player = (Player*)spawn;
  10163. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10164. if(!title)
  10165. {
  10166. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10167. return 0;
  10168. }
  10169. if(title->GetPrefix())
  10170. {
  10171. 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());
  10172. return 0;
  10173. }
  10174. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10175. player->GetClient()->SendTitleUpdate();
  10176. return 1;
  10177. }
  10178. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10179. if (!lua_interface)
  10180. return 0;
  10181. Spawn* spawn = lua_interface->GetSpawn(state);
  10182. string titleName = lua_interface->GetStringValue(state, 2);
  10183. lua_interface->ResetFunctionStack(state);
  10184. if(!spawn->IsPlayer())
  10185. {
  10186. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10187. return 0;
  10188. }
  10189. Player* player = (Player*)spawn;
  10190. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10191. if(!title)
  10192. {
  10193. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10194. return 0;
  10195. }
  10196. if(!title->GetPrefix())
  10197. {
  10198. 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());
  10199. return 0;
  10200. }
  10201. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10202. player->GetClient()->SendTitleUpdate();
  10203. return 1;
  10204. }
  10205. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10206. if (!lua_interface)
  10207. return 0;
  10208. Spawn* spawn = lua_interface->GetSpawn(state);
  10209. lua_interface->ResetFunctionStack(state);
  10210. if(!spawn->IsPlayer())
  10211. {
  10212. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10213. return 0;
  10214. }
  10215. Player* player = (Player*)spawn;
  10216. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  10217. player->GetClient()->SendTitleUpdate();
  10218. return 1;
  10219. }
  10220. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  10221. if (!lua_interface)
  10222. return 0;
  10223. Spawn* spawn = lua_interface->GetSpawn(state);
  10224. lua_interface->ResetFunctionStack(state);
  10225. if(!spawn->IsPlayer())
  10226. {
  10227. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10228. return 0;
  10229. }
  10230. Player* player = (Player*)spawn;
  10231. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  10232. player->GetClient()->SendTitleUpdate();
  10233. return 1;
  10234. }
  10235. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  10236. if (!lua_interface)
  10237. return 0;
  10238. Spawn* spawn = lua_interface->GetSpawn(state);
  10239. string field = lua_interface->GetStringValue(state, 2);
  10240. lua_interface->ResetFunctionStack(state);
  10241. if(!spawn || !spawn->IsEntity())
  10242. {
  10243. 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));
  10244. return 0;
  10245. }
  10246. Entity* ent = (Entity*)spawn;
  10247. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  10248. return 1;
  10249. }
  10250. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  10251. if (!lua_interface)
  10252. return 0;
  10253. Spawn* spawn = lua_interface->GetSpawn(state);
  10254. string field = lua_interface->GetStringValue(state, 2);
  10255. lua_interface->ResetFunctionStack(state);
  10256. if(!spawn || !spawn->IsEntity())
  10257. {
  10258. 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));
  10259. return 0;
  10260. }
  10261. Entity* ent = (Entity*)spawn;
  10262. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10263. return 1;
  10264. }
  10265. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10266. if (!lua_interface)
  10267. return 0;
  10268. Spawn* spawn = lua_interface->GetSpawn(state);
  10269. string field = lua_interface->GetStringValue(state, 2);
  10270. lua_interface->ResetFunctionStack(state);
  10271. if(!spawn || !spawn->IsEntity())
  10272. {
  10273. 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));
  10274. return 0;
  10275. }
  10276. Entity* ent = (Entity*)spawn;
  10277. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10278. return 1;
  10279. }
  10280. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  10281. if (!lua_interface)
  10282. return 0;
  10283. Spawn* spawn = lua_interface->GetSpawn(state);
  10284. string field = lua_interface->GetStringValue(state, 2);
  10285. lua_interface->ResetFunctionStack(state);
  10286. if(!spawn || !spawn->IsEntity())
  10287. {
  10288. 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));
  10289. return 0;
  10290. }
  10291. Entity* ent = (Entity*)spawn;
  10292. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  10293. return 1;
  10294. }
  10295. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  10296. if (!lua_interface)
  10297. return 0;
  10298. Spawn* spawn = lua_interface->GetSpawn(state);
  10299. string field = lua_interface->GetStringValue(state, 2);
  10300. string value = lua_interface->GetStringValue(state, 3);
  10301. lua_interface->ResetFunctionStack(state);
  10302. if(!spawn || !spawn->IsEntity())
  10303. {
  10304. 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));
  10305. return 0;
  10306. }
  10307. Entity* ent = (Entity*)spawn;
  10308. bool set_ = ent->SetInfoStructString(field, value);
  10309. lua_interface->SetBooleanValue(state, set_);
  10310. return 1;
  10311. }
  10312. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  10313. if (!lua_interface)
  10314. return 0;
  10315. Spawn* spawn = lua_interface->GetSpawn(state);
  10316. string field = lua_interface->GetStringValue(state, 2);
  10317. int64 value = lua_interface->GetInt64Value(state, 3);
  10318. lua_interface->ResetFunctionStack(state);
  10319. if(!spawn || !spawn->IsEntity())
  10320. {
  10321. 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));
  10322. return 0;
  10323. }
  10324. Entity* ent = (Entity*)spawn;
  10325. bool set_ = ent->SetInfoStructUInt(field, value);
  10326. lua_interface->SetBooleanValue(state, set_);
  10327. return 1;
  10328. }
  10329. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  10330. if (!lua_interface)
  10331. return 0;
  10332. Spawn* spawn = lua_interface->GetSpawn(state);
  10333. string field = lua_interface->GetStringValue(state, 2);
  10334. sint64 value = lua_interface->GetSInt64Value(state, 3);
  10335. lua_interface->ResetFunctionStack(state);
  10336. if(!spawn || !spawn->IsEntity())
  10337. {
  10338. 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));
  10339. return 0;
  10340. }
  10341. Entity* ent = (Entity*)spawn;
  10342. bool set_ = ent->SetInfoStructSInt(field, value);
  10343. lua_interface->SetBooleanValue(state, set_);
  10344. return 1;
  10345. }
  10346. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  10347. if (!lua_interface)
  10348. return 0;
  10349. Spawn* spawn = lua_interface->GetSpawn(state);
  10350. string field = lua_interface->GetStringValue(state, 2);
  10351. float value = lua_interface->GetFloatValue(state, 3);
  10352. lua_interface->ResetFunctionStack(state);
  10353. if(!spawn || !spawn->IsEntity())
  10354. {
  10355. 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));
  10356. return 0;
  10357. }
  10358. Entity* ent = (Entity*)spawn;
  10359. bool set_ = ent->SetInfoStructFloat(field, value);
  10360. lua_interface->SetBooleanValue(state, set_);
  10361. return 1;
  10362. }
  10363. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  10364. if (!lua_interface)
  10365. return 0;
  10366. Spawn* spawn = lua_interface->GetSpawn(state);
  10367. bool value = lua_interface->GetBooleanValue(state, 2);
  10368. lua_interface->ResetFunctionStack(state);
  10369. if(!spawn || !spawn->IsPlayer())
  10370. {
  10371. 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));
  10372. return 0;
  10373. }
  10374. ((Player*)spawn)->SetCharSheetChanged(value);
  10375. return 0;
  10376. }
  10377. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  10378. if (!lua_interface)
  10379. return 0;
  10380. Spawn* spawn = lua_interface->GetSpawn(state);
  10381. std::string fromName = lua_interface->GetStringValue(state, 2);
  10382. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10383. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10384. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10385. int32 copper = lua_interface->GetInt32Value(state, 6);
  10386. int32 silver = lua_interface->GetInt32Value(state, 7);
  10387. int32 gold = lua_interface->GetInt32Value(state, 8);
  10388. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10389. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10390. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10391. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10392. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10393. lua_interface->ResetFunctionStack(state);
  10394. if(!spawn || !spawn->IsPlayer())
  10395. {
  10396. 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));
  10397. lua_interface->SetBooleanValue(state, false);
  10398. return 1;
  10399. }
  10400. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10401. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10402. lua_interface->SetBooleanValue(state, true);
  10403. return 1;
  10404. }
  10405. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  10406. if (!lua_interface)
  10407. return 0;
  10408. int32 char_id = lua_interface->GetInt32Value(state);
  10409. std::string fromName = lua_interface->GetStringValue(state, 2);
  10410. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10411. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10412. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10413. int32 copper = lua_interface->GetInt32Value(state, 6);
  10414. int32 silver = lua_interface->GetInt32Value(state, 7);
  10415. int32 gold = lua_interface->GetInt32Value(state, 8);
  10416. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10417. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10418. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10419. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10420. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10421. lua_interface->ResetFunctionStack(state);
  10422. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10423. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10424. lua_interface->SetBooleanValue(state, true);
  10425. return 1;
  10426. }
  10427. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  10428. Spawn* widget;
  10429. if (lua_interface) {
  10430. widget = lua_interface->GetSpawn(state);
  10431. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  10432. lua_interface->ResetFunctionStack(state);
  10433. if (widget && widget->IsWidget())
  10434. {
  10435. ((Widget*)widget)->OpenDoor();
  10436. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  10437. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10438. }
  10439. else
  10440. 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));
  10441. }
  10442. return 0;
  10443. }
  10444. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  10445. Spawn* widget;
  10446. if (lua_interface) {
  10447. widget = lua_interface->GetSpawn(state);
  10448. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  10449. lua_interface->ResetFunctionStack(state);
  10450. if (widget && widget->IsWidget())
  10451. {
  10452. ((Widget*)widget)->CloseDoor();
  10453. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  10454. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10455. }
  10456. else
  10457. 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));
  10458. }
  10459. return 0;
  10460. }
  10461. int EQ2Emu_lua_IsOpen(lua_State* state) {
  10462. if (!lua_interface)
  10463. return 0;
  10464. Spawn* widget = lua_interface->GetSpawn(state);
  10465. lua_interface->ResetFunctionStack(state);
  10466. if (widget && widget->IsWidget())
  10467. {
  10468. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  10469. return 1;
  10470. }
  10471. return 0;
  10472. }
  10473. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  10474. if (!lua_interface)
  10475. return 0;
  10476. sint32 min = lua_interface->GetSInt32Value(state);
  10477. sint32 max = lua_interface->GetSInt32Value(state, 2);
  10478. lua_interface->ResetFunctionStack(state);
  10479. sint32 result = MakeRandomInt(min, max);
  10480. lua_interface->SetSInt32Value(state, result);
  10481. return 1;
  10482. }
  10483. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  10484. if (!lua_interface)
  10485. return 0;
  10486. float min = lua_interface->GetFloatValue(state);
  10487. float max = lua_interface->GetFloatValue(state, 2);
  10488. lua_interface->ResetFunctionStack(state);
  10489. float result = MakeRandomFloat(min, max);
  10490. lua_interface->SetFloatValue(state, result);
  10491. return 1;
  10492. }
  10493. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  10494. if (!lua_interface)
  10495. return 0;
  10496. Spawn* spawn = lua_interface->GetSpawn(state);
  10497. int32 value = lua_interface->GetInt32Value(state, 2);
  10498. lua_interface->ResetFunctionStack(state);
  10499. if(!spawn)
  10500. {
  10501. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10502. lua_interface->SetBooleanValue(state, false);
  10503. return 1;
  10504. }
  10505. spawn->AddIconValue(value);
  10506. lua_interface->SetBooleanValue(state, true);
  10507. return 1;
  10508. }
  10509. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  10510. if (!lua_interface)
  10511. return 0;
  10512. Spawn* spawn = lua_interface->GetSpawn(state);
  10513. int32 value = lua_interface->GetInt32Value(state, 2);
  10514. lua_interface->ResetFunctionStack(state);
  10515. if(!spawn)
  10516. {
  10517. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10518. lua_interface->SetBooleanValue(state, false);
  10519. return 1;
  10520. }
  10521. spawn->RemoveIconValue(value);
  10522. lua_interface->SetBooleanValue(state, true);
  10523. return 1;
  10524. }
  10525. int EQ2Emu_lua_GetShardID(lua_State* state) {
  10526. Spawn* npc = lua_interface->GetSpawn(state);
  10527. lua_interface->ResetFunctionStack(state);
  10528. if (npc && npc->IsNPC()) {
  10529. NPC* shard = (NPC*)npc;
  10530. int32 shardid = shard->GetShardID();
  10531. lua_interface->SetInt32Value(state, shardid);
  10532. return 1;
  10533. }
  10534. lua_interface->SetInt32Value(state, 0);
  10535. return 1;
  10536. }
  10537. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  10538. Spawn* npc = lua_interface->GetSpawn(state);
  10539. lua_interface->ResetFunctionStack(state);
  10540. if (npc && npc->IsNPC()) {
  10541. NPC* shard = (NPC*)npc;
  10542. int32 charid = shard->GetShardCharID();
  10543. lua_interface->SetInt32Value(state, charid);
  10544. return 1;
  10545. }
  10546. lua_interface->SetInt32Value(state, 0);
  10547. return 1;
  10548. }
  10549. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  10550. Spawn* npc = lua_interface->GetSpawn(state);
  10551. lua_interface->ResetFunctionStack(state);
  10552. if (npc && npc->IsNPC()) {
  10553. NPC* shard = (NPC*)npc;
  10554. int64 timestamp = shard->GetShardCreatedTimestamp();
  10555. lua_interface->SetSInt64Value(state, timestamp);
  10556. return 1;
  10557. }
  10558. lua_interface->SetSInt64Value(state, 0);
  10559. return 1;
  10560. }
  10561. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  10562. if (!lua_interface)
  10563. return 0;
  10564. int32 shardid = lua_interface->GetInt32Value(state);
  10565. lua_interface->ResetFunctionStack(state);
  10566. if(shardid < 1)
  10567. lua_interface->SetBooleanValue(state, false);
  10568. else
  10569. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  10570. return 1;
  10571. }
  10572. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  10573. if (!lua_interface)
  10574. return 0;
  10575. Spawn* spawn = lua_interface->GetSpawn(state);
  10576. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  10577. if (spawn) {
  10578. spawn->PauseMovement(delay_in_ms);
  10579. }
  10580. lua_interface->ResetFunctionStack(state);
  10581. return 0;
  10582. }
  10583. int EQ2Emu_lua_StopMovement(lua_State* state) {
  10584. if (!lua_interface)
  10585. return 0;
  10586. Spawn* spawn = lua_interface->GetSpawn(state);
  10587. if (spawn) {
  10588. spawn->StopMovement();
  10589. }
  10590. lua_interface->ResetFunctionStack(state);
  10591. return 0;
  10592. }
  10593. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  10594. Player* player = (Player*)lua_interface->GetSpawn(state);
  10595. int8 level = lua_interface->GetInt8Value(state, 2);
  10596. lua_interface->ResetFunctionStack(state);
  10597. if (player && player->IsPlayer() && level > 0) {
  10598. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  10599. return 1;
  10600. }
  10601. return 0;
  10602. }
  10603. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  10604. Player* player = (Player*)lua_interface->GetSpawn(state);
  10605. int8 level = lua_interface->GetInt8Value(state, 2);
  10606. lua_interface->ResetFunctionStack(state);
  10607. if (player && player->IsPlayer() && level > 0) {
  10608. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  10609. return 1;
  10610. }
  10611. return 0;
  10612. }
  10613. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  10614. ZoneServer* zone = lua_interface->GetZone(state);
  10615. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  10616. if (zone) {
  10617. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  10618. if (spawn) {
  10619. lua_interface->SetSpawnValue(state, spawn);
  10620. return 1;
  10621. }
  10622. }
  10623. return 0;
  10624. }
  10625. int EQ2Emu_lua_SetRailID(lua_State* state) {
  10626. if (!lua_interface)
  10627. return 0;
  10628. Spawn* spawn = lua_interface->GetSpawn(state);
  10629. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  10630. lua_interface->ResetFunctionStack(state);
  10631. bool res = false;
  10632. if(spawn && spawn->IsTransportSpawn())
  10633. {
  10634. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  10635. spawn->SetRailID(rail_id);
  10636. res = true;
  10637. }
  10638. else if (!spawn) {
  10639. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10640. }
  10641. else if(!spawn->IsTransportSpawn()) {
  10642. 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());
  10643. }
  10644. lua_interface->SetBooleanValue(state, res);
  10645. return 1;
  10646. }
  10647. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  10648. ZoneServer* zone = lua_interface->GetZone(state);
  10649. if (zone) {
  10650. lua_interface->SetBooleanValue(state, zone->IsLoading());
  10651. return 1;
  10652. }
  10653. return 0;
  10654. }
  10655. int EQ2Emu_lua_IsRunning(lua_State* state) {
  10656. Spawn* spawn = lua_interface->GetSpawn(state);
  10657. if (spawn) {
  10658. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  10659. return 1;
  10660. }
  10661. return 0;
  10662. }