Quantcast

Jump to content

» «
Photo

Check if player has a weapon and is wanted

8 replies to this topic
serabella
  • serabella

    Noob scripter

  • Members
  • Joined: 18 Jun 2009

#1

Posted 10 July 2013 - 11:54 AM

Hello!

I'm working on a simple mod. It's a mod which let's you surrend to the cops by putting down your weapons. For it to work as I wish, you need to have at least one weapon in your inventory for the effect to trigger. You should also have at least one wanted star.

Could anyone help me? How do you check if CJ has a weapon and how do you check if he's wanted?

Thanks in advance.

aStiffSausage
  • aStiffSausage

    Formerly Oksu

  • Members
  • Joined: 30 Sep 2010
  • Finland

#2

Posted 10 July 2013 - 12:07 PM

You could have tried the Opcode Search Tool... But well.

To get current wanted level, use this:
CODE
01C0: $PLAYER_WANTED_LEVEL = player $PLAYER_CHAR wanted_level


And to see if player has a weapon, well, no simple way to do it, but you could check each weapon group to see if player has weapon.
CODE
04B8: get_weapon_data_from_actor $PLAYER_ACTOR weapon_group 2 weapon 380@ ammo 381@ model 381@

serabella
  • serabella

    Noob scripter

  • Members
  • Joined: 18 Jun 2009

#3

Posted 10 July 2013 - 12:32 PM

Thank you! smile.gif

serabella
  • serabella

    Noob scripter

  • Members
  • Joined: 18 Jun 2009

#4

Posted 10 July 2013 - 12:49 PM

Ok, so here is my code. The first part works as it should (if you have less than 4 stars, then you will be able to surrender by just putting down your weapons.) If it's false that you have less than 4 stars then it should jump to surrender3 to trigger another type of surrender but it doesn't work. Nothing happens when I click "5" if I have 4 or more stars sad.gif Could anyone tell me what's wrong?

CODE

:SURREND
wait 50
if
$PLAYER_WANTED_LEVEL < 4
jf @SURREND_3
if
  Player.Defined($PLAYER_CHAR)
jf @SURREND
if
  Player.Controllable($PLAYER_CHAR)
jf @SURREND
if
0AB0:   key_pressed 53
jf @SURREND
04ED: load_animation "GRENADE"

:SURREND_1
wait 0
if
04EE:   animation "GRENADE" loaded
jf @SURREND_2
wait 0
0605: actor $PLAYER_ACTOR perform_animation_sequence "WEAPON_throw" IFP_file "GRENADE" 4.0 loop 0 0 0 0 time -1 // versionA
00BB: show_text_lowpriority GXT 'IE23' time 3000 flag 1
wait 300
0110: clear_player $PLAYER_CHAR wanted_level
048F: actor $PLAYER_ACTOR remove_weapons
wait 2700
00BB: show_text_lowpriority GXT 'MTIME3' time 3000 flag 1
jump @SURREND

:SURREND_2
jump @SURREND_1

:SURREND_3
wait 0
if
04EE:   animation "GRENADE" loaded
jf @SURREND_2
wait 0
0605: actor $PLAYER_ACTOR perform_animation_sequence "WEAPON_throw" IFP_file "GRENADE" 4.0 loop 0 0 0 0 time -1 // versionA
00BB: show_text_lowpriority GXT 'IE23' time 3000 flag 1
wait 300
0110: clear_player $PLAYER_CHAR wanted_level
048F: actor $PLAYER_ACTOR remove_weapons
wait 2700
00BB: show_text_lowpriority GXT 'MTIME3' time 3000 flag 1
jump @SURREND

aStiffSausage
  • aStiffSausage

    Formerly Oksu

  • Members
  • Joined: 30 Sep 2010
  • Finland

#5

Posted 10 July 2013 - 12:54 PM

The problem is that you are first checking for player's wanted level, then doing else operations, like checking if key is pressed and loading the animation. To fix it, just place the first check under 04ED.

serabella
  • serabella

    Noob scripter

  • Members
  • Joined: 18 Jun 2009

#6

Posted 10 July 2013 - 12:56 PM

Ah, okay so it was that simple wink.gif Thanks again!

Wesser
  • Wesser

    The complexity simplifier, the efficiency optimizer.

  • Feroci
  • Joined: 19 Aug 2006
  • Unknown

#7

Posted 10 July 2013 - 01:18 PM Edited by Wesser, 11 July 2013 - 10:11 AM.

You could check for non-melee weapons in this way:
CODE
const
   WEAPONTYPE_SPRYCAN      = 41
   WEAPONTYPE_EXTINGUISHER = 42
   WEAPONTYPE_CAMERA       = 43
   WEAPONTYPE_NIGHTVISION  = 44
   WEAPONTYPE_INFRARED     = 45
   WEAPONTYPE_ANYMELEE     = 56
   WEAPONTYPE_ANYWEAPON    = 57
   // There are more of them.
end

