Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Calling A Hotscript (SOLVED)


Kimimaru
 Share

Recommended Posts

Hey! I'm working on a script, and I'm curious to know how I would go about adding a hotkey into my script. I want to make it so that my scripted tile activates AFTER I press the CTRL key. I know that Hotscripts are handled in the Client and in the Server, but I'm not quite sure if I can do it all with SadScript. In any case, does anyone think they can help me make it so that my scripted tile executes after I press the CTRL button? Any help would be greatly appreciated.
Link to comment
Share on other sites

CTRL is already being used for the attack system (and is usually handled in the OnAttack sub), but if you look in your Main.txt, you'll find a HotScripts sub.

You should be able to add a new case, Case 17 (the vb code for CTRL is 17), which would cause that sub to activate if you hit the CTRL key (if not, you may have to add it to call that sub in the source if you hit CTRL), but if not, this should work:

Case 17
  If GetVar("ScriptedTilesData", "ScriptedTile1", "Activated") = "" Then
      Call PutVar("ScriptedTilesData", "ScriptedTile1", "Activated", "1")
  End If

Then in your scripted tile:
Case X
  If GetVar("ScriptedTilesData", "ScriptedTile1", "Activated") = "1" Then
      ' End If

But since CTRL is used for attacking, it will activate as soon as you hit a monster; so you may want to set it to only PutVar if you're in a certain map.
Link to comment
Share on other sites

This is what I have so far:

```
' Executes when a hotkey is pressed client-side.
Sub HotScript(Index, KeyID)
Select Case KeyID
' Executes when any player presses the PageUp key.
Case 1

' Executes when any player presses the Delete key.
Case 2

' Executes when players press the End key.
Case 3

' Executes when players press the PageDown key.
Case 4

' Executes when players press the CTRL key.
Case 17

  If GetVar("Respawn Points.ini", GetPlayerName(Index), "CTRL") <> "0" Then

  Call PutVar("Respawn Points.ini", GetPlayerName(Index), "CTRL", "1")

  Else

Call PutVar("Respawn Points.ini", GetPlayerName(Index), "CTRL", "1")

  End If

End Select
End Sub
```
This is what I have in Case 3 of my Scripted Tile Sub:

```
' Respawn Script

Case 3

If GetVar("Respawn Points.ini", GetPlayerName(Index), "CTRL") = 1 Then

Call PutVar("Respawn Points.ini", GetPlayerName(Index), "Map #", GetPlayerMap(Index))
Call PutVar("Respawn Points.ini", GetPlayerName(Index), "X", GetPlayerX(Index))
Call PutVar("Respawn Points.ini", GetPlayerName(Index), "Y", GetPlayerY(Index))

Call PlayerMsg(Index, "Your respawn point has been saved!", YELLOW)

Call PutVar("Respawn Points.ini", GetPlayerName(Index), "CTRL", "0")

End If
```
When you press CTRL on the tile, it doesn't activate right away. You must get off the tile and then go back on for it to activate.

Your script was helpful, but it didn't exactly work the way I wanted it to. Before, you had to only press the CTRL key once, and then the script would work whenever you stepped on the tile. I made it so that after you step on the tile, the value resets so that you need to press CTRL again to make the scripted tile activate.

The problem is that you can press CTRL **anywhere** and then step on the scripted tile, and it would work. I want to make it so that you have to press CTRL on the scripted tile, and then the scripted tile would activate.
Link to comment
Share on other sites

@Kimimaru:

> Okay, thanks! I'll see what I can do.
>
> EDIT: It didn't work. It's not creating the file in the first place when I hit CTRL. I'll try adding it in the source. Do you know where I'd have to edit it in the source? I'm still looking, but I'm not exactly sure.

I made a mistake (might be one, atleast).
Change where it says: "ScriptedTilesData" to "ScriptedTilesData.ini", see if it works then.

If not, your best bet is having like, the "Delete" key or another unused already built-in scripted hotkey to do it.

But you should be able to add it to the source like so,
In the client's source, find:
```
If KeyCode = vbKeyPageUp Then
```And above that, add:
```
If KeyCode = vbKeyControl Then
  Call SendHotScript(5)
End If

```Then under the hotscripts sub, have the code under Case 5 instead of Case 17
Link to comment
Share on other sites

