Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Embedding the Lua Engine in SA:MP via Detours

License

NotificationsYou must be signed in to change notification settings

LuxXx/samp-lua

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This DLL / ASI installs hooks to invoke lua events and registeres some exports several SA:MP functions to lua.

Similar projects can be found here:https://github.com/drakeee/samp-plugin-luahttps://github.com/THE-FYP/SAMP.Lua

Other libraries that I used:

A big thank you goes toagrippa1994 for his Utility functionality:https://github.com/SAMPProjects/Open-SAMP-API

WIP: The Lua Engine

What is Lua? Lua is a scripting language, that is designed for being embedded into other application.You can add aevents.lua file to your SA:MP directory. The Lua engine emits events when SA:MP functions are calledFor example if you call the function SendChat by using your Keybinder or by yourself the engine emits the "onSendChat" event.This event is handled by triggering the "onSendChat" a lua function inside of theevents.lua file.For Example:

functiononSendChat(msg)-- do something with your message-- return a true value to mark the command as handled, the command won't be sent.end

Not only your commands emit an event. Almost every SA:MP function calls an event.For Example (A simple Ad-Blocker):

functiononAddChatMessage(text)ifstring.match(text,'BUY PREMIUM NOW')thenreturntrueendreturnfalseend

You can also call the SA:MP functions inside lua:

functiononAddChatMessage(text,prefix)print(prefix..text)-- I repeat every messagereturnfalseend

This way to perform a response is much more faster than using a Keybinder:

functiononAddChatMessage(text)if (text=='Someone wants to refill your car for 1337$')thensendCommand('/accept refill')endreturnfalseend

You can register new commands or overwrite some:

functiononSendChat(msg)ifmsg=="/bk"thensendCommand('/f I need some backup!')returntrueendifmsg=="/help"thensendCommand('/admins')returntrueendend

Another example could be:

functiononAddChatMessage(text)ifstring.match(text,'SMS:')thenshowGameText(text,<iTime>,<iStyle>)-- SMS are important, I need them big!endreturnfalseend

Death event:

functiononDeath()sendChat('I just died in your arms tonight');end

Spam Filter:

locallastmsgfunctiononAddChatMessage(text)iflastmsg==textthenreturntrueendlastmsg=textreturnfalseend

Example for manipulating an AddChatMessage:

functiononAddChatMessage(text)if (string.find(text,'Noch')andstring.find(text,' Minuten bis zum Payday'))thenlocalminutes=string.match(text,'Noch (%d+) Minuten bis zum Payday')full_print('Geldregen in'..minutes..' Minuten',2,'Toller Prefix',16728128,5017777)returntrueendend

The shortest samp inline calculator ever: Just writecalc: <expr>, e.g.calc: 1+3*192/9

functiononAddChatMessage(text)if (string.find(text,'calc:'))thenlocalresult=load('return'..string.sub(text,7))()print('Result:'..result)returntrueendend

A /repay method

lastPayer=''lastPayment=0functiononSendChat(msg)if (msg=="/repay")thenif (lastPayer==0orlastPayer=='')thenprint("Nothing to pay")elsesendCommand("/pay"..lastPayer..""..lastPayment)endreturntrueendendfunctiononAddChatMessage(text,prefix)if (string.match(text,"payed you"))thenlastPayer,lastPayment=string.match(text,"(.*) payed you $(.*)!")endend

You may also use the default lua libraries like io, math, os, etc.

I want to implement as much events as possible. If you have suggestions, feel free to use the issue tracker.

The lua script can be reloaded during the game with/reloadlua.

TODO

EventsCommentWritten
onSendChathandles your chat and your commands, has two parameters: text and prefixYes
onAddChatMessagehandles the incoming chat messagesYes
onShowGameTextNot yet
onShowDialogNot yet
onDeathNot yet
onSpawnNot yet
onObjectCreationNot yet
onVehicleEnterNot yet
onVehicleExitNot yet
onVehicleCreationNot yet
onFreezeNot yet
onUnfreezeNot yet
onFreezeNot yet
onTeleportNot yet
onEngineStartNot yet
onEngineStopNot yet
...
CallbacksCommentWritten
sendChatsends a chat messageYes
sendCommandsends a commandYes
addChatMessagealias: print, shows a client messageYes
full_printThe full version of the print function. Call it like this: full_print(text, chattype, prefix, color, prefixColor).Yes
getHPgets the current hpNo
...
SA:MP uses several ChatTypes that you can invoke usingfull_print:
  • 2 for normal chat
  • 4 for info messages (blue font color)
  • 8 for debug messages (green font color)

If you want to test the API do the following:

  • Clone this repository
  • Install Boost and Lua, via NuGet Manager (Make sure that you are using all package resources)
  • Make sure that the sol2 library is in the root directory (if not, download it manually)
  • Compile

To use the engine, inject the lua.dll, then the samp-lua.dll.Later I you will only need to copy the samp-lua.asi into your SA:MP directory

Keep in mind that you should have a corresponding lua file in your SA:MP directory. At the moment the lua file has to be namedevents.lua.

Have fun implementing some neat things using this engine.

Greets and Have Fun

LuxXx


[8]ページ先頭

©2009-2025 Movatter.jp