if and
82D8:  not actor $PLAYER_ACTOR current_weapon == WEAPONTYPE_SPRYCAN
82D8:  not actor $PLAYER_ACTOR current_weapon == WEAPONTYPE_EXTINGUISHER
82D8:  not actor $PLAYER_ACTOR current_weapon == WEAPONTYPE_CAMERA
82D8:  not actor $PLAYER_ACTOR current_weapon == WEAPONTYPE_NIGHTVISION
82D8:  not actor $PLAYER_ACTOR current_weapon == WEAPONTYPE_INFRARED
82D8:  not actor $PLAYER_ACTOR current_weapon == WEAPONTYPE_ANYMELEE
then
   // Your code here.
end

There is a slightly less efficient (because of the script processing which parses more commands) but tricky method as follows:
CODE
const
   WEAPONTYPE_DETONATOR = 40
   WEAPONTYPE_FTHROWER  = 46
   // There are more of them.
end
const
   FIRETYPE_INSTANT_HIT = 1
   FIRETYPE_PROJECTILE  = 2
   // There are more of them.
end

0470: 1@ = actor $PLAYER_ACTOR current_weapon
0AA7: call_function 0x743C60 num_params 2 pop 2 cSkillIndex 1 sWeaponType 1@ pclWeaponInfo 2@ // getWeaponInfo
//0A8E: 2@ = 2@ + 0x00 // CWeaponInfo.m_eFireType
0A8D: 2@ = read_memory 2@ size 4 virtual_protect 0
if or
   1@ == WEAPONTYPE_DETONATOR
   1@ == WEAPONTYPE_FTHROWER
   2@ == FIRETYPE_INSTANT_HIT
   2@ == FIRETYPE_PROJECTILE
then
   // Your code here.
end

A better approach for testing whether any cop is nearby the player would be checking for his ped event:
CODE
const
   EVENT_SEEN_COP = 72
end

if
074F:  actor $PLAYER_ACTOR ped_event == EVENT_SEEN_COP
then
   // Your code here.
end

maurice16
  • maurice16

    Modder to the Maxx

  • Members
  • Joined: 02 Apr 2013

#8

Posted 12 July 2013 - 02:05 AM

Are you going to turn this in cleo mod for gta vice city, it would be awesome!!!

serabella
  • serabella

    Noob scripter

  • Members
  • Joined: 18 Jun 2009

#9

Posted 12 July 2013 - 02:39 PM

QUOTE (Wesser @ Wednesday, Jul 10 2013, 13:18)
You could check for non-melee weapons in this way:
CODE
const
   WEAPONTYPE_SPRYCAN      = 41
   WEAPONTYPE_EXTINGUISHER = 42
   WEAPONTYPE_CAMERA       = 43
   WEAPONTYPE_NIGHTVISION  = 44
   WEAPONTYPE_INFRARED     = 45
   WEAPONTYPE_ANYMELEE     = 56
   WEAPONTYPE_ANYWEAPON    = 57
   // There are more of them.
end

if and
82D8:  not actor $PLAYER_ACTOR current_weapon == WEAPONTYPE_SPRYCAN
82D8:  not actor $PLAYER_ACTOR current_weapon == WEAPONTYPE_EXTINGUISHER
82D8:  not actor $PLAYER_ACTOR current_weapon == WEAPONTYPE_CAMERA
82D8:  not actor $PLAYER_ACTOR current_weapon == WEAPONTYPE_NIGHTVISION
82D8:  not actor $PLAYER_ACTOR current_weapon == WEAPONTYPE_INFRARED
82D8:  not actor $PLAYER_ACTOR current_weapon == WEAPONTYPE_ANYMELEE
then
   // Your code here.
end

There is a slightly less efficient (because of the script processing which parses more commands) but tricky method as follows:
CODE
const
   WEAPONTYPE_DETONATOR = 40
   WEAPONTYPE_FTHROWER  = 46
   // There are more of them.
end
const
   FIRETYPE_INSTANT_HIT = 1
   FIRETYPE_PROJECTILE  = 2
   // There are more of them.
end

0470: 1@ = actor $PLAYER_ACTOR current_weapon
0AA7: call_function 0x743C60 num_params 2 pop 2 cSkillIndex 1 sWeaponType 1@ pclWeaponInfo 2@ // getWeaponInfo
//0A8E: 2@ = 2@ + 0x00 // CWeaponInfo.m_eFireType
0A8D: 2@ = read_memory 2@ size 4 virtual_protect 0
if or
   1@ == WEAPONTYPE_DETONATOR
   1@ == WEAPONTYPE_FTHROWER
   2@ == FIRETYPE_INSTANT_HIT
   2@ == FIRETYPE_PROJECTILE
then
   // Your code here.
end

A better approach for testing whether any cop is nearby the player would be checking for his ped event:
CODE
const
   EVENT_SEEN_COP = 72
end

if
074F:  actor $PLAYER_ACTOR ped_event == EVENT_SEEN_COP
then
   // Your code here.
end

Thank you very much for the help! smile.gif




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users