Question first; why do you have this?
```
        If GetVar("Respawn Points.ini", GetPlayerName(Index), "CTRL") <> "0" Then

          Call PutVar("Respawn Points.ini", GetPlayerName(Index), "CTRL", "1")

        Else

        Call PutVar("Respawn Points.ini", GetPlayerName(Index), "CTRL", "1")

        End If

```All that's doing, is saying If it doesn't = "1", add a 1, if not, add a 1 anyway.  You can remove the entire If statement.

As for the scripted tile, it's doable, best using inis; you could also just have something like:
if you want the tile the player needs to be on, to be at map=3, x=13, y=15, you could just have:
If GetPlayerMap(Index)=3 And GetPlayerX(Index)=13 And GetPlayerY(Index)=15 Then
  Call PutVar("ScriptedTilesData", "ScriptedTile1", "Activated", "1")
End If

Of course, if you really wanted to use a scripted tile for the player to step on and off, it'd invove inis and two more scripted tiles (I can do it for you though, if you want).
Link to comment
Share on other sites

@Admiral:

> Question first; why do you have this?
> ```
>         If GetVar("Respawn Points.ini", GetPlayerName(Index), "CTRL") <> "0" Then
>
>           Call PutVar("Respawn Points.ini", GetPlayerName(Index), "CTRL", "1")
>
>         Else
>
>         Call PutVar("Respawn Points.ini", GetPlayerName(Index), "CTRL", "1")
>
>         End If
>
> ```

I have this because it helps reset the value of CTRL. This variable determines whether you pressed CTRL or not. The way you had it before made it so that you can just press CTRL once and activate the script as many times as you want without having to press CTRL again. I want it so that you have to press CTRL everytime you want the scripted tile to activate. I did this by adding in this IF statement and making it so that the value is reset after you step on the scripted tile.

I'm not sure what you were talking about in the second part of your post, but I think I should explain what I'm trying to do in more detail.

This is a respawn point script, incase you haven't noticed (I'm sure you did). When the player steps on the tile, it saves his/her location and loads it when he/she dies. I want it to save your respawn point ONLY after you've stepped on the scripted tile and pressed CTRL while on the tile. I've gotten everything to work so far, except there are only 2 problems:

1) When you step on the tile and press CTRL, you must get off and then step on it again for it to save your respawn point.

2) You can press CTRL anywhere and then step on the tile and it will work.
Link to comment
Share on other sites

Yea, but the If and Else are doing the exact same thing, that's what I'm wondering, why have:
If it equals 0, putvar 1
If it does not equal 0, putvar 1

A scripted tile activates when the player walks on it, then it won't do anything else until the player walks off and on again; it doesn't work in real-time, unless you wanted to reverse things abit.

What you could do though, is have the scripted tile set the ini, and CTRL do the execution; this way, the player would walk on the scripted tile first, then hit CTRL and it would save the stuff.
Scripted tile:
Case 3
  Call PutVar("Respawn Points.ini", CStr(GetPlayerName(Index)), "CTRL", "1")

Hotkey:
  If GetVar("Respawn Points.ini", CStr(GetPlayerName(Index)), "CTRL") = "1" Then
            Call PutVar("Respawn Points.ini", CStr(GetPlayerName(Index)), "Map #", CStr(GetPlayerMap(Index)))
            Call PutVar("Respawn Points.ini", CStr(GetPlayerName(Index)), "X", CStr(GetPlayerX(Index)))
            Call PutVar("Respawn Points.ini", CStr(GetPlayerName(Index)), "Y", CStr(GetPlayerY(Index)))
            Call PlayerMsg(Index, "Your respawn point has been saved!", YELLOW)
            Call PutVar("Respawn Points.ini", CStr(GetPlayerName(Index)), "CTRL", "0")
  End If

If you wanted to set CTRL=0 (incase the player walks off the scritped tile without pressing CTRL), you could just have another scripted tile surround that one, that has this:
If GetVar("Respawn Points.ini", CStr(GetPlayerName(Index)), "CTRL") = "1" Then
  Call PutVar("Respawn Points.ini", CStr(GetPlayerName(Index)), "CTRL", "0")
End If
Link to comment
Share on other sites

Oh, okay. I see what you're saying. That makes more sense, and this seems like it would work. Thanks!

EDIT: I put this in and was wondering why it wasn't working. Then I realized that I was using the wrong Client.  XD

Thanks again!
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...