LuaFunctions.cpp 292 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517
  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 "../common/Log.h"
  29. #include <math.h>
  30. #include "HeroicOp/HeroicOp.h"
  31. #include "RaceTypes/RaceTypes.h"
  32. #include "ClientPacketFunctions.h"
  33. #include "Transmute.h"
  34. #include <boost/algorithm/string/predicate.hpp>
  35. extern WorldDatabase database;
  36. extern LuaInterface* lua_interface;
  37. extern ConfigReader configReader;
  38. extern MasterQuestList master_quest_list;
  39. extern MasterItemList master_item_list;
  40. extern MasterSpellList master_spell_list;
  41. extern World world;
  42. extern Commands commands;
  43. extern ZoneList zone_list;
  44. extern Races races;
  45. extern Classes classes;
  46. extern Variables variables;
  47. extern MasterSkillList master_skill_list;
  48. extern MasterHeroicOPList master_ho_list;
  49. extern MasterRaceTypeList race_types_list;
  50. extern MasterLanguagesList master_languages_list;
  51. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  52. if (!lua_interface)
  53. return 0;
  54. Spawn* spawn = lua_interface->GetSpawn(state);
  55. string mp3_string = lua_interface->GetStringValue(state, 2);
  56. string text_string = lua_interface->GetStringValue(state, 3);
  57. string emote_string = lua_interface->GetStringValue(state, 4);
  58. int32 key1 = lua_interface->GetInt32Value(state, 5);
  59. int32 key2 = lua_interface->GetInt32Value(state, 6);
  60. Spawn* player = lua_interface->GetSpawn(state, 7);
  61. int8 language = lua_interface->GetInt8Value(state, 8);
  62. if (spawn) {
  63. const char* mp3 = 0;
  64. const char* text = 0;
  65. const char* emote = 0;
  66. if (mp3_string.length() > 0)
  67. mp3 = mp3_string.c_str();
  68. if (text_string.length() > 0)
  69. text = text_string.c_str();
  70. if (emote_string.length() > 0)
  71. emote = emote_string.c_str();
  72. Client* client = 0;
  73. if (player && player->IsPlayer())
  74. client = spawn->GetZone()->GetClientBySpawn(player);
  75. if (client) {
  76. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  77. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  78. }
  79. else
  80. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  81. }
  82. return 0;
  83. }
  84. int EQ2Emu_lua_PlaySound(lua_State* state) {
  85. if (!lua_interface)
  86. return 0;
  87. Spawn* spawn = lua_interface->GetSpawn(state);
  88. string sound_string = lua_interface->GetStringValue(state, 2);
  89. float x = lua_interface->GetFloatValue(state, 3);
  90. float y = lua_interface->GetFloatValue(state, 4);
  91. float z = lua_interface->GetFloatValue(state, 5);
  92. Spawn* player = lua_interface->GetSpawn(state, 6);
  93. if (spawn && sound_string.length() > 0) {
  94. Client* client = 0;
  95. if (player && player->IsPlayer())
  96. client = spawn->GetZone()->GetClientBySpawn(player);
  97. if (client)
  98. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  99. else
  100. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  101. }
  102. return 0;
  103. }
  104. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  105. if (!lua_interface)
  106. return 0;
  107. Spawn* spawn = lua_interface->GetSpawn(state);
  108. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  109. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  110. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  111. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  112. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  113. if (!spawn) {
  114. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  115. return 0;
  116. }
  117. if (quest_id > 0) {
  118. //Add this quest to the list of required quests for this spawn
  119. spawn->SetQuestsRequired(quest_id, quest_step);
  120. //If private spawn value set
  121. if (private_spawn) {
  122. //Set the spawn to be private when not granted access through this quest
  123. spawn->AddAllowAccessSpawn(spawn);
  124. spawn->SetPrivateQuestSpawn(true);
  125. }
  126. //This value allows access after a quest step, or the whole quest has been completed
  127. if (continued_access)
  128. spawn->SetQuestsRequiredContinuedAccess(true);
  129. //This value will override vis_flags in the vis packet
  130. if (flag_override > 0)
  131. spawn->SetQuestsRequiredOverride(flag_override);
  132. }
  133. return 0;
  134. }
  135. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  136. if (!lua_interface)
  137. return 0;
  138. Spawn* spawn = lua_interface->GetSpawn(state);
  139. float max_distance = lua_interface->GetFloatValue(state, 2);
  140. string variable = lua_interface->GetStringValue(state, 3);
  141. string value = lua_interface->GetStringValue(state, 4);
  142. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  143. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  144. return 0;
  145. }
  146. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  147. if (!lua_interface)
  148. return 0;
  149. Client* client = 0;
  150. Spawn* player = lua_interface->GetSpawn(state);
  151. if (!player) {
  152. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  153. return 0;
  154. }
  155. if (!player->IsPlayer()) {
  156. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  157. return 0;
  158. }
  159. if (player->GetZone())
  160. client = player->GetZone()->GetClientBySpawn(player);
  161. if (!client) {
  162. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  163. return 0;
  164. }
  165. int16 value1 = lua_interface->GetInt16Value(state, 2);
  166. int16 value2 = lua_interface->GetInt16Value(state, 3);
  167. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  168. if (packet) {
  169. packet->setDataByName("unknown1", value1);
  170. packet->setDataByName("unknown2", value2);
  171. client->QueuePacket(packet->serialize());
  172. safe_delete(packet);
  173. }
  174. return 0;
  175. }
  176. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  177. if (!lua_interface)
  178. return 0;
  179. Spawn* dead = lua_interface->GetSpawn(state);
  180. Spawn* killer = lua_interface->GetSpawn(state, 2);
  181. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  182. if (dead && dead->Alive() && dead->GetZone())
  183. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  184. return 0;
  185. }
  186. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  187. if (!lua_interface)
  188. return 0;
  189. Spawn* spawn = lua_interface->GetSpawn(state);
  190. float max_distance = lua_interface->GetFloatValue(state, 2);
  191. bool include_players = lua_interface->GetInt8Value(state, 3);
  192. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  193. if (max_distance > 0 && spawn && spawn->GetZone())
  194. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  195. return 0;
  196. }
  197. int EQ2Emu_lua_Despawn(lua_State* state) {
  198. if (!lua_interface)
  199. return 0;
  200. Spawn* spawn = lua_interface->GetSpawn(state);
  201. int32 delay = lua_interface->GetInt32Value(state, 2);
  202. if (spawn && spawn->GetZone())
  203. spawn->GetZone()->Despawn(spawn, delay);
  204. return 0;
  205. }
  206. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  207. if (!lua_interface)
  208. return 0;
  209. Spawn* spawn = lua_interface->GetSpawn(state);
  210. string variable = lua_interface->GetStringValue(state, 2);
  211. string value = lua_interface->GetStringValue(state, 3);
  212. int32 type = commands.GetSpawnSetType(variable);
  213. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  214. commands.SetSpawnCommand(0, spawn, type, value.c_str());
  215. return 0;
  216. }
  217. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  218. if (!lua_interface)
  219. return 0;
  220. Spawn* spawn = lua_interface->GetSpawn(state);
  221. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  222. if (spawn && spawn_id > 0) {
  223. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  224. if (closest_spawn) {
  225. lua_interface->SetSpawnValue(state, closest_spawn);
  226. return 1;
  227. }
  228. }
  229. return 0;
  230. }
  231. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  232. if (!lua_interface)
  233. return 0;
  234. string variable_name = lua_interface->GetStringValue(state);
  235. Variable* var = variables.FindVariable(variable_name);
  236. if (var) {
  237. lua_interface->SetStringValue(state, var->GetValue());
  238. return 1;
  239. }
  240. return 0;
  241. }
  242. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  243. if (!lua_interface)
  244. return 0;
  245. int32 total_coins = lua_interface->GetInt32Value(state);
  246. if (total_coins == 0) {
  247. lua_interface->SetStringValue(state, "0 copper");
  248. return 1;
  249. }
  250. char tmp[64] = { 0 };
  251. string message = "";
  252. int32 val = 0;
  253. if (total_coins >= 1000000) {
  254. val = total_coins / 1000000;
  255. total_coins -= 1000000 * val;
  256. sprintf(tmp, " %u Platinum", val);
  257. message.append(tmp);
  258. memset(tmp, 0, 64);
  259. }
  260. if (total_coins >= 10000) {
  261. val = total_coins / 10000;
  262. total_coins -= 10000 * val;
  263. sprintf(tmp, " %u Gold", val);
  264. message.append(tmp);
  265. memset(tmp, 0, 64);
  266. }
  267. if (total_coins >= 100) {
  268. val = total_coins / 100;
  269. total_coins -= 100 * val;
  270. sprintf(tmp, " %u Silver", val);
  271. message.append(tmp);
  272. memset(tmp, 0, 64);
  273. }
  274. if (total_coins > 0) {
  275. sprintf(tmp, " %u Copper", (int32)total_coins);
  276. message.append(tmp);
  277. }
  278. lua_interface->SetStringValue(state, message.c_str());
  279. return 1;
  280. }
  281. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  282. ZoneServer* zone = lua_interface->GetZone(state);
  283. int32 group_id = lua_interface->GetInt32Value(state, 2);
  284. if (zone) {
  285. Spawn* spawn = zone->GetSpawnGroup(group_id);
  286. if (spawn) {
  287. lua_interface->SetSpawnValue(state, spawn);
  288. return 1;
  289. }
  290. }
  291. return 0;
  292. }
  293. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  294. ZoneServer* zone = lua_interface->GetZone(state);
  295. int32 location_id = lua_interface->GetInt32Value(state, 2);
  296. if (zone) {
  297. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  298. if (spawn) {
  299. lua_interface->SetSpawnValue(state, spawn);
  300. return 1;
  301. }
  302. }
  303. return 0;
  304. }
  305. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  306. Spawn* spawn = lua_interface->GetSpawn(state);
  307. if (spawn) {
  308. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  309. return 1;
  310. }
  311. return 0;
  312. }
  313. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  314. Spawn* spawn = lua_interface->GetSpawn(state);
  315. if (spawn) {
  316. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  317. return 1;
  318. }
  319. return 0;
  320. }
  321. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  322. Spawn* spawn = lua_interface->GetSpawn(state);
  323. if (spawn) {
  324. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  325. return 1;
  326. }
  327. return 0;
  328. }
  329. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  330. Spawn* spawn = lua_interface->GetSpawn(state);
  331. if (spawn) {
  332. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  333. return 1;
  334. }
  335. return 0;
  336. }
  337. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  338. Player* player = (Player*)lua_interface->GetSpawn(state);
  339. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  340. if (player && player->IsPlayer() && faction_id > 0) {
  341. lua_interface->SetInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  342. return 1;
  343. }
  344. return 0;
  345. }
  346. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  347. if (!lua_interface)
  348. return 0;
  349. Spawn* spawn = lua_interface->GetSpawn(state);
  350. int32 value = lua_interface->GetInt32Value(state, 2);
  351. if (spawn) {
  352. spawn->SetFactionID(value);
  353. }
  354. return 0;
  355. }
  356. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  357. Spawn* spawn = lua_interface->GetSpawn(state);
  358. if (spawn) {
  359. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  360. return 1;
  361. }
  362. return 0;
  363. }
  364. int EQ2Emu_lua_GetGender(lua_State* state) {
  365. Spawn* spawn = lua_interface->GetSpawn(state);
  366. if (spawn) {
  367. lua_interface->SetInt32Value(state, spawn->GetGender());
  368. return 1;
  369. }
  370. return 0;
  371. }
  372. int EQ2Emu_lua_GetTarget(lua_State* state) {
  373. Spawn* spawn = lua_interface->GetSpawn(state);
  374. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  375. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  376. return 1;
  377. }
  378. return 0;
  379. }
  380. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  381. if (!lua_interface)
  382. return 0;
  383. Spawn* spawn = lua_interface->GetSpawn(state);
  384. string mp3_string = lua_interface->GetStringValue(state, 2);
  385. int32 key1 = lua_interface->GetInt32Value(state, 3);
  386. int32 key2 = lua_interface->GetInt32Value(state, 4);
  387. Spawn* player = lua_interface->GetSpawn(state, 5);
  388. if (spawn && mp3_string.length() > 0) {
  389. Client* client = 0;
  390. if (player && player->IsPlayer())
  391. client = spawn->GetZone()->GetClientBySpawn(player);
  392. if (client) {
  393. if (((Player*)player)->WasSentSpawn(spawn->GetID()) && !((Player*)player)->WasSpawnRemoved(spawn))
  394. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  395. }
  396. else
  397. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  398. }
  399. return 0;
  400. }
  401. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  402. if (!lua_interface)
  403. return 0;
  404. Spawn* spawn = lua_interface->GetSpawn(state);
  405. if (spawn) {
  406. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  407. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  408. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  409. return 3;
  410. }
  411. return 0;
  412. }
  413. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  414. if (!lua_interface)
  415. return 0;
  416. Spawn* spawn = lua_interface->GetSpawn(state);
  417. if (spawn && spawn->IsEntity()) {
  418. int32 item_id = lua_interface->GetInt32Value(state, 2);
  419. int16 charges = lua_interface->GetInt16Value(state, 3);
  420. if (charges == 0)
  421. charges = 1;
  422. ((Entity*)spawn)->AddLootItem(item_id, charges);
  423. }
  424. return 0;
  425. }
  426. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  427. if (!lua_interface)
  428. return 0;
  429. Spawn* spawn = lua_interface->GetSpawn(state);
  430. if (spawn && spawn->IsEntity()) {
  431. int32 item_id = lua_interface->GetInt32Value(state, 2);
  432. ((Entity*)spawn)->LootItem(item_id);
  433. }
  434. return 0;
  435. }
  436. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  437. if (!lua_interface)
  438. return 0;
  439. Spawn* spawn = lua_interface->GetSpawn(state);
  440. if (spawn && spawn->IsEntity()) {
  441. int32 val = lua_interface->GetInt32Value(state, 2);
  442. ((Entity*)spawn)->AddLootCoins(val);
  443. }
  444. return 0;
  445. }
  446. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  447. if (!lua_interface)
  448. return 0;
  449. Spawn* entity = lua_interface->GetSpawn(state);
  450. Spawn* player = lua_interface->GetSpawn(state, 2);
  451. if (entity && player && player->IsPlayer()) {
  452. int32 coins = lua_interface->GetInt32Value(state, 3);
  453. vector<Item*>* items = 0;
  454. int i = 0;
  455. int32 item_id = 0;
  456. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  457. if (items == 0)
  458. items = new vector<Item*>;
  459. if (master_item_list.GetItem(item_id))
  460. items->push_back(master_item_list.GetItem(item_id));
  461. i++;
  462. }
  463. Client* client = 0;
  464. client = entity->GetZone()->GetClientBySpawn(player);
  465. if (client) {
  466. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  467. client->Loot(coins, ((Player*)player)->GetPendingLootItems(entity->GetID()), (Entity*)entity);
  468. }
  469. safe_delete(items);
  470. }
  471. return 0;
  472. }
  473. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  474. if (!lua_interface)
  475. return 0;
  476. Spawn* entity = lua_interface->GetSpawn(state);
  477. Spawn* player = lua_interface->GetSpawn(state, 2);
  478. int32 item_id = lua_interface->GetInt32Value(state, 3);
  479. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  480. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  481. return 1;
  482. }
  483. return 0;
  484. }
  485. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  486. if (!lua_interface)
  487. return 0;
  488. Spawn* entity = lua_interface->GetSpawn(state);
  489. Spawn* player = lua_interface->GetSpawn(state, 2);
  490. if (entity && entity->IsEntity() && player && player->IsPlayer()) {
  491. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  492. return 1;
  493. }
  494. return 0;
  495. }
  496. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  497. if (!lua_interface)
  498. return 0;
  499. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  500. safe_delete(conversation);
  501. conversation = new vector<ConversationOption>();
  502. lua_interface->SetConversationValue(state, conversation);
  503. return 1;
  504. }
  505. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  506. if (!lua_interface)
  507. return 0;
  508. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  509. if (conversation) {
  510. ConversationOption conv_option;
  511. conv_option.option = lua_interface->GetStringValue(state, 2);
  512. conv_option.function = lua_interface->GetStringValue(state, 3);
  513. if (conv_option.option.length() > 0)
  514. conversation->push_back(conv_option);
  515. }
  516. return 0;
  517. }
  518. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  519. if (!lua_interface)
  520. return 0;
  521. Spawn* npc = lua_interface->GetSpawn(state);
  522. Spawn* player = lua_interface->GetSpawn(state, 2);
  523. if (npc && player && player->IsPlayer() && player->GetZone()) {
  524. Client* client = player->GetZone()->GetClientBySpawn(player);
  525. if (client) {
  526. int32 conversation_id = client->GetConversationID(npc, 0);
  527. client->CloseDialog(conversation_id);
  528. }
  529. }
  530. return 0;
  531. }
  532. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  533. if (!lua_interface)
  534. return 0;
  535. Item* item = lua_interface->GetItem(state);
  536. Spawn* player = lua_interface->GetSpawn(state, 2);
  537. if (item && player && player->IsPlayer() && player->GetZone()) {
  538. Client* client = player->GetZone()->GetClientBySpawn(player);
  539. if (client) {
  540. int32 conversation_id = client->GetConversationID(0, item);
  541. client->CloseDialog(conversation_id);
  542. }
  543. }
  544. return 0;
  545. }
  546. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  547. if (!lua_interface)
  548. return 0;
  549. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  550. Spawn* spawn = 0;
  551. Item* item = 0;
  552. int8 type = lua_interface->GetInt8Value(state, 2);
  553. if (type == 1 || type == 3)
  554. spawn = lua_interface->GetSpawn(state, 3);
  555. else if (type == 2 || type == 4)
  556. item = lua_interface->GetItem(state, 3);
  557. Spawn* player = lua_interface->GetSpawn(state, 4);
  558. string text = lua_interface->GetStringValue(state, 5);
  559. string mp3 = lua_interface->GetStringValue(state, 6);
  560. int32 key1 = lua_interface->GetInt32Value(state, 7);
  561. int32 key2 = lua_interface->GetInt32Value(state, 8);
  562. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  563. Client* client = player->GetZone()->GetClientBySpawn(player);
  564. if (client) {
  565. if (spawn) {
  566. // Need to do this so the function works the same as it did before
  567. if (type == 1)
  568. type++;
  569. if (mp3.length() > 0)
  570. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  571. else
  572. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  573. }
  574. else {
  575. if (mp3.length() > 0)
  576. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  577. else
  578. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  579. }
  580. }
  581. }
  582. safe_delete(conversation);
  583. lua_interface->SetConversationValue(state, NULL);
  584. return 0;
  585. }
  586. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  587. if(!lua_interface)
  588. return 0;
  589. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  590. Item* item = lua_interface->GetItem(state, 2);
  591. Spawn* player = lua_interface->GetSpawn(state, 3);
  592. string text = lua_interface->GetStringValue(state, 4);
  593. string mp3 = lua_interface->GetStringValue(state, 5);
  594. int32 key1 = lua_interface->GetInt32Value(state, 6);
  595. int32 key2 = lua_interface->GetInt32Value(state, 7);
  596. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  597. Client* client = player->GetZone()->GetClientBySpawn(player);
  598. if(client){
  599. if(mp3.length() > 0)
  600. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  601. else
  602. client->DisplayConversation(item, conversation, (char*)text.c_str());
  603. }
  604. safe_delete(conversation);
  605. }
  606. return 0;
  607. }*/
  608. int EQ2Emu_lua_StartConversation(lua_State* state) {
  609. if (!lua_interface)
  610. return 0;
  611. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  612. Spawn* npc = lua_interface->GetSpawn(state, 2);
  613. Spawn* player = lua_interface->GetSpawn(state, 3);
  614. string text = lua_interface->GetStringValue(state, 4);
  615. string mp3 = lua_interface->GetStringValue(state, 5);
  616. int32 key1 = lua_interface->GetInt32Value(state, 6);
  617. int32 key2 = lua_interface->GetInt32Value(state, 7);
  618. if (conversation && conversation->size() > 0 && text.length() > 0 && npc && npc->IsEntity() && player && player->IsPlayer()) {
  619. Client* client = npc->GetZone()->GetClientBySpawn(player);
  620. if (mp3.length() > 0)
  621. client->DisplayConversation((Entity*)npc, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  622. else
  623. client->DisplayConversation((Entity*)npc, 1, conversation, text.c_str());
  624. safe_delete(conversation);
  625. lua_interface->SetConversationValue(state, NULL);
  626. }
  627. else
  628. 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.", npc ? npc->GetName() : "UNKNOWN", text.size() ? text.c_str() : "", conversation ? conversation->size() : -1);
  629. return 0;
  630. }
  631. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  632. if (!lua_interface)
  633. return 0;
  634. Spawn* spawn = lua_interface->GetSpawn(state);
  635. float distance = lua_interface->GetFloatValue(state, 2);
  636. string in_range_function = lua_interface->GetStringValue(state, 3);
  637. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  638. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  639. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  640. return 0;
  641. }
  642. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  643. ZoneServer* zone = lua_interface->GetZone(state);
  644. float x = lua_interface->GetFloatValue(state, 2);
  645. float y = lua_interface->GetFloatValue(state, 3);
  646. float z = lua_interface->GetFloatValue(state, 4);
  647. float max_variation = lua_interface->GetFloatValue(state, 5);
  648. string in_range_function = lua_interface->GetStringValue(state, 6);
  649. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  650. if (zone && in_range_function.length() > 0)
  651. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  652. return 0;
  653. }
  654. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  655. if (!lua_interface)
  656. return 0;
  657. Spawn* spawn = lua_interface->GetSpawn(state);
  658. if (spawn && spawn->IsEntity()) {
  659. int32 val = lua_interface->GetInt32Value(state, 2);
  660. ((Entity*)spawn)->SetLootCoins(val);
  661. }
  662. return 0;
  663. }
  664. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  665. if (!lua_interface)
  666. return 0;
  667. Spawn* spawn = lua_interface->GetSpawn(state);
  668. if (spawn && spawn->IsEntity()) {
  669. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  670. return 1;
  671. }
  672. return 0;
  673. }
  674. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  675. if (!lua_interface)
  676. return 0;
  677. Spawn* spawn = lua_interface->GetSpawn(state);
  678. float x = lua_interface->GetFloatValue(state, 2);
  679. float y = lua_interface->GetFloatValue(state, 3);
  680. float z = lua_interface->GetFloatValue(state, 4);
  681. float speed = lua_interface->GetFloatValue(state, 5);
  682. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  683. string function = lua_interface->GetStringValue(state, 7);
  684. if (spawn) {
  685. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str());
  686. spawn->GetZone()->AddMovementNPC(spawn);
  687. }
  688. lua_interface->ResetFunctionStack(state);
  689. return 0;
  690. }
  691. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  692. if (!lua_interface)
  693. return 0;
  694. Spawn* spawn = lua_interface->GetSpawn(state);
  695. if (spawn) {
  696. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  697. return 1;
  698. }
  699. return 0;
  700. }
  701. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  702. if (!lua_interface)
  703. return 0;
  704. Spawn* spawn = lua_interface->GetSpawn(state);
  705. Spawn* target = lua_interface->GetSpawn(state, 2);
  706. if (spawn && target) {
  707. if (spawn->IsEntity())
  708. // ((Entity*)spawn)->FaceTarget(target);
  709. static_cast<Entity*>(spawn)->FaceTarget(target);
  710. }
  711. lua_interface->ResetFunctionStack(state);
  712. return 0;
  713. }
  714. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  715. if (!lua_interface)
  716. return 0;
  717. Spawn* spawn = lua_interface->GetSpawn(state);
  718. float x = lua_interface->GetFloatValue(state, 2);
  719. float y = lua_interface->GetFloatValue(state, 3);
  720. float z = lua_interface->GetFloatValue(state, 4);
  721. float speed = lua_interface->GetFloatValue(state, 5);
  722. string lua_function = lua_interface->GetStringValue(state, 6);
  723. bool more_points = lua_interface->GetBooleanValue(state, 7);
  724. if (spawn) {
  725. if (speed == 0)
  726. speed = spawn->GetSpeed();
  727. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  728. }
  729. lua_interface->ResetFunctionStack(state);
  730. return 0;
  731. }
  732. int EQ2Emu_lua_Say(lua_State* state) {
  733. if (!lua_interface)
  734. return 0;
  735. Spawn* spawn = lua_interface->GetSpawn(state);
  736. string message = lua_interface->GetStringValue(state, 2);
  737. Spawn* player = lua_interface->GetSpawn(state, 3);
  738. int32 language = lua_interface->GetInt32Value(state, 4);
  739. if (spawn && message.length() > 0) {
  740. Client* client = 0;
  741. if (player && player->IsPlayer())
  742. client = spawn->GetZone()->GetClientBySpawn(player);
  743. if (client)
  744. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  745. else
  746. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  747. }
  748. lua_interface->ResetFunctionStack(state);
  749. return 0;
  750. }
  751. int EQ2Emu_lua_Shout(lua_State* state) {
  752. if (!lua_interface)
  753. return 0;
  754. Spawn* spawn = lua_interface->GetSpawn(state);
  755. string message = lua_interface->GetStringValue(state, 2);
  756. Spawn* player = lua_interface->GetSpawn(state, 3);
  757. if (spawn && message.length() > 0) {
  758. Client* client = 0;
  759. if (player && player->IsPlayer())
  760. client = spawn->GetZone()->GetClientBySpawn(player);
  761. if (client)
  762. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  763. else
  764. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), 30);
  765. }
  766. lua_interface->ResetFunctionStack(state);
  767. return 0;
  768. }
  769. int EQ2Emu_lua_SayOOC(lua_State* state) {
  770. if (!lua_interface)
  771. return 0;
  772. Spawn* spawn = lua_interface->GetSpawn(state);
  773. string message = lua_interface->GetStringValue(state, 2);
  774. Spawn* player = lua_interface->GetSpawn(state, 3);
  775. if (spawn && message.length() > 0) {
  776. Client* client = 0;
  777. if (player && player->IsPlayer())
  778. client = spawn->GetZone()->GetClientBySpawn(player);
  779. if (client)
  780. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OOC, message.c_str(), 30);
  781. else
  782. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OOC, message.c_str(), 30);
  783. }
  784. lua_interface->ResetFunctionStack(state);
  785. return 0;
  786. }
  787. int EQ2Emu_lua_Emote(lua_State* state) {
  788. if (!lua_interface)
  789. return 0;
  790. Spawn* spawn = lua_interface->GetSpawn(state);
  791. string message = lua_interface->GetStringValue(state, 2);
  792. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  793. Spawn* player = lua_interface->GetSpawn(state, 4);
  794. char* to = 0;
  795. if (spawn2)
  796. to = spawn2->GetName();
  797. if (spawn && message.length() > 0) {
  798. Client* client = 0;
  799. if (player && player->IsPlayer())
  800. client = spawn->GetZone()->GetClientBySpawn(player);
  801. if (client)
  802. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  803. else
  804. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  805. }
  806. lua_interface->ResetFunctionStack(state);
  807. return 0;
  808. }
  809. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  810. if (!lua_interface)
  811. return 0;
  812. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  813. if (!luaspell)
  814. return 0;
  815. Spawn* caster = luaspell->caster;
  816. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  817. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  818. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  819. Spawn* target = lua_interface->GetSpawn(state, 4);
  820. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  821. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  822. lua_interface->ResetFunctionStack(state);
  823. if (caster && caster->IsEntity()) {
  824. bool success = false;
  825. luaspell->resisted = false;
  826. if (target) {
  827. float distance = caster->GetDistance(target, true);
  828. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs))
  829. success = true;
  830. }
  831. if (luaspell->targets.size() > 0) {
  832. Spawn* target = 0;
  833. ZoneServer* zone = luaspell->caster->GetZone();
  834. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  835. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  836. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  837. float distance = caster->GetDistance(target, true);
  838. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs);
  839. }
  840. }
  841. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  842. success = true;
  843. }
  844. if (success) {
  845. if (caster->GetZone())
  846. caster->GetZone()->TriggerCharSheetTimer();
  847. }
  848. }
  849. return 0;
  850. }
  851. int EQ2Emu_lua_SummonItem(lua_State* state) {
  852. if (!lua_interface)
  853. return 0;
  854. Spawn* spawn = lua_interface->GetSpawn(state);
  855. int32 item_id = lua_interface->GetInt32Value(state, 2);
  856. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  857. string location = lua_interface->GetStringValue(state, 4);
  858. if (spawn && spawn->IsPlayer()) {
  859. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  860. if (client && item_id > 0) {
  861. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  862. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, 1));
  863. else
  864. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  865. if (send_messages) {
  866. Item* item = master_item_list.GetItem(item_id);
  867. if (item) {
  868. client->Message(CHANNEL_COLOR_YELLOW, "You receive \\aITEM %u 0:%s\\/a.", item->details.item_id, item->name.c_str());
  869. string popup_text = "You receive " + item->name;
  870. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  871. }
  872. }
  873. return 1;
  874. }
  875. }
  876. lua_interface->SetBooleanValue(state, false);
  877. return 1;
  878. }
  879. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  880. Spawn* spawn = lua_interface->GetSpawn(state);
  881. int32 item_id = lua_interface->GetInt32Value(state, 2);
  882. int16 quantity = lua_interface->GetInt16Value(state, 3);
  883. // default of 1 to remove
  884. if (quantity == 0)
  885. quantity = 1;
  886. Client* client;
  887. Item* item;
  888. if (spawn && spawn->IsPlayer() && item_id > 0) {
  889. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  890. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  891. if (client->RemoveItem(item, quantity)) {
  892. lua_interface->SetBooleanValue(state, true);
  893. return 1;
  894. }
  895. }
  896. }
  897. }
  898. lua_interface->SetBooleanValue(state, false);
  899. return 1;
  900. }
  901. int EQ2Emu_lua_HasItem(lua_State* state) {
  902. Spawn* player = lua_interface->GetSpawn(state);
  903. int32 item_id = lua_interface->GetInt32Value(state, 2);
  904. bool include_bank = lua_interface->GetInt8Value(state, 3);
  905. if (player && player->IsPlayer()) {
  906. bool hasItem = false;
  907. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  908. if (!hasItem)
  909. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  910. lua_interface->SetBooleanValue(state, hasItem);
  911. return 1;
  912. }
  913. lua_interface->SetBooleanValue(state, false);
  914. return 1;
  915. }
  916. int EQ2Emu_lua_Spawn(lua_State* state) {
  917. if (!lua_interface)
  918. return 0;
  919. ZoneServer* zone = lua_interface->GetZone(state);
  920. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  921. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  922. float x = lua_interface->GetFloatValue(state, 4);
  923. float y = lua_interface->GetFloatValue(state, 5);
  924. float z = lua_interface->GetFloatValue(state, 6);
  925. float heading = lua_interface->GetFloatValue(state, 7);
  926. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  927. Spawn* spawn = zone->GetSpawn(spawn_id);
  928. if (!spawn)
  929. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  930. else {
  931. spawn->SetX(x);
  932. spawn->SetZ(z);
  933. spawn->SetY(y,true,true);
  934. spawn->SetLocation(zone->GetClosestLocation(spawn));
  935. spawn->SetHeading(heading);
  936. if (restricted_npc)
  937. spawn->AddAllowAccessSpawn(spawn);
  938. const char* spawn_script = world.GetSpawnScript(spawn_id);
  939. bool scriptActive = false;
  940. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  941. scriptActive = true;
  942. spawn->SetSpawnScript(string(spawn_script));
  943. }
  944. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  945. zone->AddSpawn(spawn);
  946. if (scriptActive) {
  947. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  948. }
  949. lua_interface->SetSpawnValue(state, spawn);
  950. return 1;
  951. }
  952. }
  953. else {
  954. string output = "Invalid paramaters to LUA Spawn command: \n";
  955. if (!zone)
  956. output = output.append("\t").append("Missing zone reference. \n");
  957. if (spawn_id == 0)
  958. output = output.append("\t").append("Missing spawn_id.");
  959. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone - %s", lua_interface->GetScriptName(state), output.c_str());
  960. }
  961. return 0;
  962. }
  963. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  964. if (!lua_interface)
  965. return 0;
  966. ZoneServer* zone = lua_interface->GetZone(state);
  967. if (zone) {
  968. lua_interface->SetStringValue(state, zone->GetZoneName());
  969. return 1;
  970. }
  971. return 0;
  972. }
  973. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  974. if (!lua_interface)
  975. return 0;
  976. ZoneServer* zone = lua_interface->GetZone(state);
  977. if (zone) {
  978. lua_interface->SetInt32Value(state, zone->GetZoneID());
  979. return 1;
  980. }
  981. return 0;
  982. }
  983. int EQ2Emu_lua_GetZone(lua_State* state) {
  984. if (!lua_interface)
  985. return 0;
  986. int32 zone_id = lua_interface->GetInt32Value(state);
  987. ZoneServer* zone = 0;
  988. if (zone_id > 0)
  989. zone = zone_list.Get(zone_id);
  990. else {
  991. string zone_name = lua_interface->GetStringValue(state);
  992. if (zone_name.length() > 0) {
  993. zone = zone_list.Get(zone_name.c_str());
  994. }
  995. else {
  996. Spawn* spawn = lua_interface->GetSpawn(state);
  997. if (spawn)
  998. zone = spawn->GetZone();
  999. }
  1000. }
  1001. if (zone) {
  1002. lua_interface->SetZoneValue(state, zone);
  1003. return 1;
  1004. }
  1005. return 0;
  1006. }
  1007. int EQ2Emu_lua_AddHate(lua_State* state) {
  1008. Spawn* entity = lua_interface->GetSpawn(state);
  1009. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1010. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1011. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1012. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1013. if (entity && entity->IsEntity() && amount != 0) {
  1014. if (luaspell) {
  1015. ZoneServer* zone = luaspell->caster->GetZone();
  1016. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1017. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1018. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1019. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1020. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1021. if (send_packet)
  1022. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1023. }
  1024. }
  1025. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1026. }
  1027. else if (npc && npc->IsNPC() && npc->GetZone())
  1028. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1029. }
  1030. return 0;
  1031. }
  1032. int EQ2Emu_lua_Zone(lua_State* state) {
  1033. if (!lua_interface)
  1034. return 0;
  1035. ZoneServer* zone = lua_interface->GetZone(state);
  1036. Spawn* player = lua_interface->GetSpawn(state, 2);
  1037. Client* client = 0;
  1038. if (player && player->IsPlayer())
  1039. client = player->GetZone()->GetClientBySpawn(player);
  1040. float x = lua_interface->GetFloatValue(state, 3);
  1041. float y = lua_interface->GetFloatValue(state, 4);
  1042. float z = lua_interface->GetFloatValue(state, 5);
  1043. float heading = lua_interface->GetFloatValue(state, 6);
  1044. if (zone && client) {
  1045. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1046. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1047. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1048. {
  1049. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1050. return 0;
  1051. }
  1052. if (x != 0 || y != 0 || z != 0) {
  1053. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1054. player->SetX(x);
  1055. player->SetY(y);
  1056. player->SetZ(z);
  1057. player->SetHeading(heading);
  1058. client->Zone(zone->GetZoneName(), false);
  1059. }
  1060. else
  1061. client->Zone(zone->GetZoneName());
  1062. }
  1063. else
  1064. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1065. return 0;
  1066. }
  1067. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1068. if (!lua_interface)
  1069. return 0;
  1070. Spawn* spawn = lua_interface->GetSpawn(state);
  1071. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1072. if (spawn && spawn2)
  1073. spawn->AddAllowAccessSpawn(spawn2);
  1074. return 0;
  1075. }
  1076. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1077. if (!lua_interface)
  1078. return 0;
  1079. Spawn* target = lua_interface->GetSpawn(state);
  1080. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1081. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1082. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1083. if (!target) {
  1084. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1085. return 0;
  1086. }
  1087. if (!target->IsEntity()) {
  1088. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1089. return 0;
  1090. }
  1091. if (spell_id <= 0) {
  1092. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1093. return 0;
  1094. }
  1095. if (caster && !caster->IsEntity()) {
  1096. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1097. return 0;
  1098. }
  1099. if (spell_tier == 0)
  1100. spell_tier = 1;
  1101. if (!caster)
  1102. caster = target;
  1103. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target);
  1104. return 0;
  1105. }
  1106. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1107. if (!lua_interface)
  1108. return 0;
  1109. Spawn* target = lua_interface->GetSpawn(state);
  1110. int32 target_id = 0;
  1111. if (target)
  1112. target_id = target->GetID();
  1113. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1114. if (!luaspell)
  1115. return 0;
  1116. Spawn* caster = luaspell->caster;
  1117. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1118. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1119. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1120. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1121. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1122. //lua_interface->ResetFunctionStack(state);
  1123. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1124. vector<int16> faction_req;
  1125. vector<int16> race_req;
  1126. int32 class_req = 0;
  1127. int32 i = 0;
  1128. int8 f = 0;
  1129. int8 r = 0;
  1130. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1131. if (class_id < 100) {
  1132. class_req += pow(2.0, double(class_id - 1));
  1133. }
  1134. else if (class_id > 100 && class_id < 1000) {
  1135. race_req.push_back(class_id);
  1136. r++;
  1137. }
  1138. else {
  1139. faction_req.push_back(class_id);
  1140. f++;
  1141. }
  1142. i++;
  1143. }
  1144. if (caster && caster->IsEntity()) {
  1145. bool race_match = false;
  1146. bool success = false;
  1147. luaspell->resisted = false;
  1148. if (luaspell->initial_target == target_id) {
  1149. int xxx = 0;
  1150. }
  1151. if (luaspell->targets.size() > 0) {
  1152. ZoneServer* zone = luaspell->caster->GetZone();
  1153. Spawn* target = 0;
  1154. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1155. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1156. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1157. if (race_req.size() > 0) {
  1158. for (int8 i = 0; i < race_req.size(); i++) {
  1159. int32 xxx = target->GetLuaRaceId();
  1160. if (target->GetLuaRaceId() == race_req[i]) {
  1161. race_match = true;
  1162. }
  1163. }
  1164. }
  1165. else
  1166. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1167. if (race_match == true) {
  1168. float distance = caster->GetDistance(target, true);
  1169. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1170. }
  1171. }
  1172. }
  1173. success = true;
  1174. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1175. }
  1176. else if (target) {
  1177. //check class and race/faction here
  1178. if (race_req.size() > 0) {
  1179. for (int8 i = 0; i < race_req.size(); i++) {
  1180. if (target->GetLuaRaceId() == race_req[i]) {
  1181. race_match = true;
  1182. }
  1183. }
  1184. }
  1185. else
  1186. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1187. if (race_match == true) {
  1188. float distance = caster->GetDistance(target, true);
  1189. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1190. success = true;
  1191. }
  1192. }
  1193. if (success) {
  1194. Spell* spell = luaspell->spell;
  1195. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1196. ((Player*)caster)->InCombat(true);
  1197. if (caster->GetZone())
  1198. caster->GetZone()->TriggerCharSheetTimer();
  1199. }
  1200. }
  1201. }
  1202. return 0;
  1203. }
  1204. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1205. if (!lua_interface)
  1206. return 0;
  1207. Spawn* spawn = lua_interface->GetSpawn(state);
  1208. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1209. lua_interface->ResetFunctionStack(state);
  1210. if (spawn && value != 0) {
  1211. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1212. spawn->SetPower(spawn->GetTotalPower());
  1213. else
  1214. spawn->SetPower(spawn->GetPower() + value);
  1215. }
  1216. return 0;
  1217. }
  1218. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1219. if (!lua_interface)
  1220. return 0;
  1221. Spawn* spawn = lua_interface->GetSpawn(state);
  1222. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1223. lua_interface->ResetFunctionStack(state);
  1224. if (spawn && value != 0) {
  1225. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1226. spawn->SetHP(spawn->GetTotalHP());
  1227. else
  1228. spawn->SetHP(spawn->GetHP() + value);
  1229. }
  1230. return 0;
  1231. }
  1232. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1233. if (!lua_interface)
  1234. return 0;
  1235. Spawn* spawn = lua_interface->GetSpawn(state);
  1236. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1237. lua_interface->ResetFunctionStack(state);
  1238. if (spawn && value != 0) {
  1239. spawn->SetPower(spawn->GetPower() + value);
  1240. if (value > spawn->GetTotalHPBase())
  1241. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1242. }
  1243. return 0;
  1244. }
  1245. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1246. if (!lua_interface)
  1247. return 0;
  1248. Spawn* spawn = lua_interface->GetSpawn(state);
  1249. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1250. lua_interface->ResetFunctionStack(state);
  1251. if (spawn && value != 0) {
  1252. spawn->SetHP(spawn->GetHP() + value);
  1253. if (value > spawn->GetTotalHPBase())
  1254. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1255. }
  1256. return 0;
  1257. }
  1258. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1259. if (!lua_interface)
  1260. return 0;
  1261. Spawn* spawn = lua_interface->GetSpawn(state);
  1262. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1263. lua_interface->ResetFunctionStack(state);
  1264. if (spawn && value > 0) {
  1265. spawn->SetHP(value);
  1266. if (value > spawn->GetTotalHPBase())
  1267. spawn->SetTotalHP(value);
  1268. }
  1269. return 0;
  1270. }
  1271. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1272. if (!lua_interface)
  1273. return 0;
  1274. Spawn* spawn = lua_interface->GetSpawn(state);
  1275. float value = lua_interface->GetFloatValue(state, 2);
  1276. lua_interface->ResetFunctionStack(state);
  1277. if (spawn && spawn->IsEntity() && value > 0)
  1278. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1279. if (spawn->IsPlayer())
  1280. ((Player*)spawn)->SetCharSheetChanged(true);
  1281. return 0;
  1282. }
  1283. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1284. if (!lua_interface)
  1285. return 0;
  1286. Spawn* spawn = lua_interface->GetSpawn(state);
  1287. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1288. lua_interface->ResetFunctionStack(state);
  1289. if (spawn && spawn->IsEntity() && value > 0)
  1290. ((Entity*)spawn)->SetTotalHPBase(value);
  1291. return 0;
  1292. }
  1293. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1294. if (!lua_interface)
  1295. return 0;
  1296. Spawn* spawn = lua_interface->GetSpawn(state);
  1297. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1298. lua_interface->ResetFunctionStack(state);
  1299. if (spawn && value > 0) {
  1300. spawn->SetPower(value);
  1301. if (value > spawn->GetTotalPowerBase())
  1302. spawn->SetTotalPower(value);
  1303. }
  1304. return 0;
  1305. }
  1306. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1307. if (!lua_interface)
  1308. return 0;
  1309. Spawn* spawn = lua_interface->GetSpawn(state);
  1310. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1311. lua_interface->ResetFunctionStack(state);
  1312. if (spawn && spawn->IsEntity() && value > 0)
  1313. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1314. return 0;
  1315. }
  1316. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1317. if (!lua_interface)
  1318. return 0;
  1319. Spawn* spawn = lua_interface->GetSpawn(state);
  1320. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1321. lua_interface->ResetFunctionStack(state);
  1322. if (spawn && spawn->IsEntity() && value > 0)
  1323. ((Entity*)spawn)->SetTotalPowerBase(value);
  1324. return 0;
  1325. }
  1326. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1327. if (!lua_interface)
  1328. return 0;
  1329. Spawn* spawn = lua_interface->GetSpawn(state);
  1330. float x = lua_interface->GetFloatValue(state, 2);
  1331. float y = lua_interface->GetFloatValue(state, 3);
  1332. float z = lua_interface->GetFloatValue(state, 4);
  1333. float heading = lua_interface->GetFloatValue(state, 5);
  1334. lua_interface->ResetFunctionStack(state);
  1335. if (spawn) {
  1336. spawn->SetX(x);
  1337. spawn->SetY(y);
  1338. spawn->SetZ(z);
  1339. if (heading != 0)
  1340. spawn->SetHeading(heading);
  1341. spawn->SetSpawnOrigX(spawn->GetX());
  1342. spawn->SetSpawnOrigY(spawn->GetY());
  1343. spawn->SetSpawnOrigZ(spawn->GetZ());
  1344. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1345. if (spawn->IsPlayer()) {
  1346. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1347. if (client) {
  1348. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1349. client->QueuePacket(packet);
  1350. }
  1351. }
  1352. }
  1353. return 0;
  1354. }
  1355. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1356. if (!lua_interface)
  1357. return 0;
  1358. Spawn* spawn = lua_interface->GetSpawn(state);
  1359. float value = lua_interface->GetFloatValue(state, 2);
  1360. lua_interface->ResetFunctionStack(state);
  1361. if (spawn) {
  1362. spawn->SetHeading(value);
  1363. if (spawn->IsPlayer()) {
  1364. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1365. if (client) {
  1366. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1367. client->QueuePacket(packet);
  1368. }
  1369. }
  1370. }
  1371. return 0;
  1372. }
  1373. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1374. if (!lua_interface)
  1375. return 0;
  1376. Spawn* spawn = lua_interface->GetSpawn(state);
  1377. int16 value = lua_interface->GetInt16Value(state, 2);
  1378. lua_interface->ResetFunctionStack(state);
  1379. if (spawn)
  1380. spawn->SetModelType(value);
  1381. return 0;
  1382. }
  1383. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1384. if (!lua_interface)
  1385. return 0;
  1386. Spawn* spawn = lua_interface->GetSpawn(state);
  1387. int8 value = lua_interface->GetInt8Value(state, 2);
  1388. lua_interface->ResetFunctionStack(state);
  1389. if (spawn) {
  1390. if (spawn->IsPlayer())
  1391. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1392. else
  1393. spawn->SetAdventureClass(value);
  1394. }
  1395. return 0;
  1396. }
  1397. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1398. if (!lua_interface)
  1399. return 0;
  1400. Spawn* spawn = lua_interface->GetSpawn(state);
  1401. int8 value = lua_interface->GetInt8Value(state, 2);
  1402. lua_interface->ResetFunctionStack(state);
  1403. if (spawn) {
  1404. spawn->SetTradeskillClass(value);
  1405. if (spawn->IsEntity()) {
  1406. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class1 = classes.GetTSBaseClass(spawn->GetTradeskillClass());
  1407. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class2 = classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass());
  1408. ((Entity*)spawn)->GetInfoStruct()->tradeskill_class3 = spawn->GetTradeskillClass();
  1409. }
  1410. if (spawn->IsPlayer())
  1411. ((Player*)spawn)->SetCharSheetChanged(true);
  1412. }
  1413. return 0;
  1414. }
  1415. int EQ2Emu_lua_SetMount(lua_State* state) {
  1416. if (!lua_interface)
  1417. return 0;
  1418. Spawn* spawn = lua_interface->GetSpawn(state);
  1419. int16 value = lua_interface->GetInt16Value(state, 2);
  1420. if (spawn && spawn->IsEntity()) {
  1421. ((Entity*)spawn)->SetMount(value);
  1422. EQ2_Color color;
  1423. color.red = 255;
  1424. color.green = 255;
  1425. color.blue = 255;
  1426. ((Entity*)spawn)->SetMountColor(&color);
  1427. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1428. }
  1429. return 0;
  1430. }
  1431. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1432. if (!lua_interface)
  1433. return 0;
  1434. Spawn* spawn = lua_interface->GetSpawn(state);
  1435. EQ2_Color mount_color;
  1436. EQ2_Color saddle_color;
  1437. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1438. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1439. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1440. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1441. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1442. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1443. if (spawn && spawn->IsEntity()) {
  1444. ((Entity*)spawn)->SetMountColor(&mount_color);
  1445. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1446. }
  1447. return 0;
  1448. }
  1449. int EQ2Emu_lua_GetMount(lua_State* state) {
  1450. if (!lua_interface)
  1451. return 0;
  1452. Spawn* spawn = lua_interface->GetSpawn(state);
  1453. if (spawn && spawn->IsEntity()) {
  1454. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1455. return 1;
  1456. }
  1457. return 0;
  1458. }
  1459. int EQ2Emu_lua_GetRace(lua_State* state) {
  1460. if (!lua_interface)
  1461. return 0;
  1462. Spawn* spawn = lua_interface->GetSpawn(state);
  1463. if (spawn)
  1464. {
  1465. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  1466. lua_interface->SetInt32Value(state, spawn->GetRace());
  1467. return 1;
  1468. }
  1469. return 0;
  1470. }
  1471. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  1472. if (!lua_interface)
  1473. return 0;
  1474. Spawn* spawn = lua_interface->GetSpawn(state);
  1475. if (spawn) {
  1476. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  1477. return 1;
  1478. }
  1479. return 0;
  1480. }
  1481. int EQ2Emu_lua_GetClass(lua_State* state) {
  1482. Spawn* spawn = lua_interface->GetSpawn(state);
  1483. if (spawn) {
  1484. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  1485. return 1;
  1486. }
  1487. return 0;
  1488. }
  1489. int EQ2Emu_lua_GetClassName(lua_State* state) {
  1490. Spawn* spawn = lua_interface->GetSpawn(state);
  1491. if (spawn) {
  1492. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  1493. return 1;
  1494. }
  1495. return 0;
  1496. }
  1497. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  1498. if (!lua_interface)
  1499. return 0;
  1500. Spawn* spawn = lua_interface->GetSpawn(state);
  1501. float value = lua_interface->GetFloatValue(state, 2);
  1502. lua_interface->ResetFunctionStack(state);
  1503. if (spawn) {
  1504. spawn->SetSpeed(value);
  1505. ((Entity*)spawn)->SetSpeed(value);
  1506. if (spawn->IsPlayer()) {
  1507. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1508. if (client) {
  1509. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  1510. if (packet) {
  1511. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  1512. packet->setDataByName("speed", value);
  1513. packet->setDataByName("size", 0.51);
  1514. EQ2Packet* app = packet->serialize();
  1515. client->QueuePacket(app);
  1516. safe_delete(packet);
  1517. }
  1518. }
  1519. }
  1520. }
  1521. return 0;
  1522. }
  1523. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  1524. if (!lua_interface)
  1525. return 0;
  1526. Spawn* spawn = lua_interface->GetSpawn(state);
  1527. const int16 type = lua_interface->GetInt16Value(state, 2);
  1528. const float value = lua_interface->GetFloatValue(state, 3);
  1529. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1530. int64 class_req = 0;
  1531. int32 class_id = 0;
  1532. vector<int16> faction_req;
  1533. vector<int16> race_req;
  1534. int32 i = 0;
  1535. int8 f = 0;
  1536. int8 r = 0;
  1537. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1538. if (class_id < 100) {
  1539. class_req += pow(2.0, double(class_id - 1));
  1540. }
  1541. else if (class_id > 100 && class_id < 1000) {
  1542. race_req.push_back(class_id);
  1543. r++;
  1544. }
  1545. else {
  1546. faction_req.push_back(class_id);
  1547. f++;
  1548. }
  1549. i++;
  1550. }
  1551. if (value != 0 && type >= 0) {
  1552. if (luaspell && luaspell->spell && luaspell->caster) {
  1553. ZoneServer* zone = luaspell->caster->GetZone();
  1554. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1555. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1556. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  1557. if (target) {
  1558. if (target->IsPlayer()) {
  1559. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1560. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  1561. if (((Player*)target)->GetGroupMemberInfo())
  1562. ((Player*)target)->UpdateGroupMemberInfo();
  1563. ((Player*)target)->SetCharSheetChanged(true);
  1564. }
  1565. else if (target->IsNPC())
  1566. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1567. else
  1568. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  1569. }
  1570. }
  1571. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1572. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1573. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1574. }
  1575. else if (spawn && spawn->IsEntity()) {
  1576. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1577. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  1578. if (spawn->IsPlayer())
  1579. ((Player*)spawn)->SetCharSheetChanged(true);
  1580. }
  1581. else
  1582. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  1583. }
  1584. else
  1585. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  1586. return 0;
  1587. }
  1588. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  1589. if (!lua_interface)
  1590. return 0;
  1591. Spawn* spawn = lua_interface->GetSpawn(state);
  1592. int16 type = lua_interface->GetInt16Value(state, 2);
  1593. sint32 value = lua_interface->GetSInt32Value(state, 3);
  1594. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1595. if (!spawn) {
  1596. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  1597. return 0;
  1598. }
  1599. if (!spawn->IsEntity()) {
  1600. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  1601. return 0;
  1602. }
  1603. if (value == 0) {
  1604. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  1605. return 0;
  1606. }
  1607. if (!luaspell || !luaspell->spell) {
  1608. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  1609. return 0;
  1610. }
  1611. int32 class_req = 0;
  1612. vector<int16> faction_req;
  1613. vector<int16> race_req;
  1614. int32 class_id = 0;
  1615. int32 i = 0;
  1616. int8 f = 0;
  1617. int8 r = 0;
  1618. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  1619. if (class_id < 100) {
  1620. class_req += pow(2.0, double(class_id - 1));
  1621. }
  1622. else if (class_id > 100 && class_id < 1000) {
  1623. race_req.push_back(class_id);
  1624. r++;
  1625. }
  1626. else {
  1627. faction_req.push_back(class_id);
  1628. f++;
  1629. }
  1630. i++;
  1631. }
  1632. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  1633. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  1634. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  1635. if (spawn->IsPlayer())
  1636. ((Player*)spawn)->SetCharSheetChanged(true);
  1637. return 0;
  1638. }
  1639. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  1640. if (!lua_interface)
  1641. return 0;
  1642. Spawn* spawn = lua_interface->GetSpawn(state);
  1643. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1644. if (luaspell && luaspell->spell) {
  1645. ZoneServer* zone = luaspell->caster->GetZone();
  1646. Spawn* target = 0;
  1647. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1648. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1649. target = zone->GetSpawnByID(luaspell->targets[i]);
  1650. if (target && target->IsEntity()) {
  1651. ((Entity*)target)->RemoveSpellBonus(luaspell);
  1652. if (target->IsPlayer())
  1653. ((Player*)target)->SetCharSheetChanged(true);
  1654. }
  1655. }
  1656. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1657. }
  1658. else if (spawn && spawn->IsEntity()) {
  1659. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  1660. if (spawn->IsPlayer())
  1661. ((Player*)spawn)->SetCharSheetChanged(true);
  1662. }
  1663. return 0;
  1664. }
  1665. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  1666. if (!lua_interface)
  1667. return 0;
  1668. Spawn* spawn = lua_interface->GetSpawn(state);
  1669. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  1670. float value = lua_interface->GetFloatValue(state, 3);
  1671. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1672. if (value != 0) {
  1673. int32 spell_id = 0;
  1674. if (luaspell && luaspell->spell && luaspell->caster) {
  1675. spell_id = luaspell->spell->GetSpellID();
  1676. ZoneServer* zone = luaspell->caster->GetZone();
  1677. Spawn* target = 0;
  1678. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1679. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1680. target = zone->GetSpawnByID(luaspell->targets[i]);
  1681. if (target && target->Alive()) {
  1682. if (target->IsPlayer()) {
  1683. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  1684. Client* client = target->GetZone()->GetClientBySpawn(target);
  1685. if (client) {
  1686. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  1687. if (packet)
  1688. client->QueuePacket(packet);
  1689. }
  1690. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  1691. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  1692. }
  1693. else if (target->IsNPC()) {
  1694. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  1695. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  1696. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  1697. }
  1698. else
  1699. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  1700. }
  1701. }
  1702. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1703. }
  1704. else if (spawn) {
  1705. if (spawn->IsPlayer()) {
  1706. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  1707. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1708. if (client) {
  1709. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  1710. if (packet)
  1711. client->QueuePacket(packet);
  1712. }
  1713. }
  1714. else if (spawn->IsNPC())
  1715. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  1716. else
  1717. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  1718. }
  1719. }
  1720. else
  1721. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  1722. return 0;
  1723. }
  1724. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  1725. if (!lua_interface)
  1726. return 0;
  1727. Spawn* spawn = lua_interface->GetSpawn(state);
  1728. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1729. if (spawn && spawn->IsPlayer()) {
  1730. int32 spell_id = 0;
  1731. if (luaspell && luaspell->spell) {
  1732. spell_id = luaspell->spell->GetSpellID();
  1733. ZoneServer* zone = luaspell->caster->GetZone();
  1734. Spawn* target = 0;
  1735. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1736. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1737. target = zone->GetSpawnByID(luaspell->targets[i]);
  1738. if (target) {
  1739. if (target->IsPlayer()) {
  1740. ((Player*)target)->RemoveSkillBonus(spell_id);
  1741. Client* client = target->GetZone()->GetClientBySpawn(target);
  1742. if (client) {
  1743. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  1744. if (packet)
  1745. client->QueuePacket(packet);
  1746. }
  1747. }
  1748. else if (target->IsNPC())
  1749. ((NPC*)target)->RemoveSkillBonus(spell_id);
  1750. else
  1751. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  1752. }
  1753. }
  1754. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1755. }
  1756. else if (spawn) {
  1757. if (spawn->IsPlayer()) {
  1758. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  1759. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1760. if (client) {
  1761. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  1762. if (packet)
  1763. client->QueuePacket(packet);
  1764. }
  1765. }
  1766. else if (spawn->IsNPC())
  1767. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  1768. else
  1769. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  1770. }
  1771. }
  1772. return 0;
  1773. }
  1774. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  1775. if (!lua_interface)
  1776. return 0;
  1777. Spawn* spawn = lua_interface->GetSpawn(state);
  1778. int8 type = lua_interface->GetInt32Value(state, 2);
  1779. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  1780. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1781. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  1782. ZoneServer* zone = luaspell->caster->GetZone();
  1783. Spawn* target = 0;
  1784. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1785. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1786. target = zone->GetSpawnByID(luaspell->targets[i]);
  1787. if (target && target->IsEntity()) {
  1788. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  1789. ((Entity*)target)->AddMezSpell(luaspell);
  1790. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  1791. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  1792. if (target->IsNPC())
  1793. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1794. }
  1795. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  1796. ((Entity*)target)->AddStifleSpell(luaspell);
  1797. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  1798. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  1799. if (target->IsNPC())
  1800. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1801. }
  1802. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  1803. ((Entity*)target)->AddDazeSpell(luaspell);
  1804. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  1805. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  1806. if (target->IsNPC())
  1807. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1808. }
  1809. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  1810. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  1811. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  1812. ((Entity*)target)->AddStunSpell(luaspell);
  1813. if (target->IsNPC())
  1814. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1815. }
  1816. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  1817. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  1818. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  1819. ((Entity*)target)->AddRootSpell(luaspell);
  1820. if (target->IsNPC())
  1821. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1822. }
  1823. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  1824. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  1825. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  1826. ((Entity*)target)->AddFearSpell(luaspell);
  1827. if (target->IsNPC())
  1828. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1829. }
  1830. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  1831. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  1832. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  1833. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  1834. }
  1835. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  1836. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  1837. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  1838. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  1839. }
  1840. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  1841. ((Entity*)target)->AddSnareSpell(luaspell);
  1842. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  1843. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  1844. if (target->IsNPC())
  1845. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  1846. }
  1847. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  1848. ((Entity*)target)->AddFlightSpell(luaspell);
  1849. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  1850. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  1851. }
  1852. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  1853. ((Entity*)target)->AddGlideSpell(luaspell);
  1854. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  1855. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  1856. }
  1857. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  1858. ((Entity*)target)->AddSafefallSpell(luaspell);
  1859. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  1860. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  1861. }
  1862. else
  1863. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  1864. }
  1865. else
  1866. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  1867. }
  1868. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1869. }
  1870. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  1871. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  1872. ((Entity*)spawn)->AddMezSpell(luaspell);
  1873. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  1874. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  1875. }
  1876. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  1877. ((Entity*)spawn)->AddStifleSpell(luaspell);
  1878. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  1879. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  1880. }
  1881. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  1882. ((Entity*)spawn)->AddDazeSpell(luaspell);
  1883. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  1884. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  1885. }
  1886. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  1887. ((Entity*)spawn)->AddStunSpell(luaspell);
  1888. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  1889. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  1890. }
  1891. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  1892. ((Entity*)spawn)->AddRootSpell(luaspell);
  1893. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  1894. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  1895. }
  1896. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  1897. ((Entity*)spawn)->AddFearSpell(luaspell);
  1898. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  1899. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  1900. }
  1901. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  1902. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  1903. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  1904. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  1905. }
  1906. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  1907. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  1908. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  1909. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  1910. }
  1911. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  1912. ((Entity*)spawn)->AddSnareSpell(luaspell);
  1913. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  1914. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  1915. }
  1916. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  1917. ((Entity*)spawn)->AddFlightSpell(luaspell);
  1918. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  1919. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  1920. }
  1921. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  1922. ((Entity*)spawn)->AddGlideSpell(luaspell);
  1923. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  1924. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  1925. }
  1926. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  1927. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  1928. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  1929. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  1930. }
  1931. else
  1932. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  1933. }
  1934. else
  1935. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  1936. return 0;
  1937. }
  1938. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  1939. if (!lua_interface)
  1940. return 0;
  1941. Spawn* spawn = lua_interface->GetSpawn(state);
  1942. int8 type = lua_interface->GetInt8Value(state, 2);
  1943. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  1944. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1945. if (spawn && spawn->IsEntity()) {
  1946. if (!only_remove_spawn && luaspell && luaspell->spell) {
  1947. ZoneServer* zone = luaspell->caster->GetZone();
  1948. Spawn* target = 0;
  1949. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1950. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1951. target = zone->GetSpawnByID(luaspell->targets[i]);
  1952. if (target) {
  1953. if (type == CONTROL_EFFECT_TYPE_MEZ)
  1954. ((Entity*)target)->RemoveMezSpell(luaspell);
  1955. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  1956. ((Entity*)target)->RemoveStifleSpell(luaspell);
  1957. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  1958. ((Entity*)target)->RemoveDazeSpell(luaspell);
  1959. else if (type == CONTROL_EFFECT_TYPE_STUN)
  1960. ((Entity*)target)->RemoveStunSpell(luaspell);
  1961. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  1962. ((Entity*)target)->RemoveRootSpell(luaspell);
  1963. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  1964. ((Entity*)target)->RemoveFearSpell(luaspell);
  1965. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  1966. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  1967. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  1968. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  1969. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  1970. ((Entity*)target)->RemoveSnareSpell(luaspell);
  1971. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  1972. ((Entity*)target)->RemoveFlightSpell(luaspell);
  1973. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  1974. ((Entity*)target)->RemoveGlideSpell(luaspell);
  1975. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  1976. ((Entity*)target)->RemoveGlideSpell(luaspell);
  1977. else
  1978. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  1979. }
  1980. }
  1981. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1982. }
  1983. else if (only_remove_spawn) {
  1984. if (type == CONTROL_EFFECT_TYPE_MEZ)
  1985. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  1986. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  1987. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  1988. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  1989. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  1990. else if (type == CONTROL_EFFECT_TYPE_STUN)
  1991. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  1992. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  1993. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  1994. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  1995. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  1996. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  1997. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  1998. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  1999. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2000. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2001. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2002. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2003. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2004. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2005. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2006. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2007. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2008. else
  2009. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2010. }
  2011. }
  2012. return 0;
  2013. }
  2014. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2015. if (!lua_interface)
  2016. return 0;
  2017. Spawn* spawn = lua_interface->GetSpawn(state);
  2018. int16 value = lua_interface->GetInt16Value(state, 2);
  2019. if (spawn && spawn->IsEntity()) {
  2020. ((Entity*)spawn)->GetInfoStruct()->intel_base = value;
  2021. if (spawn->IsPlayer())
  2022. ((Player*)spawn)->SetCharSheetChanged(true);
  2023. }
  2024. return 0;
  2025. }
  2026. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2027. if (!lua_interface)
  2028. return 0;
  2029. Spawn* spawn = lua_interface->GetSpawn(state);
  2030. int16 value = lua_interface->GetInt16Value(state, 2);
  2031. if (spawn && spawn->IsEntity()) {
  2032. ((Entity*)spawn)->GetInfoStruct()->agi_base = value;
  2033. if (spawn->IsPlayer())
  2034. ((Player*)spawn)->SetCharSheetChanged(true);
  2035. }
  2036. return 0;
  2037. }
  2038. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2039. if (!lua_interface)
  2040. return 0;
  2041. Spawn* spawn = lua_interface->GetSpawn(state);
  2042. int16 value = lua_interface->GetInt16Value(state, 2);
  2043. if (spawn && spawn->IsEntity()) {
  2044. ((Entity*)spawn)->GetInfoStruct()->wis_base = value;
  2045. if (spawn->IsPlayer())
  2046. ((Player*)spawn)->SetCharSheetChanged(true);
  2047. }
  2048. return 0;
  2049. }
  2050. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2051. if (!lua_interface)
  2052. return 0;
  2053. Spawn* spawn = lua_interface->GetSpawn(state);
  2054. int16 value = lua_interface->GetInt16Value(state, 2);
  2055. if (spawn && spawn->IsEntity()) {
  2056. ((Entity*)spawn)->GetInfoStruct()->sta_base = value;
  2057. if (spawn->IsPlayer())
  2058. ((Player*)spawn)->SetCharSheetChanged(true);
  2059. }
  2060. return 0;
  2061. }
  2062. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2063. if (!lua_interface)
  2064. return 0;
  2065. Spawn* spawn = lua_interface->GetSpawn(state);
  2066. int16 value = lua_interface->GetInt16Value(state, 2);
  2067. if (spawn && spawn->IsEntity()) {
  2068. ((Entity*)spawn)->GetInfoStruct()->str_base = value;
  2069. if (spawn->IsPlayer())
  2070. ((Player*)spawn)->SetCharSheetChanged(true);
  2071. }
  2072. return 0;
  2073. }
  2074. int EQ2Emu_lua_SetInt(lua_State* state) {
  2075. if (!lua_interface)
  2076. return 0;
  2077. Spawn* spawn = lua_interface->GetSpawn(state);
  2078. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2079. if (spawn && spawn->IsEntity()) {
  2080. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2081. if (spawn->IsPlayer())
  2082. ((Player*)spawn)->SetCharSheetChanged(true);
  2083. }
  2084. return 0;
  2085. }
  2086. int EQ2Emu_lua_SetWis(lua_State* state) {
  2087. if (!lua_interface)
  2088. return 0;
  2089. Spawn* spawn = lua_interface->GetSpawn(state);
  2090. float value = lua_interface->GetFloatValue(state, 2);
  2091. if (spawn && spawn->IsEntity()) {
  2092. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2093. if (spawn->IsPlayer())
  2094. ((Player*)spawn)->SetCharSheetChanged(true);
  2095. }
  2096. return 0;
  2097. }
  2098. int EQ2Emu_lua_SetSta(lua_State* state) {
  2099. if (!lua_interface)
  2100. return 0;
  2101. Spawn* spawn = lua_interface->GetSpawn(state);
  2102. float value = lua_interface->GetFloatValue(state, 2);
  2103. if (spawn && spawn->IsEntity()) {
  2104. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2105. if (spawn->IsPlayer())
  2106. ((Player*)spawn)->SetCharSheetChanged(true);
  2107. }
  2108. return 0;
  2109. }
  2110. int EQ2Emu_lua_SetStr(lua_State* state) {
  2111. if (!lua_interface)
  2112. return 0;
  2113. Spawn* spawn = lua_interface->GetSpawn(state);
  2114. float value = lua_interface->GetFloatValue(state, 2);
  2115. if (spawn && spawn->IsEntity()) {
  2116. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2117. if (spawn->IsPlayer())
  2118. ((Player*)spawn)->SetCharSheetChanged(true);
  2119. }
  2120. return 0;
  2121. }
  2122. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2123. if (!lua_interface)
  2124. return 0;
  2125. Spawn* spawn = lua_interface->GetSpawn(state);
  2126. float value = lua_interface->GetFloatValue(state, 2);
  2127. if (spawn && spawn->IsEntity()) {
  2128. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2129. if (spawn->IsPlayer())
  2130. ((Player*)spawn)->SetCharSheetChanged(true);
  2131. }
  2132. return 0;
  2133. }
  2134. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2135. if (!lua_interface)
  2136. return 0;
  2137. Spawn* spawn = lua_interface->GetSpawn(state);
  2138. if (spawn) {
  2139. lua_interface->SetInt32Value(state, spawn->GetHP());
  2140. return 1;
  2141. }
  2142. return 0;
  2143. }
  2144. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2145. if (!lua_interface)
  2146. return 0;
  2147. Spawn* spawn = lua_interface->GetSpawn(state);
  2148. if (spawn) {
  2149. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2150. return 1;
  2151. }
  2152. return 0;
  2153. }
  2154. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2155. if (!lua_interface)
  2156. return 0;
  2157. Spawn* spawn = lua_interface->GetSpawn(state);
  2158. if (spawn) {
  2159. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2160. return 1;
  2161. }
  2162. return 0;
  2163. }
  2164. int EQ2Emu_lua_GetName(lua_State* state) {
  2165. if (!lua_interface)
  2166. return 0;
  2167. Spawn* spawn = lua_interface->GetSpawn(state);
  2168. if (spawn) {
  2169. lua_interface->SetStringValue(state, spawn->GetName());
  2170. return 1;
  2171. }
  2172. return 0;
  2173. }
  2174. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2175. Spawn* spawn = lua_interface->GetSpawn(state);
  2176. if (spawn) {
  2177. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2178. return 1;
  2179. }
  2180. return 0;
  2181. }
  2182. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2183. if (!lua_interface)
  2184. return 0;
  2185. Spawn* spawn = lua_interface->GetSpawn(state);
  2186. if (spawn) {
  2187. lua_interface->SetInt32Value(state, spawn->GetPower());
  2188. return 1;
  2189. }
  2190. return 0;
  2191. }
  2192. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2193. if (!lua_interface)
  2194. return 0;
  2195. Spawn* spawn = lua_interface->GetSpawn(state);
  2196. if (spawn) {
  2197. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2198. return 1;
  2199. }
  2200. return 0;
  2201. }
  2202. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2203. if (!lua_interface)
  2204. return 0;
  2205. Spawn* spawn = lua_interface->GetSpawn(state);
  2206. if (spawn) {
  2207. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2208. return 1;
  2209. }
  2210. return 0;
  2211. }
  2212. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2213. if (!lua_interface)
  2214. return 0;
  2215. Spawn* spawn = lua_interface->GetSpawn(state);
  2216. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2217. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2218. if (spawn && spawn2) {
  2219. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2220. lua_interface->SetFloatValue(state, distance);
  2221. return 1;
  2222. }
  2223. return 0;
  2224. }
  2225. int EQ2Emu_lua_GetX(lua_State* state) {
  2226. if (!lua_interface)
  2227. return 0;
  2228. Spawn* spawn = lua_interface->GetSpawn(state);
  2229. if (spawn) {
  2230. lua_interface->SetFloatValue(state, spawn->GetX());
  2231. return 1;
  2232. }
  2233. return 0;
  2234. }
  2235. int EQ2Emu_lua_GetY(lua_State* state) {
  2236. if (!lua_interface)
  2237. return 0;
  2238. Spawn* spawn = lua_interface->GetSpawn(state);
  2239. if (spawn) {
  2240. lua_interface->SetFloatValue(state, spawn->GetY());
  2241. return 1;
  2242. }
  2243. return 0;
  2244. }
  2245. int EQ2Emu_lua_GetZ(lua_State* state) {
  2246. if (!lua_interface)
  2247. return 0;
  2248. Spawn* spawn = lua_interface->GetSpawn(state);
  2249. if (spawn) {
  2250. lua_interface->SetFloatValue(state, spawn->GetZ());
  2251. return 1;
  2252. }
  2253. return 0;
  2254. }
  2255. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2256. if (!lua_interface)
  2257. return 0;
  2258. Spawn* spawn = lua_interface->GetSpawn(state);
  2259. if (spawn) {
  2260. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2261. return 1;
  2262. }
  2263. return 0;
  2264. }
  2265. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2266. if (!lua_interface)
  2267. return 0;
  2268. Spawn* spawn = lua_interface->GetSpawn(state);
  2269. if (spawn) {
  2270. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2271. return 1;
  2272. }
  2273. return 0;
  2274. }
  2275. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2276. if (!lua_interface)
  2277. return 0;
  2278. Spawn* spawn = lua_interface->GetSpawn(state);
  2279. if (spawn) {
  2280. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2281. return 1;
  2282. }
  2283. return 0;
  2284. }
  2285. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2286. if (!lua_interface)
  2287. return 0;
  2288. Spawn* spawn = lua_interface->GetSpawn(state);
  2289. if (spawn && spawn->IsEntity()) {
  2290. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2291. return 1;
  2292. }
  2293. return 0;
  2294. }
  2295. int EQ2Emu_lua_GetInt(lua_State* state) {
  2296. if (!lua_interface)
  2297. return 0;
  2298. Spawn* spawn = lua_interface->GetSpawn(state);
  2299. if (spawn && spawn->IsEntity()) {
  2300. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2301. return 1;
  2302. }
  2303. return 0;
  2304. }
  2305. int EQ2Emu_lua_GetWis(lua_State* state) {
  2306. if (!lua_interface)
  2307. return 0;
  2308. Spawn* spawn = lua_interface->GetSpawn(state);
  2309. if (spawn && spawn->IsEntity()) {
  2310. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2311. return 1;
  2312. }
  2313. return 0;
  2314. }
  2315. int EQ2Emu_lua_GetSta(lua_State* state) {
  2316. if (!lua_interface)
  2317. return 0;
  2318. Spawn* spawn = lua_interface->GetSpawn(state);
  2319. if (spawn && spawn->IsEntity()) {
  2320. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2321. return 1;
  2322. }
  2323. return 0;
  2324. }
  2325. int EQ2Emu_lua_GetStr(lua_State* state) {
  2326. if (!lua_interface)
  2327. return 0;
  2328. Spawn* spawn = lua_interface->GetSpawn(state);
  2329. if (spawn && spawn->IsEntity()) {
  2330. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2331. return 1;
  2332. }
  2333. return 0;
  2334. }
  2335. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2336. if (!lua_interface)
  2337. return 0;
  2338. Spawn* spawn = lua_interface->GetSpawn(state);
  2339. if (spawn && spawn->IsEntity()) {
  2340. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2341. return 1;
  2342. }
  2343. return 0;
  2344. }
  2345. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2346. if (!lua_interface)
  2347. return 0;
  2348. Spawn* spawn = lua_interface->GetSpawn(state);
  2349. if (spawn && spawn->IsEntity()) {
  2350. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2351. return 1;
  2352. }
  2353. return 0;
  2354. }
  2355. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  2356. if (!lua_interface)
  2357. return 0;
  2358. Spawn* spawn = lua_interface->GetSpawn(state);
  2359. if (spawn && spawn->IsEntity()) {
  2360. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  2361. return 1;
  2362. }
  2363. return 0;
  2364. }
  2365. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  2366. if (!lua_interface)
  2367. return 0;
  2368. Spawn* spawn = lua_interface->GetSpawn(state);
  2369. if (spawn && spawn->IsEntity()) {
  2370. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  2371. return 1;
  2372. }
  2373. return 0;
  2374. }
  2375. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  2376. if (!lua_interface)
  2377. return 0;
  2378. Spawn* spawn = lua_interface->GetSpawn(state);
  2379. if (spawn && spawn->IsEntity()) {
  2380. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  2381. return 1;
  2382. }
  2383. return 0;
  2384. }
  2385. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  2386. if (!lua_interface)
  2387. return 0;
  2388. Spawn* spawn = lua_interface->GetSpawn(state);
  2389. if (spawn && spawn->IsEntity()) {
  2390. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  2391. return 1;
  2392. }
  2393. return 0;
  2394. }
  2395. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  2396. if (!lua_interface)
  2397. return 0;
  2398. Spawn* player = lua_interface->GetSpawn(state);
  2399. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2400. int32 step = lua_interface->GetInt32Value(state, 3);
  2401. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2402. Client* client = player->GetZone()->GetClientBySpawn(player);
  2403. if (client)
  2404. client->AddPendingQuestUpdate(quest_id, step);
  2405. }
  2406. return 0;
  2407. }
  2408. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  2409. Spawn* player = lua_interface->GetSpawn(state);
  2410. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2411. int32 step = lua_interface->GetInt32Value(state, 3);
  2412. int32 progress = lua_interface->GetInt32Value(state, 4);
  2413. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2414. Client* client = player->GetZone()->GetClientBySpawn(player);
  2415. if (client)
  2416. client->AddPendingQuestUpdate(quest_id, step, progress);
  2417. }
  2418. return 0;
  2419. }
  2420. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  2421. if (!lua_interface)
  2422. return 0;
  2423. Spawn* player = lua_interface->GetSpawn(state);
  2424. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2425. if (player && player->IsPlayer() && quest_id > 0) {
  2426. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  2427. return 1;
  2428. }
  2429. return 0;
  2430. }
  2431. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  2432. if (!lua_interface)
  2433. return 0;
  2434. Spawn* player = lua_interface->GetSpawn(state);
  2435. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2436. int32 step_id = lua_interface->GetInt32Value(state, 3);
  2437. if (player && player->IsPlayer() && quest_id > 0) {
  2438. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  2439. return 1;
  2440. }
  2441. return 0;
  2442. }
  2443. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  2444. if (!lua_interface)
  2445. return 0;
  2446. Spawn* player = lua_interface->GetSpawn(state);
  2447. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2448. if (player && player->IsPlayer() && quest_id > 0) {
  2449. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  2450. return 1;
  2451. }
  2452. return 0;
  2453. }
  2454. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  2455. if (!lua_interface)
  2456. return 0;
  2457. Quest* quest = lua_interface->GetQuest(state);
  2458. string name = lua_interface->GetStringValue(state, 2);
  2459. string type = lua_interface->GetStringValue(state, 3);
  2460. string zone = lua_interface->GetStringValue(state, 4);
  2461. int16 level = lua_interface->GetInt16Value(state, 5);
  2462. string description = lua_interface->GetStringValue(state, 6);
  2463. bool load = true;
  2464. if (!quest) {
  2465. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2466. load = false;
  2467. }
  2468. if (load && name.length() == 0) {
  2469. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  2470. load = false;
  2471. }
  2472. if (load && type.length() == 0) {
  2473. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2474. load = false;
  2475. }
  2476. if (load && zone.length() == 0) {
  2477. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2478. load = false;
  2479. }
  2480. if (load && description.length() == 0) {
  2481. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2482. load = false;
  2483. }
  2484. if (load && level == 0) {
  2485. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  2486. load = false;
  2487. }
  2488. if (load)
  2489. quest->RegisterQuest(name, type, zone, level, description);
  2490. return 0;
  2491. }
  2492. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  2493. if (!lua_interface)
  2494. return 0;
  2495. Quest* quest = lua_interface->GetQuest(state);
  2496. if (quest) {
  2497. int8 level = lua_interface->GetInt16Value(state, 2);
  2498. quest->SetPrereqLevel(level);
  2499. }
  2500. return 0;
  2501. }
  2502. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  2503. if (!lua_interface)
  2504. return 0;
  2505. Quest* quest = lua_interface->GetQuest(state);
  2506. if (quest) {
  2507. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2508. quest->AddPrereqQuest(quest_id);
  2509. }
  2510. return 0;
  2511. }
  2512. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  2513. if (!lua_interface)
  2514. return 0;
  2515. Quest* quest = lua_interface->GetQuest(state);
  2516. if (quest) {
  2517. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2518. int8 quantity = lua_interface->GetInt32Value(state, 3);
  2519. if (quantity == 0)
  2520. quantity = 1;
  2521. Item* master_item = master_item_list.GetItem(item_id);
  2522. if (master_item) {
  2523. Item* item = new Item(master_item);
  2524. item->details.count = quantity;
  2525. quest->AddPrereqItem(item);
  2526. }
  2527. }
  2528. return 0;
  2529. }
  2530. int EQ2Emu_lua_HasQuest(lua_State* state) {
  2531. if (!lua_interface)
  2532. return 0;
  2533. Spawn* player = lua_interface->GetSpawn(state);
  2534. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2535. if (player && player->IsPlayer() && quest_id > 0) {
  2536. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  2537. return 1;
  2538. }
  2539. return 0;
  2540. }
  2541. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  2542. if (!lua_interface)
  2543. return 0;
  2544. Quest* quest = lua_interface->GetQuest(state);
  2545. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  2546. if (quest && spawn_id > 0)
  2547. quest->SetQuestReturnNPC(spawn_id);
  2548. return 0;
  2549. }
  2550. int EQ2Emu_lua_AddTimer(lua_State* state) {
  2551. if (!lua_interface)
  2552. return 0;
  2553. Spawn* spawn = lua_interface->GetSpawn(state);
  2554. if (!spawn) {
  2555. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  2556. return 0;
  2557. }
  2558. int32 time = lua_interface->GetInt32Value(state, 2);
  2559. if (time <= 0) {
  2560. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  2561. return 0;
  2562. }
  2563. string function = lua_interface->GetStringValue(state, 3);
  2564. if (function.length() == 0) {
  2565. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  2566. return 0;
  2567. }
  2568. int32 max_count = lua_interface->GetInt32Value(state, 4);
  2569. Spawn* player = lua_interface->GetSpawn(state, 5);
  2570. SpawnScriptTimer* timer = new SpawnScriptTimer;
  2571. timer->timer = Timer::GetCurrentTime2() + time;
  2572. timer->function = function;
  2573. timer->spawn = spawn->GetID();
  2574. timer->player = player ? player->GetID() : 0;
  2575. if (max_count == 0)
  2576. max_count = 1;
  2577. timer->max_count = max_count;
  2578. timer->current_count = 0;
  2579. spawn->GetZone()->AddSpawnScriptTimer(timer);
  2580. return 0;
  2581. }
  2582. int EQ2Emu_lua_GetQuest(lua_State* state) {
  2583. if (!lua_interface)
  2584. return 0;
  2585. Spawn* player = lua_interface->GetSpawn(state);
  2586. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2587. if (player && player->IsPlayer() && quest_id > 0) {
  2588. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  2589. return 1;
  2590. }
  2591. return 0;
  2592. }
  2593. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  2594. if (!lua_interface)
  2595. return 0;
  2596. Spawn* player = lua_interface->GetSpawn(state);
  2597. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2598. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  2599. Quest* quest = ((Player*)player)->player_quests[quest_id];
  2600. if (quest)
  2601. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  2602. return 1;
  2603. }
  2604. return 0;
  2605. }
  2606. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  2607. if (!lua_interface)
  2608. return 0;
  2609. Spawn* player = lua_interface->GetSpawn(state);
  2610. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2611. if (player && player->IsPlayer() && quest_id > 0) {
  2612. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  2613. return 1;
  2614. }
  2615. return 0;
  2616. }
  2617. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  2618. if (!lua_interface)
  2619. return 0;
  2620. Spawn* npc = lua_interface->GetSpawn(state);
  2621. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  2622. if (npc && !npc->IsPlayer() && quest_id > 0)
  2623. npc->AddProvidedQuest(quest_id);
  2624. return 0;
  2625. }
  2626. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  2627. if (!lua_interface)
  2628. return 0;
  2629. Spawn* npc = lua_interface->GetSpawn(state);
  2630. Spawn* player = lua_interface->GetSpawn(state, 2);
  2631. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  2632. /* NPC is allowed to be null */
  2633. if (player && player->IsPlayer() && quest_id > 0) {
  2634. Quest* master_quest = master_quest_list.GetQuest(quest_id);
  2635. if (master_quest) {
  2636. Client* client = player->GetZone()->GetClientBySpawn(player);
  2637. Quest* quest = new Quest(master_quest);
  2638. if (client && quest) {
  2639. client->AddPendingQuest(quest);
  2640. if (npc)
  2641. quest->SetQuestGiver(npc->GetDatabaseID());
  2642. else
  2643. quest->SetQuestGiver(0);
  2644. }
  2645. }
  2646. }
  2647. return 0;
  2648. }
  2649. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  2650. if (!lua_interface)
  2651. return 0;
  2652. Quest* quest = lua_interface->GetQuest(state);
  2653. if (quest) {
  2654. int8 class_id = lua_interface->GetInt8Value(state, 2);
  2655. quest->AddPrereqClass(class_id);
  2656. }
  2657. return 0;
  2658. }
  2659. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  2660. if (!lua_interface)
  2661. return 0;
  2662. Quest* quest = lua_interface->GetQuest(state);
  2663. if (quest) {
  2664. int8 race = lua_interface->GetInt8Value(state, 2);
  2665. quest->AddPrereqRace(race);
  2666. }
  2667. return 0;
  2668. }
  2669. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  2670. if (!lua_interface)
  2671. return 0;
  2672. Quest* quest = lua_interface->GetQuest(state);
  2673. if (quest) {
  2674. int16 model_type = lua_interface->GetInt16Value(state, 2);
  2675. quest->AddPrereqModelType(model_type);
  2676. }
  2677. return 0;
  2678. }
  2679. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  2680. if (!lua_interface)
  2681. return 0;
  2682. Quest* quest = lua_interface->GetQuest(state);
  2683. if (!quest) {
  2684. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  2685. return 0;
  2686. }
  2687. int8 level = lua_interface->GetInt8Value(state, 2);
  2688. quest->SetPrereqTSLevel(level);
  2689. return 0;
  2690. }
  2691. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  2692. if (!lua_interface)
  2693. return 0;
  2694. Quest* quest = lua_interface->GetQuest(state);
  2695. if (!quest) {
  2696. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  2697. return 0;
  2698. }
  2699. int8 class_id = lua_interface->GetInt8Value(state, 2);
  2700. quest->AddPrereqTradeskillClass(class_id);
  2701. return 0;
  2702. }
  2703. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  2704. if (!lua_interface)
  2705. return 0;
  2706. Quest* quest = lua_interface->GetQuest(state);
  2707. if (quest) {
  2708. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  2709. sint32 min = lua_interface->GetSInt32Value(state, 3);
  2710. sint32 max = lua_interface->GetSInt32Value(state, 4);
  2711. quest->AddPrereqFaction(faction_id, min, max);
  2712. }
  2713. return 0;
  2714. }
  2715. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  2716. if (!lua_interface)
  2717. return 0;
  2718. Quest* quest = lua_interface->GetQuest(state);
  2719. if (quest) {
  2720. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2721. int8 quantity = lua_interface->GetInt8Value(state, 3);
  2722. if (quantity == 0)
  2723. quantity = 1;
  2724. Item* master_item = master_item_list.GetItem(item_id);
  2725. if (master_item) {
  2726. Item* item = new Item(master_item);
  2727. item->details.count = quantity;
  2728. quest->AddSelectableRewardItem(item);
  2729. }
  2730. }
  2731. return 0;
  2732. }
  2733. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  2734. if (!lua_interface)
  2735. return 0;
  2736. Quest* quest = lua_interface->GetQuest(state);
  2737. if (quest) {
  2738. int32 item_id = lua_interface->GetInt32Value(state, 2);
  2739. int8 quantity = lua_interface->GetInt32Value(state, 3);
  2740. if (quantity == 0)
  2741. quantity = 1;
  2742. Item* master_item = master_item_list.GetItem(item_id);
  2743. if (master_item) {
  2744. Item* item = new Item(master_item);
  2745. item->details.count = quantity;
  2746. quest->AddRewardItem(item);
  2747. }
  2748. }
  2749. return 0;
  2750. }
  2751. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  2752. if (!lua_interface)
  2753. return 0;
  2754. Quest* quest = lua_interface->GetQuest(state);
  2755. if (quest) {
  2756. int32 copper = lua_interface->GetInt32Value(state, 2);
  2757. int32 silver = lua_interface->GetInt32Value(state, 3);
  2758. int32 gold = lua_interface->GetInt32Value(state, 4);
  2759. int32 plat = lua_interface->GetInt32Value(state, 5);
  2760. quest->AddRewardCoins(copper, silver, gold, plat);
  2761. }
  2762. return 0;
  2763. }
  2764. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  2765. if (!lua_interface)
  2766. return 0;
  2767. Quest* quest = lua_interface->GetQuest(state);
  2768. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  2769. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  2770. if (quest && faction_id > 0 && amount != 0)
  2771. quest->AddRewardFaction(faction_id, amount);
  2772. return 0;
  2773. }
  2774. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  2775. if (!lua_interface)
  2776. return 0;
  2777. Quest* quest = lua_interface->GetQuest(state);
  2778. if (quest) {
  2779. int32 status = lua_interface->GetInt32Value(state, 2);
  2780. quest->SetRewardStatus(status);
  2781. }
  2782. return 0;
  2783. }
  2784. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  2785. if (!lua_interface)
  2786. return 0;
  2787. Quest* quest = lua_interface->GetQuest(state);
  2788. if (quest) {
  2789. string comment = lua_interface->GetStringValue(state, 2);
  2790. quest->SetRewardComment(comment);
  2791. }
  2792. return 0;
  2793. }
  2794. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  2795. if (!lua_interface)
  2796. return 0;
  2797. Quest* quest = lua_interface->GetQuest(state);
  2798. if (quest) {
  2799. int32 exp = lua_interface->GetInt32Value(state, 2);
  2800. quest->SetRewardXP(exp);
  2801. }
  2802. return 0;
  2803. }
  2804. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  2805. Quest* quest = lua_interface->GetQuest(state);
  2806. if (quest) {
  2807. int32 step = lua_interface->GetInt32Value(state, 2);
  2808. string description = lua_interface->GetStringValue(state, 3);
  2809. int32 quantity = lua_interface->GetInt32Value(state, 4);
  2810. float percentage = lua_interface->GetFloatValue(state, 5);
  2811. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  2812. int16 icon = lua_interface->GetInt16Value(state, 7);
  2813. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  2814. const char* taskgroup = 0;
  2815. if (str_taskgroup.length() > 0)
  2816. taskgroup = str_taskgroup.c_str();
  2817. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, 0, quantity, taskgroup, 0, 0, percentage, usableitemid);
  2818. if (quest_step && icon && quantity > 0)
  2819. quest_step->SetIcon(icon);
  2820. }
  2821. return 0;
  2822. }
  2823. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  2824. if (!lua_interface)
  2825. return 0;
  2826. Quest* quest = lua_interface->GetQuest(state);
  2827. if (quest) {
  2828. int32 step = lua_interface->GetInt32Value(state, 2);
  2829. string description = lua_interface->GetStringValue(state, 3);
  2830. int32 quantity = lua_interface->GetInt32Value(state, 4);
  2831. float percentage = lua_interface->GetFloatValue(state, 5);
  2832. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  2833. int16 icon = lua_interface->GetInt16Value(state, 7);
  2834. const char* taskgroup = 0;
  2835. if (str_taskgroup.length() > 0)
  2836. taskgroup = str_taskgroup.c_str();
  2837. int32 npc_id = 0;
  2838. vector<int32>* ids = 0;
  2839. Spawn* spawn = nullptr;
  2840. int i = 0;
  2841. while ((npc_id = lua_interface->GetInt32Value(state, 8 + i))) {
  2842. if (ids == 0)
  2843. ids = new vector<int32>;
  2844. ids->push_back(npc_id);
  2845. i++;
  2846. }
  2847. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_KILL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  2848. if (quest_step && icon > 0 && quantity > 0)
  2849. quest_step->SetIcon(icon);
  2850. }
  2851. return 0;
  2852. }
  2853. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  2854. if (!lua_interface)
  2855. return 0;
  2856. Quest* quest = lua_interface->GetQuest(state);
  2857. if (quest) {
  2858. int32 step = lua_interface->GetInt32Value(state, 2);
  2859. string description = lua_interface->GetStringValue(state, 3);
  2860. int32 quantity = lua_interface->GetInt32Value(state, 4);
  2861. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  2862. int16 icon = lua_interface->GetInt16Value(state, 6);
  2863. const char* taskgroup = 0;
  2864. if (str_taskgroup.length() > 0)
  2865. taskgroup = str_taskgroup.c_str();
  2866. int32 npc_id = 0;
  2867. vector<int32>* ids = 0;
  2868. int i = 0;
  2869. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  2870. if (ids == 0)
  2871. ids = new vector<int32>;
  2872. ids->push_back(npc_id);
  2873. i++;
  2874. }
  2875. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  2876. if (quest_step && icon > 0)
  2877. quest_step->SetIcon(icon);
  2878. if (quest->GetPlayer()) {
  2879. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  2880. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  2881. }
  2882. }
  2883. return 0;
  2884. }
  2885. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  2886. if (!lua_interface)
  2887. return 0;
  2888. Quest* quest = lua_interface->GetQuest(state);
  2889. if (quest) {
  2890. int32 step = lua_interface->GetInt32Value(state, 2);
  2891. string description = lua_interface->GetStringValue(state, 3);
  2892. int32 quantity = lua_interface->GetInt32Value(state, 4);
  2893. float percentage = lua_interface->GetFloatValue(state, 5);
  2894. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  2895. int16 icon = lua_interface->GetInt16Value(state, 7);
  2896. const char* taskgroup = 0;
  2897. if (str_taskgroup.length() > 0)
  2898. taskgroup = str_taskgroup.c_str();
  2899. int32 item_id = 0;
  2900. vector<int32>* ids = 0;
  2901. int i = 0;
  2902. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  2903. if (ids == 0)
  2904. ids = new vector<int32>;
  2905. ids->push_back(item_id);
  2906. i++;
  2907. }
  2908. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  2909. if (quest_step && icon > 0 && quantity > 0)
  2910. quest_step->SetIcon(icon);
  2911. }
  2912. return 0;
  2913. }
  2914. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  2915. if (!lua_interface)
  2916. return 0;
  2917. Quest* quest = lua_interface->GetQuest(state);
  2918. if (quest) {
  2919. int32 step = lua_interface->GetInt32Value(state, 2);
  2920. string description = lua_interface->GetStringValue(state, 3);
  2921. float max_variation = lua_interface->GetFloatValue(state, 4);
  2922. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  2923. int16 icon = lua_interface->GetInt16Value(state, 6);
  2924. const char* taskgroup = 0;
  2925. if (str_taskgroup.length() > 0)
  2926. taskgroup = str_taskgroup.c_str();
  2927. vector<Location>* locations = 0;
  2928. int i = 7;
  2929. while (true) {
  2930. Location loc;
  2931. loc.x = lua_interface->GetFloatValue(state, i);
  2932. loc.y = lua_interface->GetFloatValue(state, i + 1);
  2933. loc.z = lua_interface->GetFloatValue(state, i + 2);
  2934. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  2935. break;
  2936. if (locations == 0)
  2937. locations = new vector<Location>;
  2938. locations->push_back(loc);
  2939. i += 3;
  2940. }
  2941. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  2942. if (quest_step && icon > 0)
  2943. quest_step->SetIcon(icon);
  2944. }
  2945. return 0;
  2946. }
  2947. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  2948. if (!lua_interface)
  2949. return 0;
  2950. Quest* quest = lua_interface->GetQuest(state);
  2951. if (quest) {
  2952. int32 step = lua_interface->GetInt32Value(state, 2);
  2953. string description = lua_interface->GetStringValue(state, 3);
  2954. float max_variation = lua_interface->GetFloatValue(state, 4);
  2955. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  2956. int16 icon = lua_interface->GetInt16Value(state, 6);
  2957. const char* taskgroup = 0;
  2958. if (str_taskgroup.length() > 0)
  2959. taskgroup = str_taskgroup.c_str();
  2960. vector<Location>* locations = 0;
  2961. int i = 7;
  2962. while (true) {
  2963. Location loc;
  2964. loc.x = lua_interface->GetFloatValue(state, i);
  2965. loc.y = lua_interface->GetFloatValue(state, i + 1);
  2966. loc.z = lua_interface->GetFloatValue(state, i + 2);
  2967. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  2968. break;
  2969. if (locations == 0)
  2970. locations = new vector<Location>;
  2971. locations->push_back(loc);
  2972. i += 3;
  2973. }
  2974. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  2975. if (quest_step && icon > 0)
  2976. quest_step->SetIcon(icon);
  2977. }
  2978. return 0;
  2979. }
  2980. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  2981. Quest* quest = lua_interface->GetQuest(state);
  2982. if (quest) {
  2983. int32 step = lua_interface->GetInt32Value(state, 2);
  2984. string description = lua_interface->GetStringValue(state, 3);
  2985. int32 quantity = lua_interface->GetInt32Value(state, 4);
  2986. float percentage = lua_interface->GetFloatValue(state, 5);
  2987. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  2988. int16 icon = lua_interface->GetInt16Value(state, 7);
  2989. const char* taskgroup = 0;
  2990. if (str_taskgroup.length() > 0)
  2991. taskgroup = str_taskgroup.c_str();
  2992. int32 spell_id = 0;
  2993. vector<int32>* ids = 0;
  2994. int i = 0;
  2995. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  2996. if (ids == 0)
  2997. ids = new vector<int32>;
  2998. ids->push_back(spell_id);
  2999. i++;
  3000. }
  3001. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3002. if (quest_step && icon > 0 && quantity > 0)
  3003. quest_step->SetIcon(icon);
  3004. }
  3005. return 0;
  3006. }
  3007. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3008. if (!lua_interface)
  3009. return 0;
  3010. Quest* quest = lua_interface->GetQuest(state);
  3011. if (quest) {
  3012. int32 step = lua_interface->GetInt32Value(state, 2);
  3013. string description = lua_interface->GetStringValue(state, 3);
  3014. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3015. float percentage = lua_interface->GetFloatValue(state, 5);
  3016. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3017. int16 icon = lua_interface->GetInt16Value(state, 7);
  3018. const char* taskgroup = 0;
  3019. if (str_taskgroup.length() > 0)
  3020. taskgroup = str_taskgroup.c_str();
  3021. int32 item_id = 0;
  3022. vector<int32>* ids = 0;
  3023. int i = 0;
  3024. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3025. if (ids == 0)
  3026. ids = new vector<int32>;
  3027. ids->push_back(item_id);
  3028. i++;
  3029. }
  3030. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3031. if (quest_step && icon > 0 && quantity > 0)
  3032. quest_step->SetIcon(icon);
  3033. }
  3034. return 0;
  3035. }
  3036. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3037. if (!lua_interface)
  3038. return 0;
  3039. Quest* quest = lua_interface->GetQuest(state);
  3040. if (quest) {
  3041. int32 step = lua_interface->GetInt32Value(state, 2);
  3042. string description = lua_interface->GetStringValue(state, 3);
  3043. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3044. float percentage = lua_interface->GetFloatValue(state, 5);
  3045. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3046. int16 icon = lua_interface->GetInt16Value(state, 7);
  3047. const char* taskgroup = 0;
  3048. if (str_taskgroup.length() > 0)
  3049. taskgroup = str_taskgroup.c_str();
  3050. int32 item_id = 0;
  3051. vector<int32>* ids = 0;
  3052. int i = 0;
  3053. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3054. if (ids == 0)
  3055. ids = new vector<int32>;
  3056. ids->push_back(item_id);
  3057. i++;
  3058. }
  3059. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3060. if (quest_step && icon > 0 && quantity > 0)
  3061. quest_step->SetIcon(icon);
  3062. }
  3063. return 0;
  3064. }
  3065. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3066. if (!lua_interface)
  3067. return 0;
  3068. Quest* quest = lua_interface->GetQuest(state);
  3069. if (quest) {
  3070. string action = lua_interface->GetStringValue(state, 2);
  3071. if (action.length() > 0)
  3072. quest->SetCompleteAction(action);
  3073. }
  3074. return 0;
  3075. }
  3076. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3077. if (!lua_interface)
  3078. return 0;
  3079. Quest* quest = lua_interface->GetQuest(state);
  3080. if (quest) {
  3081. int32 step = lua_interface->GetInt32Value(state, 2);
  3082. string action = lua_interface->GetStringValue(state, 3);
  3083. if (step > 0 && action.length() > 0)
  3084. quest->AddCompleteAction(step, action);
  3085. }
  3086. return 0;
  3087. }
  3088. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3089. if (!lua_interface)
  3090. return 0;
  3091. Quest* quest = lua_interface->GetQuest(state);
  3092. if (quest) {
  3093. int32 step = lua_interface->GetInt32Value(state, 2);
  3094. string action = lua_interface->GetStringValue(state, 3);
  3095. if (step > 0 && action.length() > 0)
  3096. quest->AddProgressAction(step, action);
  3097. }
  3098. return 0;
  3099. }
  3100. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3101. if (!lua_interface)
  3102. return 0;
  3103. Quest* quest = lua_interface->GetQuest(state);
  3104. string description = lua_interface->GetStringValue(state, 2);
  3105. if (quest && description.length() > 0)
  3106. quest->SetDescription(description);
  3107. return 0;
  3108. }
  3109. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3110. if (!lua_interface)
  3111. return 0;
  3112. Quest* quest = lua_interface->GetQuest(state);
  3113. string description = lua_interface->GetStringValue(state, 2);
  3114. if (quest && description.length() > 0)
  3115. quest->SetCompletedDescription(description);
  3116. return 0;
  3117. }
  3118. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  3119. if (!lua_interface)
  3120. return 0;
  3121. Quest* quest = lua_interface->GetQuest(state);
  3122. int32 step = lua_interface->GetInt32Value(state, 2);
  3123. string description = lua_interface->GetStringValue(state, 3);
  3124. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3125. if (quest && step > 0 && description.length() > 0) {
  3126. quest->SetTaskGroupDescription(step, description, display_bullets);
  3127. if (quest->GetPlayer()) {
  3128. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3129. if (client)
  3130. client->SendQuestUpdateStep(quest, step, false);
  3131. }
  3132. }
  3133. return 0;
  3134. }
  3135. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  3136. if (!lua_interface)
  3137. return 0;
  3138. Quest* quest = lua_interface->GetQuest(state);
  3139. int32 step = lua_interface->GetInt32Value(state, 2);
  3140. string description = lua_interface->GetStringValue(state, 3);
  3141. if (quest && step > 0 && description.length() > 0) {
  3142. quest->SetStepDescription(step, description);
  3143. if (quest->GetPlayer()) {
  3144. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3145. if (client)
  3146. client->SendQuestUpdateStep(quest, step);
  3147. }
  3148. }
  3149. return 0;
  3150. }
  3151. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  3152. Quest* quest = lua_interface->GetQuest(state);
  3153. string zone = lua_interface->GetStringValue(state, 2);
  3154. if (quest && zone.length() > 0)
  3155. quest->SetZone(zone);
  3156. return 0;
  3157. }
  3158. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  3159. if (!lua_interface)
  3160. return 0;
  3161. Quest* quest = lua_interface->GetQuest(state);
  3162. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3163. if (quest && spawn) {
  3164. if (spawn->IsPlayer()) {
  3165. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3166. if (client)
  3167. client->AddPendingQuestReward(quest);
  3168. }
  3169. }
  3170. return 0;
  3171. }
  3172. int EQ2Emu_lua_Harvest(lua_State* state) {
  3173. if (!lua_interface)
  3174. return 0;
  3175. Spawn* player = lua_interface->GetSpawn(state);
  3176. Spawn* node = lua_interface->GetSpawn(state, 2);
  3177. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  3178. Client* client = player->GetZone()->GetClientBySpawn(player);
  3179. if (client) {
  3180. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  3181. ((GroundSpawn*)node)->ProcessHarvest(client);
  3182. if (((GroundSpawn*)node)->GetNumberHarvests() == 0)
  3183. player->GetZone()->RemoveSpawn(true, node, true);
  3184. }
  3185. }
  3186. else if (player && player->IsPlayer()) {
  3187. Client* client = player->GetZone()->GetClientBySpawn(player);
  3188. if (client)
  3189. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  3190. }
  3191. return 0;
  3192. }
  3193. int EQ2Emu_lua_Bind(lua_State* state) {
  3194. if (!lua_interface)
  3195. return 0;
  3196. Spawn* spawn = lua_interface->GetSpawn(state);
  3197. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  3198. float x = lua_interface->GetFloatValue(state, 3);
  3199. float y = lua_interface->GetFloatValue(state, 4);
  3200. float z = lua_interface->GetFloatValue(state, 5);
  3201. float h = lua_interface->GetFloatValue(state, 6);
  3202. if (!spawn) {
  3203. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  3204. return 0;
  3205. }
  3206. if (!spawn->IsPlayer()) {
  3207. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  3208. return 0;
  3209. }
  3210. if (zone_id == 0) {
  3211. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3212. if (!client) {
  3213. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  3214. return 0;
  3215. }
  3216. if (!client->Bind())
  3217. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  3218. }
  3219. else {
  3220. Player* player = (Player*)spawn;
  3221. player->GetPlayerInfo()->SetBindZone(zone_id);
  3222. player->GetPlayerInfo()->SetBindX(x);
  3223. player->GetPlayerInfo()->SetBindY(y);
  3224. player->GetPlayerInfo()->SetBindZ(z);
  3225. player->GetPlayerInfo()->SetBindHeading(h);
  3226. }
  3227. return 0;
  3228. }
  3229. int EQ2Emu_lua_Gate(lua_State* state) {
  3230. if (!lua_interface)
  3231. return 0;
  3232. Spawn* spawn = lua_interface->GetSpawn(state);
  3233. if (spawn) {
  3234. if (spawn->IsPlayer()) {
  3235. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3236. if (client) {
  3237. if (!client->Gate())
  3238. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  3239. }
  3240. }
  3241. }
  3242. return 0;
  3243. }
  3244. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  3245. if (!lua_interface)
  3246. return 0;
  3247. bool ret = false;
  3248. Spawn* spawn = lua_interface->GetSpawn(state);
  3249. if (spawn) {
  3250. if (spawn->IsPlayer()) {
  3251. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3252. if (client)
  3253. ret = client->BindAllowed();
  3254. }
  3255. }
  3256. lua_interface->SetBooleanValue(state, ret);
  3257. return 1;
  3258. }
  3259. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  3260. if (!lua_interface)
  3261. return 0;
  3262. bool ret = false;
  3263. Spawn* spawn = lua_interface->GetSpawn(state);
  3264. if (spawn) {
  3265. if (spawn->IsPlayer()) {
  3266. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3267. if (client)
  3268. ret = client->GateAllowed();
  3269. }
  3270. }
  3271. lua_interface->SetBooleanValue(state, ret);
  3272. return 1;
  3273. }
  3274. int EQ2Emu_lua_IsAlive(lua_State* state) {
  3275. Spawn* spawn = lua_interface->GetSpawn(state);
  3276. if (spawn) {
  3277. lua_interface->SetBooleanValue(state, spawn->Alive());
  3278. return 1;
  3279. }
  3280. return 0;
  3281. }
  3282. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  3283. if (!lua_interface)
  3284. return 0;
  3285. Spawn* spawn = lua_interface->GetSpawn(state);
  3286. if (spawn && spawn->IsEntity()) {
  3287. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  3288. return 1;
  3289. }
  3290. return 0;
  3291. }
  3292. int EQ2Emu_lua_SendMessage(lua_State* state) {
  3293. Spawn* spawn = lua_interface->GetSpawn(state);
  3294. string message = lua_interface->GetStringValue(state, 2);
  3295. string color_str = lua_interface->GetStringValue(state, 3);
  3296. int8 color = CHANNEL_COLOR_WHITE;
  3297. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  3298. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3299. if (client) {
  3300. if (color_str.length() > 0) {
  3301. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  3302. color = CHANNEL_COLOR_RED;
  3303. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  3304. color = CHANNEL_COLOR_YELLOW;
  3305. }
  3306. client->SimpleMessage(color, message.c_str());
  3307. }
  3308. }
  3309. return 0;
  3310. }
  3311. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  3312. Spawn* spawn = lua_interface->GetSpawn(state);
  3313. string message = lua_interface->GetStringValue(state, 2);
  3314. int8 red = lua_interface->GetInt8Value(state, 3);
  3315. int8 green = lua_interface->GetInt8Value(state, 4);
  3316. int8 blue = lua_interface->GetInt8Value(state, 5);
  3317. if (!spawn) {
  3318. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  3319. return 0;
  3320. }
  3321. int32 words = ::CountWordsInString(message.c_str());
  3322. if (words < 5)
  3323. words = 5;
  3324. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3325. if (client)
  3326. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  3327. return 0;
  3328. }
  3329. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  3330. Spawn* spawn = lua_interface->GetSpawn(state);
  3331. int8 param = lua_interface->GetInt8Value(state, 2);
  3332. int8 param_value = lua_interface->GetInt8Value(state, 3);
  3333. int8 value = lua_interface->GetInt8Value(state, 4);
  3334. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  3335. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3336. if (client) {
  3337. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  3338. switch (param) {
  3339. case 1: {
  3340. packet->setDataByName("parameter1", param_value);
  3341. break;
  3342. }
  3343. case 2: {
  3344. packet->setDataByName("parameter2", param_value);
  3345. break;
  3346. }
  3347. case 3: {
  3348. packet->setDataByName("parameter3", param_value);
  3349. break;
  3350. }
  3351. case 4: {
  3352. packet->setDataByName("parameter4", param_value);
  3353. break;
  3354. }
  3355. case 5: {
  3356. packet->setDataByName("parameter5", param_value);
  3357. break;
  3358. }
  3359. }
  3360. packet->setDataByName("value", value);
  3361. client->QueuePacket(packet->serialize());
  3362. safe_delete(packet);
  3363. }
  3364. }
  3365. return 0;
  3366. }
  3367. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  3368. Spawn* spawn = lua_interface->GetSpawn(state);
  3369. if (spawn && spawn->IsPlayer()) {
  3370. if (((Player*)spawn)->GetIsTracking())
  3371. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  3372. else
  3373. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  3374. }
  3375. return 0;
  3376. }
  3377. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  3378. Spawn* player = lua_interface->GetSpawn(state);
  3379. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  3380. string name = lua_interface->GetStringValue(state, 3);
  3381. float distance = lua_interface->GetFloatValue(state, 4);
  3382. string command = lua_interface->GetStringValue(state, 5);
  3383. string error_text = lua_interface->GetStringValue(state, 6);
  3384. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  3385. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  3386. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  3387. if (spawn) {
  3388. if (distance == 0)
  3389. distance = 10.0f;
  3390. if (command.length() == 0)
  3391. command = name;
  3392. if (command.length() < 1 && name.length() < 1)
  3393. {
  3394. // have to run this first to send a 'blank' default command, then remove all commands from the list
  3395. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  3396. spawn->RemovePrimaryCommands();
  3397. }
  3398. else
  3399. {
  3400. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  3401. }
  3402. }
  3403. return 0;
  3404. }
  3405. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  3406. if (!lua_interface)
  3407. return 0;
  3408. Spawn* player = lua_interface->GetSpawn(state);
  3409. int32 spellid = lua_interface->GetInt32Value(state, 2);
  3410. int16 tier = lua_interface->GetInt16Value(state, 3);
  3411. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3412. if (player && spell && player->IsPlayer()) {
  3413. Client* client = player->GetZone()->GetClientBySpawn(player);
  3414. if (client) {
  3415. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  3416. {
  3417. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3418. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  3419. client->GetPlayer()->UnlockSpell(spell);
  3420. client->SendSpellUpdate(spell);
  3421. }
  3422. else
  3423. {
  3424. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  3425. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  3426. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  3427. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  3428. client->GetPlayer()->UnlockSpell(spell);
  3429. client->SendSpellUpdate(spell);
  3430. }
  3431. //if (client ) {
  3432. // ((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);
  3433. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  3434. if (outapp)
  3435. client->QueuePacket(outapp);
  3436. }
  3437. }
  3438. return 0;
  3439. }
  3440. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  3441. if (!lua_interface)
  3442. return 0;
  3443. Spawn* player = lua_interface->GetSpawn(state);
  3444. if (player && player->IsPlayer()) {
  3445. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  3446. return 1;
  3447. }
  3448. return 0;
  3449. }
  3450. int EQ2Emu_lua_Attack(lua_State* state) {
  3451. if (lua_interface) {
  3452. Spawn* npc = lua_interface->GetSpawn(state);
  3453. Spawn* player = lua_interface->GetSpawn(state, 2);
  3454. if (npc && player && npc->IsNPC() && player->IsPlayer())
  3455. ((NPC*)npc)->AddHate((Entity*)player, 100);
  3456. }
  3457. return 0;
  3458. }
  3459. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  3460. if (lua_interface) {
  3461. Spawn* target = lua_interface->GetSpawn(state);
  3462. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  3463. if (target && target->GetZone())
  3464. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  3465. }
  3466. return 0;
  3467. }
  3468. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  3469. Spawn* player;
  3470. if (lua_interface) {
  3471. player = lua_interface->GetSpawn(state);
  3472. if (player && player->IsPlayer()) {
  3473. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  3474. return 1;
  3475. }
  3476. }
  3477. return 0;
  3478. }
  3479. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  3480. Spawn* player;
  3481. Client* client;
  3482. if (lua_interface) {
  3483. player = lua_interface->GetSpawn(state);
  3484. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  3485. if ((client = player->GetZone()->GetClientBySpawn(player)))
  3486. client->HandInCollections();
  3487. }
  3488. return 0;
  3489. }
  3490. int EQ2Emu_lua_UseWidget(lua_State* state) {
  3491. Spawn* widget;
  3492. if (lua_interface) {
  3493. widget = lua_interface->GetSpawn(state);
  3494. if (widget && widget->IsWidget())
  3495. ((Widget*)widget)->HandleUse(NULL, "");
  3496. }
  3497. return 0;
  3498. }
  3499. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  3500. Spawn* spawn = 0;
  3501. int32 primary_list = 0;
  3502. int32 secondary_list = 0;
  3503. if (lua_interface) {
  3504. spawn = lua_interface->GetSpawn(state);
  3505. primary_list = lua_interface->GetInt32Value(state, 2);
  3506. secondary_list = lua_interface->GetInt32Value(state, 3);
  3507. if (!spawn->IsNPC()) {
  3508. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  3509. return 0;
  3510. }
  3511. NPC* npc = (NPC*)spawn;
  3512. npc->SetPrimarySpellList(primary_list);
  3513. npc->SetSecondarySpellList(secondary_list);
  3514. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  3515. }
  3516. return 0;
  3517. }
  3518. int EQ2Emu_lua_GetPet(lua_State* state) {
  3519. if (!lua_interface)
  3520. return 0;
  3521. Spawn* spawn = lua_interface->GetSpawn(state);
  3522. if (spawn) {
  3523. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  3524. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  3525. return 1;
  3526. }
  3527. }
  3528. return 0;
  3529. }
  3530. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  3531. if (!lua_interface)
  3532. return 0;
  3533. Spawn* spawn = lua_interface->GetSpawn(state);
  3534. if (spawn) {
  3535. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  3536. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  3537. return 1;
  3538. }
  3539. }
  3540. return 0;
  3541. }
  3542. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  3543. if (!lua_interface)
  3544. return 0;
  3545. Spawn* spawn = lua_interface->GetSpawn(state);
  3546. if (spawn) {
  3547. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  3548. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  3549. return 1;
  3550. }
  3551. }
  3552. return 0;
  3553. }
  3554. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  3555. if (!lua_interface)
  3556. return 0;
  3557. Spawn* spawn = lua_interface->GetSpawn(state);
  3558. if (spawn) {
  3559. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  3560. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  3561. return 1;
  3562. }
  3563. }
  3564. return 0;
  3565. }
  3566. int EQ2Emu_lua_Charm(lua_State* state) {
  3567. if (!lua_interface)
  3568. return 0;
  3569. Spawn* owner = lua_interface->GetSpawn(state);
  3570. Spawn* pet = lua_interface->GetSpawn(state, 2);
  3571. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  3572. if (!luaspell) {
  3573. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  3574. return 0;
  3575. }
  3576. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  3577. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  3578. pet->SetPet(true);
  3579. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  3580. ((NPC*)pet)->SetOwner((Entity*)owner);
  3581. // If owner is player and player does not have a summoned pet set the players charsheet
  3582. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  3583. Player* player = (Player*)owner;
  3584. player->GetInfoStruct()->pet_id = player->GetIDWithPlayerSpawn(pet);
  3585. strcpy(player->GetInfoStruct()->pet_name, pet->GetName());
  3586. player->GetInfoStruct()->pet_movement = 2;
  3587. player->GetInfoStruct()->pet_behavior = 3;
  3588. player->GetInfoStruct()->pet_health_pct = 1.0f;
  3589. player->GetInfoStruct()->pet_power_pct = 1.0f;
  3590. // Make sure the values get sent to the client
  3591. player->SetCharSheetChanged(true);
  3592. }
  3593. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  3594. pet->SetSpawnScript("");
  3595. // Set faction to the same as the owner
  3596. pet->SetFactionID(owner->GetFactionID());
  3597. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  3598. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  3599. // Clear hate list
  3600. ((NPC*)pet)->Brain()->ClearHate();
  3601. // Set the brain to a pet brain
  3602. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  3603. }
  3604. return 0;
  3605. }
  3606. int EQ2Emu_lua_GetGroup(lua_State* state) {
  3607. if (!lua_interface)
  3608. return 0;
  3609. Spawn* spawn = lua_interface->GetSpawn(state);
  3610. if (!spawn) {
  3611. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  3612. return 0;
  3613. }
  3614. vector<Spawn*> groupMembers;
  3615. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  3616. groupMembers = *spawn->GetSpawnGroup();
  3617. }
  3618. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  3619. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  3620. deque<GroupMemberInfo*>::iterator itr;
  3621. deque<GroupMemberInfo*>* members = world.GetGroupManager()->GetGroupMembers(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  3622. GroupMemberInfo* info = 0;
  3623. for (itr = members->begin(); itr != members->end(); itr++) {
  3624. info = *itr;
  3625. if (info->client)
  3626. groupMembers.push_back(info->client->GetPlayer());
  3627. }
  3628. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  3629. }
  3630. else
  3631. return 0;
  3632. lua_createtable(state, groupMembers.size(), 0);
  3633. int newTable = lua_gettop(state);
  3634. for (int32 i = 0; i < groupMembers.size(); i++) {
  3635. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  3636. lua_rawseti(state, newTable, i + 1);
  3637. }
  3638. return 1;
  3639. }
  3640. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  3641. if (!lua_interface)
  3642. return 0;
  3643. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  3644. lua_interface->SetOptionWindowValue(state, option_window);
  3645. return 1;
  3646. }
  3647. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  3648. if (!lua_interface)
  3649. return 0;
  3650. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  3651. if (option_window) {
  3652. OptionWindowOption option_window_option;
  3653. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  3654. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  3655. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  3656. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  3657. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  3658. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  3659. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  3660. option_window->push_back(option_window_option);
  3661. }
  3662. return 0;
  3663. }
  3664. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  3665. if (!lua_interface)
  3666. return 0;
  3667. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  3668. Spawn* player = lua_interface->GetSpawn(state, 2);
  3669. string window_title = lua_interface->GetStringValue(state, 3);
  3670. string cancel_command = lua_interface->GetStringValue(state, 4);
  3671. Client* client = player->GetZone()->GetClientBySpawn(player);
  3672. if (option_window && window_title.length() > 0 && client) {
  3673. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  3674. if (!packet)
  3675. return 0;
  3676. packet->setDataByName("title_text", window_title.c_str());
  3677. if (cancel_command.length() > 0)
  3678. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  3679. packet->setArrayLengthByName("num_selections", option_window->size());
  3680. vector<OptionWindowOption>::iterator itr;
  3681. int8 i = 0;
  3682. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  3683. OptionWindowOption opt = *itr;
  3684. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  3685. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  3686. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  3687. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  3688. if (opt.optionCommand.length() > 0)
  3689. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  3690. if (opt.optionConfirmTitle.length() > 0)
  3691. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  3692. i++;
  3693. }
  3694. client->QueuePacket(packet->serialize());
  3695. safe_delete(option_window);
  3696. safe_delete(packet);
  3697. }
  3698. return 0;
  3699. }
  3700. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  3701. if (!lua_interface)
  3702. return 0;
  3703. Spawn* spawn = lua_interface->GetSpawn(state);
  3704. if (spawn) {
  3705. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  3706. return 1;
  3707. }
  3708. else
  3709. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  3710. return 0;
  3711. }
  3712. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  3713. if (!lua_interface)
  3714. return 0;
  3715. Spawn* spawn = lua_interface->GetSpawn(state);
  3716. if (spawn) {
  3717. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  3718. return 1;
  3719. }
  3720. else
  3721. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  3722. return 0;
  3723. }
  3724. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  3725. if (!lua_interface)
  3726. return 0;
  3727. Spawn* spawn = lua_interface->GetSpawn(state);
  3728. if (spawn) {
  3729. int8 class_id = spawn->GetTradeskillClass();
  3730. // Need to add 42 for the offset in the array
  3731. class_id += 44;
  3732. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  3733. return 1;
  3734. }
  3735. else
  3736. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  3737. return 0;
  3738. }
  3739. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  3740. if (!lua_interface)
  3741. return 0;
  3742. Spawn* spawn = lua_interface->GetSpawn(state);
  3743. int16 level = lua_interface->GetInt8Value(state, 2);
  3744. if (spawn) {
  3745. if (spawn->IsPlayer())
  3746. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  3747. else
  3748. spawn->SetTSLevel(level);
  3749. }
  3750. else
  3751. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  3752. return 0;
  3753. }
  3754. int EQ2Emu_lua_SummonPet(lua_State* state) {
  3755. // Check to see if we have a valid lua_interface
  3756. if (!lua_interface)
  3757. return 0;
  3758. // Get the spawn that is getting the pet
  3759. Spawn* spawn = lua_interface->GetSpawn(state);
  3760. // Get the DB ID of the pet
  3761. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  3762. // The max level the pet can gain
  3763. int8 max_level = lua_interface->GetInt8Value(state, 3);
  3764. // Get the spell that this command was called from
  3765. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  3766. // Check to make sure the spawn pointer is valid
  3767. if (!spawn) {
  3768. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  3769. return 0;
  3770. }
  3771. // Check to make sure the spawn is an entity
  3772. if (!spawn->IsEntity()) {
  3773. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  3774. return 0;
  3775. }
  3776. // Check to make sure the spawn doesn't already have a pet of this type
  3777. if (((Entity*)spawn)->GetPet()) {
  3778. if (spawn->IsPlayer()) {
  3779. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3780. if (client)
  3781. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  3782. }
  3783. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  3784. return 0;
  3785. }
  3786. // Check to see if the DB ID for the pet is set
  3787. if (pet_id == 0) {
  3788. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  3789. return 0;
  3790. }
  3791. // Check to see if the pointer to the spell is valid
  3792. if (!luaspell) {
  3793. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  3794. return 0;
  3795. }
  3796. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  3797. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  3798. if (!pet) {
  3799. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  3800. return 0;
  3801. }
  3802. // Check to make sure the pet is an npc
  3803. if (!pet->IsNPC()) {
  3804. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  3805. return 0;
  3806. }
  3807. // Spawn the pet at the same location as the owner
  3808. pet->SetX(spawn->GetX());
  3809. pet->SetY(spawn->GetY());
  3810. pet->SetZ(spawn->GetZ());
  3811. pet->SetLocation(spawn->GetLocation());
  3812. pet->SetHeading(spawn->GetHeading());
  3813. spawn->GetZone()->AddSpawn(pet);
  3814. /*
  3815. const char* spawn_script = world.GetSpawnScript(pet_id);
  3816. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  3817. spawn->SetSpawnScript(string(spawn_script));
  3818. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  3819. }*/
  3820. // Get a random pet name
  3821. string random_pet_name;
  3822. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  3823. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  3824. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  3825. // If player set various values for the char sheet (pet window)
  3826. if (spawn->IsPlayer()) {
  3827. Player* player = (Player*)spawn;
  3828. player->GetInfoStruct()->pet_id = player->GetIDWithPlayerSpawn(pet);
  3829. strcpy(player->GetInfoStruct()->pet_name, random_pet_name.c_str());
  3830. player->GetInfoStruct()->pet_movement = 2;
  3831. player->GetInfoStruct()->pet_behavior = 3;
  3832. player->GetInfoStruct()->pet_health_pct = 1.0f;
  3833. player->GetInfoStruct()->pet_power_pct = 1.0f;
  3834. // Make sure the values get sent to the client
  3835. player->SetCharSheetChanged(true);
  3836. }
  3837. // Set the pets name
  3838. pet->SetName(random_pet_name.c_str());
  3839. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  3840. if (max_level > 0)
  3841. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  3842. else
  3843. pet->SetLevel(spawn->GetLevel());
  3844. // Set the max level this pet can reach
  3845. ((NPC*)pet)->SetMaxPetLevel(max_level);
  3846. // Set the faction of the pet to the same faction as the owner
  3847. pet->SetFactionID(spawn->GetFactionID());
  3848. // Set the spawn as a pet
  3849. pet->SetPet(true);
  3850. // Give a pointer of the owner to the pet
  3851. ((NPC*)pet)->SetOwner((Entity*)spawn);
  3852. // Give a pointer of the pet to the owner
  3853. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  3854. // Set the pet type
  3855. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  3856. // Set the spell id used to create this pet
  3857. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  3858. // Set the spell tier used to create this pet
  3859. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  3860. // Set the pets spawn type to 6
  3861. pet->SetSpawnType(6);
  3862. // Set the pets brain
  3863. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  3864. // Check to see if the pet has a subtitle
  3865. if (strlen(pet->GetSubTitle()) > 0) {
  3866. // Add the players name to the front of the sub title
  3867. string pet_subtitle;
  3868. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  3869. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  3870. // Set the pets subtitle to the new one
  3871. pet->SetSubTitle(pet_subtitle.c_str());
  3872. }
  3873. // Add the "Pet Options" entity command to the pet
  3874. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  3875. // Set the pet as the return value for this function
  3876. lua_interface->SetSpawnValue(state, pet);
  3877. return 1;
  3878. }
  3879. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  3880. if (!lua_interface)
  3881. return 0;
  3882. Spawn* spawn = lua_interface->GetSpawn(state);
  3883. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  3884. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  3885. if (!spawn) {
  3886. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  3887. return 0;
  3888. }
  3889. if (!spawn->IsEntity()) {
  3890. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  3891. return 0;
  3892. }
  3893. if (((Entity*)spawn)->GetDeityPet()) {
  3894. if (spawn->IsPlayer()) {
  3895. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3896. if (client)
  3897. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  3898. }
  3899. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  3900. return 0;
  3901. }
  3902. if (pet_id == 0) {
  3903. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  3904. return 0;
  3905. }
  3906. if (!luaspell) {
  3907. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  3908. return 0;
  3909. }
  3910. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  3911. if (!pet) {
  3912. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  3913. return 0;
  3914. }
  3915. if (!pet->IsNPC()) {
  3916. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  3917. return 0;
  3918. }
  3919. pet->SetX(spawn->GetX());
  3920. pet->SetY(spawn->GetY());
  3921. pet->SetZ(spawn->GetZ());
  3922. pet->SetLocation(spawn->GetLocation());
  3923. pet->SetHeading(spawn->GetHeading());
  3924. spawn->GetZone()->AddSpawn(pet);
  3925. string random_pet_name;
  3926. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  3927. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  3928. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  3929. pet->SetName(random_pet_name.c_str());
  3930. pet->SetLevel(spawn->GetLevel());
  3931. pet->SetFactionID(spawn->GetFactionID());
  3932. pet->SetPet(true);
  3933. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  3934. ((NPC*)pet)->SetOwner((Entity*)spawn);
  3935. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  3936. pet->SetSpawnType(6);
  3937. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  3938. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  3939. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  3940. if (strlen(pet->GetSubTitle()) > 0) {
  3941. string pet_subtitle;
  3942. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  3943. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  3944. pet->SetSubTitle(pet_subtitle.c_str());
  3945. }
  3946. // deity and cosmetic pets are not attackable
  3947. pet->SetAttackable(false);
  3948. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  3949. lua_interface->SetSpawnValue(state, pet);
  3950. return 1;
  3951. }
  3952. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  3953. if (!lua_interface)
  3954. return 0;
  3955. Spawn* spawn = lua_interface->GetSpawn(state);
  3956. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  3957. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  3958. if (!spawn) {
  3959. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  3960. return 0;
  3961. }
  3962. if (!spawn->IsEntity()) {
  3963. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  3964. return 0;
  3965. }
  3966. if (((Entity*)spawn)->GetCosmeticPet()) {
  3967. if (spawn->IsPlayer()) {
  3968. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  3969. if (client)
  3970. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  3971. }
  3972. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  3973. return 0;
  3974. }
  3975. if (pet_id == 0) {
  3976. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  3977. return 0;
  3978. }
  3979. if (!luaspell) {
  3980. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  3981. return 0;
  3982. }
  3983. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  3984. if (!pet) {
  3985. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  3986. return 0;
  3987. }
  3988. if (!pet->IsNPC()) {
  3989. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  3990. return 0;
  3991. }
  3992. pet->SetX(spawn->GetX());
  3993. pet->SetY(spawn->GetY());
  3994. pet->SetZ(spawn->GetZ());
  3995. pet->SetLocation(spawn->GetLocation());
  3996. pet->SetHeading(spawn->GetHeading());
  3997. spawn->GetZone()->AddSpawn(pet);
  3998. string random_pet_name;
  3999. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4000. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4001. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4002. pet->SetName(random_pet_name.c_str());
  4003. pet->SetLevel(spawn->GetLevel());
  4004. pet->SetFactionID(spawn->GetFactionID());
  4005. pet->SetPet(true);
  4006. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4007. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4008. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4009. pet->SetSpawnType(6);
  4010. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4011. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4012. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4013. if (strlen(pet->GetSubTitle()) > 0) {
  4014. string pet_subtitle;
  4015. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4016. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4017. pet->SetSubTitle(pet_subtitle.c_str());
  4018. }
  4019. pet->SetAttackable(false);
  4020. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4021. lua_interface->SetSpawnValue(state, pet);
  4022. return 1;
  4023. }
  4024. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4025. if (!lua_interface)
  4026. return 0;
  4027. Spawn* spawn = lua_interface->GetSpawn(state);
  4028. if (!spawn) {
  4029. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4030. return 0;
  4031. }
  4032. if (!spawn->IsPet()) {
  4033. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4034. return 0;
  4035. }
  4036. if (!((NPC*)spawn)->IsDismissing())
  4037. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn);
  4038. return 0;
  4039. }
  4040. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4041. if (!lua_interface)
  4042. return 0;
  4043. Quest* quest = lua_interface->GetQuest(state);
  4044. if (!quest) {
  4045. 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));
  4046. return 0;
  4047. }
  4048. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4049. if (feather_color > 0)
  4050. quest->SetFeatherColor(feather_color);
  4051. return 0;
  4052. }
  4053. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  4054. if (!lua_interface)
  4055. return 0;
  4056. Spawn* spawn = lua_interface->GetSpawn(state);
  4057. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4058. if (!spawn) {
  4059. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4060. return 0;
  4061. }
  4062. if (!spawn2) {
  4063. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4064. return 0;
  4065. }
  4066. spawn->RemoveSpawnAccess(spawn2);
  4067. return 0;
  4068. }
  4069. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  4070. if (!lua_interface)
  4071. return 0;
  4072. ZoneServer* zone = lua_interface->GetZone(state);
  4073. int32 location_id = lua_interface->GetInt32Value(state, 2);
  4074. if (!zone) {
  4075. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  4076. return 0;
  4077. }
  4078. if (location_id == 0) {
  4079. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  4080. return 0;
  4081. }
  4082. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  4083. if (!location) {
  4084. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  4085. return 0;
  4086. }
  4087. Spawn* spawn = 0;
  4088. if (location->entities[0]) {
  4089. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  4090. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  4091. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  4092. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  4093. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  4094. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  4095. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  4096. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  4097. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  4098. spawn = zone->AddSignSpawn(location, location->entities[0]);
  4099. if (spawn) {
  4100. const char* script = 0;
  4101. for (int x = 0; x < 3; x++) {
  4102. switch (x) {
  4103. case 0:
  4104. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  4105. break;
  4106. case 1:
  4107. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  4108. break;
  4109. case 2:
  4110. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  4111. break;
  4112. }
  4113. if (script && lua_interface->GetSpawnScript(script) != 0) {
  4114. spawn->SetSpawnScript(string(script));
  4115. break;
  4116. }
  4117. }
  4118. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4119. lua_interface->SetSpawnValue(state, spawn);
  4120. return 1;
  4121. }
  4122. else {
  4123. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  4124. safe_delete(spawn);
  4125. }
  4126. }
  4127. return 0;
  4128. }
  4129. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  4130. if (!lua_interface)
  4131. return 0;
  4132. Spawn* caster = lua_interface->GetSpawn(state);
  4133. Spawn* target = lua_interface->GetSpawn(state, 2);
  4134. int32 id = lua_interface->GetInt32Value(state, 3);
  4135. string command = lua_interface->GetStringValue(state, 4);
  4136. if (!caster) {
  4137. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  4138. return 0;
  4139. }
  4140. if (!target) {
  4141. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  4142. return 0;
  4143. }
  4144. if (!caster->IsPlayer()) {
  4145. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  4146. return 0;
  4147. }
  4148. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  4149. if (!entity_command) {
  4150. 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());
  4151. return 0;
  4152. }
  4153. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  4154. if (!client) {
  4155. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  4156. return 0;
  4157. }
  4158. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  4159. return 0;
  4160. }
  4161. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  4162. if (!lua_interface)
  4163. return 0;
  4164. Spawn* spawn = lua_interface->GetSpawn(state);
  4165. if (!spawn) {
  4166. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  4167. return 0;
  4168. }
  4169. if (!spawn->IsNPC()) {
  4170. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  4171. return 0;
  4172. }
  4173. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  4174. return 0;
  4175. }
  4176. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  4177. if (!lua_interface)
  4178. return 0;
  4179. Spawn* spawn = lua_interface->GetSpawn(state);
  4180. int16 tick = lua_interface->GetInt16Value(state, 2);
  4181. if (!spawn) {
  4182. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  4183. return 0;
  4184. }
  4185. if (!spawn->IsNPC()) {
  4186. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  4187. return 0;
  4188. }
  4189. if (tick < 20) {
  4190. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  4191. return 0;
  4192. }
  4193. ((NPC*)spawn)->Brain()->SetTick(tick);
  4194. return 0;
  4195. }
  4196. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  4197. if (!lua_interface)
  4198. return 0;
  4199. Spawn* spawn = lua_interface->GetSpawn(state);
  4200. Spawn* target = lua_interface->GetSpawn(state, 2);
  4201. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  4202. if (!spawn) {
  4203. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4204. return 0;
  4205. }
  4206. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  4207. spawn->SetFollowTarget(target, follow_distance);
  4208. return 0;
  4209. }
  4210. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  4211. if (!lua_interface)
  4212. return 0;
  4213. Spawn* spawn = lua_interface->GetSpawn(state);
  4214. if (!spawn) {
  4215. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4216. return 0;
  4217. }
  4218. Spawn* target = spawn->GetFollowTarget();
  4219. if (target) {
  4220. lua_interface->SetSpawnValue(state, target);
  4221. return 1;
  4222. }
  4223. return 0;
  4224. }
  4225. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  4226. if (!lua_interface)
  4227. return 0;
  4228. Spawn* spawn = lua_interface->GetSpawn(state);
  4229. if (!spawn) {
  4230. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  4231. return 0;
  4232. }
  4233. if (spawn->following)
  4234. spawn->following = false;
  4235. else
  4236. spawn->following = true;
  4237. return 0;
  4238. }
  4239. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  4240. if (!lua_interface)
  4241. return 0;
  4242. Spawn* spawn = lua_interface->GetSpawn(state);
  4243. if (!spawn) {
  4244. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  4245. return 0;
  4246. }
  4247. lua_interface->SetBooleanValue(state, spawn->following);
  4248. return 1;
  4249. }
  4250. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  4251. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  4252. // I will attempt to explain how this function works for future refrence
  4253. // Fist lets make sure lua_interface is valid, if not return out
  4254. if (!lua_interface)
  4255. return 0;
  4256. // Next we grab the first 2 params same as we usually would
  4257. Spawn* spawn = lua_interface->GetSpawn(state);
  4258. string var = lua_interface->GetStringValue(state, 2);
  4259. // 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
  4260. // 1 = Spawn
  4261. // 2 = Zone
  4262. // 3 = Item
  4263. // 4 = Quest
  4264. // 5 = String
  4265. // 6 = nil (null)
  4266. int8 dataType = 0;
  4267. // Define pointers for each potential type
  4268. Spawn* spawnVal = 0;
  4269. ZoneServer* zone = 0;
  4270. Item* item = 0;
  4271. Quest* quest = 0;
  4272. string val;
  4273. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  4274. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  4275. // options window are also light user data be we do not handle those.
  4276. // We check with lua_islightuserdata(lua_State*, index)
  4277. if (lua_islightuserdata(state, 3)) {
  4278. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  4279. // and convert it to LUAUserData*
  4280. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  4281. // Check to make sure the data we got is valid, if not give an error
  4282. if (!data || !data->IsCorrectlyInitialized()) {
  4283. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  4284. }
  4285. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  4286. else if (data->IsSpawn()) {
  4287. spawnVal = data->spawn;
  4288. dataType = 1;
  4289. }
  4290. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  4291. else if (data->IsZone()) {
  4292. zone = data->zone;
  4293. dataType = 2;
  4294. }
  4295. // Check if data is a Item, if so set our Item pointer and the dataType variable
  4296. else if (data->IsItem()) {
  4297. item = data->item;
  4298. dataType = 3;
  4299. }
  4300. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  4301. else if (data->IsQuest()) {
  4302. quest = data->quest;
  4303. dataType = 4;
  4304. }
  4305. }
  4306. // Wasn't light user data, check if it is nil(null)
  4307. else if (lua_isnil(state, 3)) {
  4308. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  4309. dataType = 6;
  4310. }
  4311. // Wasn't light user data or nil (null), must be a string
  4312. else {
  4313. // Set the string and dataType variable
  4314. val = lua_interface->GetStringValue(state, 3);
  4315. dataType = 5;
  4316. }
  4317. // We now have all the params, lets check to make sure they are valid
  4318. if (!spawn) {
  4319. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4320. return 0;
  4321. }
  4322. if (var.length() == 0) {
  4323. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4324. return 0;
  4325. }
  4326. if (dataType == 0) {
  4327. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  4328. return 0;
  4329. }
  4330. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  4331. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  4332. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  4333. switch (dataType) {
  4334. case 1:
  4335. // 1 = Spawn
  4336. spawn->AddTempVariable(var, spawnVal);
  4337. break;
  4338. case 2:
  4339. // 2 = Zone
  4340. spawn->AddTempVariable(var, zone);
  4341. break;
  4342. case 3:
  4343. // 3 = Item
  4344. spawn->AddTempVariable(var, item);
  4345. break;
  4346. case 4:
  4347. // 4 = Quest
  4348. spawn->AddTempVariable(var, quest);
  4349. break;
  4350. case 5:
  4351. // 5 = String
  4352. spawn->AddTempVariable(var, val);
  4353. break;
  4354. case 6:
  4355. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  4356. spawn->DeleteTempVariable(var);
  4357. break;
  4358. }
  4359. // And we are done so return out
  4360. return 0;
  4361. }
  4362. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  4363. if (!lua_interface)
  4364. return 0;
  4365. Spawn* spawn = lua_interface->GetSpawn(state);
  4366. string var = lua_interface->GetStringValue(state, 2);
  4367. if (!spawn) {
  4368. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  4369. return 0;
  4370. }
  4371. if (var.length() == 0) {
  4372. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  4373. return 0;
  4374. }
  4375. // This will tell us the type of data this variable contains, uses the same values as the previous function
  4376. int8 type = spawn->GetTempVariableType(var);
  4377. Spawn* spawn2 = 0;
  4378. ZoneServer* zone = 0;
  4379. Item* item = 0;
  4380. Quest* quest = 0;
  4381. // Set the lua function return value based on the type of data the variable contains
  4382. switch (type) {
  4383. case 1:
  4384. spawn2 = spawn->GetTempVariableSpawn(var);
  4385. if (!spawn2)
  4386. return 0;
  4387. lua_interface->SetSpawnValue(state, spawn2);
  4388. break;
  4389. case 2:
  4390. zone = spawn->GetTempVariableZone(var);
  4391. if (!zone)
  4392. return 0;
  4393. lua_interface->SetZoneValue(state, zone);
  4394. break;
  4395. case 3:
  4396. item = spawn->GetTempVariableItem(var);
  4397. if (!item)
  4398. return 0;
  4399. lua_interface->SetItemValue(state, item);
  4400. break;
  4401. case 4:
  4402. quest = spawn->GetTempVariableQuest(var);
  4403. if (!quest)
  4404. return 0;
  4405. lua_interface->SetQuestValue(state, quest);
  4406. break;
  4407. case 5:
  4408. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  4409. break;
  4410. default:
  4411. // Not a valid type then the variable was not set so return out
  4412. return 0;
  4413. }
  4414. // Return value was set so return out
  4415. return 1;
  4416. }
  4417. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  4418. {
  4419. if (!lua_interface)
  4420. return 0;
  4421. Quest* quest = lua_interface->GetQuest(state);
  4422. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4423. string description = lua_interface->GetStringValue(state, 3);
  4424. int32 item_id = lua_interface->GetInt32Value(state, 4);
  4425. if (!quest) {
  4426. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  4427. lua_interface->SetBooleanValue(state, false);
  4428. return 1;
  4429. }
  4430. if (!spawn) {
  4431. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  4432. lua_interface->SetBooleanValue(state, false);
  4433. return 1;
  4434. }
  4435. if (!spawn->IsPlayer()) {
  4436. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  4437. lua_interface->SetBooleanValue(state, false);
  4438. return 1;
  4439. }
  4440. if (item_id == 0) {
  4441. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  4442. lua_interface->SetBooleanValue(state, false);
  4443. return 1;
  4444. }
  4445. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4446. if (!client) {
  4447. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  4448. lua_interface->SetBooleanValue(state, false);
  4449. return 1;
  4450. }
  4451. Item* item = master_item_list.GetItem(item_id);
  4452. if (!item) {
  4453. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  4454. lua_interface->SetBooleanValue(state, false);
  4455. return 1;
  4456. }
  4457. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", client->GetVersion());
  4458. if (packet) {
  4459. packet->setDataByName("title", "Quest Reward!");
  4460. packet->setDataByName("name", quest->GetName());
  4461. packet->setDataByName("description", description.c_str());
  4462. packet->setDataByName("level", quest->GetLevel());
  4463. packet->setArrayLengthByName("num_rewards", 1);
  4464. packet->setArrayDataByName("reward_id", item->details.item_id);
  4465. if (client->GetVersion() < 860)
  4466. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, -1);
  4467. else if (client->GetVersion() < 1193)
  4468. packet->setItemArrayDataByName("item", item, (Player*)spawn);
  4469. else
  4470. packet->setItemArrayDataByName("item", item, (Player*)spawn, 0, 0, 2);
  4471. client->QueuePacket(packet->serialize());
  4472. safe_delete(packet);
  4473. lua_interface->SetBooleanValue(state, client->AddItem(item_id, 1));
  4474. client->Message(CHANNEL_COLOR_YELLOW, "You receive \\aITEM %u 0:%s\\/a.", item->details.item_id, item->name.c_str());
  4475. return 1;
  4476. }
  4477. lua_interface->SetBooleanValue(state, false);
  4478. return 1;
  4479. }
  4480. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  4481. if (!lua_interface)
  4482. return 0;
  4483. Quest* quest = lua_interface->GetQuest(state);
  4484. if (!quest) {
  4485. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  4486. return 0;
  4487. }
  4488. quest->SetRepeatable(true);
  4489. return 0;
  4490. }
  4491. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  4492. if (!lua_interface)
  4493. return 0;
  4494. Spawn* spawn = lua_interface->GetSpawn(state);
  4495. if (!spawn) {
  4496. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  4497. return 0;
  4498. }
  4499. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  4500. string ret = classes.GetClassNameCase(base_class);
  4501. if (ret.length() > 0) {
  4502. lua_interface->SetStringValue(state, ret.c_str());
  4503. return 1;
  4504. }
  4505. return 0;
  4506. }
  4507. int EQ2Emu_lua_AddWard(lua_State* state) {
  4508. if (!lua_interface)
  4509. return 0;
  4510. int32 damage = lua_interface->GetInt32Value(state);
  4511. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  4512. int8 wardType = lua_interface->GetInt8Value(state, 3);
  4513. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  4514. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  4515. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  4516. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  4517. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  4518. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4519. bool ward_was_added = false;
  4520. ZoneServer* zone = spell->caster->GetZone();
  4521. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  4522. for (int32 i = 0; i < spell->targets.size(); i++) {
  4523. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  4524. if (!target)
  4525. continue;
  4526. if (target->IsEntity()) {
  4527. // If the ward is already active remove it
  4528. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  4529. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  4530. // Create new ward info
  4531. WardInfo* ward = new WardInfo;
  4532. ward->Spell = spell;
  4533. ward->BaseDamage = damage;
  4534. ward->DamageLeft = damage;
  4535. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  4536. ward->keepWard = keepWard;
  4537. ward->WardType = wardType;
  4538. if (damageAbsorptionPercent > 100)
  4539. damageAbsorptionPercent = 100;
  4540. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  4541. if (damageAbsorptionMaxHealthPercent > 100)
  4542. damageAbsorptionMaxHealthPercent = 100;
  4543. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  4544. ward->RedirectDamagePercent = redirectDamagePercent;
  4545. ward->LastRedirectDamage = 0;
  4546. ward->LastAbsorbedDamage = 0;
  4547. ward->HitCount = 0;
  4548. spell->num_triggers = maxHitCount;
  4549. spell->had_triggers = true;
  4550. spell->cancel_after_all_triggers = false;
  4551. ward->MaxHitCount = maxHitCount;
  4552. if (wardType == WARD_TYPE_MAGICAL)
  4553. ward->DamageType = damageTypes;
  4554. // Add the ward to the entity
  4555. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  4556. ward_was_added = true;
  4557. }
  4558. }
  4559. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  4560. if (ward_was_added && spell->caster->IsPlayer()) {
  4561. spell->had_dmg_remaining = true;
  4562. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  4563. }
  4564. return 0;
  4565. }
  4566. int EQ2Emu_lua_AddToWard(lua_State* state) {
  4567. if (!lua_interface)
  4568. return 0;
  4569. int32 amount = lua_interface->GetInt32Value(state);
  4570. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4571. WardInfo* ward = 0;
  4572. ZoneServer* zone = spell->caster->GetZone();
  4573. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  4574. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  4575. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  4576. ward = target->GetWard(spell->spell->GetSpellID());
  4577. if (ward) {
  4578. ward->DamageLeft += amount;
  4579. if (ward->DamageLeft > ward->BaseDamage)
  4580. ward->DamageLeft = ward->BaseDamage;
  4581. for (int32 i = 0; i < spell->targets.size(); i++) {
  4582. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  4583. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  4584. }
  4585. }
  4586. }
  4587. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  4588. if (ward && spell->caster->IsPlayer())
  4589. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  4590. return 0;
  4591. }
  4592. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  4593. if (!lua_interface)
  4594. return 0;
  4595. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4596. if (!spell) {
  4597. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  4598. return 0;
  4599. }
  4600. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  4601. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  4602. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  4603. if (ward) {
  4604. lua_interface->SetInt32Value(state, ward->DamageLeft);
  4605. return 1;
  4606. }
  4607. }
  4608. return 0;
  4609. }
  4610. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  4611. if (!lua_interface)
  4612. return 0;
  4613. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4614. if (!spell) {
  4615. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  4616. return 0;
  4617. }
  4618. string type = lua_interface->GetStringValue(state, 2);
  4619. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  4620. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  4621. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  4622. if (ward) {
  4623. if (boost::iequals(type, "damageleft"))
  4624. lua_interface->SetInt32Value(state, ward->DamageLeft);
  4625. else if (boost::iequals(type, "basedamage"))
  4626. lua_interface->SetInt32Value(state, ward->BaseDamage);
  4627. else if (boost::iequals(type, "keepward"))
  4628. lua_interface->SetBooleanValue(state, ward->keepWard);
  4629. else if (boost::iequals(type, "wardtype"))
  4630. lua_interface->SetInt32Value(state, ward->WardType);
  4631. else if (boost::iequals(type, "dmgabsorptionpct"))
  4632. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  4633. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  4634. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  4635. else if (boost::iequals(type, "redirectdamagepercent"))
  4636. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  4637. else if (boost::iequals(type, "lastredirectdamage"))
  4638. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  4639. else if (boost::iequals(type, "lastabsorbeddamage"))
  4640. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  4641. else if (boost::iequals(type, "hitcount"))
  4642. lua_interface->SetInt32Value(state, ward->HitCount);
  4643. else if (boost::iequals(type, "maxhitcount"))
  4644. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  4645. else
  4646. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  4647. return 1;
  4648. }
  4649. }
  4650. return 0;
  4651. }
  4652. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  4653. if (!lua_interface)
  4654. return 0;
  4655. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4656. ZoneServer* zone = spell->caster->GetZone();
  4657. Spawn* target = 0;
  4658. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  4659. for (int32 i = 0; i < spell->targets.size(); i++) {
  4660. target = zone->GetSpawnByID(spell->targets.at(i));
  4661. if (target && target->IsEntity()) {
  4662. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  4663. }
  4664. }
  4665. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  4666. return 0;
  4667. }
  4668. int EQ2Emu_lua_Interrupt(lua_State* state)
  4669. {
  4670. if (!lua_interface)
  4671. return 0;
  4672. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  4673. Spawn* target = lua_interface->GetSpawn(state, 2);
  4674. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4675. if (!caster)
  4676. {
  4677. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  4678. return 0;
  4679. }
  4680. if (!target)
  4681. {
  4682. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  4683. return 0;
  4684. }
  4685. if (!spell) {
  4686. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  4687. return 0;
  4688. }
  4689. if (!target->IsEntity() && !spell)
  4690. {
  4691. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  4692. return 0;
  4693. }
  4694. if (!target && spell) {
  4695. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  4696. for (int8 i = 0; i < spell->targets.size(); i++) {
  4697. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  4698. if (!target || !target->IsEntity())
  4699. continue;
  4700. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  4701. }
  4702. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  4703. }
  4704. else
  4705. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  4706. return 0;
  4707. }
  4708. int EQ2Emu_lua_Stealth(lua_State* state) {
  4709. if (!lua_interface)
  4710. return 0;
  4711. int8 type = lua_interface->GetInt8Value(state);
  4712. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4713. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4714. if (!spell) {
  4715. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  4716. return 0;
  4717. }
  4718. ZoneServer* zone = spell->caster->GetZone();
  4719. if (spawn) {
  4720. if (spawn->IsEntity()) {
  4721. if (type == 1) {
  4722. ((Entity*)spawn)->AddStealthSpell(spell);
  4723. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  4724. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  4725. }
  4726. else if (type == 2) {
  4727. ((Entity*)spawn)->AddInvisSpell(spell);
  4728. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  4729. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  4730. }
  4731. return 0;
  4732. }
  4733. else {
  4734. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  4735. return 0;
  4736. }
  4737. }
  4738. else {
  4739. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  4740. for (int32 i = 0; i < spell->targets.size(); i++) {
  4741. spawn = zone->GetSpawnByID(spell->targets.at(i));
  4742. if (!spawn || !spawn->IsEntity())
  4743. continue;
  4744. if (type == 1) {
  4745. ((Entity*)spawn)->AddStealthSpell(spell);
  4746. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  4747. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  4748. }
  4749. else if (type == 2) {
  4750. ((Entity*)spawn)->AddInvisSpell(spell);
  4751. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  4752. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  4753. }
  4754. else {
  4755. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  4756. break;
  4757. }
  4758. }
  4759. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  4760. }
  4761. return 0;
  4762. }
  4763. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  4764. if (!lua_interface)
  4765. return 0;
  4766. Spawn* spawn = lua_interface->GetSpawn(state);
  4767. if (!spawn) {
  4768. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  4769. return 0;
  4770. }
  4771. if (spawn->IsEntity()) {
  4772. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  4773. return 1;
  4774. }
  4775. else
  4776. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  4777. return 0;
  4778. }
  4779. int EQ2Emu_lua_IsInvis(lua_State* state) {
  4780. if (!lua_interface)
  4781. return 0;
  4782. Spawn* spawn = lua_interface->GetSpawn(state);
  4783. if (!spawn) {
  4784. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  4785. return 0;
  4786. }
  4787. if (spawn->IsEntity()) {
  4788. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  4789. return 1;
  4790. }
  4791. else
  4792. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  4793. return 0;
  4794. }
  4795. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  4796. if (!lua_interface)
  4797. return 0;
  4798. Spawn* player = lua_interface->GetSpawn(state);
  4799. int32 item_id = lua_interface->GetInt32Value(state, 2);
  4800. if (!player->IsPlayer()) {
  4801. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  4802. return 0;
  4803. }
  4804. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  4805. return 1;
  4806. }
  4807. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  4808. if (!lua_interface)
  4809. return 0;
  4810. Spawn* player = lua_interface->GetSpawn(state);
  4811. int8 slot = lua_interface->GetInt8Value(state, 2);
  4812. if (!player) {
  4813. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  4814. return 0;
  4815. }
  4816. if (!player->IsPlayer()) {
  4817. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  4818. return 0;
  4819. }
  4820. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  4821. if (!item) {
  4822. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  4823. return 0;
  4824. }
  4825. lua_interface->SetItemValue(state, item);
  4826. return 1;
  4827. }
  4828. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  4829. if (!lua_interface)
  4830. return 0;
  4831. Spawn* player = lua_interface->GetSpawn(state);
  4832. int32 id = lua_interface->GetInt32Value(state, 2);
  4833. if (!player) {
  4834. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  4835. return 0;
  4836. }
  4837. if (!player->IsPlayer()) {
  4838. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  4839. return 0;
  4840. }
  4841. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  4842. if (!item) {
  4843. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  4844. return 0;
  4845. }
  4846. lua_interface->SetItemValue(state, item);
  4847. return 1;
  4848. }
  4849. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  4850. if (!lua_interface)
  4851. return 0;
  4852. Spawn* player = lua_interface->GetSpawn(state);
  4853. int32 id = lua_interface->GetInt32Value(state, 2);
  4854. int8 count = lua_interface->GetInt8Value(state, 3);
  4855. bool include_bank = lua_interface->GetInt8Value(state, 4);
  4856. if (!player) {
  4857. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  4858. return 0;
  4859. }
  4860. if (!player->IsPlayer()) {
  4861. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  4862. return 0;
  4863. }
  4864. if (!count)
  4865. count = 1;
  4866. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  4867. if (!item) {
  4868. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  4869. return 0;
  4870. }
  4871. lua_interface->SetItemValue(state, item);
  4872. return 1;
  4873. }
  4874. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  4875. if (!lua_interface)
  4876. return 0;
  4877. Spawn* spawn = lua_interface->GetSpawn(state);
  4878. int32 anim = lua_interface->GetInt32Value(state, 2);
  4879. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  4880. int8 type = lua_interface->GetInt8Value(state, 4);
  4881. if (!spawn) {
  4882. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  4883. return 0;
  4884. }
  4885. if (spawn2) {
  4886. if (spawn2->IsPlayer()) {
  4887. if (type != 1 && type != 2)
  4888. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  4889. else
  4890. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  4891. return 0;
  4892. }
  4893. else {
  4894. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  4895. return 0;
  4896. }
  4897. }
  4898. else
  4899. spawn->GetZone()->PlayAnimation(spawn, anim);
  4900. return 0;
  4901. }
  4902. int EQ2Emu_lua_IsPet(lua_State* state) {
  4903. if (!lua_interface)
  4904. return 0;
  4905. Spawn* spawn = lua_interface->GetSpawn(state);
  4906. if (!spawn) {
  4907. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4908. return 0;
  4909. }
  4910. lua_interface->SetBooleanValue(state, spawn->IsPet());
  4911. return 1;
  4912. }
  4913. int EQ2Emu_lua_GetOwner(lua_State* state) {
  4914. if (!lua_interface)
  4915. return 0;
  4916. Spawn* spawn = lua_interface->GetSpawn(state);
  4917. if (!spawn) {
  4918. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  4919. return 0;
  4920. }
  4921. if (!spawn->IsNPC()) {
  4922. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  4923. return 0;
  4924. }
  4925. if (((NPC*)spawn)->GetOwner()) {
  4926. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  4927. return 1;
  4928. }
  4929. return 0;
  4930. }
  4931. int EQ2Emu_lua_SetTarget(lua_State* state) {
  4932. if (!lua_interface)
  4933. return 0;
  4934. Spawn* spawn = lua_interface->GetSpawn(state);
  4935. Spawn* target = lua_interface->GetSpawn(state, 2);
  4936. if (!spawn) {
  4937. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  4938. return 0;
  4939. }
  4940. if (!spawn) {
  4941. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  4942. return 0;
  4943. }
  4944. spawn->SetTarget(target);
  4945. return 0;
  4946. }
  4947. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  4948. if (!lua_interface)
  4949. return 0;
  4950. Spawn* spawn = lua_interface->GetSpawn(state);
  4951. bool val = lua_interface->GetBooleanValue(state, 2);
  4952. if (!spawn) {
  4953. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  4954. return 0;
  4955. }
  4956. if (!spawn->IsEntity()) {
  4957. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  4958. return 0;
  4959. }
  4960. ((Entity*)spawn)->InCombat(val);
  4961. if (val) {
  4962. spawn->ClearRunningLocations();
  4963. spawn->CalculateRunningLocation(true);
  4964. }
  4965. return 0;
  4966. }
  4967. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  4968. if (!lua_interface)
  4969. return 0;
  4970. Spawn* spawn1 = lua_interface->GetSpawn(state);
  4971. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  4972. if (!spawn1) {
  4973. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  4974. return 0;
  4975. }
  4976. if (!spawn2) {
  4977. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  4978. return 0;
  4979. }
  4980. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  4981. return 1;
  4982. }
  4983. int EQ2Emu_lua_Runback(lua_State* state) {
  4984. if (!lua_interface)
  4985. return 0;
  4986. Spawn* spawn = lua_interface->GetSpawn(state);
  4987. if (!spawn) {
  4988. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  4989. return 0;
  4990. }
  4991. if (!spawn->IsNPC()) {
  4992. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  4993. return 0;
  4994. }
  4995. ((NPC*)spawn)->Runback();
  4996. return 0;
  4997. }
  4998. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  4999. if (!lua_interface)
  5000. return 0;
  5001. Spawn* spawn = lua_interface->GetSpawn(state);
  5002. if (!spawn) {
  5003. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  5004. return 0;
  5005. }
  5006. if (!spawn->IsNPC()) {
  5007. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5008. return 0;
  5009. }
  5010. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  5011. return 1;
  5012. }
  5013. int EQ2Emu_lua_IsCasting(lua_State* state) {
  5014. if (!lua_interface)
  5015. return 0;
  5016. Spawn* spawn = lua_interface->GetSpawn(state);
  5017. if (!spawn) {
  5018. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  5019. return 0;
  5020. }
  5021. if (!spawn->IsEntity()) {
  5022. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5023. return 0;
  5024. }
  5025. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  5026. return 1;
  5027. }
  5028. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  5029. if (!lua_interface)
  5030. return 0;
  5031. Spawn* spawn = lua_interface->GetSpawn(state);
  5032. if (!spawn) {
  5033. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5034. return 0;
  5035. }
  5036. if (!spawn->IsEntity()) {
  5037. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5038. return 0;
  5039. }
  5040. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  5041. return 1;
  5042. }
  5043. int EQ2Emu_lua_IsStunned(lua_State* state) {
  5044. if (!lua_interface)
  5045. return 0;
  5046. Spawn* spawn = lua_interface->GetSpawn(state);
  5047. if (!spawn) {
  5048. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5049. return 0;
  5050. }
  5051. if (!spawn->IsEntity()) {
  5052. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5053. return 0;
  5054. }
  5055. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  5056. return 1;
  5057. }
  5058. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  5059. if (!lua_interface)
  5060. return 0;
  5061. Spawn* spawn = lua_interface->GetSpawn(state);
  5062. if (!spawn) {
  5063. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  5064. return 0;
  5065. }
  5066. if (!spawn->IsEntity()) {
  5067. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5068. return 0;
  5069. }
  5070. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  5071. return 1;
  5072. }
  5073. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  5074. if (!lua_interface)
  5075. return 0;
  5076. Spawn* spawn = lua_interface->GetSpawn(state);
  5077. Spawn* target = lua_interface->GetSpawn(state, 2);
  5078. float distance = lua_interface->GetFloatValue(state, 3);
  5079. if (!spawn) {
  5080. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  5081. return 0;
  5082. }
  5083. if (!target) {
  5084. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5085. return 0;
  5086. }
  5087. if (!spawn->IsNPC()) {
  5088. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5089. return 0;
  5090. }
  5091. if (!target->IsEntity()) {
  5092. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  5093. return 0;
  5094. }
  5095. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  5096. return 1;
  5097. }
  5098. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  5099. if (!lua_interface)
  5100. return 0;
  5101. Spawn* spawn = lua_interface->GetSpawn(state);
  5102. Spawn* target = lua_interface->GetSpawn(state, 2);
  5103. float distance = lua_interface->GetFloatValue(state, 3);
  5104. if (!spawn) {
  5105. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  5106. return 0;
  5107. }
  5108. if (!target) {
  5109. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  5110. return 0;
  5111. }
  5112. if (!spawn->IsNPC()) {
  5113. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5114. return 0;
  5115. }
  5116. if (!target->IsEntity()) {
  5117. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  5118. return 0;
  5119. }
  5120. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  5121. return 0;
  5122. }
  5123. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  5124. if (!lua_interface)
  5125. return 0;
  5126. Spawn* spawn = lua_interface->GetSpawn(state);
  5127. if (!spawn) {
  5128. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  5129. return 0;
  5130. }
  5131. if (!spawn->IsNPC()) {
  5132. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5133. return 0;
  5134. }
  5135. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  5136. return 1;
  5137. }
  5138. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  5139. if (!lua_interface)
  5140. return 0;
  5141. Spawn* spawn = lua_interface->GetSpawn(state);
  5142. if (!spawn) {
  5143. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  5144. return 0;
  5145. }
  5146. if (!spawn->IsNPC()) {
  5147. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5148. return 0;
  5149. }
  5150. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  5151. return 1;
  5152. }
  5153. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  5154. if (!lua_interface)
  5155. return 0;
  5156. Spawn* spawn = lua_interface->GetSpawn(state);
  5157. if (!spawn) {
  5158. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  5159. return 0;
  5160. }
  5161. if (!spawn->IsNPC()) {
  5162. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5163. return 0;
  5164. }
  5165. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  5166. if (hated) {
  5167. lua_interface->SetSpawnValue(state, hated);
  5168. return 1;
  5169. }
  5170. return 0;
  5171. }
  5172. int EQ2Emu_lua_ClearHate(lua_State* state) {
  5173. if (!lua_interface)
  5174. return 0;
  5175. Spawn* spawn = lua_interface->GetSpawn(state);
  5176. Spawn* hated = lua_interface->GetSpawn(state, 2);
  5177. if (!spawn) {
  5178. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  5179. return 0;
  5180. }
  5181. if (!spawn->IsNPC()) {
  5182. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  5183. return 0;
  5184. }
  5185. if (!hated) {
  5186. ((NPC*)spawn)->Brain()->ClearHate();
  5187. return 0;
  5188. }
  5189. else
  5190. {
  5191. if (!hated->IsEntity()) {
  5192. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  5193. return 0;
  5194. }
  5195. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  5196. return 0;
  5197. }
  5198. return 0;
  5199. }
  5200. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  5201. if (!lua_interface)
  5202. return 0;
  5203. Spawn* spawn = lua_interface->GetSpawn(state);
  5204. if (!spawn) {
  5205. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  5206. return 0;
  5207. }
  5208. if (!spawn->IsNPC()) {
  5209. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  5210. return 0;
  5211. }
  5212. ((NPC*)spawn)->Brain()->ClearEncounter();
  5213. return 0;
  5214. }
  5215. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  5216. if (!lua_interface)
  5217. return 0;
  5218. Spawn* spawn = lua_interface->GetSpawn(state);
  5219. if (!spawn) {
  5220. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5221. return 0;
  5222. }
  5223. if (!spawn->IsNPC()) {
  5224. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5225. return 0;
  5226. }
  5227. // Temp list to store hate list
  5228. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  5229. if (encounterList->size() == 0) {
  5230. safe_delete(encounterList);
  5231. return 0;
  5232. }
  5233. lua_createtable(state, encounterList->size(), 0);
  5234. int newTable = lua_gettop(state);
  5235. for (int32 i = 0; i < encounterList->size(); i++) {
  5236. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  5237. if (temp)
  5238. lua_interface->SetSpawnValue(state, temp);
  5239. lua_rawseti(state, newTable, i + 1);
  5240. }
  5241. safe_delete(encounterList);
  5242. return 1;
  5243. }
  5244. int EQ2Emu_lua_GetHateList(lua_State* state) {
  5245. if (!lua_interface)
  5246. return 0;
  5247. Spawn* spawn = lua_interface->GetSpawn(state);
  5248. if (!spawn) {
  5249. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  5250. return 0;
  5251. }
  5252. if (!spawn->IsNPC()) {
  5253. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  5254. return 0;
  5255. }
  5256. // Temp list to store hate list
  5257. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  5258. if (hateList->size() == 0) {
  5259. safe_delete(hateList);
  5260. return 0;
  5261. }
  5262. lua_createtable(state, hateList->size(), 0);
  5263. int newTable = lua_gettop(state);
  5264. for (int32 i = 0; i < hateList->size(); i++) {
  5265. lua_interface->SetSpawnValue(state, hateList->at(i));
  5266. lua_rawseti(state, newTable, i + 1);
  5267. }
  5268. safe_delete(hateList);
  5269. return 1;
  5270. }
  5271. int EQ2Emu_lua_HasGroup(lua_State* state) {
  5272. if (!lua_interface)
  5273. return 0;
  5274. Spawn* spawn = lua_interface->GetSpawn(state);
  5275. if (!spawn) {
  5276. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  5277. return 0;
  5278. }
  5279. if (spawn->IsPlayer()) {
  5280. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  5281. lua_interface->SetBooleanValue(state, true);
  5282. else
  5283. lua_interface->SetBooleanValue(state, false);
  5284. return 1;
  5285. }
  5286. else {
  5287. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  5288. return 1;
  5289. }
  5290. }
  5291. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  5292. if (!lua_interface)
  5293. return 0;
  5294. Quest* quest = lua_interface->GetQuest(state);
  5295. if (!quest) {
  5296. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  5297. return 0;
  5298. }
  5299. quest->SetCompletedFlag(true);
  5300. return 0;
  5301. }
  5302. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  5303. if (!lua_interface)
  5304. return 0;
  5305. Spawn* spawn = lua_interface->GetSpawn(state);
  5306. int32 spellID = lua_interface->GetInt32Value(state, 2);
  5307. int8 tier = lua_interface->GetInt8Value(state, 3);
  5308. if (!spawn) {
  5309. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  5310. return 0;
  5311. }
  5312. if (!spawn->IsEntity()) {
  5313. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5314. return 0;
  5315. }
  5316. if (spellID == 0) {
  5317. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  5318. return 0;
  5319. }
  5320. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  5321. if (effect) {
  5322. if (tier > 0) {
  5323. // If a tier was passed chec to see if it is the same as the effect
  5324. if (tier == effect->tier)
  5325. lua_interface->SetBooleanValue(state, true);
  5326. else
  5327. lua_interface->SetBooleanValue(state, false);
  5328. return 1;
  5329. }
  5330. else {
  5331. // Have an effect but no tier was passed so return true
  5332. lua_interface->SetBooleanValue(state, true);
  5333. }
  5334. return 1;
  5335. }
  5336. // no effect so return false
  5337. lua_interface->SetBooleanValue(state, false);
  5338. return 1;
  5339. }
  5340. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  5341. if (!lua_interface)
  5342. return 0;
  5343. Spawn* spawn = lua_interface->GetSpawn(state);
  5344. int32 id = lua_interface->GetInt32Value(state, 2);
  5345. ZoneServer* zone = lua_interface->GetZone(state, 3);
  5346. Spawn* spawn2 = 0;
  5347. vector<Spawn*> list;
  5348. if (!spawn) {
  5349. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  5350. return 0;
  5351. }
  5352. //If zone not provided, use spawn's zone
  5353. if (!zone)
  5354. zone = spawn->GetZone();
  5355. list = zone->GetSpawnsByID(id);
  5356. if (list.size() == 0) {
  5357. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  5358. return 0;
  5359. }
  5360. vector<Spawn*>::iterator itr = list.begin();
  5361. for (int8 i = 0; i < list.size(); i++) {
  5362. spawn2 = itr[i];
  5363. if (spawn2)
  5364. spawn2->AddAllowAccessSpawn(spawn);
  5365. }
  5366. return 0;
  5367. }
  5368. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  5369. if (!lua_interface)
  5370. return 0;
  5371. Spawn* spawn = lua_interface->GetSpawn(state);
  5372. int32 id = lua_interface->GetInt32Value(state, 2);
  5373. ZoneServer* zone = lua_interface->GetZone(state, 3);
  5374. Spawn* spawn2 = 0;
  5375. if (!spawn) {
  5376. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  5377. return 0;
  5378. }
  5379. //If zone not provided, use spawn's zone
  5380. if (!zone)
  5381. zone = spawn->GetZone();
  5382. vector<Spawn*> list = zone->GetSpawnsByID(id);
  5383. vector<Spawn*>::iterator itr = list.begin();
  5384. if (list.size() == 0) {
  5385. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  5386. return 0;
  5387. }
  5388. for (int8 i = 0; i < list.size(); i++) {
  5389. spawn2 = itr[i];
  5390. if (spawn2)
  5391. spawn2->RemoveSpawnAccess(spawn);
  5392. }
  5393. return 0;
  5394. }
  5395. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  5396. if (!lua_interface)
  5397. return 0;
  5398. Quest* quest = lua_interface->GetQuest(state);
  5399. if (!quest) {
  5400. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  5401. return 0;
  5402. }
  5403. quest->SetYellowName(true);
  5404. return 0;
  5405. }
  5406. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  5407. if (!lua_interface)
  5408. return 0;
  5409. Spawn* spawn = lua_interface->GetSpawn(state);
  5410. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  5411. if (!spawn) {
  5412. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  5413. return 0;
  5414. }
  5415. if (!spawn->IsPlayer()) {
  5416. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  5417. return 0;
  5418. }
  5419. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  5420. return 1;
  5421. }
  5422. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  5423. if (!lua_interface)
  5424. return 0;
  5425. Spawn* spawn = lua_interface->GetSpawn(state);
  5426. if (!spawn) {
  5427. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  5428. return 0;
  5429. }
  5430. if (!spawn->IsPlayer()) {
  5431. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  5432. return 0;
  5433. }
  5434. ZoneServer* zone = spawn->GetZone();
  5435. if (!zone) {
  5436. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  5437. return 0;
  5438. }
  5439. Instance_Type iType = zone->GetInstanceType();
  5440. if (iType == SOLO_LOCKOUT_INSTANCE ||
  5441. iType == GROUP_LOCKOUT_INSTANCE ||
  5442. iType == RAID_LOCKOUT_INSTANCE ||
  5443. iType == SOLO_PERSIST_INSTANCE ||
  5444. iType == GROUP_PERSIST_INSTANCE ||
  5445. iType == RAID_PERSIST_INSTANCE) {
  5446. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  5447. if (data) {
  5448. // Check to see if the timer has already been set, if it has return out.
  5449. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  5450. return 0;
  5451. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  5452. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  5453. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5454. if (client) {
  5455. string time_msg = "";
  5456. int32 time = data->success_lockout_time;
  5457. int16 hour;
  5458. int8 min;
  5459. int8 sec;
  5460. hour = time / 3600;
  5461. time = time % 3600;
  5462. min = time / 60;
  5463. time = time % 60;
  5464. sec = time;
  5465. if (hour > 0) {
  5466. char temp[10];
  5467. sprintf(temp, " %i", hour);
  5468. time_msg.append(temp);
  5469. time_msg.append(" hour");
  5470. time_msg.append((hour > 1) ? "s" : "");
  5471. }
  5472. if (min > 0) {
  5473. char temp[5];
  5474. sprintf(temp, " %i", min);
  5475. time_msg.append(temp);
  5476. time_msg.append(" minute");
  5477. time_msg.append((min > 1) ? "s" : "");
  5478. }
  5479. // Only add seconds if minutes and hours are 0
  5480. if (hour == 0 && min == 0 && sec > 0) {
  5481. char temp[5];
  5482. sprintf(temp, " %i", sec);
  5483. time_msg.append(temp);
  5484. time_msg.append(" second");
  5485. time_msg.append((sec > 1) ? "s" : "");
  5486. }
  5487. 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());
  5488. }
  5489. }
  5490. else
  5491. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  5492. }
  5493. else
  5494. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  5495. return 0;
  5496. }
  5497. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  5498. if (!lua_interface)
  5499. return 0;
  5500. Spawn* spawn = lua_interface->GetSpawn(state);
  5501. if (!spawn) {
  5502. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  5503. return 0;
  5504. }
  5505. if (!spawn->IsPlayer()) {
  5506. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  5507. return 0;
  5508. }
  5509. ZoneServer* zone = spawn->GetZone();
  5510. if (!zone) {
  5511. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  5512. return 0;
  5513. }
  5514. Instance_Type iType = zone->GetInstanceType();
  5515. if (iType == SOLO_LOCKOUT_INSTANCE ||
  5516. iType == GROUP_LOCKOUT_INSTANCE ||
  5517. iType == RAID_LOCKOUT_INSTANCE ||
  5518. iType == SOLO_PERSIST_INSTANCE ||
  5519. iType == GROUP_PERSIST_INSTANCE ||
  5520. iType == RAID_PERSIST_INSTANCE) {
  5521. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  5522. if (data) {
  5523. // Check to see if the timer has already been set, if it has return out.
  5524. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  5525. return 0;
  5526. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  5527. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  5528. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5529. if (client) {
  5530. string time_msg = "";
  5531. int32 time = data->failure_lockout_time;
  5532. int16 hour;
  5533. int8 min;
  5534. int8 sec;
  5535. hour = time / 3600;
  5536. time = time % 3600;
  5537. min = time / 60;
  5538. time = time % 60;
  5539. sec = time;
  5540. if (hour > 0) {
  5541. char temp[10];
  5542. sprintf(temp, " %i", hour);
  5543. time_msg.append(temp);
  5544. time_msg.append(" hour");
  5545. time_msg.append((hour > 1) ? "s" : "");
  5546. }
  5547. if (min > 0) {
  5548. char temp[5];
  5549. sprintf(temp, " %i", min);
  5550. time_msg.append(temp);
  5551. time_msg.append(" minute");
  5552. time_msg.append((min > 1) ? "s" : "");
  5553. }
  5554. // Only add seconds if minutes and hours are 0
  5555. if (hour == 0 && min == 0 && sec > 0) {
  5556. char temp[5];
  5557. sprintf(temp, " %i", sec);
  5558. time_msg.append(temp);
  5559. time_msg.append(" second");
  5560. time_msg.append((sec > 1) ? "s" : "");
  5561. }
  5562. 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());
  5563. }
  5564. }
  5565. else
  5566. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  5567. }
  5568. else
  5569. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  5570. return 0;
  5571. }
  5572. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  5573. if (!lua_interface)
  5574. return 0;
  5575. Spawn* spawn = lua_interface->GetSpawn(state);
  5576. if (!spawn) {
  5577. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  5578. return 0;
  5579. }
  5580. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  5581. return 1;
  5582. }
  5583. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  5584. if (!lua_interface)
  5585. return 0;
  5586. Spawn* player = lua_interface->GetSpawn(state);
  5587. Spawn* ground = lua_interface->GetSpawn(state, 2);
  5588. if (!player) {
  5589. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  5590. return 0;
  5591. }
  5592. if (!player->IsPlayer()) {
  5593. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  5594. return 0;
  5595. }
  5596. if (!ground) {
  5597. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  5598. return 0;
  5599. }
  5600. if (!ground->IsGroundSpawn()) {
  5601. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  5602. return 0;
  5603. }
  5604. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  5605. if (!groundspawn_entries) {
  5606. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  5607. return 0;
  5608. }
  5609. Skill* skill = 0;
  5610. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  5611. if (collection_skill == "Collecting")
  5612. skill = ((Player*)player)->GetSkillByName("Gathering");
  5613. else
  5614. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  5615. if (!skill) {
  5616. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  5617. return 0;
  5618. }
  5619. vector<GroundSpawnEntry*>::iterator itr;
  5620. GroundSpawnEntry* entry = 0;
  5621. bool can_harvest = false;
  5622. sint32 min_skill = -1;
  5623. // first, iterate through groundspawn_entries, discard tables player cannot use
  5624. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  5625. {
  5626. entry = *itr;
  5627. if (min_skill == -1 || entry->min_skill_level < min_skill)
  5628. min_skill = entry->min_skill_level;
  5629. // if player lacks skill, skip table
  5630. if (entry->min_skill_level > skill->current_val)
  5631. continue;
  5632. // if bonus, but player lacks level, skip table
  5633. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  5634. continue;
  5635. can_harvest = true;
  5636. break;
  5637. }
  5638. lua_interface->SetBooleanValue(state, can_harvest);
  5639. // If false, send the message to the client
  5640. if (!can_harvest) {
  5641. Client* client = player->GetZone()->GetClientBySpawn(player);
  5642. if (client) {
  5643. string msg = "You do not have enough skill to ";
  5644. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  5645. msg.append("gather");
  5646. else if (collection_skill == "Mining")
  5647. msg.append("mine");
  5648. else if (collection_skill == "Trapping")
  5649. msg.append("trap");
  5650. else if (collection_skill == "Foresting")
  5651. msg.append("forest");
  5652. else if (collection_skill == "Fishing")
  5653. msg.append("catch");
  5654. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  5655. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), skill->current_val);
  5656. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  5657. }
  5658. }
  5659. return 1;
  5660. }
  5661. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  5662. if (!lua_interface)
  5663. return 0;
  5664. Spawn* player = lua_interface->GetSpawn(state);
  5665. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  5666. if (!player) {
  5667. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  5668. return 0;
  5669. }
  5670. if (!player->IsPlayer()) {
  5671. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  5672. return 0;
  5673. }
  5674. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  5675. lua_interface->SetBooleanValue(state, ret);
  5676. return 1;
  5677. }
  5678. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  5679. // Check to see if we have a valid lua_interface
  5680. if (!lua_interface)
  5681. return 0;
  5682. // Get the spawn that is getting the pet
  5683. Spawn* spawn = lua_interface->GetSpawn(state);
  5684. Spawn* target = lua_interface->GetSpawn(state, 2);
  5685. // Get the DB ID of the pet
  5686. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  5687. float x = lua_interface->GetFloatValue(state, 4);
  5688. float y = lua_interface->GetFloatValue(state, 5);
  5689. float z = lua_interface->GetFloatValue(state, 6);
  5690. // Get the spell that this command was called from
  5691. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5692. // Check to make sure the spawn pointer is valid
  5693. if (!spawn) {
  5694. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5695. return 0;
  5696. }
  5697. // Check to make sure the spawn is an entity
  5698. if (!spawn->IsEntity()) {
  5699. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5700. return 0;
  5701. }
  5702. if (!target) {
  5703. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  5704. return 0;
  5705. }
  5706. if (!target->IsEntity()) {
  5707. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  5708. return 0;
  5709. }
  5710. // Check to see if the DB ID for the pet is set
  5711. if (pet_id == 0) {
  5712. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5713. return 0;
  5714. }
  5715. // Check to see if the pointer to the spell is valid
  5716. if (!luaspell) {
  5717. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5718. return 0;
  5719. }
  5720. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  5721. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5722. if (!pet) {
  5723. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  5724. return 0;
  5725. }
  5726. // Check to make sure the pet is an npc
  5727. if (!pet->IsNPC()) {
  5728. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  5729. return 0;
  5730. }
  5731. if (x == 0)
  5732. x = spawn->GetX();
  5733. if (y == 0)
  5734. y = spawn->GetY();
  5735. if (z == 0)
  5736. z = spawn->GetZ();
  5737. // Spawn the pet at the same location as the owner
  5738. pet->SetX(x);
  5739. pet->SetY(y);
  5740. pet->SetZ(z);
  5741. pet->SetLocation(spawn->GetLocation());
  5742. pet->SetHeading(spawn->GetHeading());
  5743. spawn->GetZone()->AddSpawn(pet);
  5744. /*
  5745. const char* spawn_script = world.GetSpawnScript(pet_id);
  5746. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  5747. spawn->SetSpawnScript(string(spawn_script));
  5748. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5749. }*/
  5750. // Get a random pet name
  5751. string random_pet_name;
  5752. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5753. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5754. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5755. // Set the pets name
  5756. pet->SetName(random_pet_name.c_str());
  5757. // Set the level of the pet to the owners level
  5758. pet->SetLevel(spawn->GetLevel());
  5759. // Set the faction of the pet to the same faction as the owner
  5760. pet->SetFactionID(spawn->GetFactionID());
  5761. // Set the spawn as a pet
  5762. pet->SetPet(true);
  5763. // Give a pointer of the owner to the pet
  5764. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5765. // Set the pet type
  5766. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  5767. // Set the spell id used to create this pet
  5768. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5769. // Set the spell tier used to create this pet
  5770. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5771. // Set the pets spawn type to 6
  5772. pet->SetSpawnType(6);
  5773. // Set the pets brain
  5774. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  5775. // Check to see if the pet has a subtitle
  5776. if (strlen(pet->GetSubTitle()) > 0) {
  5777. // Add the players name to the front of the sub title
  5778. string pet_subtitle;
  5779. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5780. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5781. // Set the pets subtitle to the new one
  5782. pet->SetSubTitle(pet_subtitle.c_str());
  5783. }
  5784. // Set the pet as the return value for this function
  5785. lua_interface->SetSpawnValue(state, pet);
  5786. return 1;
  5787. }
  5788. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  5789. if (!lua_interface)
  5790. return 0;
  5791. Spawn* spawn = lua_interface->GetSpawn(state);
  5792. Spawn* player = lua_interface->GetSpawn(state, 2);
  5793. float max_distance = lua_interface->GetFloatValue(state, 3);
  5794. string type = lua_interface->GetStringValue(state, 4);
  5795. if (!spawn || (spawn && spawn->IsPlayer())) {
  5796. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  5797. return 0;
  5798. }
  5799. if (!player || (player && !player->IsPlayer())) {
  5800. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  5801. return 0;
  5802. }
  5803. Client* client = 0;
  5804. if (player->GetZone())
  5805. client = player->GetZone()->GetClientBySpawn(player);
  5806. if (!client) {
  5807. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  5808. return 0;
  5809. }
  5810. //Set max_distance to default if not set or not proper value
  5811. if (max_distance <= 0)
  5812. max_distance = 500;
  5813. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  5814. if (packet) {
  5815. float unknown2_3 = 0;
  5816. int8 placement_mode = 0;
  5817. if (type == "wall") {
  5818. placement_mode = 2;
  5819. unknown2_3 = 150;
  5820. }
  5821. else if (type == "ceiling")
  5822. placement_mode = 1;
  5823. packet->setDataByName("placement_mode", placement_mode);
  5824. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  5825. packet->setDataByName("model_type", spawn->GetModelType());
  5826. packet->setDataByName("unknown", 1); //size
  5827. packet->setDataByName("unknown2", 1); //size 2
  5828. packet->setDataByName("unknown2", .5, 1); //size 3
  5829. packet->setDataByName("unknown2", 3, 2);
  5830. packet->setDataByName("unknown2", unknown2_3, 3);
  5831. packet->setDataByName("max_distance", max_distance);
  5832. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  5833. client->QueuePacket(packet->serialize());
  5834. safe_delete(packet);
  5835. }
  5836. return 0;
  5837. }
  5838. int EQ2Emu_lua_GetItemType(lua_State* state) {
  5839. if (!lua_interface)
  5840. return 0;
  5841. Item* item = lua_interface->GetItem(state);
  5842. if (!item) {
  5843. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  5844. return 0;
  5845. }
  5846. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  5847. return 1;
  5848. }
  5849. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  5850. if (!lua_interface)
  5851. return 0;
  5852. Spawn* spawn = lua_interface->GetSpawn(state);
  5853. if (!spawn) {
  5854. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  5855. return 0;
  5856. }
  5857. if (spawn->GetZone())
  5858. spawn->GetZone()->AddTransportSpawn(spawn);
  5859. return 0;
  5860. }
  5861. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  5862. if (!lua_interface)
  5863. return 0;
  5864. Skill* skill = lua_interface->GetSkill(state);
  5865. if (!skill) {
  5866. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  5867. return 0;
  5868. }
  5869. lua_interface->SetInt32Value(state, skill->current_val);
  5870. return 1;
  5871. }
  5872. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  5873. if (!lua_interface)
  5874. return 0;
  5875. Skill* skill = lua_interface->GetSkill(state);
  5876. if (!skill) {
  5877. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  5878. return 0;
  5879. }
  5880. lua_interface->SetInt32Value(state, skill->max_val);
  5881. return 1;
  5882. }
  5883. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  5884. if (!lua_interface)
  5885. return 0;
  5886. Skill* skill = lua_interface->GetSkill(state);
  5887. if (!skill) {
  5888. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  5889. return 0;
  5890. }
  5891. lua_interface->SetStringValue(state, skill->name.data.c_str());
  5892. return 1;
  5893. }
  5894. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  5895. if (!lua_interface)
  5896. return 0;
  5897. Skill* skill = lua_interface->GetSkill(state);
  5898. int16 value = lua_interface->GetInt16Value(state, 2);
  5899. if (!skill) {
  5900. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  5901. return 0;
  5902. }
  5903. skill->max_val = value;
  5904. if (skill->max_val < skill->current_val)
  5905. skill->current_val = skill->max_val;
  5906. return 0;
  5907. }
  5908. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  5909. if (!lua_interface)
  5910. return 0;
  5911. Skill* skill = lua_interface->GetSkill(state);
  5912. int16 value = lua_interface->GetInt16Value(state, 2);
  5913. if (!skill) {
  5914. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  5915. return 0;
  5916. }
  5917. if (value > skill->max_val)
  5918. skill->current_val = skill->max_val;
  5919. else
  5920. skill->current_val = value;
  5921. return 0;
  5922. }
  5923. int EQ2Emu_lua_GetSkill(lua_State* state) {
  5924. if (!lua_interface)
  5925. return 0;
  5926. Spawn* spawn = lua_interface->GetSpawn(state);
  5927. string name = lua_interface->GetStringValue(state, 2);
  5928. if (!spawn) {
  5929. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  5930. return 0;
  5931. }
  5932. if (!spawn->IsEntity()) {
  5933. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  5934. return 0;
  5935. }
  5936. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  5937. if (skill) {
  5938. lua_interface->SetSkillValue(state, skill);
  5939. return 1;
  5940. }
  5941. return 0;
  5942. }
  5943. int EQ2Emu_lua_AddProc(lua_State* state) {
  5944. if (!lua_interface)
  5945. return 0;
  5946. Spawn* spawn = lua_interface->GetSpawn(state);
  5947. int8 type = lua_interface->GetInt8Value(state, 2);
  5948. float chance = lua_interface->GetFloatValue(state, 3);
  5949. Item* item = lua_interface->GetItem(state, 4);
  5950. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  5951. LuaSpell* spell = 0;
  5952. if (!spawn && (!spell || !use_all_spelltargets)) {
  5953. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  5954. return 0;
  5955. }
  5956. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  5957. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  5958. return 0;
  5959. }
  5960. if (!item)
  5961. spell = lua_interface->GetCurrentSpell(state);
  5962. if (!item && !spell) {
  5963. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  5964. return 0;
  5965. }
  5966. if (spell && use_all_spelltargets) {
  5967. Spawn* target;
  5968. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5969. for (int8 i = 0; i < spell->targets.size(); i++) {
  5970. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5971. if (!target || !target->IsEntity())
  5972. continue;
  5973. ((Entity*)target)->AddProc(type, chance, item, spell);
  5974. }
  5975. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5976. }
  5977. else
  5978. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  5979. return 0;
  5980. }
  5981. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  5982. if (!lua_interface)
  5983. return 0;
  5984. Spawn* spawn = lua_interface->GetSpawn(state);
  5985. Item* item = lua_interface->GetItem(state, 2);
  5986. LuaSpell* spell = 0;
  5987. if (!spawn) {
  5988. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  5989. return 0;
  5990. }
  5991. if (!spawn->IsEntity()) {
  5992. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  5993. return 0;
  5994. }
  5995. if (!item)
  5996. spell = lua_interface->GetCurrentSpell(state);
  5997. if (!item && !spell) {
  5998. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  5999. return 0;
  6000. }
  6001. if (spell) {
  6002. Spawn* target;
  6003. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6004. for (int8 i = 0; i < spell->targets.size(); i++) {
  6005. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6006. if (!target || !target->IsEntity())
  6007. continue;
  6008. ((Entity*)target)->RemoveProc(item, spell);
  6009. }
  6010. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6011. spell->caster->RemoveProc(item, spell);
  6012. }
  6013. else
  6014. ((Entity*)spawn)->RemoveProc(item, spell);
  6015. return 0;
  6016. }
  6017. int EQ2Emu_lua_Knockback(lua_State* state) {
  6018. if (!lua_interface)
  6019. return 0;
  6020. Spawn* target_spawn = lua_interface->GetSpawn(state);
  6021. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6022. int32 duration = lua_interface->GetInt32Value(state, 3);
  6023. float vertical = lua_interface->GetFloatValue(state, 4);
  6024. float horizontal = lua_interface->GetFloatValue(state, 5);
  6025. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  6026. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6027. if (!target_spawn) {
  6028. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  6029. return 0;
  6030. }
  6031. if (!spawn) {
  6032. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6033. return 0;
  6034. }
  6035. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  6036. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6037. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  6038. if (packet) {
  6039. packet->setDataByName("target_x", target_spawn->GetX());
  6040. packet->setDataByName("target_y", target_spawn->GetY());
  6041. packet->setDataByName("target_z", target_spawn->GetZ());
  6042. packet->setDataByName("vertical_movement", vertical);
  6043. packet->setDataByName("horizontal_movement", horizontal);
  6044. if (use_heading)
  6045. packet->setDataByName("use_player_heading", 1);
  6046. client->QueuePacket(packet->serialize());
  6047. }
  6048. safe_delete(packet);
  6049. }
  6050. return 0;
  6051. }
  6052. int EQ2Emu_lua_IsEpic(lua_State* state) {
  6053. if (!lua_interface)
  6054. return 0;
  6055. Spawn* spawn = lua_interface->GetSpawn(state);
  6056. if (!spawn) {
  6057. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6058. return 0;
  6059. }
  6060. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  6061. return 1;
  6062. }
  6063. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  6064. if (!lua_interface)
  6065. return 0;
  6066. Spawn* caster = lua_interface->GetSpawn(state);
  6067. Spawn* target = lua_interface->GetSpawn(state, 2);
  6068. string name = lua_interface->GetStringValue(state, 3);
  6069. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  6070. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  6071. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  6072. string success_msg = lua_interface->GetStringValue(state, 7);
  6073. string effect_msg = lua_interface->GetStringValue(state, 8);
  6074. if (!caster) {
  6075. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6076. return 0;
  6077. }
  6078. if (!caster->IsEntity()) {
  6079. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  6080. return 0;
  6081. }
  6082. if (!target) {
  6083. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6084. return 0;
  6085. }
  6086. if (!target->IsEntity()) {
  6087. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  6088. return 0;
  6089. }
  6090. if (name.length() == 0) {
  6091. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  6092. return 0;
  6093. }
  6094. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  6095. return 0;
  6096. }
  6097. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  6098. if (!lua_interface)
  6099. return 0;
  6100. string name = lua_interface->GetStringValue(state);
  6101. if (name.length() == 0) {
  6102. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  6103. return 0;
  6104. }
  6105. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  6106. if (!skill) {
  6107. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  6108. return 0;
  6109. }
  6110. lua_interface->SetInt32Value(state, skill->skill_id);
  6111. return 1;
  6112. }
  6113. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  6114. if (!lua_interface)
  6115. return 0;
  6116. Spawn* spawn = lua_interface->GetSpawn(state);
  6117. if (!spawn) {
  6118. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  6119. return 0;
  6120. }
  6121. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  6122. return 1;
  6123. }
  6124. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  6125. if (!lua_interface)
  6126. return 0;
  6127. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6128. if (!luaspell) {
  6129. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  6130. return 0;
  6131. }
  6132. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  6133. return 1;
  6134. }
  6135. int EQ2Emu_lua_IsBehind(lua_State* state) {
  6136. if (!lua_interface)
  6137. return 0;
  6138. Spawn* spawn = lua_interface->GetSpawn(state);
  6139. Spawn* target = lua_interface->GetSpawn(state, 2);
  6140. if (!spawn) {
  6141. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  6142. return 0;
  6143. }
  6144. if (!spawn->IsEntity()) {
  6145. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6146. return 0;
  6147. }
  6148. if (!target) {
  6149. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  6150. return 0;
  6151. }
  6152. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  6153. return 1;
  6154. }
  6155. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  6156. if (!lua_interface)
  6157. return 0;
  6158. Spawn* spawn = lua_interface->GetSpawn(state);
  6159. Spawn* target = lua_interface->GetSpawn(state, 2);
  6160. if (!spawn) {
  6161. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  6162. return 0;
  6163. }
  6164. if (!spawn->IsEntity()) {
  6165. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6166. return 0;
  6167. }
  6168. if (!target) {
  6169. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  6170. return 0;
  6171. }
  6172. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  6173. return 1;
  6174. }
  6175. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  6176. if (!lua_interface)
  6177. return 0;
  6178. Item* item = lua_interface->GetItem(state);
  6179. if (!item) {
  6180. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  6181. return 0;
  6182. }
  6183. lua_interface->SetInt32Value(state, item->details.count);
  6184. return 1;
  6185. }
  6186. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  6187. if (!lua_interface)
  6188. return 0;
  6189. Item* item = lua_interface->GetItem(state);
  6190. Spawn* owner = lua_interface->GetSpawn(state, 2);
  6191. int16 new_count = lua_interface->GetInt32Value(state, 3);
  6192. if (!item) {
  6193. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  6194. return 0;
  6195. }
  6196. if (!owner) {
  6197. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  6198. return 0;
  6199. }
  6200. if (!owner->IsPlayer()) {
  6201. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  6202. return 0;
  6203. }
  6204. if (item->stack_count < new_count) {
  6205. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  6206. return 0;
  6207. }
  6208. if (new_count > 0) {
  6209. item->details.count = new_count;
  6210. item->save_needed = true;
  6211. }
  6212. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  6213. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  6214. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  6215. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  6216. else
  6217. {
  6218. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  6219. return 0;
  6220. }
  6221. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  6222. if (!client)
  6223. return 0;
  6224. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  6225. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion());
  6226. if (app)
  6227. client->QueuePacket(app);
  6228. return 0;
  6229. }
  6230. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  6231. if (!lua_interface)
  6232. return 0;
  6233. int32 time = lua_interface->GetInt32Value(state);
  6234. string function = lua_interface->GetStringValue(state, 2);
  6235. Spawn* caster = lua_interface->GetSpawn(state, 3);
  6236. Spawn* target = lua_interface->GetSpawn(state, 4);
  6237. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6238. if (time == 0) {
  6239. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  6240. return 0;
  6241. }
  6242. if (function.length() == 0) {
  6243. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  6244. return 0;
  6245. }
  6246. if (!spell) {
  6247. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  6248. return 0;
  6249. }
  6250. SpellScriptTimer* timer = new SpellScriptTimer;
  6251. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  6252. #ifdef WIN32
  6253. ZeroMemory(timer, sizeof(SpellScriptTimer));
  6254. #else
  6255. bzero(timer, sizeof(SpellScriptTimer));
  6256. #endif*/
  6257. timer->caster = 0;
  6258. timer->deleteWhenDone = false;
  6259. timer->target = 0;
  6260. timer->time = Timer::GetCurrentTime2() + time;
  6261. timer->customFunction = function;
  6262. timer->spell = spell;
  6263. if (caster)
  6264. timer->caster = caster->GetID();
  6265. if (target)
  6266. timer->target = target->GetID();
  6267. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  6268. return 0;
  6269. }
  6270. int EQ2Emu_lua_Resurrect(lua_State* state) {
  6271. if (!lua_interface)
  6272. return 0;
  6273. float hp_perc = lua_interface->GetFloatValue(state);
  6274. float power_perc = lua_interface->GetFloatValue(state, 2);
  6275. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  6276. Spawn* target = lua_interface->GetSpawn(state, 4);
  6277. string heal_name = lua_interface->GetStringValue(state, 5);
  6278. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  6279. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  6280. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6281. if (!spell) {
  6282. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  6283. return 0;
  6284. }
  6285. Entity* caster = spell->caster;
  6286. if (!caster) {
  6287. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  6288. return 0;
  6289. }
  6290. Client* client = 0;
  6291. PendingResurrection* rez = 0;
  6292. ZoneServer* zone = spell->caster->GetZone();
  6293. if (!target) {
  6294. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6295. if (spell->targets.size() > 0) {
  6296. vector<int32> spell_targets = spell->targets;
  6297. for (int8 i = 0; i < spell_targets.size(); i++) {
  6298. target = zone->GetSpawnByID(spell_targets.at(i));
  6299. if (!target)
  6300. continue;
  6301. if (!target->IsPlayer())
  6302. continue;
  6303. client = target->GetZone()->GetClientBySpawn(target);
  6304. if (!client)
  6305. continue;
  6306. rez = client->GetCurrentRez();
  6307. if (rez->active)
  6308. continue;
  6309. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  6310. rez->active = true;
  6311. rez->caster = caster;
  6312. rez->expire_timer = new Timer;
  6313. int32 duration = spell->spell->GetSpellDuration();
  6314. rez->expire_timer->Start(duration * 100);
  6315. rez->hp_perc = hp_perc;
  6316. rez->mp_perc = power_perc;
  6317. rez->range = spell->spell->GetSpellData()->range;
  6318. rez->spell_name = spell->spell->GetName();
  6319. if (heal_name.length() > 0)
  6320. rez->heal_name = heal_name;
  6321. else
  6322. rez->heal_name = rez->spell_name;
  6323. rez->no_calcs = no_calcs;
  6324. rez->crit_mod = crit_mod;
  6325. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  6326. if (send_window)
  6327. client->SendResurrectionWindow();
  6328. else {
  6329. target->GetZone()->ResurrectSpawn(target, client);
  6330. rez->should_delete = true;
  6331. }
  6332. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  6333. }
  6334. }
  6335. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6336. }
  6337. else {
  6338. client = target->GetZone()->GetClientBySpawn(target);
  6339. if (!client)
  6340. return 0;
  6341. rez = client->GetCurrentRez();
  6342. if (rez->active)
  6343. return 0;
  6344. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  6345. rez->active = true;
  6346. rez->caster = caster;
  6347. rez->expire_timer = new Timer;
  6348. int32 duration = spell->spell->GetSpellDuration();
  6349. rez->expire_timer->Start(duration * 100);
  6350. rez->hp_perc = hp_perc;
  6351. rez->mp_perc = power_perc;
  6352. rez->range = spell->spell->GetSpellData()->range;
  6353. rez->spell_name = spell->spell->GetName();
  6354. if (heal_name.length() > 0)
  6355. rez->heal_name = heal_name;
  6356. else
  6357. rez->heal_name = rez->spell_name;
  6358. rez->no_calcs = no_calcs;
  6359. rez->crit_mod = crit_mod;
  6360. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  6361. if (send_window)
  6362. client->SendResurrectionWindow();
  6363. else {
  6364. target->GetZone()->ResurrectSpawn(target, client);
  6365. rez->should_delete = true;
  6366. }
  6367. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  6368. }
  6369. return 0;
  6370. }
  6371. int EQ2Emu_lua_SetVision(lua_State* state) {
  6372. if (!lua_interface)
  6373. return 0;
  6374. Spawn* spawn = lua_interface->GetSpawn(state);
  6375. int8 vision = lua_interface->GetInt8Value(state, 2);
  6376. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6377. if (!spawn) {
  6378. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  6379. return 0;
  6380. }
  6381. if (!spawn->IsEntity()) {
  6382. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6383. return 0;
  6384. }
  6385. if (spell && spell->targets.size() > 0) {
  6386. ZoneServer* zone = spell->caster->GetZone();
  6387. for (int8 i = 0; i < spell->targets.size(); i++) {
  6388. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6389. if (target->IsEntity()) {
  6390. ((Entity*)target)->GetInfoStruct()->vision = vision;
  6391. if (target->IsPlayer())
  6392. ((Player*)target)->SetCharSheetChanged(true);
  6393. }
  6394. }
  6395. }
  6396. else {
  6397. ((Entity*)spawn)->GetInfoStruct()->vision = vision;
  6398. if (spawn->IsPlayer())
  6399. ((Player*)spawn)->SetCharSheetChanged(true);
  6400. }
  6401. return 0;
  6402. }
  6403. int EQ2Emu_lua_BlurVision(lua_State* state) {
  6404. if (!lua_interface)
  6405. return 0;
  6406. Spawn* spawn = lua_interface->GetSpawn(state);
  6407. float intensity = lua_interface->GetFloatValue(state, 2);
  6408. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6409. if (!spawn) {
  6410. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  6411. return 0;
  6412. }
  6413. if (!spawn->IsEntity()) {
  6414. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6415. return 0;
  6416. }
  6417. if (spell && spell->targets.size() > 0) {
  6418. ZoneServer* zone = spell->caster->GetZone();
  6419. for (int8 i = 0; i < spell->targets.size(); i++) {
  6420. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6421. if (target && target->IsEntity()) {
  6422. ((Entity*)target)->GetInfoStruct()->drunk = intensity;
  6423. if (target->IsPlayer())
  6424. ((Player*)target)->SetCharSheetChanged(true);
  6425. }
  6426. }
  6427. }
  6428. else {
  6429. ((Entity*)spawn)->GetInfoStruct()->drunk = intensity;
  6430. if (spawn->IsPlayer())
  6431. ((Player*)spawn)->SetCharSheetChanged(true);
  6432. }
  6433. return 0;
  6434. }
  6435. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  6436. if (!lua_interface)
  6437. return 0;
  6438. Spawn* spawn = lua_interface->GetSpawn(state);
  6439. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  6440. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6441. if (!spawn) {
  6442. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  6443. return 0;
  6444. }
  6445. if (!spawn->IsEntity()) {
  6446. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  6447. return 0;
  6448. }
  6449. if (spell && spell->targets.size() > 0) {
  6450. ZoneServer* zone = spell->caster->GetZone();
  6451. for (int8 i = 0; i < spell->targets.size(); i++) {
  6452. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6453. if (target->IsEntity()) {
  6454. ((Entity*)target)->GetInfoStruct()->breathe_underwater = breatheUnderwater;
  6455. if (target->IsPlayer())
  6456. ((Player*)target)->SetCharSheetChanged(true);
  6457. }
  6458. }
  6459. }
  6460. else {
  6461. ((Entity*)spawn)->GetInfoStruct()->breathe_underwater = breatheUnderwater;
  6462. if (spawn->IsPlayer())
  6463. ((Player*)spawn)->SetCharSheetChanged(true);
  6464. }
  6465. return 0;
  6466. }
  6467. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  6468. if (!lua_interface)
  6469. return 0;
  6470. Item* item = lua_interface->GetItem(state);
  6471. int8 type = lua_interface->GetInt32Value(state, 2);
  6472. if (!item) {
  6473. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  6474. return 0;
  6475. }
  6476. if (type == 1)
  6477. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  6478. else if (type == 2)
  6479. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  6480. return 1;
  6481. }
  6482. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  6483. if (!lua_interface)
  6484. return 0;
  6485. Spawn* target = lua_interface->GetSpawn(state);
  6486. float val = lua_interface->GetFloatValue(state, 2);
  6487. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6488. // Added from Gangrenous post
  6489. if (spell && spell->resisted)
  6490. return 0;
  6491. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  6492. if (val > 1.0f)
  6493. val = 1.0f - (val / 100.0f);
  6494. if (spell && spell->spell && spell->targets.size() > 0) {
  6495. ZoneServer* zone = spell->caster->GetZone();
  6496. for (int32 i = 0; i != spell->targets.size(); i++) {
  6497. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  6498. if (spawn && spawn->IsEntity()) {
  6499. ((Entity*)spawn)->SetSpeedMultiplier(val);
  6500. if (spawn->IsPlayer())
  6501. ((Player*)spawn)->SetCharSheetChanged(true);
  6502. }
  6503. }
  6504. }
  6505. else {
  6506. if (target && target->IsEntity()) {
  6507. ((Entity*)target)->SetSpeedMultiplier(val);
  6508. if (target->IsPlayer())
  6509. ((Player*)target)->SetCharSheetChanged(true);
  6510. }
  6511. }
  6512. return 0;
  6513. }
  6514. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  6515. if (!lua_interface)
  6516. return 0;
  6517. Spawn* spawn = lua_interface->GetSpawn(state);
  6518. int16 model = lua_interface->GetInt16Value(state, 2);
  6519. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6520. if (spell && spell->spell && spell->targets.size() > 0) {
  6521. ZoneServer* zone = spell->caster->GetZone();
  6522. for (int32 i = 0; i < spell->targets.size(); i++) {
  6523. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6524. if (target)
  6525. target->SetIllusionModel(model);
  6526. }
  6527. }
  6528. else {
  6529. if (!spawn) {
  6530. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  6531. return 0;
  6532. }
  6533. spawn->SetIllusionModel(model);
  6534. }
  6535. return 0;
  6536. }
  6537. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  6538. if (!lua_interface)
  6539. return 0;
  6540. Spawn* spawn = lua_interface->GetSpawn(state);
  6541. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6542. if (spell && spell->spell && spell->targets.size() > 0) {
  6543. ZoneServer* zone = spell->caster->GetZone();
  6544. for (int32 i = 0; i < spell->targets.size(); i++) {
  6545. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  6546. if (target)
  6547. target->SetIllusionModel(0);
  6548. }
  6549. }
  6550. else {
  6551. if (!spawn) {
  6552. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  6553. return 0;
  6554. }
  6555. spawn->SetIllusionModel(0);
  6556. }
  6557. return 0;
  6558. }
  6559. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  6560. if (!lua_interface)
  6561. return 0;
  6562. Spawn* caster = lua_interface->GetSpawn(state);
  6563. Spawn* target = lua_interface->GetSpawn(state, 2);
  6564. float chance = lua_interface->GetFloatValue(state, 3);
  6565. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6566. if (!caster) {
  6567. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6568. return 0;
  6569. }
  6570. if (!caster->IsEntity()) {
  6571. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  6572. return 0;
  6573. }
  6574. if (!target) {
  6575. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6576. return 0;
  6577. }
  6578. if (!target->IsEntity()) {
  6579. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  6580. return 0;
  6581. }
  6582. if (chance <= 0) {
  6583. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  6584. return 0;
  6585. }
  6586. if (!spell) {
  6587. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  6588. return 0;
  6589. }
  6590. if (((Entity*)caster)->GetThreatTransfer()) {
  6591. return 0;
  6592. }
  6593. ThreatTransfer* transfer = new ThreatTransfer;
  6594. transfer->Target = target->GetID();
  6595. transfer->Amount = chance;
  6596. transfer->Spell = spell;
  6597. ((Entity*)caster)->SetThreatTransfer(transfer);
  6598. return 0;
  6599. }
  6600. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  6601. if (!lua_interface)
  6602. return 0;
  6603. Spawn* spawn = lua_interface->GetSpawn(state);
  6604. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6605. if (!spawn) {
  6606. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6607. return 0;
  6608. }
  6609. if (!spell) {
  6610. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  6611. return 0;
  6612. }
  6613. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  6614. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  6615. safe_delete(transfer);
  6616. ((Entity*)spawn)->SetThreatTransfer(0);
  6617. }
  6618. return 0;
  6619. }
  6620. int EQ2Emu_lua_CureByType(lua_State* state) {
  6621. if (!lua_interface)
  6622. return 0;
  6623. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6624. if (!spell) {
  6625. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  6626. return 0;
  6627. }
  6628. int8 cure_count = lua_interface->GetInt8Value(state);
  6629. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  6630. string cure_name = lua_interface->GetStringValue(state, 3);
  6631. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  6632. Spawn* target = lua_interface->GetSpawn(state, 5);
  6633. if (target) {
  6634. if (!target->IsEntity()) {
  6635. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  6636. return 0;
  6637. }
  6638. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  6639. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  6640. }
  6641. else {
  6642. ZoneServer* zone = spell->caster->GetZone();
  6643. vector<int32> targets = spell->targets;
  6644. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6645. for (int8 i = 0; i < targets.size(); i++) {
  6646. target = zone->GetSpawnByID(targets.at(i));
  6647. if (!target || !target->IsEntity())
  6648. continue;
  6649. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  6650. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  6651. }
  6652. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6653. }
  6654. return 0;
  6655. }
  6656. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  6657. if (!lua_interface)
  6658. return 0;
  6659. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6660. if (!spell) {
  6661. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  6662. return 0;
  6663. }
  6664. int8 cure_count = lua_interface->GetInt8Value(state);
  6665. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  6666. string cure_name = lua_interface->GetStringValue(state, 3);
  6667. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  6668. Spawn* target = lua_interface->GetSpawn(state, 5);
  6669. if (target) {
  6670. if (!target->IsEntity()) {
  6671. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  6672. return 0;
  6673. }
  6674. if (((Entity*)target)->GetDetCount() > 0)
  6675. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  6676. }
  6677. else {
  6678. ZoneServer* zone = spell->caster->GetZone();
  6679. vector<int32> targets = spell->targets;
  6680. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6681. for (int8 i = 0; i < targets.size(); i++) {
  6682. target = zone->GetSpawnByID(targets.at(i));
  6683. if (!target || !target->IsEntity())
  6684. continue;
  6685. if (((Entity*)target)->GetDetCount() > 0)
  6686. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  6687. }
  6688. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6689. }
  6690. return 0;
  6691. }
  6692. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  6693. if (!lua_interface)
  6694. return 0;
  6695. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6696. if (!spell) {
  6697. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  6698. return 0;
  6699. }
  6700. if (!spell->caster) {
  6701. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  6702. return 0;
  6703. }
  6704. if (!spell->caster->GetZone()) {
  6705. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  6706. return 0;
  6707. }
  6708. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  6709. return 0;
  6710. }
  6711. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  6712. if (!lua_interface)
  6713. return 0;
  6714. Spawn* spawn = lua_interface->GetSpawn(state);
  6715. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6716. if (!spell) {
  6717. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  6718. return 0;
  6719. }
  6720. if (spawn && spawn->IsEntity())
  6721. ((Entity*)spawn)->RemoveStealthSpell(spell);
  6722. else {
  6723. ZoneServer* zone = spell->caster->GetZone();
  6724. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6725. for (int32 i = 0; i < spell->targets.size(); i++) {
  6726. spawn = zone->GetSpawnByID(spell->targets.at(i));
  6727. if (!spawn || !spawn->IsEntity())
  6728. continue;
  6729. ((Entity*)spawn)->RemoveStealthSpell(spell);
  6730. }
  6731. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6732. }
  6733. return 0;
  6734. }
  6735. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  6736. if (!lua_interface)
  6737. return 0;
  6738. Spawn* spawn = lua_interface->GetSpawn(state);
  6739. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6740. if (!spell) {
  6741. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  6742. return 0;
  6743. }
  6744. if (spawn && spawn->IsEntity())
  6745. ((Entity*)spawn)->RemoveInvisSpell(spell);
  6746. else {
  6747. ZoneServer* zone = spell->caster->GetZone();
  6748. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6749. for (int32 i = 0; i < spell->targets.size(); i++) {
  6750. spawn = zone->GetSpawnByID(spell->targets.at(i));
  6751. if (!spawn || !spawn->IsEntity())
  6752. continue;
  6753. ((Entity*)spawn)->RemoveInvisSpell(spell);
  6754. }
  6755. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6756. }
  6757. return 0;
  6758. }
  6759. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  6760. if (!lua_interface)
  6761. return 0;
  6762. Spawn* caster = lua_interface->GetSpawn(state);
  6763. int8 class_id = lua_interface->GetInt8Value(state, 2);
  6764. if (!caster) {
  6765. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  6766. return 0;
  6767. }
  6768. if (!caster->IsPlayer()) {
  6769. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  6770. return 0;
  6771. }
  6772. Spawn* target = caster->GetTarget();
  6773. if (!target) {
  6774. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  6775. return 0;
  6776. }
  6777. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  6778. if (!client) {
  6779. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  6780. return 0;
  6781. }
  6782. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  6783. if (ho) {
  6784. ho->SetTarget(target->GetID());
  6785. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  6786. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  6787. if (((Entity*)caster)->GetGroupMemberInfo()) {
  6788. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  6789. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  6790. deque<GroupMemberInfo*>::iterator itr;
  6791. deque<GroupMemberInfo*>* members = world.GetGroupManager()->GetGroupMembers(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  6792. for (itr = members->begin(); itr != members->end(); itr++) {
  6793. if ((*itr)->client)
  6794. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  6795. }
  6796. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  6797. }
  6798. else
  6799. safe_delete(ho);
  6800. }
  6801. else {
  6802. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  6803. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  6804. }
  6805. else
  6806. safe_delete(ho);
  6807. }
  6808. }
  6809. return 0;
  6810. }
  6811. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  6812. if (!lua_interface)
  6813. return 0;
  6814. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6815. if (!spell) {
  6816. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  6817. return 0;
  6818. }
  6819. int16 triggerCount = lua_interface->GetInt16Value(state);
  6820. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  6821. if (!triggerCount) {
  6822. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  6823. return 0;
  6824. }
  6825. spell->num_triggers = triggerCount;
  6826. spell->had_triggers = true;
  6827. spell->cancel_after_all_triggers = cancel_after_triggers;
  6828. return 0;
  6829. }
  6830. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  6831. if (!lua_interface)
  6832. return 0;
  6833. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6834. if (!spell) {
  6835. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  6836. return 0;
  6837. }
  6838. lua_interface->SetInt32Value(state, spell->num_triggers);
  6839. return 1;
  6840. }
  6841. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  6842. if (!lua_interface)
  6843. return 0;
  6844. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6845. if (!spell) {
  6846. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  6847. return 0;
  6848. }
  6849. int16 remove_count = lua_interface->GetInt16Value(state);
  6850. if (!remove_count)
  6851. remove_count = 1;
  6852. if (remove_count >= spell->num_triggers) {
  6853. spell->num_triggers = 0;
  6854. if (spell->cancel_after_all_triggers)
  6855. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  6856. }
  6857. else {
  6858. spell->num_triggers -= remove_count;
  6859. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  6860. }
  6861. return 0;
  6862. }
  6863. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  6864. if (!lua_interface)
  6865. return 0;
  6866. Spawn* spawn = lua_interface->GetSpawn(state);
  6867. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  6868. if (!spawn) {
  6869. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  6870. return 0;
  6871. }
  6872. if (!copy_spawn) {
  6873. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  6874. return 0;
  6875. }
  6876. spawn->CopySpawnAppearance(copy_spawn);
  6877. return 0;
  6878. }
  6879. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  6880. if (!lua_interface)
  6881. return 0;
  6882. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6883. int8 type = lua_interface->GetInt8Value(state);
  6884. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6885. if (!spell) {
  6886. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  6887. return 0;
  6888. }
  6889. if (spawn) {
  6890. if (!spawn->IsEntity()) {
  6891. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  6892. return 0;
  6893. }
  6894. Entity* entity = ((Entity*)spawn);
  6895. switch (type) {
  6896. case IMMUNITY_TYPE_AOE:
  6897. entity->AddAOEImmunity(spell);
  6898. if (!(spell->effect_bitmask & EFFECT_FLAG_AOE_IMMUNE))
  6899. spell->effect_bitmask += EFFECT_FLAG_AOE_IMMUNE;
  6900. break;
  6901. case IMMUNITY_TYPE_STUN:
  6902. entity->AddStunImmunity(spell);
  6903. if (!(spell->effect_bitmask & EFFECT_FLAG_STUN_IMMUNE))
  6904. spell->effect_bitmask += EFFECT_FLAG_STUN_IMMUNE;
  6905. break;
  6906. case IMMUNITY_TYPE_ROOT:
  6907. entity->AddRootImmunity(spell);
  6908. if (!(spell->effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE))
  6909. spell->effect_bitmask += EFFECT_FLAG_ROOT_IMMUNE;
  6910. break;
  6911. case IMMUNITY_TYPE_DAZE:
  6912. entity->AddDazeImmunity(spell);
  6913. if (!(spell->effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE))
  6914. spell->effect_bitmask += EFFECT_FLAG_DAZE_IMMUNE;
  6915. break;
  6916. case IMMUNITY_TYPE_FEAR:
  6917. entity->AddFearImmunity(spell);
  6918. if (!(spell->effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE))
  6919. spell->effect_bitmask += EFFECT_FLAG_FEAR_IMMUNE;
  6920. break;
  6921. case IMMUNITY_TYPE_MEZ:
  6922. entity->AddMezImmunity(spell);
  6923. if (!(spell->effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE))
  6924. spell->effect_bitmask += EFFECT_FLAG_MEZ_IMMUNE;
  6925. break;
  6926. case IMMUNITY_TYPE_STIFLE:
  6927. entity->AddStifleImmunity(spell);
  6928. if (!(spell->effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE))
  6929. spell->effect_bitmask += EFFECT_FLAG_STIFLE_IMMUNE;
  6930. break;
  6931. default:
  6932. lua_interface->LogError("%s: LUA AddImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  6933. }
  6934. }
  6935. else {
  6936. bool should_break = false;
  6937. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6938. for (int8 i = 0; i < spell->targets.size(); i++) {
  6939. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6940. if (!spawn || !spawn->IsEntity())
  6941. continue;
  6942. Entity* entity = ((Entity*)spawn);
  6943. switch (type) {
  6944. case IMMUNITY_TYPE_AOE:
  6945. entity->AddAOEImmunity(spell);
  6946. if (!(spell->effect_bitmask & EFFECT_FLAG_AOE_IMMUNE))
  6947. spell->effect_bitmask += EFFECT_FLAG_AOE_IMMUNE;
  6948. break;
  6949. case IMMUNITY_TYPE_STUN:
  6950. entity->AddStunImmunity(spell);
  6951. if (!(spell->effect_bitmask & EFFECT_FLAG_STUN_IMMUNE))
  6952. spell->effect_bitmask += EFFECT_FLAG_STUN_IMMUNE;
  6953. break;
  6954. case IMMUNITY_TYPE_ROOT:
  6955. entity->AddRootImmunity(spell);
  6956. if (!(spell->effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE))
  6957. spell->effect_bitmask += EFFECT_FLAG_ROOT_IMMUNE;
  6958. break;
  6959. case IMMUNITY_TYPE_DAZE:
  6960. entity->AddDazeImmunity(spell);
  6961. if (!(spell->effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE))
  6962. spell->effect_bitmask += EFFECT_FLAG_DAZE_IMMUNE;
  6963. break;
  6964. case IMMUNITY_TYPE_FEAR:
  6965. entity->AddFearImmunity(spell);
  6966. if (!(spell->effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE))
  6967. spell->effect_bitmask += EFFECT_FLAG_FEAR_IMMUNE;
  6968. break;
  6969. case IMMUNITY_TYPE_MEZ:
  6970. entity->AddMezImmunity(spell);
  6971. if (!(spell->effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE))
  6972. spell->effect_bitmask += EFFECT_FLAG_MEZ_IMMUNE;
  6973. break;
  6974. case IMMUNITY_TYPE_STIFLE:
  6975. entity->AddStifleImmunity(spell);
  6976. if (!(spell->effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE))
  6977. spell->effect_bitmask += EFFECT_FLAG_STIFLE_IMMUNE;
  6978. break;
  6979. default:
  6980. lua_interface->LogError("%s: LUA AddImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  6981. should_break = true;
  6982. }
  6983. if (should_break)
  6984. break;
  6985. }
  6986. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6987. }
  6988. return 0;
  6989. }
  6990. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  6991. if (!lua_interface)
  6992. return 0;
  6993. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6994. int8 type = lua_interface->GetInt8Value(state);
  6995. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6996. if (!spell) {
  6997. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  6998. return 0;
  6999. }
  7000. if (spawn) {
  7001. if (!spawn->IsEntity()) {
  7002. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  7003. return 0;
  7004. }
  7005. Entity* entity = ((Entity*)spawn);
  7006. switch (type) {
  7007. case IMMUNITY_TYPE_AOE:
  7008. entity->RemoveAOEImmunity(spell);
  7009. break;
  7010. case IMMUNITY_TYPE_STUN:
  7011. entity->RemoveStunImmunity(spell);
  7012. break;
  7013. case IMMUNITY_TYPE_ROOT:
  7014. entity->RemoveRootImmunity(spell);
  7015. break;
  7016. case IMMUNITY_TYPE_DAZE:
  7017. entity->RemoveDazeImmunity(spell);
  7018. break;
  7019. case IMMUNITY_TYPE_FEAR:
  7020. entity->RemoveFearImmunity(spell);
  7021. break;
  7022. case IMMUNITY_TYPE_MEZ:
  7023. entity->RemoveMezImmunity(spell);
  7024. break;
  7025. case IMMUNITY_TYPE_STIFLE:
  7026. entity->RemoveStifleImmunity(spell);
  7027. break;
  7028. default:
  7029. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7030. }
  7031. }
  7032. else {
  7033. bool should_break = false;
  7034. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7035. for (int8 i = 0; i < spell->targets.size(); i++) {
  7036. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7037. if (!spawn || !spawn->IsEntity())
  7038. continue;
  7039. Entity* entity = ((Entity*)spawn);
  7040. switch (type) {
  7041. case IMMUNITY_TYPE_AOE:
  7042. entity->RemoveAOEImmunity(spell);
  7043. break;
  7044. case IMMUNITY_TYPE_STUN:
  7045. entity->RemoveStunImmunity(spell);
  7046. break;
  7047. case IMMUNITY_TYPE_ROOT:
  7048. entity->RemoveRootImmunity(spell);
  7049. break;
  7050. case IMMUNITY_TYPE_DAZE:
  7051. entity->RemoveDazeImmunity(spell);
  7052. break;
  7053. case IMMUNITY_TYPE_FEAR:
  7054. entity->RemoveFearImmunity(spell);
  7055. break;
  7056. case IMMUNITY_TYPE_MEZ:
  7057. entity->RemoveMezImmunity(spell);
  7058. break;
  7059. case IMMUNITY_TYPE_STIFLE:
  7060. entity->RemoveStifleImmunity(spell);
  7061. break;
  7062. default:
  7063. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: invalid immunity type", lua_interface->GetScriptName(state));
  7064. should_break = true;
  7065. }
  7066. if (should_break)
  7067. break;
  7068. }
  7069. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7070. }
  7071. return 0;
  7072. }
  7073. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  7074. if (!lua_interface)
  7075. return 0;
  7076. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7077. if (!spell) {
  7078. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  7079. return 0;
  7080. }
  7081. float snare = lua_interface->GetFloatValue(state);
  7082. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7083. // convert the val to the speed multipler value (100 - val)
  7084. float val = 100.0 - snare;
  7085. val /= 100.0;
  7086. if (spawn) {
  7087. if (!spawn->IsEntity()) {
  7088. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  7089. return 0;
  7090. }
  7091. ((Entity*)spawn)->SetSnareValue(spell, val);
  7092. }
  7093. else {
  7094. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7095. for (int8 i = 0; i < spell->targets.size(); i++) {
  7096. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7097. if (!spawn || !spawn->IsEntity())
  7098. continue;
  7099. ((Entity*)spawn)->SetSnareValue(spell, val);
  7100. }
  7101. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7102. }
  7103. return 0;
  7104. }
  7105. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  7106. if (!lua_interface)
  7107. return 0;
  7108. Spawn* spawn = lua_interface->GetSpawn(state);
  7109. int16 race_id = lua_interface->GetInt16Value(state, 2);
  7110. if (!spawn) {
  7111. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7112. return 0;
  7113. }
  7114. if (race_id == 0) {
  7115. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  7116. return 0;
  7117. }
  7118. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  7119. return 1;
  7120. }
  7121. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  7122. if (!lua_interface)
  7123. return 0;
  7124. Spawn* spawn = lua_interface->GetSpawn(state);
  7125. if (!spawn) {
  7126. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7127. return 0;
  7128. }
  7129. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  7130. return 1;
  7131. }
  7132. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  7133. if (!lua_interface)
  7134. return 0;
  7135. Spawn* spawn = lua_interface->GetSpawn(state);
  7136. if (!spawn) {
  7137. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  7138. return 0;
  7139. }
  7140. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  7141. return 1;
  7142. }
  7143. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  7144. if (!lua_interface)
  7145. return 0;
  7146. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7147. if (!spell) {
  7148. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  7149. return 0;
  7150. }
  7151. lua_interface->SetStringValue(state, spell->spell->GetName());
  7152. return 1;
  7153. }
  7154. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  7155. if (!lua_interface)
  7156. return 0;
  7157. Quest* quest = lua_interface->GetQuest(state);
  7158. if (!quest) {
  7159. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7160. return 0;
  7161. }
  7162. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  7163. return 1;
  7164. }
  7165. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  7166. if (!lua_interface)
  7167. return 0;
  7168. Quest* quest = lua_interface->GetQuest(state);
  7169. int32 flags = lua_interface->GetInt32Value(state, 2);
  7170. if (!quest) {
  7171. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  7172. return 0;
  7173. }
  7174. quest->SetQuestFlags(flags);
  7175. return 0;
  7176. }
  7177. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  7178. if (!lua_interface)
  7179. return 0;
  7180. Quest* quest = lua_interface->GetQuest(state);
  7181. Spawn* player = lua_interface->GetSpawn(state, 2);
  7182. int32 step = lua_interface->GetInt32Value(state, 3);
  7183. int32 duration = lua_interface->GetInt32Value(state, 4);
  7184. string action = lua_interface->GetStringValue(state, 5);
  7185. if (!quest) {
  7186. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  7187. return 0;
  7188. }
  7189. if (!player) {
  7190. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7191. return 0;
  7192. }
  7193. if (!player->IsPlayer()) {
  7194. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7195. return 0;
  7196. }
  7197. if (step == 0) {
  7198. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  7199. return 0;
  7200. }
  7201. if (duration == 0) {
  7202. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  7203. return 0;
  7204. }
  7205. if (action.length() == 0) {
  7206. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  7207. return 0;
  7208. }
  7209. Client* client = player->GetZone()->GetClientBySpawn(player);
  7210. if (!client) {
  7211. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  7212. return 0;
  7213. }
  7214. quest->SetTimerStep(step);
  7215. quest->AddFailedAction(step, action);
  7216. quest->SetStepTimer(duration);
  7217. client->AddQuestTimer(quest->GetQuestID());
  7218. return 0;
  7219. }
  7220. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  7221. if (!lua_interface)
  7222. return 0;
  7223. Quest* quest = lua_interface->GetQuest(state);
  7224. Spawn* player = lua_interface->GetSpawn(state, 2);
  7225. if (!quest) {
  7226. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  7227. return 0;
  7228. }
  7229. if (!player) {
  7230. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7231. return 0;
  7232. }
  7233. if (!player->IsPlayer()) {
  7234. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7235. return 0;
  7236. }
  7237. Client* client = player->GetZone()->GetClientBySpawn(player);
  7238. if (!client) {
  7239. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  7240. return 0;
  7241. }
  7242. quest->SetTimerStep(0);
  7243. quest->SetStepTimer(0);
  7244. client->RemoveQuestTimer(quest->GetQuestID());
  7245. return 0;
  7246. }
  7247. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  7248. if (!lua_interface)
  7249. return 0;
  7250. Spawn* player = lua_interface->GetSpawn(state);
  7251. Quest* quest = lua_interface->GetQuest(state, 2);
  7252. int32 step = lua_interface->GetInt32Value(state, 3);
  7253. if (!player) {
  7254. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7255. return 0;
  7256. }
  7257. if (!player->IsPlayer()) {
  7258. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7259. return 0;
  7260. }
  7261. if (!quest) {
  7262. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  7263. return 0;
  7264. }
  7265. if (step == 0) {
  7266. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  7267. return 0;
  7268. }
  7269. Client* client = player->GetZone()->GetClientBySpawn(player);
  7270. if (!client) {
  7271. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  7272. return 0;
  7273. }
  7274. if (quest->RemoveQuestStep(step, client)) {
  7275. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  7276. client->GetCurrentZone()->SendQuestUpdates(client);
  7277. }
  7278. else
  7279. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  7280. return 0;
  7281. }
  7282. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  7283. if (!lua_interface)
  7284. return 0;
  7285. Quest* quest = lua_interface->GetQuest(state, 1);
  7286. int32 step = lua_interface->GetInt32Value(state, 2);
  7287. string desc = lua_interface->GetStringValue(state, 3);
  7288. string task_group = lua_interface->GetStringValue(state, 4);
  7289. if (!quest) {
  7290. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  7291. return 0;
  7292. }
  7293. if (step == 0) {
  7294. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  7295. return 0;
  7296. }
  7297. QuestStep* quest_step = quest->GetQuestStep(step);
  7298. if (!quest_step) {
  7299. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  7300. return 0;
  7301. }
  7302. quest_step->SetStepProgress(0);
  7303. quest_step->SetTaskGroup(task_group);
  7304. quest_step->SetDescription(desc);
  7305. return 0;
  7306. }
  7307. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  7308. if (!lua_interface)
  7309. return 0;
  7310. Quest* quest = lua_interface->GetQuest(state);
  7311. int32 step = lua_interface->GetInt32Value(state, 2);
  7312. string action = lua_interface->GetStringValue(state, 3);
  7313. if (!quest) {
  7314. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  7315. return 0;
  7316. }
  7317. if (step == 0) {
  7318. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  7319. return 0;
  7320. }
  7321. if (action.length() == 0) {
  7322. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  7323. return 0;
  7324. }
  7325. quest->AddFailedAction(step, action);
  7326. return 0;
  7327. }
  7328. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  7329. if (!lua_interface)
  7330. return 0;
  7331. Spawn* player = lua_interface->GetSpawn(state);
  7332. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  7333. int32 step = lua_interface->GetInt32Value(state, 3);
  7334. if (!player) {
  7335. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  7336. return 0;
  7337. }
  7338. if (!player->IsPlayer()) {
  7339. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  7340. return 0;
  7341. }
  7342. if (quest_id == 0) {
  7343. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  7344. return 0;
  7345. }
  7346. if (step == 0) {
  7347. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  7348. return 0;
  7349. }
  7350. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  7351. if (!quest) {
  7352. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  7353. return 0;
  7354. }
  7355. quest->StepFailed(step);
  7356. return 0;
  7357. }
  7358. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  7359. if (!lua_interface)
  7360. return 0;
  7361. Spawn* player = lua_interface->GetSpawn(state);
  7362. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  7363. if (!player) {
  7364. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  7365. return 0;
  7366. }
  7367. if (!player->IsPlayer()) {
  7368. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  7369. return 0;
  7370. }
  7371. if (quest_id == 0) {
  7372. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  7373. return 0;
  7374. }
  7375. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  7376. if (!quest) {
  7377. lua_interface->SetInt32Value(state, 0);
  7378. return 1;
  7379. }
  7380. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  7381. return 1;
  7382. }
  7383. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  7384. if (!lua_interface)
  7385. return 0;
  7386. string name = lua_interface->GetStringValue(state);
  7387. string value = lua_interface->GetStringValue(state, 2);
  7388. string comment = lua_interface->GetStringValue(state, 3);
  7389. if (name.length() == 0) {
  7390. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  7391. return 0;
  7392. }
  7393. if (value.length() == 0) {
  7394. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  7395. return 0;
  7396. }
  7397. string varname = string("lua_").append(name);
  7398. Variable* var = variables.FindVariable(varname);
  7399. if (var)
  7400. var->SetValue(value.c_str());
  7401. else {
  7402. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  7403. variables.AddVariable(var);
  7404. }
  7405. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  7406. return 0;
  7407. }
  7408. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  7409. if (!lua_interface)
  7410. return 0;
  7411. string name = lua_interface->GetStringValue(state);
  7412. if (name.length() == 0) {
  7413. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  7414. return 0;
  7415. }
  7416. string varname = string("lua_").append(name);
  7417. Variable* var = variables.FindVariable(varname);
  7418. if (var)
  7419. lua_interface->SetStringValue(state, var->GetValue());
  7420. else
  7421. lua_interface->SetStringValue(state, "NULL");
  7422. return 1;
  7423. }
  7424. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  7425. if (!lua_interface)
  7426. return 0;
  7427. Spawn* player = lua_interface->GetSpawn(state);
  7428. int32 language_id = lua_interface->GetInt32Value(state, 2);
  7429. if (!player) {
  7430. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  7431. return 0;
  7432. }
  7433. if (!player->IsPlayer()) {
  7434. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  7435. return 0;
  7436. }
  7437. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  7438. return 1;
  7439. }
  7440. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  7441. if (!lua_interface)
  7442. return 0;
  7443. Spawn* player = lua_interface->GetSpawn(state);
  7444. int32 language_id = lua_interface->GetInt32Value(state, 2);
  7445. if (!player) {
  7446. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  7447. return 0;
  7448. }
  7449. if (!player->IsPlayer()) {
  7450. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  7451. return 0;
  7452. }
  7453. Language* language = master_languages_list.GetLanguage(language_id);
  7454. if (language)
  7455. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  7456. return 0;
  7457. }
  7458. int EQ2Emu_lua_IsNight(lua_State* state) {
  7459. if (!lua_interface)
  7460. return 0;
  7461. ZoneServer* zone = lua_interface->GetZone(state);
  7462. if (!zone) {
  7463. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  7464. return 0;
  7465. }
  7466. lua_interface->SetBooleanValue(state, zone->IsDusk());
  7467. return 1;
  7468. }
  7469. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  7470. if (!lua_interface)
  7471. return 0;
  7472. Spawn* spawn = lua_interface->GetSpawn(state);
  7473. if (!spawn) {
  7474. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  7475. return 0;
  7476. }
  7477. if (!spawn->IsWidget()) {
  7478. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  7479. return 0;
  7480. }
  7481. ((Widget*)spawn)->SetMultiFloorLift(true);
  7482. if (spawn->GetZone())
  7483. spawn->GetZone()->AddTransportSpawn(spawn);
  7484. return 0;
  7485. }
  7486. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  7487. if (!lua_interface)
  7488. return 0;
  7489. Spawn* player = lua_interface->GetSpawn(state);
  7490. int32 path = lua_interface->GetInt32Value(state, 2);
  7491. if (!player) {
  7492. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  7493. return 0;
  7494. }
  7495. if (!player->IsPlayer()) {
  7496. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7497. return 0;
  7498. }
  7499. if (path == 0) {
  7500. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  7501. return 0;
  7502. }
  7503. Client* client = player->GetZone()->GetClientBySpawn(player);
  7504. if (!client) {
  7505. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  7506. return 0;
  7507. }
  7508. client->SendFlightAutoMount(path);
  7509. return 0;
  7510. }
  7511. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  7512. if (!lua_interface)
  7513. return 0;
  7514. Spawn* player = lua_interface->GetSpawn(state);
  7515. if (!player) {
  7516. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  7517. return 0;
  7518. }
  7519. if (!player->IsPlayer()) {
  7520. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7521. return 0;
  7522. }
  7523. Client* client = player->GetZone()->GetClientBySpawn(player);
  7524. if (!client) {
  7525. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  7526. return 0;
  7527. }
  7528. client->EndAutoMount();
  7529. return 0;
  7530. }
  7531. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  7532. if (!lua_interface)
  7533. return 0;
  7534. Spawn* player = lua_interface->GetSpawn(state);
  7535. if (!player) {
  7536. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  7537. return 0;
  7538. }
  7539. if (!player->IsPlayer()) {
  7540. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7541. return 0;
  7542. }
  7543. Client* client = player->GetZone()->GetClientBySpawn(player);
  7544. if (!client) {
  7545. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  7546. return 0;
  7547. }
  7548. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  7549. return 1;
  7550. }
  7551. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  7552. if (!lua_interface)
  7553. return 0;
  7554. Spawn* player = lua_interface->GetSpawn(state);
  7555. int32 event_id = lua_interface->GetInt32Value(state, 2);
  7556. int32 value = lua_interface->GetInt32Value(state, 3);
  7557. int32 value2 = lua_interface->GetInt32Value(state, 4);
  7558. if (!player) {
  7559. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  7560. return 0;
  7561. }
  7562. if (!player->IsPlayer()) {
  7563. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  7564. return 0;
  7565. }
  7566. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  7567. return 0;
  7568. }
  7569. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  7570. if (!lua_interface)
  7571. return 0;
  7572. Spawn* player = lua_interface->GetSpawn(state);
  7573. int32 event_id = lua_interface->GetInt32Value(state, 2);
  7574. if (!player) {
  7575. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  7576. return 0;
  7577. }
  7578. if (!player->IsPlayer()) {
  7579. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  7580. return 0;
  7581. }
  7582. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  7583. if (!hd)
  7584. return 0;
  7585. lua_interface->SetInt32Value(state, hd->Value);
  7586. lua_interface->SetInt32Value(state, hd->Value2);
  7587. return 2;
  7588. }
  7589. int EQ2Emu_lua_SetGridID(lua_State* state) {
  7590. if (!lua_interface)
  7591. return 0;
  7592. Spawn* spawn = lua_interface->GetSpawn(state);
  7593. int32 grid = lua_interface->GetInt32Value(state, 2);
  7594. if (!spawn) {
  7595. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  7596. return 0;
  7597. }
  7598. if (grid == 0) {
  7599. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  7600. return 0;
  7601. }
  7602. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  7603. return 0;
  7604. }
  7605. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  7606. if (!lua_interface)
  7607. return 0;
  7608. Spawn* spawn = lua_interface->GetSpawn(state);
  7609. int32 event_id = lua_interface->GetInt32Value(state, 2);
  7610. int32 value1 = lua_interface->GetInt32Value(state, 3);
  7611. int32 value2 = lua_interface->GetInt32Value(state, 4);
  7612. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  7613. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  7614. if (!spawn) {
  7615. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  7616. return 0;
  7617. }
  7618. //Add this quest to the list of required quests for this spawn
  7619. spawn->SetRequiredHistory(event_id, value1, value2);
  7620. //If private spawn value set
  7621. if (private_spawn) {
  7622. //Set the spawn to be private when not granted access via history
  7623. spawn->AddAllowAccessSpawn(spawn);
  7624. spawn->SetPrivateQuestSpawn(true);
  7625. }
  7626. //This value will override vis_flags in the vis packet
  7627. if (flag_override > 0)
  7628. spawn->SetQuestsRequiredOverride(flag_override);
  7629. return 0;
  7630. }
  7631. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  7632. if (!lua_interface)
  7633. return 0;
  7634. Spawn* player = lua_interface->GetSpawn(state);
  7635. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  7636. int32 step_id = lua_interface->GetInt32Value(state, 3);
  7637. if (!player) {
  7638. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  7639. return 0;
  7640. }
  7641. if (!player->IsPlayer()) {
  7642. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  7643. return 0;
  7644. }
  7645. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  7646. return 1;
  7647. }
  7648. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  7649. if (!lua_interface)
  7650. return 0;
  7651. Spawn* player = lua_interface->GetSpawn(state);
  7652. int8 level = lua_interface->GetInt8Value(state, 2);
  7653. if (!player) {
  7654. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  7655. return 0;
  7656. }
  7657. if (!player->IsPlayer()) {
  7658. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  7659. return 0;
  7660. }
  7661. if (level == 0) {
  7662. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  7663. return 0;
  7664. }
  7665. Client* client = player->GetZone()->GetClientBySpawn(player);
  7666. if (!client) {
  7667. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  7668. return 0;
  7669. }
  7670. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  7671. client->GetPlayer()->SetXP(1);
  7672. client->GetPlayer()->SetNeededXP();
  7673. return 0;
  7674. }
  7675. int EQ2Emu_lua_AddCoin(lua_State* state) {
  7676. if (!lua_interface)
  7677. return 0;
  7678. Spawn* player = lua_interface->GetSpawn(state);
  7679. int32 amount = lua_interface->GetInt32Value(state, 2);
  7680. if (!player) {
  7681. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  7682. return 0;
  7683. }
  7684. if (!player->IsPlayer()) {
  7685. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  7686. return 0;
  7687. }
  7688. if (amount == 0) {
  7689. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  7690. return 0;
  7691. }
  7692. ((Player*)player)->AddCoins(amount);
  7693. return 0;
  7694. }
  7695. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  7696. if (!lua_interface)
  7697. return 0;
  7698. Spawn* player = lua_interface->GetSpawn(state);
  7699. int32 amount = lua_interface->GetInt32Value(state, 2);
  7700. if (!player) {
  7701. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  7702. return 0;
  7703. }
  7704. if (!player->IsPlayer()) {
  7705. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  7706. return 0;
  7707. }
  7708. if (amount == 0) {
  7709. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  7710. return 0;
  7711. }
  7712. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  7713. return 1;
  7714. }
  7715. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  7716. if (!lua_interface)
  7717. return 0;
  7718. ZoneServer* zone = lua_interface->GetZone(state);
  7719. if (!zone) {
  7720. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  7721. return 0;
  7722. }
  7723. vector<Entity*> players = zone->GetPlayers();
  7724. if (players.size() == 0)
  7725. return 0;
  7726. lua_createtable(state, players.size(), 0);
  7727. int newTable = lua_gettop(state);
  7728. for (int32 i = 0; i < players.size(); i++) {
  7729. lua_interface->SetSpawnValue(state, players.at(i));
  7730. lua_rawseti(state, newTable, i + 1);
  7731. }
  7732. return 1;
  7733. }
  7734. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  7735. if (!lua_interface)
  7736. return 0;
  7737. ZoneServer* zone = lua_interface->GetZone(state, 1);
  7738. if (!zone) {
  7739. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  7740. return 0;
  7741. }
  7742. int32 group_id = lua_interface->GetInt32Value(state, 2);
  7743. //Map of <placement_id, location_id>
  7744. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  7745. map<int32, int32>::iterator itr;
  7746. vector<Spawn*> group;
  7747. for (itr = locs->begin(); itr != locs->end(); itr++) {
  7748. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  7749. if (!location) {
  7750. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  7751. return 0;
  7752. }
  7753. Spawn* spawn = 0;
  7754. if (location->entities[0]) {
  7755. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  7756. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  7757. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  7758. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  7759. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  7760. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  7761. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  7762. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  7763. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  7764. spawn = zone->AddSignSpawn(location, location->entities[0]);
  7765. if (spawn) {
  7766. const char* script = 0;
  7767. for (int x = 0; x < 3; x++) {
  7768. switch (x) {
  7769. case 0:
  7770. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  7771. break;
  7772. case 1:
  7773. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  7774. break;
  7775. case 2:
  7776. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  7777. break;
  7778. }
  7779. if (script && lua_interface->GetSpawnScript(script) != 0) {
  7780. spawn->SetSpawnScript(string(script));
  7781. break;
  7782. }
  7783. }
  7784. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  7785. lua_interface->SetSpawnValue(state, spawn);
  7786. group.push_back(spawn);
  7787. }
  7788. else {
  7789. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
  7790. safe_delete(spawn);
  7791. }
  7792. }
  7793. }
  7794. if (!group.empty()) {
  7795. lua_createtable(state, group.size(), 0);
  7796. int newTable = lua_gettop(state);
  7797. for (int32 i = 0; i < group.size(); i++) {
  7798. lua_interface->SetSpawnValue(state, group[i]);
  7799. lua_rawseti(state, newTable, i + 1);
  7800. }
  7801. }
  7802. else
  7803. lua_pushnil(state);
  7804. return 1;
  7805. }
  7806. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  7807. if (!lua_interface)
  7808. return 0;
  7809. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  7810. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  7811. int16 leeway = lua_interface->GetInt16Value(state, 3);
  7812. if (!spawn) {
  7813. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  7814. return 0;
  7815. }
  7816. if (anim_id == 0) {
  7817. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  7818. return 0;
  7819. }
  7820. if (leeway == 0)
  7821. leeway = 5000;
  7822. spawn->SetSpawnAnim(anim_id);
  7823. spawn->SetSpawnAnimLeeway(leeway);
  7824. return 0;
  7825. }
  7826. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  7827. if (!lua_interface)
  7828. return 0;
  7829. Spawn* player = lua_interface->GetSpawn(state);
  7830. if (!player) {
  7831. return 0;
  7832. }
  7833. Client* client = player->GetZone()->GetClientBySpawn(player);
  7834. if (!client) {
  7835. return 0;
  7836. }
  7837. lua_interface->SetInt32Value(state, client->GetVersion());
  7838. return 1;
  7839. }
  7840. int EQ2Emu_lua_GetItemID(lua_State* state) {
  7841. if (!lua_interface)
  7842. return 0;
  7843. Item* item = lua_interface->GetItem(state);
  7844. if (!item) {
  7845. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  7846. return 0;
  7847. }
  7848. lua_interface->SetInt32Value(state, item->details.item_id);
  7849. return 1;
  7850. }
  7851. int EQ2Emu_lua_IsEntity(lua_State* state) {
  7852. if (!lua_interface)
  7853. return 0;
  7854. Spawn* spawn = lua_interface->GetSpawn(state);
  7855. if (!spawn) {
  7856. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  7857. return 0;
  7858. }
  7859. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  7860. return 1;
  7861. }
  7862. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  7863. if (!lua_interface)
  7864. return 0;
  7865. Spawn* spawn = lua_interface->GetSpawn(state);
  7866. if (!spawn) {
  7867. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  7868. return 0;
  7869. }
  7870. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  7871. return 1;
  7872. }
  7873. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  7874. if (!lua_interface)
  7875. return 0;
  7876. Spawn* spawn = lua_interface->GetSpawn(state);
  7877. if (!spawn) {
  7878. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  7879. return 0;
  7880. }
  7881. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  7882. return 1;
  7883. }
  7884. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  7885. if (!lua_interface)
  7886. return 0;
  7887. Spawn* spawn = lua_interface->GetSpawn(state);
  7888. if (!spawn) {
  7889. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  7890. return 0;
  7891. }
  7892. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  7893. return 1;
  7894. }
  7895. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  7896. if (!lua_interface)
  7897. return 0;
  7898. Spawn* spawn = lua_interface->GetSpawn(state);
  7899. float pct = lua_interface->GetFloatValue(state, 2);
  7900. if (!spawn) {
  7901. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  7902. return 0;
  7903. }
  7904. if (pct == 0) {
  7905. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  7906. return 0;
  7907. }
  7908. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  7909. lua_interface->SetInt32Value(state, amount);
  7910. return 1;
  7911. }
  7912. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  7913. if (!lua_interface)
  7914. return 0;
  7915. Spawn* spawn = lua_interface->GetSpawn(state);
  7916. float pct = lua_interface->GetFloatValue(state, 2);
  7917. if (!spawn) {
  7918. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  7919. return 0;
  7920. }
  7921. if (pct == 0) {
  7922. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  7923. return 0;
  7924. }
  7925. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  7926. lua_interface->SetInt32Value(state, amount);
  7927. return 1;
  7928. }
  7929. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  7930. if (!lua_interface)
  7931. return 0;
  7932. Spawn* spawn = lua_interface->GetSpawn(state);
  7933. if (!spawn) {
  7934. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  7935. return 0;
  7936. }
  7937. if (!spawn->IsPlayer()) {
  7938. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  7939. return 0;
  7940. }
  7941. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  7942. return 1;
  7943. }
  7944. int EQ2Emu_lua_Evac(lua_State* state) {
  7945. if (!lua_interface)
  7946. return 0;
  7947. Spawn* target = lua_interface->GetSpawn(state);
  7948. if (target) {
  7949. float x = target->GetZone()->GetSafeX();
  7950. float y = target->GetZone()->GetSafeY();
  7951. float z = target->GetZone()->GetSafeZ();
  7952. float h = target->GetZone()->GetSafeHeading();
  7953. target->SetX(x);
  7954. target->SetY(y);
  7955. target->SetZ(z);
  7956. target->SetHeading(h);
  7957. target->SetSpawnOrigX(target->GetX());
  7958. target->SetSpawnOrigY(target->GetY());
  7959. target->SetSpawnOrigZ(target->GetZ());
  7960. target->SetSpawnOrigHeading(target->GetHeading());
  7961. if (target->IsPlayer()) {
  7962. Client* client = target->GetZone()->GetClientBySpawn(target);
  7963. if (client) {
  7964. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  7965. if (packet)
  7966. {
  7967. packet->setDataByName("x", x);
  7968. packet->setDataByName("y", y);
  7969. packet->setDataByName("z", z);
  7970. client->QueuePacket(packet->serialize());
  7971. safe_delete(packet);
  7972. }
  7973. }
  7974. }
  7975. }
  7976. else {
  7977. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7978. ZoneServer* zone = spell->caster->GetZone();
  7979. float x = spell->caster->GetZone()->GetSafeX();
  7980. float y = spell->caster->GetZone()->GetSafeY();
  7981. float z = spell->caster->GetZone()->GetSafeZ();
  7982. float h = spell->caster->GetZone()->GetSafeHeading();
  7983. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7984. for (int32 i = 0; i < spell->targets.size(); i++) {
  7985. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  7986. if (!target2)
  7987. continue;
  7988. target2->SetX(x);
  7989. target2->SetY(y);
  7990. target2->SetZ(z);
  7991. target2->SetHeading(h);
  7992. target2->SetSpawnOrigX(target2->GetX());
  7993. target2->SetSpawnOrigY(target2->GetY());
  7994. target2->SetSpawnOrigZ(target2->GetZ());
  7995. target2->SetSpawnOrigHeading(target2->GetHeading());
  7996. if (target2->IsPlayer()) {
  7997. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  7998. if (client) {
  7999. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  8000. if (packet)
  8001. {
  8002. packet->setDataByName("x", x);
  8003. packet->setDataByName("y", y);
  8004. packet->setDataByName("z", z);
  8005. client->QueuePacket(packet->serialize());
  8006. safe_delete(packet);
  8007. }
  8008. }
  8009. }
  8010. }
  8011. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8012. }
  8013. return 0;
  8014. }
  8015. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  8016. if (!lua_interface)
  8017. return 0;
  8018. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8019. if (!luaspell) {
  8020. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8021. return 0;
  8022. }
  8023. int8 tier = luaspell->spell->GetSpellTier();
  8024. lua_interface->SetInt32Value(state, tier);
  8025. return 1;
  8026. }
  8027. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  8028. if (!lua_interface)
  8029. return 0;
  8030. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  8031. if (!luaspell) {
  8032. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  8033. return 0;
  8034. }
  8035. int32 spell_id = luaspell->spell->GetSpellID();
  8036. lua_interface->SetInt32Value(state, spell_id);
  8037. return 1;
  8038. }
  8039. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  8040. if (!lua_interface)
  8041. return 0;
  8042. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8043. if (!spawn) {
  8044. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8045. return 0;
  8046. }
  8047. if (!spawn->IsPlayer()) {
  8048. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8049. return 0;
  8050. }
  8051. ZoneServer* zone = spawn->GetZone();
  8052. if (!zone) {
  8053. return 0;
  8054. }
  8055. Client* client = zone->GetClientBySpawn(spawn);
  8056. if (!client) {
  8057. return 0;
  8058. }
  8059. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  8060. return 0;
  8061. }
  8062. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  8063. if (!lua_interface)
  8064. return 0;
  8065. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8066. if (!spawn) {
  8067. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  8068. return 0;
  8069. }
  8070. if (!spawn->IsPlayer()) {
  8071. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  8072. return 0;
  8073. }
  8074. ZoneServer* zone = spawn->GetZone();
  8075. if (!zone) {
  8076. return 0;
  8077. }
  8078. Client* client = zone->GetClientBySpawn(spawn);
  8079. if (!client) {
  8080. return 0;
  8081. }
  8082. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  8083. return 0;
  8084. }
  8085. int EQ2Emu_lua_ProcHate(lua_State* state) {
  8086. if (!lua_interface)
  8087. return 0;
  8088. Spawn* caster = lua_interface->GetSpawn(state);
  8089. Spawn* target = lua_interface->GetSpawn(state, 2);
  8090. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  8091. string spell_name = lua_interface->GetStringValue(state, 4);
  8092. if (!caster) {
  8093. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8094. return 0;
  8095. }
  8096. if (!caster->IsEntity()) {
  8097. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  8098. return 0;
  8099. }
  8100. if (!target) {
  8101. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8102. return 0;
  8103. }
  8104. if (!target->IsEntity()) {
  8105. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  8106. return 0;
  8107. }
  8108. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  8109. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  8110. return 0;
  8111. }
  8112. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  8113. if (!lua_interface)
  8114. return 0;
  8115. Spawn* spawn = lua_interface->GetSpawn(state);
  8116. Spawn* target = lua_interface->GetSpawn(state, 2);
  8117. if (spawn && target)
  8118. return spawn->CheckLoS(target);
  8119. return 0;
  8120. }
  8121. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  8122. if (!lua_interface)
  8123. return 0;
  8124. Spawn* spawn = lua_interface->GetSpawn(state);
  8125. float x = lua_interface->GetFloatValue(state, 2);
  8126. float y = lua_interface->GetFloatValue(state, 3);
  8127. float z = lua_interface->GetFloatValue(state, 4);
  8128. if (spawn)
  8129. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  8130. return 0;
  8131. }
  8132. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  8133. if (!lua_interface)
  8134. return 0;
  8135. ZoneServer* zone = lua_interface->GetZone(state);
  8136. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  8137. if (zone)
  8138. zone->SetExpansionFlag(xpackFlag);
  8139. return 0;
  8140. }
  8141. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  8142. if (!lua_interface)
  8143. return 0;
  8144. ZoneServer* zone = lua_interface->GetZone(state);
  8145. if (zone) {
  8146. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  8147. return 1;
  8148. }
  8149. return 0;
  8150. }
  8151. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  8152. if (!lua_interface)
  8153. return 0;
  8154. Spawn* spawn = lua_interface->GetSpawn(state);
  8155. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  8156. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  8157. float distance = lua_interface->GetFloatValue(state, 4);
  8158. string in_range_function = lua_interface->GetStringValue(state, 5);
  8159. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  8160. if (spawn && distance > 0 && in_range_function.length() > 0)
  8161. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  8162. return 0;
  8163. }
  8164. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  8165. if (!lua_interface)
  8166. return 0;
  8167. Spawn* spawn = lua_interface->GetSpawn(state);
  8168. Spawn* target = lua_interface->GetSpawn(state, 2);
  8169. if (spawn && target)
  8170. {
  8171. if (spawn->IsPlayer() && target->IsEntity())
  8172. {
  8173. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  8174. return 1;
  8175. }
  8176. else if (spawn->IsEntity() && target->IsEntity())
  8177. {
  8178. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  8179. return 1;
  8180. }
  8181. }
  8182. return 0;
  8183. }
  8184. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  8185. if (!lua_interface)
  8186. return 0;
  8187. Spawn* spawn = lua_interface->GetSpawn(state);
  8188. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  8189. if (spawn && spawn->IsEntity())
  8190. {
  8191. ((Entity*)spawn)->SetSeeInvisSpell(val);
  8192. if (spawn->IsPlayer())
  8193. {
  8194. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  8195. if (client)
  8196. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  8197. }
  8198. }
  8199. return 0;
  8200. }
  8201. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  8202. if (!lua_interface)
  8203. return 0;
  8204. Spawn* spawn = lua_interface->GetSpawn(state);
  8205. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  8206. if (spawn && spawn->IsEntity())
  8207. {
  8208. ((Entity*)spawn)->SetSeeHideSpell(val);
  8209. if (spawn->IsPlayer())
  8210. {
  8211. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  8212. if (client)
  8213. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  8214. }
  8215. }
  8216. return 0;
  8217. }
  8218. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  8219. {
  8220. if (!lua_interface)
  8221. return 0;
  8222. Spawn* player = lua_interface->GetSpawn(state);
  8223. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8224. string command = lua_interface->GetStringValue(state, 3);
  8225. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  8226. if (spawn && player && player->IsPlayer())
  8227. {
  8228. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  8229. bool res = false;
  8230. if (cmd)
  8231. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  8232. lua_interface->SetBooleanValue(state, res);
  8233. return 1;
  8234. }
  8235. return 0;
  8236. }
  8237. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  8238. {
  8239. if (!lua_interface)
  8240. return 0;
  8241. Spawn* spawn = lua_interface->GetSpawn(state);
  8242. string command = lua_interface->GetStringValue(state, 2);
  8243. if (spawn && command.length() > 0)
  8244. spawn->RemovePrimaryEntityCommand(command.c_str());
  8245. return 0;
  8246. }
  8247. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  8248. if (!lua_interface)
  8249. return 0;
  8250. Spawn* spawn = lua_interface->GetSpawn(state);
  8251. float distance = lua_interface->GetFloatValue(state, 2);
  8252. string command = lua_interface->GetStringValue(state, 3);
  8253. Spawn* player = lua_interface->GetSpawn(state, 4);
  8254. if (spawn) {
  8255. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  8256. }
  8257. return 0;
  8258. }
  8259. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  8260. if (!lua_interface)
  8261. return 0;
  8262. Spawn* spawn = lua_interface->GetSpawn(state);
  8263. Spawn* player = lua_interface->GetSpawn(state, 2);
  8264. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  8265. if (spawn && player && transport_id && player->IsPlayer()) {
  8266. Client* client = 0;
  8267. if (player && player->IsPlayer())
  8268. client = player->GetZone()->GetClientBySpawn(player);
  8269. if (!client)
  8270. return 0;
  8271. vector<TransportDestination*> destinations;
  8272. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  8273. if (destinations.size())
  8274. {
  8275. client->SetTemporaryTransportID(transport_id);
  8276. client->ProcessTeleport(spawn, &destinations, transport_id);
  8277. }
  8278. else
  8279. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  8280. }
  8281. return 0;
  8282. }
  8283. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  8284. if (!lua_interface)
  8285. return 0;
  8286. Spawn* player = lua_interface->GetSpawn(state);
  8287. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  8288. if (player && player->IsPlayer()) {
  8289. Client* client = 0;
  8290. if (player && player->IsPlayer())
  8291. client = player->GetZone()->GetClientBySpawn(player);
  8292. if (!client)
  8293. return 0;
  8294. client->SetTemporaryTransportID(transport_id);
  8295. }
  8296. return 0;
  8297. }
  8298. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  8299. if (!lua_interface)
  8300. return 0;
  8301. Spawn* player = lua_interface->GetSpawn(state);
  8302. if (player && player->IsPlayer()) {
  8303. Client* client = 0;
  8304. if (player && player->IsPlayer())
  8305. client = player->GetZone()->GetClientBySpawn(player);
  8306. if (!client)
  8307. return 0;
  8308. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  8309. return 1;
  8310. }
  8311. return 0;
  8312. }