Peaverin Posted March 5, 2015 Author Share Posted March 5, 2015 Hi, I though it was already possible to call a custom script with an Item in E.Worlds, but it isn't, so there's a tutorial for those who want to do it. It is very basic but some people may need it:1st: Both Client and Server side>! ->In modConstants, after the last item constant, you put:>! ```Public Const ITEM_TYPE_CSCRIPT As Byte = 10```In my case is ten because the last item constant I had was 9, but you'll have to put the next to the last number. This will set a new item type.>! >! >! ->In modTypes, in Public Type ItemRec, add this before the End Type:>! ```CScriptNumber As Byte```This will create a new property for items, that indicates the Custom Script number.>! Note: If you want to have more than 255 Custom Scripts (I doubt that), set it As Long instead of As Byte. 2nd: Client Side>! In Frm Editor_Item:>! ->Create a new frame, named fraCScript. Inside this frame create a new label named lblCScript (its caption should be Custom Script: 1). Also, create a scrollbar named scrlCScript. Set the scrollbar max to 255 if you set the CScriptNumber as Byte before, or set it at more if you set it at As Long. This way, you won't be able to exced 255 and won't cause any bug. Double click the scrollbar and paste this code:>! ```Private Sub scrlCScript_Change() If EditorIndex < 1 Or EditorIndex > MAX_ITEMS Then Exit Sub ' If debug mode, handle error then exit out If App.LogMode = 1 And Options.Debug = 1 Then On Error GoTo ErrorHandler lblCScript.Caption = "Custom Script: " & scrlCScript.Value Item(EditorIndex).CScriptNumber = scrlCScript.Value Exit Sub' Error handlerErrorHandler: HandleError "scrlCScript_Change", "frmEditor_Item", Err.Number, Err.Description, Err.Source, Err.HelpContext Err.ClearEnd Sub```->Then, in Private Sub cmbType_Click() after this:>! ``` If (frmEditor_Item.cmbType.ListIndex = ITEM_TYPE_RECIPE) Then fraRecipe.Visible = True Else fraRecipe.Visible = False End If```Add this:>! ```>! If (cmbType.ListIndex = ITEM_TYPE_CSCRIPT) Then fraCScript.Visible = True Else fraCScript.Visible = False End If```->In Public Sub ItemEditorInit() before End With, add:>! ```>! 'custom script If (frmEditor_Item.cmbType.ListIndex = ITEM_TYPE_CSCRIPT) Then frmEditor_Item.fraCScript.Visible = True frmEditor_Item.scrlCScript.Value = .CScriptNumber Else frmEditor_Item.fraCScript.Visible = False End If>! ```>! ->In Private Function generateItemsForTab. After this: ```>! Case ITEM_TYPE_RECIPE ret = populateSpecificType(tempItems, ITEM_TYPE_RECIPE)```Copy this:>! ```>! Case ITEM_TYPE_CSCRIPT ret = populateSpecificType(tempItems, ITEM_TYPE_CSCRIPT)```We're done with client now. 3rd: Server SideNow, in Server, in Public Sub Useitem, before End Select, copy this:```'Custom Script Case ITEM_TYPE_CSCRIPT 'get the item script number n = Item(ItemNum).CScriptNumber Call CustomScript(index, n) Call TakeInvSlot(index, InvNum, 1) Call SendInventoryUpdate(Index, invNum)```Note: If you want the item to be reusable, delete this line:```Call TakeInvSlot(index, InvNum, 1)```Using Custom ScriptsThis is an example of custom scripts, in mod CustomScripts in Server:```Public Sub CustomScript(index As Long, caseID As Long)Dim n As Byte Select Case caseID Case "0" PlayerMsg index, "You just activated custom script " & caseID & ". It works hell yea.", BrightRed Case "1" n = Random(0, 20) If (n < 1) Then Call GiveInvItem(index, 10, 1, 110, 3, True) PlayerMsg index, "You've obtained the Eclipse Sword!", Magenta ElseIf (n < 5) Then Call GiveInvItem(index, 3, 1, 110, 3, True) PlayerMsg index, "You've obtained a diamond!", White Else Call GiveInvItem(index, 1, 20, -1, 3, True) PlayerMsg index, "You obtain 20 gold!", Black End If Case Else PlayerMsg index, "You just activated custom script " & caseID & ". This script is not yet programmed.", BrightRed End SelectEnd Sub```So if Custom Script Number is 0, it'll say "You just activated custom script 0\. It works hell yea." And if Custom Script Number is 1, it'll give you a random item with 5% chances to obtain the Eclipse Sword, 20%chances to obtain a diamond and 75% to obtain 20 gold. Custom Scripts can be used for many things, it just depends on your imagination, so having the option to call a custom script with an item is pretty good. If you have any problem, please report it, although I might not be able to solve it if it's something dificult, to be honest i don't really know anything about vb6, I just looked at the code in order to work out how to do little edits.Enjoy and report any bug if found! Link to comment Share on other sites More sharing options...
Peaverin Posted March 5, 2015 Author Share Posted March 5, 2015 Add this:``` If (cmbType.ListIndex = ITEM_TYPE_CSCRIPT) Then fraCScript.Visible = True Else fraCScript.Visible = False End If```->In Public Sub ItemEditorInit() before End With, add:``` 'custom script If (frmEditor_Item.cmbType.ListIndex = ITEM_TYPE_CSCRIPT) Then frmEditor_Item.fraCScript.Visible = True frmEditor_Item.scrlCScript.Value = .CScriptNumber Else frmEditor_Item.fraCScript.Visible = False End If```->In Private Function generateItemsForTab. After this:``` Case ITEM_TYPE_RECIPE ret = populateSpecificType(tempItems, ITEM_TYPE_RECIPE)```Copy this:``` Case ITEM_TYPE_CSCRIPT ret = populateSpecificType(tempItems, ITEM_TYPE_CSCRIPT)```We're done with client now.3rd: Server SideNow, in Server, in Public Sub Useitem, before End Select, copy this:```'Custom Script Case ITEM_TYPE_CSCRIPT 'get the item script number n = Item(ItemNum).CScriptNumber Call CustomScript(index, n) Call TakeInvSlot(index, InvNum, 1)```Note: If you want the item to be reusable, delete this line:```Call TakeInvSlot(index, InvNum, 1)```Using Custom ScriptsThis is an example of custom scripts, in mod CustomScripts in Server:```Public Sub CustomScript(index As Long, caseID As Long)Dim n As Byte Select Case caseID Case "0" PlayerMsg index, "You just activated custom script " & caseID & ". It works hell yea.", BrightRed Case "1" n = Random(0, 20) If (n < 1) Then Call GiveInvItem(index, 10, 1, 110, 3, True) PlayerMsg index, "You've obtained the Eclipse Sword!", Magenta ElseIf (n < 5) Then Call GiveInvItem(index, 3, 1, 110, 3, True) PlayerMsg index, "You've obtained a diamond!", White Else Call GiveInvItem(index, 1, 20, -1, 3, True) PlayerMsg index, "You obtain 20 gold!", Black End If Case Else PlayerMsg index, "You just activated custom script " & caseID & ". This script is not yet programmed.", BrightRed End SelectEnd Sub```So if Custom Script Number is 0, it'll say "You just activated custom script 0\. It works hell yea." And if Custom Script Number is 1, it'll give you a random item with 5% chances to obtain the Eclipse Sword, 20%chances to obtain a diamond and 75% to obtain 20 gold. Custom Scripts can be used for many things, it just depends on your imagination, so having the option to call a custom script with an item is pretty good. If you have any problem, please report it, although I might not be able to solve it if it's something dificult, to be honest i don't really know anything about vb6, I just looked at the code in order to work out how to do little edits. Link to comment Share on other sites More sharing options...
Peaverin Posted March 5, 2015 Author Share Posted March 5, 2015 I had some problems because the forum didn't let me to put all the tutorial in just one post. But it's done now. Enjoy and report any bug if found! Link to comment Share on other sites More sharing options...
Officer Johnson Posted March 7, 2015 Share Posted March 7, 2015 Fixed the topic all into one post for ya, and deleted the other posts. Link to comment Share on other sites More sharing options...
Peaverin Posted March 31, 2015 Author Share Posted March 31, 2015 I'm not going to share anymore of my scripts since out of 260 views there isn't even a single comment :angry:. I bet 50% of people here hasn't even commented a post and just comes, takes all the scripts he can and leaves. Link to comment Share on other sites More sharing options...
BeNjO Posted March 31, 2015 Share Posted March 31, 2015 Welcome to the internet :D Link to comment Share on other sites More sharing options...
Mohenjo Daro Posted March 31, 2015 Share Posted March 31, 2015 I haven't even seen your codes yet lol, but nice addition :) Link to comment Share on other sites More sharing options...
Golf Posted April 9, 2015 Share Posted April 9, 2015 Nice Link to comment Share on other sites More sharing options...
Tic Tac 2 Posted April 30, 2015 Share Posted April 30, 2015 After using an item, the item stays in your inventory as a graphical bug, but if you drag it or click it it disappears.Under this:```'Custom Script Case ITEM_TYPE_CSCRIPT 'get the item script number n = Item(ItemNum).CScriptNumber Call CustomScript(Index, n) Call TakeInvSlot(Index, invNum, 1)```Put this```Call SendInventoryUpdate(Index, invNum)``` Link to comment Share on other sites More sharing options...
SkywardRiver Posted April 30, 2015 Share Posted April 30, 2015 Find "TakeInvItem" or something along those lines and use that function in the UseItem section of this tutorial. Link to comment Share on other sites More sharing options...
Tic Tac 2 Posted April 30, 2015 Share Posted April 30, 2015 > Find "TakeInvItem" or something along those lines and use that function in the UseItem section of this tutorial.Edited the post, found an easy fix *_* Link to comment Share on other sites More sharing options...
Peaverin Posted April 30, 2015 Author Share Posted April 30, 2015 Thanks, I'm going to edit the main post now. Link to comment Share on other sites More sharing options...
Tic Tac 2 Posted May 1, 2015 Share Posted May 1, 2015 How would i do this with spells?I tried adding the server side code to CastSpellbut apparently CSScriptNumber gets highlighted with error "Method or Data Member not found"I got CSScriptNumber as byte in typesin enumerations i got SPELL_TYPE_CSSCRIPT defined too Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now