Quantcast

Jump to content

» «
Photo

A namespace cannot directly contain members such as fields or methods

5 replies to this topic
Zolika1351
  • Zolika1351

    Ladies, hide your titties!

  • Members
  • Joined: 16 Jun 2014
  • Hungary

#1

Posted 05 December 2016 - 05:01 PM

I was trying to make a simple script to set the animation to swimming just for the lols, following this tutorial:

http://gtaxscripting...animations.html

This is my code:

using System;
using System.Windows.Forms;
using GTA;
using System.Collections.Generic;

If e.Key = Keys.NumPad1 Then
    Dim AnimSet As AnimationSet
    Dim AnimName As String = "idle"
    
    AnimSet = New AnimationSet("swimming")
    
    Player.Character.Animation.Play(AnimSet, AnimName, 8, AnimationFlags.Unknown11 Or AnimationFlags.Unknown05)
End If

 

But then ScriptHookDotNet said:

Line 6: A namespace cannot directly contain members such as fields or methods


fastman92
  • fastman92

    фастман92 | ف

  • Members
  • Joined: 28 Jul 2009
  • Poland
  • Best Total Overhaul 2017 Contribution [GTA: Underground]
    Best Conversion 2016 [GTA: Underground] [Contribution]
    Contribution Award [Mods]

#2

Posted 05 December 2016 - 05:21 PM Edited by fastman92, 05 December 2016 - 05:24 PM.

The code needs to be put inside a function, you added an orphaned code and wonder why it can't be compiled.

Jitnaught
  • Jitnaught

    Grass tastes bad

  • Members
  • Joined: 24 Aug 2013
  • United-States

#3

Posted 05 December 2016 - 05:24 PM

Multiple problems with the code.

1. You are using a mix of C# and VB code. Pick one of the languages and use that one solely.

2. You have to declare a class that inherits the GTA.Script class, and put your code within.

3. You have to handle the KeyDown/Up event and put your If statement in that function.

 

Like this (VB)

Imports System
Imports GTA
Imports System.Drawing
Imports System.Windows.Forms

Public Class SwimmingAnimScript Inherits Script
	Public Sub New()
	
	End Sub
	
	Shadows Sub SwimmiongAnimScript_KeyDown(ByVal sender As Object, ByVal e As GTA.KeyEventArgs) Handles MyBase.KeyDown
		If e.Key = Keys.NumPad1 Then
			Dim AnimSet As AnimationSet
			Dim AnimName As String = "idle"
    
			AnimSet = New AnimationSet("swimming")
    
			Player.Character.Animation.Play(AnimSet, AnimName, 8, AnimationFlags.Unknown11 Or AnimationFlags.Unknown05)
		End If
	End Sub
End Class

or this (C#)

using System;
using GTA;
using System.Drawing;
using System.Windows.Forms;

public class SwimmingAnimScript : Script
{
	public SwimmingAnimScript()
	{
		KeyDown += SwimmingAnimScript_KeyDown;
	}
	
	private void SwimmiongAnimScript_KeyDown(object sender, GTA.KeyEventArgs e)
	{
		if (e.Key == Keys.NumPad1)
		{
			AnimationSet animSet = new AnimationSet("swimming");
			string animName = "idle";
    
			Player.Character.Animation.Play(animSet, animName, 8, AnimationFlags.Unknown11 | AnimationFlags.Unknown05);
		}
	}
}

Zolika1351
  • Zolika1351

    Ladies, hide your titties!

  • Members
  • Joined: 16 Jun 2014
  • Hungary

#4

Posted 05 December 2016 - 07:10 PM

 

Multiple problems with the code.

1. You are using a mix of C# and VB code. Pick one of the languages and use that one solely.

2. You have to declare a class that inherits the GTA.Script class, and put your code within.

3. You have to handle the KeyDown/Up event and put your If statement in that function.

 

Thanks, now I have another error, I wanted to speed up the animation with another script, but I got the error:

The term "native" does not exist in the current context.

Tried adding "using GTA.Native" but it didn't work

Code:

using System;
using GTA;
using GTA.Native;
using System.Drawing;
using System.Windows.Forms;

public class FastAnimScript : Script
{
    public FastAnimScript()
    {
        KeyDown += FastAnimScript_KeyDown;
    }
    
    private void FastAnimScript_KeyDown(object sender, GTA.KeyEventArgs e)
    {
        if (e.Key == Keys.Add)
        {
            Native.Function.Call("SET_CHAR_ALL_ANIMS_SPEED", Player.Character, 2.0);
        }
        if (e.Key == Keys.Y)
        {
            Native.Function.Call("SET_CHAR_ALL_ANIMS_SPEED", Player.Character, 5.0);
        }
    }
}


Jitnaught
  • Jitnaught

    Grass tastes bad

  • Members
  • Joined: 24 Aug 2013
  • United-States

#5

Posted 05 December 2016 - 07:15 PM Edited by Jitnaught, 05 December 2016 - 07:15 PM.

Add "GTA." (without quotes) in front of your Native.Function.Call's.

 

So that it looks like "GTA.Native.Function.Call(...);"


Zolika1351
  • Zolika1351

    Ladies, hide your titties!

  • Members
  • Joined: 16 Jun 2014
  • Hungary

#6

Posted 05 December 2016 - 07:17 PM Edited by Zolika1351, 05 December 2016 - 07:17 PM.

Thanks





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users